From dccb716f3932b3f35fb479c3a047e4c8b6cc59c6 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 19 Jan 2019 11:41:11 -0500 Subject: [PATCH] enum PlayMode tells whether there's cut preview; out of Project.h --- src/AdornedRulerPanel.cpp | 11 +++++----- src/AudioIO.cpp | 2 +- src/MixerBoard.cpp | 8 +++++-- src/Project.h | 7 ------- src/effects/Effect.cpp | 7 ++++--- src/menus/TransportMenus.cpp | 10 ++++----- src/toolbars/ControlToolBar.cpp | 29 +++++++++++++++++--------- src/toolbars/ControlToolBar.h | 13 +++++++++--- src/toolbars/TranscriptionToolBar.cpp | 13 +++++------- src/tracks/ui/PlayIndicatorOverlay.cpp | 6 ++++-- src/tracks/ui/Scrubbing.cpp | 13 ++---------- 11 files changed, 61 insertions(+), 58 deletions(-) diff --git a/src/AdornedRulerPanel.cpp b/src/AdornedRulerPanel.cpp index 18b74cc33..8731a8441 100644 --- a/src/AdornedRulerPanel.cpp +++ b/src/AdornedRulerPanel.cpp @@ -1587,18 +1587,17 @@ void AdornedRulerPanel::StartQPPlay(bool looped, bool cutPreview) else options.timeTrack = NULL; - ControlToolBar::PlayAppearance appearance = - cutPreview ? ControlToolBar::PlayAppearance::CutPreview - : options.playLooped ? ControlToolBar::PlayAppearance::Looped - : ControlToolBar::PlayAppearance::Straight; + auto mode = + cutPreview ? PlayMode::cutPreviewPlay + : options.playLooped ? PlayMode::loopedPlay + : PlayMode::normalPlay; mPlayRegionStart = start; mPlayRegionEnd = end; Refresh(); ctb->PlayPlayRegion((SelectedRegion(start, end)), - options, PlayMode::normalPlay, - appearance, + options, mode, false, true); diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index aa3e73916..53de3a852 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -5371,7 +5371,7 @@ void AudioIoCallback::SendVuOutputMeterData( //MixerBoard* pMixerBoard = mOwningProject->GetMixerBoard(); //if (pMixerBoard) // pMixerBoard->UpdateMeters(GetStreamTime(), - // (pProj->mLastPlayMode == loopedPlay)); + // (pProj->GetControlToolBar()->GetLastPlayMode() == loopedPlay)); } mUpdatingMeters = false; } diff --git a/src/MixerBoard.cpp b/src/MixerBoard.cpp index 8051b333d..d4b9beb4e 100644 --- a/src/MixerBoard.cpp +++ b/src/MixerBoard.cpp @@ -54,6 +54,7 @@ #endif #include "commands/CommandManager.h" +#include "toolbars/ControlToolBar.h" // class MixerTrackSlider @@ -1344,8 +1345,11 @@ void MixerBoard::OnTimer(wxCommandEvent &event) // audacityAudioCallback where it calls gAudioIO->mOutputMeter->UpdateDisplay(). if (mProject->IsAudioActive()) { - UpdateMeters(gAudioIO->GetStreamTime(), - (mProject->mLastPlayMode == PlayMode::loopedPlay)); + UpdateMeters( + gAudioIO->GetStreamTime(), + (mProject->GetControlToolBar()->GetLastPlayMode() + == PlayMode::loopedPlay) + ); } // Let other listeners get the notification diff --git a/src/Project.h b/src/Project.h index a2f5ea230..143860b04 100644 --- a/src/Project.h +++ b/src/Project.h @@ -116,12 +116,6 @@ using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >; extern AProjectArray gAudacityProjects; -enum class PlayMode : int { - normalPlay, - oneSecondPlay, // Disables auto-scrolling - loopedPlay // Disables auto-scrolling -}; - enum StatusBarField { stateStatusBarField = 1, mainStatusBarField = 2, @@ -524,7 +518,6 @@ public: void WriteXMLHeader(XMLWriter &xmlFile) const; - PlayMode mLastPlayMode{ PlayMode::normalPlay }; ViewInfo mViewInfo; // Audio IO callback methods diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index f13866a6d..7376c4af1 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -3529,9 +3529,10 @@ void EffectUIHost::OnPlay(wxCommandEvent & WXUNUSED(evt)) mPlayPos = mRegion.t1(); } - mProject->GetControlToolBar()->PlayPlayRegion - (SelectedRegion(mPlayPos, mRegion.t1()), - mProject->GetDefaultPlayOptions(), PlayMode::normalPlay); + mProject->GetControlToolBar()->PlayPlayRegion( + SelectedRegion(mPlayPos, mRegion.t1()), + mProject->GetDefaultPlayOptions(), + PlayMode::normalPlay ); } } diff --git a/src/menus/TransportMenus.cpp b/src/menus/TransportMenus.cpp index f9f755c6a..9b5abe1d4 100644 --- a/src/menus/TransportMenus.cpp +++ b/src/menus/TransportMenus.cpp @@ -707,9 +707,9 @@ void OnPlayOneSecond(const CommandContext &context) auto options = project.GetDefaultPlayOptions(); double pos = trackPanel->GetMostRecentXPos(); - controlToolBar->PlayPlayRegion - (SelectedRegion(pos - 0.5, pos + 0.5), options, - PlayMode::oneSecondPlay); + controlToolBar->PlayPlayRegion( + SelectedRegion(pos - 0.5, pos + 0.5), options, + PlayMode::oneSecondPlay); } /// The idea for this function (and first implementation) @@ -759,8 +759,8 @@ void OnPlayToSelection(const CommandContext &context) auto controlToolBar = project.GetControlToolBar(); auto playOptions = project.GetDefaultPlayOptions(); - controlToolBar->PlayPlayRegion - (SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay); + controlToolBar->PlayPlayRegion( + SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay); } // The next 4 functions provide a limited version of the diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index 9d74eeb40..affa80811 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -537,7 +537,6 @@ bool ControlToolBar::IsRecordDown() const int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, PlayMode mode, - PlayAppearance appearance, /* = PlayOption::Straight */ bool backwards, /* = false */ bool playWhiteSpace /* = false */) // STRONG-GUARANTEE (for state of mCutPreviewTracks) @@ -563,7 +562,18 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, if (backwards) std::swap(t0, t1); - SetPlay(true, appearance); + { + PlayAppearance appearance; + switch( mode ) { + case PlayMode::cutPreviewPlay: + appearance = PlayAppearance::CutPreview; break; + case PlayMode::loopedPlay: + appearance = PlayAppearance::Looped; break; + default: + appearance = PlayAppearance::Straight; break; + } + SetPlay(true, appearance); + } bool success = false; auto cleanup = finally( [&] { @@ -577,7 +587,7 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, if (gAudioIO->IsBusy()) return -1; - const bool cutpreview = appearance == PlayAppearance::CutPreview; + const bool cutpreview = mode == PlayMode::cutPreviewPlay; if (cutpreview && t0==t1) return -1; /* msmeyer: makes no sense */ @@ -589,7 +599,7 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, if (!t) return -1; // Should never happen, but... - p->mLastPlayMode = mode; + mLastPlayMode = mode; bool hasaudio; if (useMidi) @@ -744,14 +754,13 @@ void ControlToolBar::PlayCurrentRegion(bool looped /* = false */, options.playLooped = looped; if (cutpreview) options.timeTrack = NULL; - ControlToolBar::PlayAppearance appearance = - cutpreview ? ControlToolBar::PlayAppearance::CutPreview - : looped ? ControlToolBar::PlayAppearance::Looped - : ControlToolBar::PlayAppearance::Straight; + auto mode = + cutpreview ? PlayMode::cutPreviewPlay + : options.playLooped ? PlayMode::loopedPlay + : PlayMode::normalPlay; PlayPlayRegion(SelectedRegion(playRegionStart, playRegionEnd), options, - (looped ? PlayMode::loopedPlay : PlayMode::normalPlay), - appearance); + mode); } } diff --git a/src/toolbars/ControlToolBar.h b/src/toolbars/ControlToolBar.h index a3f45da7d..77d06b878 100644 --- a/src/toolbars/ControlToolBar.h +++ b/src/toolbars/ControlToolBar.h @@ -33,8 +33,12 @@ class TimeTrack; struct AudioIOStartStreamOptions; class SelectedRegion; -// Defined in Project.h -enum class PlayMode : int; +enum class PlayMode : int { + normalPlay, + oneSecondPlay, // Disables auto-scrolling + loopedPlay, // Disables auto-scrolling + cutPreviewPlay +}; class WaveTrack; using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >; @@ -100,7 +104,6 @@ class ControlToolBar final : public ToolBar { int PlayPlayRegion(const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, PlayMode playMode, - PlayAppearance appearance = PlayAppearance::Straight, bool backwards = false, // Allow t0 and t1 to be beyond end of tracks bool playWhiteSpace = false); @@ -133,6 +136,8 @@ class ControlToolBar final : public ToolBar { // Cancel the addition of temporary recording tracks into the project void CancelRecording(); + PlayMode GetLastPlayMode() const { return mLastPlayMode; } + private: static AButton *MakeButton( @@ -192,6 +197,8 @@ class ControlToolBar final : public ToolBar { wxString mStateRecord; wxString mStatePause; + PlayMode mLastPlayMode{ PlayMode::normalPlay }; + public: DECLARE_CLASS(ControlToolBar) diff --git a/src/toolbars/TranscriptionToolBar.cpp b/src/toolbars/TranscriptionToolBar.cpp index 4eef25ee2..35741b583 100644 --- a/src/toolbars/TranscriptionToolBar.cpp +++ b/src/toolbars/TranscriptionToolBar.cpp @@ -483,18 +483,15 @@ void TranscriptionToolBar::PlayAtSpeed(bool looped, bool cutPreview) AudioIOStartStreamOptions options(p->GetDefaultPlayOptions()); options.playLooped = looped; // No need to set cutPreview options. - // Due to a rather hacky approach, the appearance is used - // to signal use of cutpreview to code below. options.timeTrack = mTimeTrack.get(); - ControlToolBar::PlayAppearance appearance = - cutPreview ? ControlToolBar::PlayAppearance::CutPreview - : looped ? ControlToolBar::PlayAppearance::Looped - : ControlToolBar::PlayAppearance::Straight; + auto mode = + cutPreview ? PlayMode::cutPreviewPlay + : options.playLooped ? PlayMode::loopedPlay + : PlayMode::normalPlay; p->GetControlToolBar()->PlayPlayRegion (SelectedRegion(playRegionStart, playRegionEnd), options, - PlayMode::normalPlay, - appearance); + mode); } else { diff --git a/src/tracks/ui/PlayIndicatorOverlay.cpp b/src/tracks/ui/PlayIndicatorOverlay.cpp index ff96f69d4..f32589ac9 100644 --- a/src/tracks/ui/PlayIndicatorOverlay.cpp +++ b/src/tracks/ui/PlayIndicatorOverlay.cpp @@ -17,6 +17,7 @@ Paul Licameli split from TrackPanel.cpp #include "../../Project.h" #include "../../TrackPanel.h" #include "Scrubbing.h" +#include "../../toolbars/ControlToolBar.h" #include @@ -176,9 +177,10 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event) playPos >= 0 && !onScreen ) { // msmeyer: But only if not playing looped or in one-second mode // PRL: and not scrolling with play/record head fixed + auto mode = mProject->GetControlToolBar()->GetLastPlayMode(); if (!pinned && - mProject->mLastPlayMode != PlayMode::loopedPlay && - mProject->mLastPlayMode != PlayMode::oneSecondPlay && + mode != PlayMode::loopedPlay && + mode != PlayMode::oneSecondPlay && !gAudioIO->IsPaused()) { auto newPos = playPos; diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index d4d29abab..c5862b0e3 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -394,13 +394,6 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) #endif std::max(0.0, MinStutter); - ControlToolBar::PlayAppearance appearance = - // commented out to fix Bug 1241 - // mSeeking - // ? ControlToolBar::PlayAppearance::Seek - // : ControlToolBar::PlayAppearance::Scrub; - ControlToolBar::PlayAppearance::Straight; -// const bool cutPreview = false; const bool backwards = time1 < time0; #ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL static const double maxScrubSpeedBase = @@ -421,7 +414,7 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) mScrubToken = ctb->PlayPlayRegion(SelectedRegion(time0, time1), options, - PlayMode::normalPlay, appearance, backwards); + PlayMode::normalPlay, backwards); if (mScrubToken <= 0) { // Bug1627 (part of it): // infinite error spew when trying to start scrub: @@ -485,8 +478,6 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1) mOptions.adjustStart = false; mOptions.isPlayingAtSpeed = true; - ControlToolBar::PlayAppearance appearance = ControlToolBar::PlayAppearance::Straight; - const bool backwards = time1 < time0; #ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL static const double maxScrubSpeedBase = @@ -510,7 +501,7 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1) mScrubToken = // Reduce time by 'stopTolerance' fudge factor, so that the Play will stop. ctb->PlayPlayRegion(SelectedRegion(time0, time1-stopTolerance), options, - PlayMode::normalPlay, appearance, backwards); + PlayMode::normalPlay, backwards); if (mScrubToken >= 0) { mLastScrubPosition = 0;