1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-05 22:28:57 +02:00

Rewrite undo handling for Stretch to be more like other drags...

... that is, push a state only at button-up.

The undo during each drag increment didn't actually happen, because of a check
in OnUndo whether there is a drag in progress!

But this is not necessary to fix the excessive number of undo items, because
commit 63ae687bafd1123bf4bf7d00070e1dd9f38dc8a2 already did that by other means.

It only removes an unusual usage.
This commit is contained in:
Paul Licameli 2017-05-22 13:13:21 -04:00
parent 2eb6285ddc
commit 9fb7185ea4
2 changed files with 22 additions and 50 deletions

View File

@ -1837,6 +1837,13 @@ void TrackPanel::HandleSelect(wxMouseEvent & event)
SelectionHandleClick(event, t, rect);
} else if (event.LeftUp() || event.RightUp()) {
mSnapManager.reset();
if ( mStretchState.mStretching ) {
MakeParentPushState(_("Stretch Note Track"), _("Stretch"),
UndoPush::CONSOLIDATE | UndoPush::AUTOSAVE);
Refresh(false);
SetCapturedTrack( NULL );
}
else {
// Do not draw yellow lines
if (mSnapLeft != -1 || mSnapRight != -1) {
mSnapLeft = mSnapRight = -1;
@ -1851,6 +1858,7 @@ void TrackPanel::HandleSelect(wxMouseEvent & event)
// This stops center snapping with mouse movement
mFreqSelMode = FREQ_SEL_INVALID;
#endif
}
} else if (event.LeftDClick() && !event.ShiftDown()) {
if (!mCapturedTrack) {
@ -2284,18 +2292,13 @@ void TrackPanel::SelectionHandleClick(wxMouseEvent & event,
mStretchState.mLeftBeats = qBeat1 - qBeat0;
mStretchState.mRightBeats = 0;
}
mViewInfo->selectedRegion.setTimes(mStretchState.mSel0, mStretchState.mSel1);
mStretchState.mStretching = true;
mStretchState.mStretched = false;
/* i18n-hint: (noun) The track that is used for MIDI notes which can be
dragged to change their duration.*/
MakeParentPushState(_("Stretch Note Track"),
/* i18n-hint: In the history list, indicates a MIDI note has
been dragged to change its duration (stretch it). Using either past
or present tense is fine here. If unsure, go for whichever is
shorter.*/
_("Stretch"));
// Do this before we change the selection
MakeParentModifyState( false );
mViewInfo->selectedRegion.setTimes
(mStretchState.mSel0, mStretchState.mSel1);
mStretchState.mStretching = true;
// Full refresh since the label area may need to indicate
// newly selected tracks. (I'm really not sure if the label area
@ -2774,33 +2777,6 @@ void TrackPanel::ResetFreqSelectionPin(double hintFrequency, bool logF)
void TrackPanel::Stretch(int mouseXCoordinate, int trackLeftEdge,
Track *pTrack)
{
if (mStretchState.mStretched) { // Undo stretch and redo it with NEW mouse coordinates
// Drag handling was not originally implemented with Undo in mind --
// there are saved pointers to tracks that are not supposed to change.
// Undo will change tracks, so convert pTrack, mCapturedTrack to index
// values, then look them up after the Undo
TrackListIterator iter(GetTracks());
int pTrackIndex = pTrack->GetIndex();
int capturedTrackIndex =
(mCapturedTrack ? mCapturedTrack->GetIndex() : 0);
GetProject()->OnUndo();
// Undo brings us back to the pre-click state, but we want to
// quantize selected region to integer beat boundaries. These
// were saved in mStretchSel[12] variables:
mViewInfo->selectedRegion.setTimes
(mStretchState.mSel0, mStretchState.mSel1);
mStretchState.mStretched = false;
int index = 0;
for (Track *t = iter.First(GetTracks()); t; t = iter.Next()) {
if (index == pTrackIndex) pTrack = t;
if (mCapturedTrack && index == capturedTrackIndex) mCapturedTrack = t;
index++;
}
}
if (pTrack == NULL && mCapturedTrack != NULL)
pTrack = mCapturedTrack;
@ -2867,9 +2843,6 @@ void TrackPanel::Stretch(int mouseXCoordinate, int trackLeftEdge,
wxASSERT(false);
break;
}
MakeParentPushState(_("Stretch Note Track"), _("Stretch"),
UndoPush::CONSOLIDATE | UndoPush::AUTOSAVE);
mStretchState.mStretched = true;
Refresh(false);
}
#endif

View File

@ -327,7 +327,6 @@ class AUDACITY_DLL_API TrackPanel final : public OverlayPanel {
struct StretchState {
StretchEnum mMode { stretchCenter }; // remembers what to drag
bool mStretching {}; // true between mouse down and mouse up
bool mStretched {}; // true after drag has pushed state
double mStart {}; // time of initial mouse position, quantized
// to the nearest beat
double mSel0 {}; // initial sel0 (left) quantized to nearest beat