From 6147705199306ab28bdc986ce68c0644ac3b2467 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 24 Apr 2016 15:13:03 -0400 Subject: [PATCH] Vary status string (leftmost in the status bar) for the four kinds of scrub. --- src/toolbars/ControlToolBar.cpp | 39 +++++++++++------------- src/toolbars/ControlToolBar.h | 1 - src/tracks/ui/Scrubbing.cpp | 54 +++++++++++++++++++++++++++------ src/tracks/ui/Scrubbing.h | 7 +++++ 4 files changed, 69 insertions(+), 32 deletions(-) diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index bacaebfb0..d454f5a0d 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -107,7 +107,6 @@ ControlToolBar::ControlToolBar() /* i18n-hint: These are strings for the status bar, and indicate whether Audacity is playing or recording or stopped, and whether it is paused. */ mStatePlay = XO("Playing"); - mStateScrub = XO("Scrubbing"); mStateStop = XO("Stopped"); mStateRecord = XO("Recording"); mStatePause = XO("Paused"); @@ -1175,28 +1174,24 @@ void ControlToolBar::ClearCutPreviewTracks() int ControlToolBar::WidthForStatusBar(wxStatusBar* const sb) { int xMax = 0; - int x, y; + const auto pauseString = wxT(" ") + wxGetTranslation(mStatePause); - sb->GetTextExtent(wxString(wxGetTranslation(mStatePlay)) + wxT(" ") + - wxString(wxGetTranslation(mStatePause)) + wxT("."), &x, &y); - if (x > xMax) - xMax = x; + auto update = [&] (const wxString &state, bool pauseToo) { + int x, y; + sb->GetTextExtent( + wxGetTranslation(state) + ( pauseToo ? pauseString : wxString{} ) + wxT("."), + &x, &y + ); + xMax = std::max(x, xMax); + }; - sb->GetTextExtent(wxString(wxGetTranslation(mStateStop)) + wxT(" ") + - wxString(wxGetTranslation(mStatePause)) + wxT("."), &x, &y); - if (x > xMax) - xMax = x; - - sb->GetTextExtent(wxString(wxGetTranslation(mStateRecord)) + wxT(" ") + - wxString(wxGetTranslation(mStatePause)) + wxT("."), &x, &y); - if (x > xMax) - xMax = x; + update(mStatePlay, true); + update(mStateStop, true); + update(mStateRecord, true); // Note that Scrubbing + Paused is not allowed. - sb->GetTextExtent(wxString(wxGetTranslation(mStateScrub)) + - wxT("."), &x, &y); - if (x > xMax) - xMax = x; + for(const auto &state : Scrubber::GetAllUntranslatedStatusStrings()) + update(state, false); return xMax + 30; // added constant needed because xMax isn't large enough for some reason, plus some space. } @@ -1206,8 +1201,10 @@ wxString ControlToolBar::StateForStatusBar() wxString state; auto pProject = GetActiveProject(); - if (pProject && pProject->GetScrubber().HasStartedScrubbing()) - state = wxGetTranslation(mStateScrub); + auto scrubState = + pProject ? pProject->GetScrubber().GetUntranslatedStateString() : wxString(); + if (!scrubState.IsEmpty()) + state = wxGetTranslation(scrubState); else if (mPlay->IsDown()) state = wxGetTranslation(mStatePlay); else if (mRecord->IsDown()) diff --git a/src/toolbars/ControlToolBar.h b/src/toolbars/ControlToolBar.h index bac16e409..c4244e0f5 100644 --- a/src/toolbars/ControlToolBar.h +++ b/src/toolbars/ControlToolBar.h @@ -158,7 +158,6 @@ class ControlToolBar final : public ToolBar { // strings for status bar wxString mStatePlay; - wxString mStateScrub; wxString mStateStop; wxString mStateRecord; wxString mStatePause; diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index e3155a007..f8921b832 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -139,22 +139,43 @@ namespace { const struct MenuItem { wxString name; wxString label; + wxString status; void (Scrubber::*memFn)(); bool scroll; bool seek; + + const wxString &GetStatus() const { return status; } } menuItems[] = { /* i18n-hint: These commands assist the user in finding a sound by ear. ... "Scrubbing" is variable-speed playback, ... "Seeking" is normal speed playback but with skips, ... "Scrolling" keeps the playback position at a fixed place on screen while the waveform moves */ - { wxT("Scrub"), XO("&Scrub"), &Scrubber::OnScrub, false, false }, - { wxT("ScrollScrub"), XO("Sc&rolling Scrub"), &Scrubber::OnScrollScrub, true, false }, - { wxT("Seek"), XO("See&k"), &Scrubber::OnSeek, false, true }, - { wxT("ScrollSeek"), XO("Scrollin&g Seek"), &Scrubber::OnScrollSeek, true, true }, + { wxT("Scrub"), XO("&Scrub"), XO("Scrubbing"), + &Scrubber::OnScrub, false, false }, + + { wxT("ScrollScrub"), XO("Sc&rolling Scrub"), XO("Scrolling Scrub"), + &Scrubber::OnScrollScrub, true, false }, + + { wxT("Seek"), XO("See&k"), XO("Seeking"), + &Scrubber::OnSeek, false, true }, + + { wxT("ScrollSeek"), XO("Scrollin&g Seek"), XO("Scrolling Seek"), + &Scrubber::OnScrollSeek, true, true } }; enum { nMenuItems = sizeof(menuItems) / sizeof(*menuItems) }; + + inline const MenuItem &FindMenuItem(bool scroll, bool seek) + { + return *std::find_if(menuItems, menuItems + nMenuItems, + [=](const MenuItem &item) { + return scroll == item.scroll && + seek == item.seek; + } + ); + } + } void Scrubber::MarkScrubStart( @@ -619,6 +640,24 @@ void Scrubber::OnScrollSeek() DoScrub(true, true); } +const wxString &Scrubber::GetUntranslatedStateString() const +{ + if (HasStartedScrubbing()) { + auto item = FindMenuItem(mSmoothScrollingScrub, mAlwaysSeeking); + return item.status; + } + else return {}; +} + +std::vector Scrubber::GetAllUntranslatedStatusStrings() +{ + using namespace std; + vector results; + transform(menuItems, menuItems + nMenuItems, back_inserter(results), + mem_fun_ref(&MenuItem::GetStatus)); + return move(results); +} + void Scrubber::AddMenuItems() { auto cm = mProject->GetCommandManager(); @@ -644,13 +683,8 @@ void Scrubber::UncheckAllMenuItems() void Scrubber::CheckMenuItem() { if(HasStartedScrubbing()) { - auto &item = *std::find_if(menuItems, menuItems + nMenuItems, - [=](const MenuItem &item) { - return mSmoothScrollingScrub == item.scroll && - mAlwaysSeeking == item.seek; - } - ); auto cm = mProject->GetCommandManager(); + auto item = FindMenuItem(mSmoothScrollingScrub, mAlwaysSeeking); cm->Check(item.name, true); } } diff --git a/src/tracks/ui/Scrubbing.h b/src/tracks/ui/Scrubbing.h index 2ca11dcb3..54e64f874 100644 --- a/src/tracks/ui/Scrubbing.h +++ b/src/tracks/ui/Scrubbing.h @@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp #ifndef __AUDACITY_SCRUBBING__ #define __AUDACITY_SCRUBBING__ +#include #include #include @@ -68,6 +69,12 @@ public: void OnSeek(); void OnScrollSeek(); + // A string to put in the leftmost part of the status bar. + const wxString &GetUntranslatedStateString() const; + + // All possible status strings. + static std::vector GetAllUntranslatedStatusStrings(); + private: void DoScrub(bool scroll, bool seek); void OnActivateOrDeactivateApp(wxActivateEvent & event);