1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-25 16:48:44 +02:00

Scrub bar no longer has separate start/stop; tooltips mention keys

This commit is contained in:
Paul Licameli 2016-06-15 23:40:37 -04:00
commit 801724a852
5 changed files with 103 additions and 78 deletions

View File

@ -69,6 +69,7 @@
#include "../tracks/ui/Scrubbing.h" #include "../tracks/ui/Scrubbing.h"
#include "../prefs/PlaybackPrefs.h" #include "../prefs/PlaybackPrefs.h"
#include "../toolbars/ToolManager.h"
IMPLEMENT_CLASS(ControlToolBar, ToolBar); IMPLEMENT_CLASS(ControlToolBar, ToolBar);
@ -831,6 +832,9 @@ void ControlToolBar::StopPlaying(bool stopStream /* = true*/)
meter->Clear(); meter->Clear();
} }
} }
const auto toolbar = project->GetToolManager()->GetToolBar(ScrubbingBarID);
toolbar->EnableDisableButtons();
} }
void ControlToolBar::Pause() void ControlToolBar::Pause()

View File

@ -389,8 +389,8 @@ IMPLEMENT_CLASS(ScrubbingToolBar, ToolBar);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar ) BEGIN_EVENT_TABLE( ScrubbingToolBar, ToolBar )
EVT_COMMAND_RANGE( STBStartID, EVT_COMMAND_RANGE( STBFirstButton,
STBStartID + STBNumButtons - 1, STBFirstButton + STBNumButtons - 1,
wxEVT_COMMAND_BUTTON_CLICKED, wxEVT_COMMAND_BUTTON_CLICKED,
ScrubbingToolBar::OnButton ) ScrubbingToolBar::OnButton )
END_EVENT_TABLE() END_EVENT_TABLE()
@ -444,8 +444,6 @@ void ScrubbingToolBar::Populate()
MakeButtonBackgroundsSmall(); MakeButtonBackgroundsSmall();
/* Buttons */ /* Buttons */
AddButton(bmpPlay, bmpStop, bmpPlayDisabled, STBStartID,
_("Start scrubbing"), true);
AddButton(bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID, AddButton(bmpScrub, bmpScrub, bmpScrubDisabled, STBScrubID,
_("Scrub"), true); _("Scrub"), true);
AddButton(bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID, AddButton(bmpSeek, bmpSeek, bmpSeekDisabled, STBSeekID,
@ -472,30 +470,53 @@ void ScrubbingToolBar::UpdatePrefs()
void ScrubbingToolBar::RegenerateTooltips() void ScrubbingToolBar::RegenerateTooltips()
{ {
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
std::vector<wxString> 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();
const auto scrubButton = mButtons[STBScrubID];
const auto seekButton = mButtons[STBSeekID];
wxString label;
label = (
scrubber.Scrubs()
/* i18n-hint: These commands assist the user in finding a sound by ear. ... /* i18n-hint: These commands assist the user in finding a sound by ear. ...
"Scrubbing" is variable-speed playback, ... "Scrubbing" is variable-speed playback, ...
"Seeking" is normal speed playback but with skips "Seeking" is normal speed playback but with skips
*/ */
auto project = GetActiveProject(); ? _("Stop Scrubbing")
if (project) { : _("Start Scrubbing")
auto startStop = mButtons[STBStartID]; );
auto &scrubber = project->GetScrubber(); fn(*scrubButton, label, wxT("Scrub"));
if(scrubber.HasStartedScrubbing() || scrubber.IsScrubbing()) {
if (scrubber.Seeks()) label = (
startStop->SetToolTip(_("Stop seeking")); scrubber.Seeks()
else /* i18n-hint: These commands assist the user in finding a sound by ear. ...
startStop->SetToolTip(_("Stop scrubbing")); "Scrubbing" is variable-speed playback, ...
"Seeking" is normal speed playback but with skips
*/
? _("Stop Seeking")
: _("Start Seeking")
);
fn(*seekButton, label, wxT("Seek"));
label = (
project->GetRulerPanel()->ShowingScrubBar()
? _("Hide Scrub Bar")
: _("Show Scrub Bar")
);
fn(*mButtons[STBBarID], label, wxT("ToggleScrubBar"));
} }
else {
if (scrubber.Seeks())
startStop->SetToolTip(_("Start seeking"));
else
startStop->SetToolTip(_("Start scrubbing"));
}
}
mButtons[STBScrubID]->SetToolTip(_("Scrub"));
mButtons[STBSeekID]->SetToolTip(_("Seek"));
mButtons[STBBarID]->SetToolTip(_("Scrub bar"));
#endif #endif
} }
@ -508,9 +529,6 @@ void ScrubbingToolBar::OnButton(wxCommandEvent &event)
int id = event.GetId(); int id = event.GetId();
switch (id) { switch (id) {
case STBStartID:
scrubber.OnStartStop(event);
break;
case STBScrubID: case STBScrubID:
scrubber.OnScrub(event); scrubber.OnScrub(event);
break; break;
@ -538,25 +556,36 @@ void ScrubbingToolBar::EnableDisableButtons()
if (!p) return; if (!p) return;
auto &scrubber = p->GetScrubber(); auto &scrubber = p->GetScrubber();
if (scrubber.Scrubs()) const auto canScrub = scrubber.CanScrub();
if (scrubber.Scrubs()) {
scrubButton->PushDown(); scrubButton->PushDown();
else scrubButton->Enable();
scrubButton->PopUp(); }
else {
if (scrubber.Seeks()) scrubButton->PopUp();
seekButton->PushDown(); if (canScrub)
else scrubButton->Enable();
seekButton->PopUp(); else
scrubButton->Disable();
const auto startButton = mButtons[STBStartID]; }
if (scrubber.CanScrub())
startButton->Enable(); if (scrubber.Seeks()) {
else seekButton->PushDown();
startButton->Disable(); seekButton->Enable();
}
mButtons[STBBarID]->Enable(); else {
if (p->GetRulerPanel()->ShowingScrubBar()) seekButton->PopUp();
mButtons[STBBarID]->PushDown(); if (canScrub)
else seekButton->Enable();
mButtons[STBBarID]->PopUp(); else
seekButton->Disable();
}
const auto barButton = mButtons[STBBarID];
barButton->Enable();
if (p->GetRulerPanel()->ShowingScrubBar())
barButton->PushDown();
else
barButton->PopUp();
} }

View File

@ -113,12 +113,12 @@ class wxWindow;
class AButton; class AButton;
enum { enum {
STBStartID,
STBScrubID, STBScrubID,
STBSeekID, STBSeekID,
STBBarID, STBBarID,
STBNumButtons STBNumButtons,
STBFirstButton = STBScrubID
}; };
class ScrubbingToolBar final : public ToolBar { class ScrubbingToolBar final : public ToolBar {

View File

@ -229,18 +229,13 @@ namespace {
"Seeking" is normal speed playback but with skips, ... "Seeking" is normal speed playback but with skips, ...
*/ */
{ wxT("Scrub"), XO("&Scrub"), XO("Scrubbing"), { wxT("Scrub"), XO("&Scrub"), XO("Scrubbing"),
AlwaysEnabledFlag, CanStopAudioStreamFlag,
&Scrubber::OnScrub, false, &Scrubber::Scrubs, &Scrubber::OnScrub, false, &Scrubber::Scrubs,
}, },
{ wxT("Seek"), XO("See&k"), XO("Seeking"), { wxT("Seek"), XO("See&k"), XO("Seeking"),
AlwaysEnabledFlag,
&Scrubber::OnSeek, true, &Scrubber::Seeks,
},
{ wxT("StartStopScrubSeek"), XO("Star&t/Stop"), XO(""),
CanStopAudioStreamFlag, CanStopAudioStreamFlag,
&Scrubber::OnStartStop, true, nullptr &Scrubber::OnSeek, true, &Scrubber::Seeks,
}, },
{ wxT("ToggleScrubBar"), XO("Scrub Bar"), XO(""), { 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) inline const MenuItem &FindMenuItem(bool seek)
{ {
@ -535,7 +530,8 @@ bool Scrubber::IsScrubbing() const
{ {
if (mScrubToken <= 0) if (mScrubToken <= 0)
return false; return false;
else if (mScrubToken == mProject->GetAudioIOToken()) else if (mScrubToken == mProject->GetAudioIOToken() &&
mProject->IsAudioActive())
return true; return true;
else { else {
const_cast<Scrubber&>(*this).mScrubToken = -1; const_cast<Scrubber&>(*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() bool Scrubber::ShouldDrawScrubSpeed()
{ {
if (mDragging) if (mDragging)
@ -800,11 +806,9 @@ void Scrubber::DoScrub()
mProject->GetControlToolBar()->StopPlaying(); mProject->GetControlToolBar()->StopPlaying();
} }
void Scrubber::OnScrubOrSeek(bool &toToggle, bool &other) void Scrubber::OnScrubOrSeek(bool seek)
{ {
toToggle = !toToggle; mSeeking = seek;
if (toToggle)
other = false;
if (HasStartedScrubbing()) { if (HasStartedScrubbing()) {
// Show the correct status. // Show the correct status.
@ -821,22 +825,19 @@ void Scrubber::OnScrubOrSeek(bool &toToggle, bool &other)
scrubbingToolBar->EnableDisableButtons(); scrubbingToolBar->EnableDisableButtons();
scrubbingToolBar->RegenerateTooltips(); scrubbingToolBar->RegenerateTooltips();
DoScrub();
CheckMenuItems(); CheckMenuItems();
} }
void Scrubber::OnScrub(wxCommandEvent&) void Scrubber::OnScrub(wxCommandEvent&)
{ {
OnScrubOrSeek(mScrubbing, mSeeking); OnScrubOrSeek(false);
} }
void Scrubber::OnSeek(wxCommandEvent&) void Scrubber::OnSeek(wxCommandEvent&)
{ {
OnScrubOrSeek(mSeeking, mScrubbing); OnScrubOrSeek(true);
}
void Scrubber::OnStartStop(wxCommandEvent&)
{
DoScrub();
} }
void Scrubber::OnToggleScrubBar(wxCommandEvent&) void Scrubber::OnToggleScrubBar(wxCommandEvent&)
@ -852,15 +853,14 @@ enum { CMD_ID = 8000 };
BEGIN_EVENT_TABLE(Scrubber, wxEvtHandler) BEGIN_EVENT_TABLE(Scrubber, wxEvtHandler)
EVT_MENU(CMD_ID, Scrubber::OnScrub) EVT_MENU(CMD_ID, Scrubber::OnScrub)
EVT_MENU(CMD_ID + 1, Scrubber::OnSeek) EVT_MENU(CMD_ID + 1, Scrubber::OnSeek)
EVT_MENU(CMD_ID + 2, Scrubber::OnStartStop) EVT_MENU(CMD_ID + 2, Scrubber::OnToggleScrubBar)
EVT_MENU(CMD_ID + 3, Scrubber::OnToggleScrubBar)
END_EVENT_TABLE() END_EVENT_TABLE()
BEGIN_EVENT_TABLE(Scrubber::Forwarder, wxEvtHandler) BEGIN_EVENT_TABLE(Scrubber::Forwarder, wxEvtHandler)
EVT_MOUSE_EVENTS(Scrubber::Forwarder::OnMouse) EVT_MOUSE_EVENTS(Scrubber::Forwarder::OnMouse)
END_EVENT_TABLE() END_EVENT_TABLE()
static_assert(nMenuItems == 4, "wrong number of items"); static_assert(nMenuItems == 3, "wrong number of items");
const wxString &Scrubber::GetUntranslatedStateString() const 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. // Return the enabled state for the menu item that really launches the scrub or seek.
auto cm = mProject->GetCommandManager(); auto cm = mProject->GetCommandManager();
return cm->GetEnabled(menuItems[StartMenuItem].name); return cm->GetEnabled(menuItems[ 0 ].name);
} }
void Scrubber::AddMenuItems() void Scrubber::AddMenuItems()

View File

@ -97,12 +97,8 @@ public:
void SetScrollScrubbing(bool value) void SetScrollScrubbing(bool value)
{ mSmoothScrollingScrub = value; } { mSmoothScrollingScrub = value; }
bool Seeks() const bool Seeks() const;
{ return mSeeking; } bool Scrubs() const;
bool Scrubs() const
{ return mScrubbing; }
bool ShowsBar() const; bool ShowsBar() const;
void Cancel() void Cancel()
@ -122,10 +118,9 @@ public:
// For popup // For popup
void PopulatePopupMenu(wxMenu &menu); void PopulatePopupMenu(wxMenu &menu);
void OnScrubOrSeek(bool &toToggle, bool &other); void OnScrubOrSeek(bool seek);
void OnScrub(wxCommandEvent&); void OnScrub(wxCommandEvent&);
void OnSeek(wxCommandEvent&); void OnSeek(wxCommandEvent&);
void OnStartStop(wxCommandEvent&);
void OnToggleScrubBar(wxCommandEvent&); void OnToggleScrubBar(wxCommandEvent&);
// A string to put in the leftmost part of the status bar // A string to put in the leftmost part of the status bar
@ -163,9 +158,6 @@ private:
wxCoord mLastScrubPosition {}; wxCoord mLastScrubPosition {};
bool mSmoothScrollingScrub; 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 mSeeking {};
bool mDragging {}; bool mDragging {};