From 8cba525b6cabc0437d206415357315c205592a8e Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 15 Jun 2016 20:00:47 -0400 Subject: [PATCH 1/2] No more separate start/stop button on Scrubbing toolbar... ... This finalizes (I hope) the set of buttons, but maybe not their left to right order. Behavior of the scrub bar is still not settled. --- src/toolbars/ControlToolBar.cpp | 4 ++ src/toolbars/EditToolBar.cpp | 91 ++++++++++++++++++--------------- src/toolbars/EditToolBar.h | 4 +- src/tracks/ui/Scrubbing.cpp | 48 ++++++++--------- src/tracks/ui/Scrubbing.h | 14 ++--- 5 files changed, 84 insertions(+), 77 deletions(-) diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index 4ead8e117..a8cb8d15e 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -69,6 +69,7 @@ #include "../tracks/ui/Scrubbing.h" #include "../prefs/PlaybackPrefs.h" +#include "../toolbars/ToolManager.h" IMPLEMENT_CLASS(ControlToolBar, ToolBar); @@ -831,6 +832,9 @@ void ControlToolBar::StopPlaying(bool stopStream /* = true*/) meter->Clear(); } } + + const auto toolbar = project->GetToolManager()->GetToolBar(ScrubbingBarID); + toolbar->EnableDisableButtons(); } void ControlToolBar::Pause() diff --git a/src/toolbars/EditToolBar.cpp b/src/toolbars/EditToolBar.cpp index 0de851951..fb1fd5f24 100644 --- a/src/toolbars/EditToolBar.cpp +++ b/src/toolbars/EditToolBar.cpp @@ -1,4 +1,4 @@ - /********************************************************************** +/********************************************************************** Audacity: A Digital Audio Editor @@ -389,8 +389,8 @@ IMPLEMENT_CLASS(ScrubbingToolBar, ToolBar); //////////////////////////////////////////////////////////// BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar ) -EVT_COMMAND_RANGE( STBStartID, - STBStartID + STBNumButtons - 1, +EVT_COMMAND_RANGE( STBFirstButton, + STBFirstButton + STBNumButtons - 1, wxEVT_COMMAND_BUTTON_CLICKED, ScrubbingToolBar::OnButton ) END_EVENT_TABLE() @@ -444,8 +444,6 @@ void ScrubbingToolBar::Populate() MakeButtonBackgroundsSmall(); /* Buttons */ - AddButton(bmpPlay, bmpStop, bmpPlayDisabled, STBStartID, - _("Start scrubbing"), true); AddButton(bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID, _("Scrub"), true); AddButton(bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID, @@ -472,29 +470,34 @@ void ScrubbingToolBar::UpdatePrefs() void ScrubbingToolBar::RegenerateTooltips() { #if wxUSE_TOOLTIPS - /* 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 - */ auto project = GetActiveProject(); if (project) { - auto startStop = mButtons[STBStartID]; auto &scrubber = project->GetScrubber(); - if(scrubber.HasStartedScrubbing() || scrubber.IsScrubbing()) { - if (scrubber.Seeks()) - startStop->SetToolTip(_("Stop seeking")); - else - startStop->SetToolTip(_("Stop scrubbing")); - } - else { - if (scrubber.Seeks()) - startStop->SetToolTip(_("Start seeking")); - else - startStop->SetToolTip(_("Start scrubbing")); - } + + const auto scrubButton = mButtons[STBScrubID]; + const auto seekButton = mButtons[STBSeekID]; + + scrubButton->SetToolTip( + scrubber.Scrubs() + /* 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 + */ + ? _("Stop Scrubbing") + : _("Start Scrubbing") + ); + + seekButton->SetToolTip( + scrubber.Seeks() + /* 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 + */ + ? _("Stop Seeking") + : _("Start Seeking") + ); } - mButtons[STBScrubID]->SetToolTip(_("Scrub")); - mButtons[STBSeekID]->SetToolTip(_("Seek")); + mButtons[STBBarID]->SetToolTip(_("Scrub bar")); #endif } @@ -508,9 +511,6 @@ void ScrubbingToolBar::OnButton(wxCommandEvent &event) int id = event.GetId(); switch (id) { - case STBStartID: - scrubber.OnStartStop(event); - break; case STBScrubID: scrubber.OnScrub(event); break; @@ -538,25 +538,36 @@ void ScrubbingToolBar::EnableDisableButtons() if (!p) return; auto &scrubber = p->GetScrubber(); - if (scrubber.Scrubs()) + const auto canScrub = scrubber.CanScrub(); + + if (scrubber.Scrubs()) { scrubButton->PushDown(); - else + scrubButton->Enable(); + } + else { scrubButton->PopUp(); + if (canScrub) + scrubButton->Enable(); + else + scrubButton->Disable(); + } - if (scrubber.Seeks()) + if (scrubber.Seeks()) { seekButton->PushDown(); - else + seekButton->Enable(); + } + else { seekButton->PopUp(); + if (canScrub) + seekButton->Enable(); + else + seekButton->Disable(); + } - const auto startButton = mButtons[STBStartID]; - if (scrubber.CanScrub()) - startButton->Enable(); - else - startButton->Disable(); - - mButtons[STBBarID]->Enable(); + const auto barButton = mButtons[STBBarID]; + barButton->Enable(); if (p->GetRulerPanel()->ShowingScrubBar()) - mButtons[STBBarID]->PushDown(); + barButton->PushDown(); else - mButtons[STBBarID]->PopUp(); + barButton->PopUp(); } diff --git a/src/toolbars/EditToolBar.h b/src/toolbars/EditToolBar.h index 6a1e45dba..088136896 100644 --- a/src/toolbars/EditToolBar.h +++ b/src/toolbars/EditToolBar.h @@ -113,12 +113,12 @@ class wxWindow; class AButton; enum { - STBStartID, STBScrubID, STBSeekID, STBBarID, - STBNumButtons + STBNumButtons, + STBFirstButton = STBScrubID }; class ScrubbingToolBar final : public ToolBar { diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index cccd13877..d2e29b4ba 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -229,18 +229,13 @@ namespace { "Seeking" is normal speed playback but with skips, ... */ { wxT("Scrub"), XO("&Scrub"), XO("Scrubbing"), - AlwaysEnabledFlag, + CanStopAudioStreamFlag, &Scrubber::OnScrub, false, &Scrubber::Scrubs, }, { wxT("Seek"), XO("See&k"), XO("Seeking"), - AlwaysEnabledFlag, - &Scrubber::OnSeek, true, &Scrubber::Seeks, - }, - - { wxT("StartStopScrubSeek"), XO("Star&t/Stop"), XO(""), CanStopAudioStreamFlag, - &Scrubber::OnStartStop, true, nullptr + &Scrubber::OnSeek, true, &Scrubber::Seeks, }, { wxT("ToggleScrubBar"), XO("Scrub Bar"), XO(""), @@ -249,7 +244,7 @@ namespace { }, }; - enum { nMenuItems = sizeof(menuItems) / sizeof(*menuItems), StartMenuItem = 2 }; + enum { nMenuItems = sizeof(menuItems) / sizeof(*menuItems) }; inline const MenuItem &FindMenuItem(bool seek) { @@ -535,7 +530,8 @@ bool Scrubber::IsScrubbing() const { if (mScrubToken <= 0) return false; - else if (mScrubToken == mProject->GetAudioIOToken()) + else if (mScrubToken == mProject->GetAudioIOToken() && + mProject->IsAudioActive()) return true; else { const_cast(*this).mScrubToken = -1; @@ -545,6 +541,16 @@ bool Scrubber::IsScrubbing() const } } +bool Scrubber::Seeks() const +{ + return (HasStartedScrubbing() || IsScrubbing()) && mSeeking; +} + +bool Scrubber::Scrubs() const +{ + return (HasStartedScrubbing() || IsScrubbing()) && !mSeeking; +} + bool Scrubber::ShouldDrawScrubSpeed() { if (mDragging) @@ -800,11 +806,9 @@ void Scrubber::DoScrub() mProject->GetControlToolBar()->StopPlaying(); } -void Scrubber::OnScrubOrSeek(bool &toToggle, bool &other) +void Scrubber::OnScrubOrSeek(bool seek) { - toToggle = !toToggle; - if (toToggle) - other = false; + mSeeking = seek; if (HasStartedScrubbing()) { // Show the correct status. @@ -821,22 +825,19 @@ void Scrubber::OnScrubOrSeek(bool &toToggle, bool &other) scrubbingToolBar->EnableDisableButtons(); scrubbingToolBar->RegenerateTooltips(); + DoScrub(); + CheckMenuItems(); } void Scrubber::OnScrub(wxCommandEvent&) { - OnScrubOrSeek(mScrubbing, mSeeking); + OnScrubOrSeek(false); } void Scrubber::OnSeek(wxCommandEvent&) { - OnScrubOrSeek(mSeeking, mScrubbing); -} - -void Scrubber::OnStartStop(wxCommandEvent&) -{ - DoScrub(); + OnScrubOrSeek(true); } void Scrubber::OnToggleScrubBar(wxCommandEvent&) @@ -852,15 +853,14 @@ enum { CMD_ID = 8000 }; BEGIN_EVENT_TABLE(Scrubber, wxEvtHandler) EVT_MENU(CMD_ID, Scrubber::OnScrub) EVT_MENU(CMD_ID + 1, Scrubber::OnSeek) - EVT_MENU(CMD_ID + 2, Scrubber::OnStartStop) - EVT_MENU(CMD_ID + 3, Scrubber::OnToggleScrubBar) + EVT_MENU(CMD_ID + 2, Scrubber::OnToggleScrubBar) 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 == 3, "wrong number of items"); const wxString &Scrubber::GetUntranslatedStateString() const { @@ -890,7 +890,7 @@ bool Scrubber::CanScrub() const { // Return the enabled state for the menu item that really launches the scrub or seek. auto cm = mProject->GetCommandManager(); - return cm->GetEnabled(menuItems[StartMenuItem].name); + return cm->GetEnabled(menuItems[ 0 ].name); } void Scrubber::AddMenuItems() diff --git a/src/tracks/ui/Scrubbing.h b/src/tracks/ui/Scrubbing.h index 378514ba6..760847837 100644 --- a/src/tracks/ui/Scrubbing.h +++ b/src/tracks/ui/Scrubbing.h @@ -97,12 +97,8 @@ public: void SetScrollScrubbing(bool value) { mSmoothScrollingScrub = value; } - bool Seeks() const - { return mSeeking; } - - bool Scrubs() const - { return mScrubbing; } - + bool Seeks() const; + bool Scrubs() const; bool ShowsBar() const; void Cancel() @@ -122,10 +118,9 @@ public: // For popup void PopulatePopupMenu(wxMenu &menu); - void OnScrubOrSeek(bool &toToggle, bool &other); + void OnScrubOrSeek(bool seek); void OnScrub(wxCommandEvent&); void OnSeek(wxCommandEvent&); - void OnStartStop(wxCommandEvent&); void OnToggleScrubBar(wxCommandEvent&); // A string to put in the leftmost part of the status bar @@ -163,9 +158,6 @@ private: wxCoord mLastScrubPosition {}; bool mSmoothScrollingScrub; - // These hold the three-way choice among click-to-scrub, click-to-seek, or disabled. - // Not both true. - bool mScrubbing {}; bool mSeeking {}; bool mDragging {}; From 07cf46826af2fd4748533155850142b1938da537 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 15 Jun 2016 23:20:00 -0400 Subject: [PATCH 2/2] Scrub bar tooltips mention shortcut keys --- src/toolbars/EditToolBar.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/toolbars/EditToolBar.cpp b/src/toolbars/EditToolBar.cpp index fb1fd5f24..ed2920d28 100644 --- a/src/toolbars/EditToolBar.cpp +++ b/src/toolbars/EditToolBar.cpp @@ -470,6 +470,16 @@ void ScrubbingToolBar::UpdatePrefs() void ScrubbingToolBar::RegenerateTooltips() { #if wxUSE_TOOLTIPS + std::vector commands; + auto fn = [&] + (AButton &button, const wxString &label, const wxString &command) + { + commands.clear(); + commands.push_back(label); + commands.push_back(command); + ToolBar::SetButtonToolTip(button, commands); + }; + auto project = GetActiveProject(); if (project) { auto &scrubber = project->GetScrubber(); @@ -477,7 +487,8 @@ void ScrubbingToolBar::RegenerateTooltips() const auto scrubButton = mButtons[STBScrubID]; const auto seekButton = mButtons[STBSeekID]; - scrubButton->SetToolTip( + wxString label; + label = ( scrubber.Scrubs() /* i18n-hint: These commands assist the user in finding a sound by ear. ... "Scrubbing" is variable-speed playback, ... @@ -486,8 +497,9 @@ void ScrubbingToolBar::RegenerateTooltips() ? _("Stop Scrubbing") : _("Start Scrubbing") ); + fn(*scrubButton, label, wxT("Scrub")); - seekButton->SetToolTip( + label = ( scrubber.Seeks() /* i18n-hint: These commands assist the user in finding a sound by ear. ... "Scrubbing" is variable-speed playback, ... @@ -496,9 +508,15 @@ void ScrubbingToolBar::RegenerateTooltips() ? _("Stop Seeking") : _("Start Seeking") ); - } + fn(*seekButton, label, wxT("Seek")); - mButtons[STBBarID]->SetToolTip(_("Scrub bar")); + label = ( + project->GetRulerPanel()->ShowingScrubBar() + ? _("Hide Scrub Bar") + : _("Show Scrub Bar") + ); + fn(*mButtons[STBBarID], label, wxT("ToggleScrubBar")); + } #endif }