1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-06 14:52:34 +02:00

Vary status string (leftmost in the status bar) for the four kinds of scrub.

This commit is contained in:
Paul Licameli 2016-04-24 15:13:03 -04:00
parent 0d5a409e9a
commit 6147705199
4 changed files with 69 additions and 32 deletions

View File

@ -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())

View File

@ -158,7 +158,6 @@ class ControlToolBar final : public ToolBar {
// strings for status bar
wxString mStatePlay;
wxString mStateScrub;
wxString mStateStop;
wxString mStateRecord;
wxString mStatePause;

View File

@ -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<wxString> Scrubber::GetAllUntranslatedStatusStrings()
{
using namespace std;
vector<wxString> 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);
}
}

View File

@ -11,6 +11,7 @@ Paul Licameli split from TrackPanel.cpp
#ifndef __AUDACITY_SCRUBBING__
#define __AUDACITY_SCRUBBING__
#include <vector>
#include <wx/event.h>
#include <wx/longlong.h>
@ -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<wxString> GetAllUntranslatedStatusStrings();
private:
void DoScrub(bool scroll, bool seek);
void OnActivateOrDeactivateApp(wxActivateEvent & event);