From f5c4c85653ed36feef4447c8ff145ade3535522a Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 5 Jun 2016 01:03:24 -0400 Subject: [PATCH] New scrubbing toolbar; remove ruler pushbuttons. --- src/Menus.cpp | 9 ++ src/Menus.h | 1 + src/commands/ScreenshotCommand.cpp | 4 + src/toolbars/EditToolBar.cpp | 187 ++++++++++++++++++++++++++++- src/toolbars/EditToolBar.h | 61 ++++++++++ src/toolbars/ToolBar.h | 1 + src/toolbars/ToolManager.cpp | 1 + src/tracks/ui/Scrubbing.cpp | 11 +- src/widgets/Ruler.cpp | 49 +------- src/widgets/Ruler.h | 2 - 10 files changed, 275 insertions(+), 51 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 22e6d73eb..bd9a21549 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -726,6 +726,7 @@ void AudacityProject::CreateMenusAndCommands() c->AddCheck(wxT("ShowTranscriptionTB"), _("Transcri&ption Toolbar"), FN(OnShowTranscriptionToolBar), 0, AlwaysEnabledFlag, AlwaysEnabledFlag); /* i18n-hint: Clicking this menu item shows the toolbar with the big buttons on it (play record etc)*/ c->AddCheck(wxT("ShowTransportTB"), _("&Transport Toolbar"), FN(OnShowTransportToolBar), 0, AlwaysEnabledFlag, AlwaysEnabledFlag); + c->AddCheck(wxT("ShowScrubbingTB"), _("Scrubbing Toolbar"), FN(OnShowScrubbingToolBar), 0, AlwaysEnabledFlag, AlwaysEnabledFlag); c->AddSeparator(); @@ -1807,6 +1808,8 @@ void AudacityProject::ModifyToolbarMenus() return; } + mCommandManager.Check(wxT("ShowScrubbingTB"), + mToolManager->IsVisible(ScrubbingBarID)); mCommandManager.Check(wxT("ShowDeviceTB"), mToolManager->IsVisible(DeviceBarID)); mCommandManager.Check(wxT("ShowEditTB"), @@ -5438,6 +5441,12 @@ void AudacityProject::OnShowMixerToolBar() ModifyToolbarMenus(); } +void AudacityProject::OnShowScrubbingToolBar() +{ + mToolManager->ShowHide( ScrubbingBarID ); + ModifyToolbarMenus(); +} + void AudacityProject::OnShowSelectionToolBar() { mToolManager->ShowHide( SelectionBarID ); diff --git a/src/Menus.h b/src/Menus.h index 88391d723..cfb115c0f 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -305,6 +305,7 @@ void OnShowSelectionToolBar(); #ifdef EXPERIMENTAL_SPECTRAL_EDITING void OnShowSpectralSelectionToolBar(); #endif +void OnShowScrubbingToolBar(); void OnShowToolsToolBar(); void OnShowTranscriptionToolBar(); void OnResetToolBars(); diff --git a/src/commands/ScreenshotCommand.cpp b/src/commands/ScreenshotCommand.cpp index 0c8cf0540..8460303c8 100644 --- a/src/commands/ScreenshotCommand.cpp +++ b/src/commands/ScreenshotCommand.cpp @@ -452,6 +452,10 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context) { CaptureToolbar(context.GetProject()->GetToolManager(), TranscriptionBarID, fileName); } + else if (captureMode.IsSameAs(wxT("scrubbing"))) + { + CaptureToolbar(context.GetProject()->GetToolManager(), ScrubbingBarID, fileName); + } else if (captureMode.IsSameAs(wxT("trackpanel"))) { TrackPanel *panel = context.GetProject()->GetTrackPanel(); diff --git a/src/toolbars/EditToolBar.cpp b/src/toolbars/EditToolBar.cpp index b8dec35eb..77d2757a6 100644 --- a/src/toolbars/EditToolBar.cpp +++ b/src/toolbars/EditToolBar.cpp @@ -1,4 +1,4 @@ -/********************************************************************** + /********************************************************************** Audacity: A Digital Audio Editor @@ -330,3 +330,188 @@ void EditToolBar::EnableDisableButtons() mButtons[ETBSyncLockID]->PopUp(); #endif } + + +// PRL: to do: move the below to its own file +// Much of this is imitative of EditToolBar. Should there be a common base +// class? +#include "../Audacity.h" + +// For compilers that support precompilation, includes "wx/wx.h". +#include + +#ifndef WX_PRECOMP +#include +#include +#include +#include +#include +#endif + +#include "../AllThemeResources.h" +#include "../AudioIO.h" +#include "../ImageManipulation.h" +#include "../Internat.h" +#include "../Prefs.h" +#include "../Project.h" +#include "../Theme.h" +#include "../Track.h" +#include "../UndoManager.h" +#include "../widgets/AButton.h" +#include "../tracks/ui/Scrubbing.h" + +#include "../Experimental.h" + +IMPLEMENT_CLASS(ScrubbingToolBar, ToolBar); + +//const int BUTTON_WIDTH = 27; +//const int SEPARATOR_WIDTH = 14; + +//////////////////////////////////////////////////////////// +/// Methods for ScrubbingToolBar +//////////////////////////////////////////////////////////// + +BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar ) +EVT_COMMAND_RANGE( STBStartID, + STBStartID + STBNumButtons - 1, + wxEVT_COMMAND_BUTTON_CLICKED, + ScrubbingToolBar::OnButton ) +END_EVENT_TABLE() + +//Standard contructor +ScrubbingToolBar::ScrubbingToolBar() +: ToolBar(ScrubbingBarID, _("Scrub"), wxT("Scrub")) +{ +} + +ScrubbingToolBar::~ScrubbingToolBar() +{ +} + +void ScrubbingToolBar::Create(wxWindow * parent) +{ + ToolBar::Create(parent); +} + +/// This is a convenience function that allows for button creation in +/// MakeButtons() with fewer arguments +/// Very similar to code in ControlToolBar... +AButton *ScrubbingToolBar::AddButton + (teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, + int id, + const wxChar *label, + bool toggle) +{ + AButton *&r = mButtons[id]; + + r = ToolBar::MakeButton + (this, + bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredHiliteSmall, + eEnabledUp, eEnabledDown, eDisabled, + wxWindowID(id), + wxDefaultPosition, + toggle, + theTheme.ImageSize( bmpRecoloredUpSmall )); + + r->SetLabel(label); + // JKC: Unlike ControlToolBar, does not have a focus rect. Shouldn't it? + // r->SetFocusRect( r->GetRect().Deflate( 4, 4 ) ); + + Add( r, 0, wxALIGN_CENTER ); + + return r; +} + +void ScrubbingToolBar::Populate() +{ + MakeButtonBackgroundsSmall(); + + /* Buttons */ + AddButton(bmpPlay, bmpPlay, bmpPlayDisabled, STBStartID, + _("Start scrubbing"), false); + AddButton(bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID, + _("Scrub"), true); + AddButton(bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID, + _("Seek"), true); + + + RegenerateTooltips(); +} + +void ScrubbingToolBar::UpdatePrefs() +{ + RegenerateTooltips(); + + // Set label to pull in language change + SetLabel(_("Scrubbing")); + + // Give base class a chance + ToolBar::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 + */ + mButtons[STBStartID]->SetToolTip(_("Start scrubbing or seeking")); + mButtons[STBScrubID]->SetToolTip(_("Scrub")); + mButtons[STBSeekID]->SetToolTip(_("Seek")); +#endif +} + +void ScrubbingToolBar::OnButton(wxCommandEvent &event) +{ + AudacityProject *p = GetActiveProject(); + if (!p) return; + auto &scrubber = p->GetScrubber(); + + int id = event.GetId(); + + switch (id) { + case STBStartID: + mButtons[STBStartID]->PopUp(); + scrubber.OnStart(event); + break; + case STBScrubID: + scrubber.OnScrub(event); + break; + case STBSeekID: + scrubber.OnSeek(event); + break; + default: + wxASSERT(false); + } + + EnableDisableButtons(); +} + +void ScrubbingToolBar::EnableDisableButtons() +{ + const auto scrubButton = mButtons[STBScrubID]; + scrubButton->SetEnabled(true); + const auto seekButton = mButtons[STBSeekID]; + seekButton->SetEnabled(true); + + AudacityProject *p = GetActiveProject(); + if (!p) return; + + auto &scrubber = p->GetScrubber(); + if (scrubber.Scrubs()) + scrubButton->PushDown(); + else + scrubButton->PopUp(); + + if (scrubber.Seeks()) + seekButton->PushDown(); + else + seekButton->PopUp(); + + const auto startButton = mButtons[STBStartID]; + if (scrubber.CanScrub()) + startButton->Enable(); + else + startButton->Disable(); +} diff --git a/src/toolbars/EditToolBar.h b/src/toolbars/EditToolBar.h index b39b8a3ce..6198660ff 100644 --- a/src/toolbars/EditToolBar.h +++ b/src/toolbars/EditToolBar.h @@ -97,5 +97,66 @@ class EditToolBar final : public ToolBar { DECLARE_EVENT_TABLE(); }; +// PRL: to do: move this to its own file + +#include + +#include "ToolBar.h" +#include "../Theme.h" +#include "../Experimental.h" + +class wxCommandEvent; +class wxDC; +class wxImage; +class wxWindow; + +class AButton; + +enum { + STBStartID, + STBScrubID, + STBSeekID, + + STBNumButtons +}; + +class ScrubbingToolBar final : public ToolBar { + +public: + + ScrubbingToolBar(); + virtual ~ScrubbingToolBar(); + + void Create(wxWindow *parent); + + void OnButton(wxCommandEvent & event); + + void Populate(); + void Repaint(wxDC * WXUNUSED(dc)) {}; + void EnableDisableButtons(); + void UpdatePrefs(); + +private: + + AButton *AddButton(teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, + int id, const wxChar *label, bool toggle = false); + + void MakeButtons(); + + void RegenerateTooltips(); + + AButton *mButtons[STBNumButtons]; + + wxImage *upImage; + wxImage *downImage; + wxImage *hiliteImage; + +public: + + DECLARE_CLASS(EditToolBar); + DECLARE_EVENT_TABLE(); +}; + + #endif diff --git a/src/toolbars/ToolBar.h b/src/toolbars/ToolBar.h index 37a94b892..340da44de 100644 --- a/src/toolbars/ToolBar.h +++ b/src/toolbars/ToolBar.h @@ -71,6 +71,7 @@ enum MixerBarID, EditBarID, TranscriptionBarID, + ScrubbingBarID, DeviceBarID, SelectionBarID, #ifdef EXPERIMENTAL_SPECTRAL_EDITING diff --git a/src/toolbars/ToolManager.cpp b/src/toolbars/ToolManager.cpp index 1cc1f1c19..12f0acb41 100644 --- a/src/toolbars/ToolManager.cpp +++ b/src/toolbars/ToolManager.cpp @@ -448,6 +448,7 @@ ToolManager::ToolManager( AudacityProject *parent ) #ifdef EXPERIMENTAL_SPECTRAL_EDITING mBars[SpectralSelectionBarID] = new SpectralSelectionBar(); #endif + mBars[ ScrubbingBarID ] = new ScrubbingToolBar(); // We own the timer mTimer.SetOwner( this ); diff --git a/src/tracks/ui/Scrubbing.cpp b/src/tracks/ui/Scrubbing.cpp index 54a91e2fd..7f1397c5a 100644 --- a/src/tracks/ui/Scrubbing.cpp +++ b/src/tracks/ui/Scrubbing.cpp @@ -854,18 +854,23 @@ bool Scrubber::CanScrub() const void Scrubber::AddMenuItems() { auto cm = mProject->GetCommandManager(); - auto flags = cm->GetDefaultFlags() | WaveTracksExistFlag; - auto mask = cm->GetDefaultMask() | WaveTracksExistFlag; + auto flag = WaveTracksExistFlag; + auto flags = cm->GetDefaultFlags() | flag; + auto mask = cm->GetDefaultMask() | flag; cm->BeginSubMenu(_("Scru&bbing")); for (const auto &item : menuItems) { if (!item.GetStatus().empty()) cm->AddCheck(item.name, wxGetTranslation(item.label), FNT(Scrubber, this, item.memFn), - false, flags, mask); + false, + // Less restricted: + AlwaysEnabledFlag, AlwaysEnabledFlag); else + // The start item cm->AddItem(item.name, wxGetTranslation(item.label), FNT(Scrubber, this, item.memFn), + // More restricted: flags, mask); } cm->EndSubMenu(); diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 265f1a078..bed7b01ae 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -1920,8 +1920,6 @@ enum { OnLockPlayRegionID, OnTogglePinnedStateID, - OnScrubID, - OnSeekID, }; BEGIN_EVENT_TABLE(AdornedRulerPanel, OverlayPanel) @@ -1943,12 +1941,6 @@ BEGIN_EVENT_TABLE(AdornedRulerPanel, OverlayPanel) EVT_COMMAND( OnTogglePinnedStateID, wxEVT_COMMAND_BUTTON_CLICKED, AdornedRulerPanel::OnTogglePinnedState ) - EVT_COMMAND( OnScrubID, - wxEVT_COMMAND_BUTTON_CLICKED, - AdornedRulerPanel::OnScrub ) - EVT_COMMAND( OnSeekID, - wxEVT_COMMAND_BUTTON_CLICKED, - AdornedRulerPanel::OnSeek ) END_EVENT_TABLE() @@ -2117,8 +2109,6 @@ void AdornedRulerPanel::ReCreateButtons() bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredHiliteSmall, bmpUnpinnedPlayRecordHead, bmpUnpinnedPlayRecordHead, bmpUnpinnedPlayRecordHead, size); - buttonMaker(OnScrubID, bmpScrub, true); - buttonMaker(OnSeekID, bmpSeek, true); UpdateButtonStates(); } @@ -2180,7 +2170,10 @@ void AdornedRulerPanel::RegenerateTooltips(StatusChoice choice) } break; case StatusChoice::EnteringScrubZone : - this->SetToolTip(ScrubbingMessage(mProject->GetScrubber())); + { + const auto message = ScrubbingMessage(mProject->GetScrubber()); + this->SetToolTip(message); + } break; default: this->SetToolTip(NULL); @@ -2825,30 +2818,6 @@ void AdornedRulerPanel::UpdateButtonStates() auto &scrubber = mProject->GetScrubber(); - { - const auto scrubButton = static_cast(FindWindow(OnScrubID)); - /* i18n-hint: These commands assist the user in finding a sound by ear. ... - "Scrubbing" is variable-speed playback - */ - common(scrubButton, wxT("Scrub"), _("Scrub")); - if (scrubber.Scrubs()) - scrubButton->PushDown(); - else - scrubButton->PopUp(); - } - - { - const auto seekButton = static_cast(FindWindow(OnSeekID)); - /* i18n-hint: These commands assist the user in finding a sound by ear. ... - "Seeking" is normal speed playback but with skips - */ - common(seekButton, wxT("Seek"), _("Seek")); - if (scrubber.Seeks()) - seekButton->PushDown(); - else - seekButton->PopUp(); - } - if(mShowScrubbing != (scrubber.Scrubs() || scrubber.Seeks())) OnToggleScrubbing(); } @@ -2859,16 +2828,6 @@ void AdornedRulerPanel::OnTogglePinnedState(wxCommandEvent & event) UpdateButtonStates(); } -void AdornedRulerPanel::OnSeek(wxCommandEvent & event) -{ - mProject->GetScrubber().OnSeek(event); -} - -void AdornedRulerPanel::OnScrub(wxCommandEvent & event) -{ - mProject->GetScrubber().OnScrub(event); -} - void AdornedRulerPanel::OnCaptureLost(wxMouseCaptureLostEvent & WXUNUSED(evt)) { HideQuickPlayIndicator(); diff --git a/src/widgets/Ruler.h b/src/widgets/Ruler.h index 5f6635834..6a6786f6a 100644 --- a/src/widgets/Ruler.h +++ b/src/widgets/Ruler.h @@ -414,8 +414,6 @@ private: void OnLockPlayRegion(wxCommandEvent &evt); void OnToggleScrubbing(/*wxCommandEvent&*/); - void OnScrub(wxCommandEvent&); - void OnSeek(wxCommandEvent&); void OnContextMenu(wxContextMenuEvent & WXUNUSED(event));