From d5915491b313803ba3b75d4c701119e1d74b08be Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 18 Apr 2016 17:50:17 -0400 Subject: [PATCH] Bug1342: Loop-play (and other things) before scrub (and other things)... ... should not disable auto-scrolling of the window during playback. --- src/Menus.cpp | 41 ++++++++++---------------- src/MixerBoard.cpp | 2 +- src/Project.h | 8 ++--- src/effects/Effect.cpp | 2 +- src/toolbars/ControlToolBar.cpp | 11 +++---- src/toolbars/ControlToolBar.h | 4 +++ src/toolbars/TranscriptionToolBar.cpp | 1 + src/tracks/ui/PlayIndicatorOverlay.cpp | 4 +-- src/tracks/ui/Scrubbing.cpp | 3 +- src/widgets/Ruler.cpp | 2 +- 10 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 5adffbe12..e6c302196 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -2076,9 +2076,9 @@ void AudacityProject::OnPlayOneSecond() return; double pos = mTrackPanel->GetMostRecentXPos(); - mLastPlayMode = oneSecondPlay; GetControlToolBar()->PlayPlayRegion - (SelectedRegion(pos - 0.5, pos + 0.5), GetDefaultPlayOptions()); + (SelectedRegion(pos - 0.5, pos + 0.5), GetDefaultPlayOptions(), + PlayMode::oneSecondPlay); } @@ -2115,14 +2115,13 @@ void AudacityProject::OnPlayToSelection() // where the cursor is. // TODO: have 'playing attributes' such as 'with_autoscroll' // rather than modes, since that's how we're now using the modes. - mLastPlayMode = oneSecondPlay; // An alternative, commented out below, is to disable autoscroll // only when playing a short region, less than or equal to a second. // mLastPlayMode = ((t1-t0) > 1.0) ? normalPlay : oneSecondPlay; GetControlToolBar()->PlayPlayRegion - (SelectedRegion(t0, t1), GetDefaultPlayOptions()); + (SelectedRegion(t0, t1), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); } // The next 4 functions provide a limited version of the @@ -2137,9 +2136,7 @@ void AudacityProject::OnPlayBeforeSelectionStart() double beforeLen; gPrefs->Read(wxT("/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0); - mLastPlayMode = oneSecondPlay; // this disables auto scrolling, as in OnPlayToSelection() - - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0 - beforeLen, t0), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0 - beforeLen, t0), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); } void AudacityProject::OnPlayAfterSelectionStart() @@ -2152,12 +2149,11 @@ void AudacityProject::OnPlayAfterSelectionStart() double afterLen; gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0); - mLastPlayMode = oneSecondPlay; // this disables auto scrolling, as in OnPlayToSelection() - if ( t1 - t0 > 0.0 && t1 - t0 < afterLen ) - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0, t1), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0, t1), GetDefaultPlayOptions(), + PlayMode::oneSecondPlay); else - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0, t0 + afterLen), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0, t0 + afterLen), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); } void AudacityProject::OnPlayBeforeSelectionEnd() @@ -2170,12 +2166,11 @@ void AudacityProject::OnPlayBeforeSelectionEnd() double beforeLen; gPrefs->Read(wxT("/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0); - mLastPlayMode = oneSecondPlay; // this disables auto scrolling, as in OnPlayToSelection() - if ( t1 - t0 > 0.0 && t1 - t0 < beforeLen ) - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0, t1), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0, t1), GetDefaultPlayOptions(), + PlayMode::oneSecondPlay); else - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t1 - beforeLen, t1), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t1 - beforeLen, t1), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); } @@ -2188,9 +2183,7 @@ void AudacityProject::OnPlayAfterSelectionEnd() double afterLen; gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0); - mLastPlayMode = oneSecondPlay; // this disables auto scrolling, as in OnPlayToSelection() - - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t1, t1 + afterLen), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t1, t1 + afterLen), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); } void AudacityProject::OnPlayBeforeAndAfterSelectionStart() @@ -2205,12 +2198,10 @@ void AudacityProject::OnPlayBeforeAndAfterSelectionStart() double afterLen; gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0); - mLastPlayMode = oneSecondPlay; // this disables auto scrolling, as in OnPlayToSelection() - if ( t1 - t0 > 0.0 && t1 - t0 < afterLen ) - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0 - beforeLen, t1), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0 - beforeLen, t1), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); else - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0 - beforeLen, t0 + afterLen), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0 - beforeLen, t0 + afterLen), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); } void AudacityProject::OnPlayBeforeAndAfterSelectionEnd() @@ -2225,12 +2216,10 @@ void AudacityProject::OnPlayBeforeAndAfterSelectionEnd() double afterLen; gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0); - mLastPlayMode = oneSecondPlay; // this disables auto scrolling, as in OnPlayToSelection() - if ( t1 - t0 > 0.0 && t1 - t0 < beforeLen ) - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0, t1 + afterLen), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t0, t1 + afterLen), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); else - GetControlToolBar()->PlayPlayRegion(SelectedRegion(t1 - beforeLen, t1 + afterLen), GetDefaultPlayOptions()); + GetControlToolBar()->PlayPlayRegion(SelectedRegion(t1 - beforeLen, t1 + afterLen), GetDefaultPlayOptions(), PlayMode::oneSecondPlay); } diff --git a/src/MixerBoard.cpp b/src/MixerBoard.cpp index 574e733e9..3cc9e59ad 100644 --- a/src/MixerBoard.cpp +++ b/src/MixerBoard.cpp @@ -1723,7 +1723,7 @@ void MixerBoard::OnTimer(wxCommandEvent &event) if (mProject->IsAudioActive()) { UpdateMeters(gAudioIO->GetStreamTime(), - (mProject->mLastPlayMode == loopedPlay)); + (mProject->mLastPlayMode == PlayMode::loopedPlay)); } // Let other listeners get the notification diff --git a/src/Project.h b/src/Project.h index 2e24b33d8..fa7e51a61 100644 --- a/src/Project.h +++ b/src/Project.h @@ -117,10 +117,10 @@ extern AProjectArray gAudacityProjects; WX_DEFINE_ARRAY(wxMenu *, MenuArray); -enum PlayMode { +enum class PlayMode : int { normalPlay, - oneSecondPlay, - loopedPlay + oneSecondPlay, // Disables auto-scrolling + loopedPlay // Disables auto-scrolling }; enum StatusBarField { @@ -494,7 +494,7 @@ public: void WriteXMLHeader(XMLWriter &xmlFile); - PlayMode mLastPlayMode{ normalPlay }; + PlayMode mLastPlayMode{ PlayMode::normalPlay }; ViewInfo mViewInfo; // Audio IO callback methods diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 7a97bc8d5..1737f806d 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -3429,7 +3429,7 @@ void EffectUIHost::OnPlay(wxCommandEvent & WXUNUSED(evt)) mProject->GetControlToolBar()->PlayPlayRegion (SelectedRegion(mPlayPos, mRegion.t1()), - mProject->GetDefaultPlayOptions()); + mProject->GetDefaultPlayOptions(), PlayMode::normalPlay); } } diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index 662fec926..c3dc1b510 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -475,6 +475,7 @@ bool ControlToolBar::IsRecordDown() int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, + PlayMode mode, bool cutpreview, /* = false */ bool backwards, /* = false */ bool playWhiteSpace /* = false */) @@ -518,6 +519,8 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, return -1; // Should never happen, but... } + p->mLastPlayMode = mode; + bool hasaudio = false; TrackListIterator iter(t); for (Track *trk = iter.First(); trk; trk = iter.Next()) { @@ -673,10 +676,6 @@ void ControlToolBar::PlayCurrentRegion(bool looped /* = false */, if (p) { - if (looped) - p->mLastPlayMode = loopedPlay; - else - p->mLastPlayMode = normalPlay; double playRegionStart, playRegionEnd; p->GetPlayRegion(&playRegionStart, &playRegionEnd); @@ -686,7 +685,9 @@ void ControlToolBar::PlayCurrentRegion(bool looped /* = false */, if (cutpreview) options.timeTrack = NULL; PlayPlayRegion(SelectedRegion(playRegionStart, playRegionEnd), - options, cutpreview); + options, + (looped ? PlayMode::loopedPlay : PlayMode::normalPlay), + cutpreview); } } diff --git a/src/toolbars/ControlToolBar.h b/src/toolbars/ControlToolBar.h index bcc2d123c..86f7ae35c 100644 --- a/src/toolbars/ControlToolBar.h +++ b/src/toolbars/ControlToolBar.h @@ -34,6 +34,9 @@ class TimeTrack; struct AudioIOStartStreamOptions; class SelectedRegion; +// Defined in Project.h +enum class PlayMode : int; + // In the GUI, ControlToolBar appears as the "Transport Toolbar". "Control Toolbar" is historic. class ControlToolBar final : public ToolBar { @@ -74,6 +77,7 @@ class ControlToolBar final : public ToolBar { // Return the Audio IO token or -1 for failure int PlayPlayRegion(const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, + PlayMode playMode, bool cutpreview = false, bool backwards = false, // Allow t0 and t1 to be beyond end of tracks bool playWhiteSpace = false); diff --git a/src/toolbars/TranscriptionToolBar.cpp b/src/toolbars/TranscriptionToolBar.cpp index 4f5daadba..3d4d6ffa3 100644 --- a/src/toolbars/TranscriptionToolBar.cpp +++ b/src/toolbars/TranscriptionToolBar.cpp @@ -462,6 +462,7 @@ void TranscriptionToolBar::PlayAtSpeed(bool looped, bool cutPreview) p->GetControlToolBar()->PlayPlayRegion (SelectedRegion(playRegionStart, playRegionEnd), options, + PlayMode::normalPlay, cutPreview); } } diff --git a/src/tracks/ui/PlayIndicatorOverlay.cpp b/src/tracks/ui/PlayIndicatorOverlay.cpp index 1359b84c2..6b7e48b9a 100644 --- a/src/tracks/ui/PlayIndicatorOverlay.cpp +++ b/src/tracks/ui/PlayIndicatorOverlay.cpp @@ -132,8 +132,8 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event) // BG: Scroll screen if option is set // msmeyer: But only if not playing looped or in one-second mode if (viewInfo.bUpdateTrackIndicator && - mProject->mLastPlayMode != loopedPlay && - mProject->mLastPlayMode != oneSecondPlay && + mProject->mLastPlayMode != PlayMode::loopedPlay && + mProject->mLastPlayMode != PlayMode::oneSecondPlay && playPos >= 0 && !onScreen && !gAudioIO->IsPaused()) diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index db63ab698..9f5f8f234 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -216,7 +216,8 @@ bool Scrubber::MaybeStartScrubbing(const wxMouseEvent &event) #endif mScrubSpeedDisplayCountdown = 0; mScrubToken = - ctb->PlayPlayRegion(SelectedRegion(time0, time1), options, cutPreview, backwards); + ctb->PlayPlayRegion(SelectedRegion(time0, time1), options, + PlayMode::normalPlay, cutPreview, backwards); } } else diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 72562453d..79805a5d0 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -2288,7 +2288,7 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) options.timeTrack = NULL; ctb->PlayPlayRegion((SelectedRegion(start, end)), - options, + options, PlayMode::normalPlay, evt.ControlDown(), false, true);