From eafc416d55a4135888e405de45aadba033398c2c Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 30 May 2016 10:24:50 -0400 Subject: [PATCH] Remove double-click and scrolling menu items for scrub/seek... ... Use the toggle button on the ruler instead --- src/Menus.cpp | 9 ++++- src/toolbars/ControlToolBar.cpp | 10 +++++ src/tracks/ui/Scrubbing.cpp | 68 ++++++++------------------------- src/tracks/ui/Scrubbing.h | 7 ++-- src/widgets/Ruler.cpp | 5 +-- 5 files changed, 36 insertions(+), 63 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 1bfc8ffb7..a4a7e42e5 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -2372,8 +2372,8 @@ void AudacityProject::OnToggleSoundActivated() void AudacityProject::OnTogglePinnedHead() { - PlaybackPrefs::SetPinnedHeadPreference( - !PlaybackPrefs::GetPinnedHeadPreference(), true); + bool value = !PlaybackPrefs::GetPinnedHeadPreference(); + PlaybackPrefs::SetPinnedHeadPreference(value, true); ModifyAllProjectToolbarMenus(); // Change what happens in case transport is in progress right now @@ -2384,7 +2384,12 @@ void AudacityProject::OnTogglePinnedHead() auto ruler = GetRulerPanel(); if (ruler) // Update button image + ruler->UpdateButtonStates(); + + auto &scrubber = GetScrubber(); + if (scrubber.HasStartedScrubbing()) + scrubber.SetScrollScrubbing(value); } void AudacityProject::OnTogglePlayRecording() diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index e374ff680..debaf4980 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -1258,6 +1258,16 @@ void ControlToolBar::StartScrollingIfPreferred() { if (PlaybackPrefs::GetPinnedHeadPreference()) StartScrolling(); +#ifdef __WXMAC__ + else if (::GetActiveProject()->GetScrubber().HasStartedScrubbing()) { + // PRL: cause many "unnecessary" refreshes. For reasons I don't understand, + // doing this causes wheel rotation events (mapped from the double finger vertical + // swipe) to be delivered more uniformly to the application, so that speed control + // works better. + ::GetActiveProject()->GetPlaybackScroller().Activate + (AudacityProject::PlaybackScroller::Mode::Refresh); + } +#endif else StopScrolling(); } diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index 80bc6d60a..79a947747 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -19,6 +19,7 @@ Paul Licameli split from TrackPanel.cpp #include "../../TrackPanelCell.h" #include "../../TrackPanelCellIterator.h" #include "../../commands/CommandFunctors.h" +#include "../../prefs/PlaybackPrefs.h" #include "../../toolbars/ControlToolBar.h" #undef USE_TRANSCRIPTION_TOOLBAR @@ -219,7 +220,6 @@ namespace { wxString label; wxString status; void (Scrubber::*memFn)(wxCommandEvent&); - bool scroll; bool seek; const wxString &GetStatus() const { return status; } @@ -230,26 +230,20 @@ namespace { "Scrolling" keeps the playback position at a fixed place on screen while the waveform moves */ { wxT("Scrub"), XO("&Scrub"), XO("Scrubbing"), - &Scrubber::OnScrub, false, false }, - - { wxT("ScrollScrub"), XO("Sc&rolling Scrub"), XO("Scrolling Scrub"), - &Scrubber::OnScrollScrub, true, false }, + &Scrubber::OnScrub, false }, { wxT("Seek"), XO("See&k"), XO("Seeking"), - &Scrubber::OnSeek, false, true }, + &Scrubber::OnSeek, true }, - { wxT("ScrollSeek"), XO("Scro&lling Seek"), XO("Scrolling Seek"), - &Scrubber::OnScrollSeek, true, true } }; enum { nMenuItems = sizeof(menuItems) / sizeof(*menuItems) }; - inline const MenuItem &FindMenuItem(bool scroll, bool seek) + inline const MenuItem &FindMenuItem(bool seek) { return *std::find_if(menuItems, menuItems + nMenuItems, [=](const MenuItem &item) { - return scroll == item.scroll && - seek == item.seek; + return seek == item.seek; } ); } @@ -382,7 +376,6 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx) mOptions.startClockTimeMillis = ::wxGetLocalTimeMillis(); if (IsScrubbing()) { - ActivateScroller(); mPaused = false; mLastScrubPosition = xx; @@ -780,29 +773,11 @@ bool Scrubber::PollIsSeeking() return mDragging || (mAlwaysSeeking || ::wxGetMouseState().LeftIsDown()); } -void Scrubber::ActivateScroller() -{ - const auto ctb = mProject->GetControlToolBar(); - if (mSmoothScrollingScrub) - ctb->StartScrolling(); - else { -#ifdef __WXMAC__ - // PRL: cause many "unnecessary" refreshes. For reasons I don't understand, - // doing this causes wheel rotation events (mapped from the double finger vertical - // swipe) to be delivered more uniformly to the application, so that speed control - // works better. - mProject->GetPlaybackScroller().Activate - (AudacityProject::PlaybackScroller::Mode::Refresh); -#else - ctb->StopScrolling(); -#endif - } -} - -void Scrubber::DoScrub(bool scroll, bool seek) +void Scrubber::DoScrub(bool seek) { const bool wasScrubbing = IsScrubbing(); - const bool match = (scroll == mSmoothScrollingScrub && seek == mAlwaysSeeking); + const bool match = (seek == mAlwaysSeeking); + const bool scroll = PlaybackPrefs::GetPinnedHeadPreference(); if (!wasScrubbing) { auto tp = mProject->GetTrackPanel(); wxCoord xx = tp->ScreenToClient(::wxGetMouseState().GetPosition()).x; @@ -817,7 +792,6 @@ void Scrubber::DoScrub(bool scroll, bool seek) } else if(!match) { mSmoothScrollingScrub = scroll; - ActivateScroller(); mAlwaysSeeking = seek; UncheckAllMenuItems(); CheckMenuItem(); @@ -835,45 +809,33 @@ void Scrubber::DoScrub(bool scroll, bool seek) void Scrubber::OnScrub(wxCommandEvent&) { - DoScrub(false, false); -} - -void Scrubber::OnScrollScrub(wxCommandEvent&) -{ - DoScrub(true, false); + DoScrub(false); } void Scrubber::OnSeek(wxCommandEvent&) { - DoScrub(false, true); -} - -void Scrubber::OnScrollSeek(wxCommandEvent&) -{ - DoScrub(true, true); + DoScrub(true); } enum { CMD_ID = 8000 }; BEGIN_EVENT_TABLE(Scrubber, wxEvtHandler) EVT_MENU(CMD_ID, Scrubber::OnScrub) - EVT_MENU(CMD_ID + 1, Scrubber::OnScrollScrub) - EVT_MENU(CMD_ID + 2, Scrubber::OnSeek) - EVT_MENU(CMD_ID + 3, Scrubber::OnScrollSeek) + EVT_MENU(CMD_ID + 1, Scrubber::OnSeek) END_EVENT_TABLE() BEGIN_EVENT_TABLE(Scrubber::Forwarder, wxEvtHandler) EVT_MOUSE_EVENTS(Scrubber::Forwarder::OnMouse) END_EVENT_TABLE() -static_assert(nMenuItems == 4, "wrong number of items"); +static_assert(nMenuItems == 2, "wrong number of items"); const wxString &Scrubber::GetUntranslatedStateString() const { static wxString empty; if (HasStartedScrubbing()) { - auto &item = FindMenuItem(mSmoothScrollingScrub, mAlwaysSeeking); + auto &item = FindMenuItem(mAlwaysSeeking); return item.status; } else @@ -923,7 +885,7 @@ void Scrubber::PopulateMenu(wxMenu &menu) auto cm = mProject->GetCommandManager(); const MenuItem *checkedItem = HasStartedScrubbing() - ? &FindMenuItem(mSmoothScrollingScrub, mAlwaysSeeking) + ? &FindMenuItem(mAlwaysSeeking) : nullptr; for (const auto &item : menuItems) { if (cm->GetEnabled(item.name)) { @@ -953,7 +915,7 @@ void Scrubber::CheckMenuItem() #ifdef CHECKABLE_SCRUB_MENU_ITEMS if(HasStartedScrubbing()) { auto cm = mProject->GetCommandManager(); - auto item = FindMenuItem(mSmoothScrollingScrub, mAlwaysSeeking); + auto item = FindMenuItem(mAlwaysSeeking); cm->Check(item.name, true); } #endif diff --git a/src/tracks/ui/Scrubbing.h b/src/tracks/ui/Scrubbing.h index f5add7f1f..930d48751 100644 --- a/src/tracks/ui/Scrubbing.h +++ b/src/tracks/ui/Scrubbing.h @@ -98,6 +98,8 @@ public: bool IsScrollScrubbing() const // If true, implies HasStartedScrubbing() { return mSmoothScrollingScrub; } + void SetScrollScrubbing(bool value) + { mSmoothScrollingScrub = value; } bool IsAlwaysSeeking() const { return mAlwaysSeeking; } @@ -119,9 +121,7 @@ public: void PopulateMenu(wxMenu &menu); void OnScrub(wxCommandEvent&); - void OnScrollScrub(wxCommandEvent&); void OnSeek(wxCommandEvent&); - void OnScrollSeek(wxCommandEvent&); // A string to put in the leftmost part of the status bar. const wxString &GetUntranslatedStateString() const; @@ -133,8 +133,7 @@ public: bool IsPaused() const; private: - void ActivateScroller(); - void DoScrub(bool scroll, bool seek); + void DoScrub(bool seek); void OnActivateOrDeactivateApp(wxActivateEvent & event); void UncheckAllMenuItems(); void CheckMenuItem(); diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index e88ae7b0f..ef80f0023 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -2360,9 +2360,6 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) if (scrubber.IsScrubbing()) evt.Skip(); - else if (evt.LeftDClick()) - // On the second button down, switch the pending scrub to scrolling - scrubber.MarkScrubStart(evt.m_x, true, false); else evt.Skip(); @@ -2421,7 +2418,7 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt) } else if (!HasCapture() && inScrubZone) { if (evt.LeftDown()) { - scrubber.MarkScrubStart(evt.m_x, false, false); + scrubber.MarkScrubStart(evt.m_x, PlaybackPrefs::GetPinnedHeadPreference(), false); UpdateStatusBarAndTooltips(StatusChoice::EnteringScrubZone); } ShowQuickPlayIndicator();