1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-25 08:38:39 +02:00

Transport status message, buttons, scrolling update in idle time...

... so the functions that start and stop streams don't really need the
ControlToolBar object.

This also makes the intended momentary push-down of the Stop button visible,
as was apparently intended, when playback stops for other reasons than a
click on that button.
This commit is contained in:
Paul Licameli 2019-07-01 17:28:59 -04:00
commit 73fb2a2a82
7 changed files with 181 additions and 192 deletions

View File

@ -192,6 +192,27 @@ void ProjectAudioManager::OnSoundActivationThreshold()
} }
} }
bool ProjectAudioManager::Playing() const
{
auto gAudioIO = AudioIO::Get();
return
gAudioIO->IsBusy() &&
ControlToolBar::Get( mProject ).CanStopAudioStream() &&
// ... and not merely monitoring
!gAudioIO->IsMonitoring() &&
// ... and not punch-and-roll recording
gAudioIO->GetNumCaptureChannels() == 0;
}
bool ProjectAudioManager::Recording() const
{
auto gAudioIO = AudioIO::Get();
return
gAudioIO->IsBusy() &&
ControlToolBar::Get( mProject).CanStopAudioStream() &&
gAudioIO->GetNumCaptureChannels() > 0;
}
AudioIOStartStreamOptions AudioIOStartStreamOptions
DefaultPlayOptions( AudacityProject &project ) DefaultPlayOptions( AudacityProject &project )
{ {
@ -256,8 +277,7 @@ bool DoPlayStopSelect
//If busy, stop playing, make sure everything is unpaused. //If busy, stop playing, make sure everything is unpaused.
if (scrubber.HasMark() || if (scrubber.HasMark() ||
gAudioIO->IsStreamActive(token)) { gAudioIO->IsStreamActive(token)) {
toolbar.SetPlay(false); //Pops toolbar.SetStop(); //Pushes stop down
toolbar.SetStop(true); //Pushes stop down
// change the selection // change the selection
auto time = gAudioIO->GetStreamTime(); auto time = gAudioIO->GetStreamTime();
@ -312,8 +332,6 @@ void DoPlayStopSelect(AudacityProject &project)
toolbar.OnStop(evt); toolbar.OnStop(evt);
else if (!gAudioIO->IsBusy()) { else if (!gAudioIO->IsBusy()) {
//Otherwise, start playing (assuming audio I/O isn't busy) //Otherwise, start playing (assuming audio I/O isn't busy)
//toolbar->SetPlay(true); // Not needed as set in PlayPlayRegion()
toolbar.SetStop(false);
// Will automatically set mLastPlayMode // Will automatically set mLastPlayMode
toolbar.PlayCurrentRegion(false); toolbar.PlayCurrentRegion(false);
@ -330,11 +348,8 @@ void DoPause( AudacityProject &project )
void DoRecord( AudacityProject &project ) void DoRecord( AudacityProject &project )
{ {
wxCommandEvent evt;
evt.SetInt(2); // 0 is default, use 1 to set shift on, 2 to clear it
auto &controlToolBar = ControlToolBar::Get( project ); auto &controlToolBar = ControlToolBar::Get( project );
controlToolBar.OnRecord(evt); controlToolBar.OnRecord(false);
} }
void DoLockPlayRegion( AudacityProject &project ) void DoLockPlayRegion( AudacityProject &project )
@ -369,11 +384,6 @@ void DoTogglePinnedHead( AudacityProject &project )
TracksPrefs::SetPinnedHeadPreference(value, true); TracksPrefs::SetPinnedHeadPreference(value, true);
MenuManager::ModifyAllProjectToolbarMenus(); MenuManager::ModifyAllProjectToolbarMenus();
// Change what happens in case transport is in progress right now
auto ctb = ControlToolBar::Find( *GetActiveProject() );
if (ctb)
ctb->StartScrollingIfPreferred();
auto &ruler = AdornedRulerPanel::Get( project ); auto &ruler = AdornedRulerPanel::Get( project );
// Update button image // Update button image
ruler.UpdateButtonStates(); ruler.UpdateButtonStates();

View File

@ -35,6 +35,27 @@ public:
void SetTimerRecordCancelled() { mTimerRecordCanceled = true; } void SetTimerRecordCancelled() { mTimerRecordCanceled = true; }
void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; } void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; }
bool Paused() const { return mPaused; }
bool Playing() const;
// Whether recording into this project (not just into some project) is
// active
bool Recording() const;
bool Stopping() const { return mStopping; }
// Whether the last attempt to start recording requested appending to tracks
bool Appending() const { return mAppending; }
bool Looping() const { return mLooping; }
bool Cutting() const { return mCutting; }
void SetPaused( bool value ) { mPaused = value; }
void SetAppending( bool value ) { mAppending = value; }
void SetLooping( bool value ) { mLooping = value; }
void SetCutting( bool value ) { mCutting = value; }
void SetStopping( bool value ) { mStopping = value; }
private: private:
// Audio IO callback methods // Audio IO callback methods
void OnAudioIORate(int rate) override; void OnAudioIORate(int rate) override;
@ -48,6 +69,12 @@ private:
//flag for cancellation of timer record. //flag for cancellation of timer record.
bool mTimerRecordCanceled{ false }; bool mTimerRecordCanceled{ false };
bool mPaused{ false };
bool mAppending{ false };
bool mLooping{ false };
bool mCutting{ false };
bool mStopping{ false };
}; };
AudioIOStartStreamOptions DefaultPlayOptions( AudacityProject &project ); AudioIOStartStreamOptions DefaultPlayOptions( AudacityProject &project );

View File

@ -822,7 +822,6 @@ void ProjectWindow::Init()
wxString msg = wxString::Format(_("Welcome to Audacity version %s"), wxString msg = wxString::Format(_("Welcome to Audacity version %s"),
AUDACITY_VERSION_STRING); AUDACITY_VERSION_STRING);
statusBar->SetStatusText(msg, mainStatusBarField); statusBar->SetStatusText(msg, mainStatusBarField);
ControlToolBar::Get( project ).UpdateStatusBar( &project );
wxTheApp->Bind(EVT_THEME_CHANGE, &ProjectWindow::OnThemeChange, this); wxTheApp->Bind(EVT_THEME_CHANGE, &ProjectWindow::OnThemeChange, this);

View File

@ -42,8 +42,7 @@ namespace {
/// and pops the play button up. Then, if nothing is now /// and pops the play button up. Then, if nothing is now
/// playing, it pushes the play button down and enables /// playing, it pushes the play button down and enables
/// the stop button. /// the stop button.
bool MakeReadyToPlay(AudacityProject &project, bool MakeReadyToPlay(AudacityProject &project)
bool loop = false, bool cutpreview = false)
{ {
auto &toolbar = ControlToolBar::Get( project ); auto &toolbar = ControlToolBar::Get( project );
wxCommandEvent evt; wxCommandEvent evt;
@ -53,8 +52,9 @@ bool MakeReadyToPlay(AudacityProject &project,
if (gAudioIO->IsStreamActive( if (gAudioIO->IsStreamActive(
ProjectAudioIO::Get( project ).GetAudioIOToken() ProjectAudioIO::Get( project ).GetAudioIOToken()
)) { )) {
// Make momentary changes of button appearances
toolbar.SetPlay(false); //Pops toolbar.SetPlay(false); //Pops
toolbar.SetStop(true); //Pushes stop down toolbar.SetStop(); //Pushes stop down
toolbar.OnStop(evt); toolbar.OnStop(evt);
::wxMilliSleep(100); ::wxMilliSleep(100);
@ -65,13 +65,6 @@ bool MakeReadyToPlay(AudacityProject &project,
if (gAudioIO->IsBusy()) if (gAudioIO->IsBusy())
return false; return false;
ControlToolBar::PlayAppearance appearance =
cutpreview ? ControlToolBar::PlayAppearance::CutPreview
: loop ? ControlToolBar::PlayAppearance::Looped
: ControlToolBar::PlayAppearance::Straight;
toolbar.SetPlay(true, appearance);
toolbar.SetStop(false);
return true; return true;
} }
@ -97,8 +90,7 @@ void DoPlayStop(const CommandContext &context)
//If this project is playing, stop playing, make sure everything is unpaused. //If this project is playing, stop playing, make sure everything is unpaused.
auto gAudioIO = AudioIOBase::Get(); auto gAudioIO = AudioIOBase::Get();
if (gAudioIO->IsStreamActive(token)) { if (gAudioIO->IsStreamActive(token)) {
toolbar.SetPlay(false); //Pops toolbar.SetStop(); //Pushes stop down
toolbar.SetStop(true); //Pushes stop down
toolbar.StopPlaying(); toolbar.StopPlaying();
} }
else if (gAudioIO->IsStreamActive()) { else if (gAudioIO->IsStreamActive()) {
@ -116,8 +108,7 @@ void DoPlayStop(const CommandContext &context)
if(iter != finish) { if(iter != finish) {
auto otherProject = *iter; auto otherProject = *iter;
auto &otherToolbar = ControlToolBar::Get( *otherProject ); auto &otherToolbar = ControlToolBar::Get( *otherProject );
otherToolbar.SetPlay(false); //Pops otherToolbar.SetStop(); //Pushes stop down
otherToolbar.SetStop(true); //Pushes stop down
otherToolbar.StopPlaying(); otherToolbar.StopPlaying();
} }
@ -126,8 +117,6 @@ void DoPlayStop(const CommandContext &context)
//update the playing area //update the playing area
window.TP_DisplaySelection(); window.TP_DisplaySelection();
//Otherwise, start playing (assuming audio I/O isn't busy) //Otherwise, start playing (assuming audio I/O isn't busy)
//toolbar->SetPlay(true); // Not needed as done in PlayPlayRegion.
toolbar.SetStop(false);
// Will automatically set mLastPlayMode // Will automatically set mLastPlayMode
toolbar.PlayCurrentRegion(false); toolbar.PlayCurrentRegion(false);
@ -135,8 +124,6 @@ void DoPlayStop(const CommandContext &context)
} }
else if (!gAudioIO->IsBusy()) { else if (!gAudioIO->IsBusy()) {
//Otherwise, start playing (assuming audio I/O isn't busy) //Otherwise, start playing (assuming audio I/O isn't busy)
//toolbar->SetPlay(true); // Not needed as done in PlayPlayRegion.
toolbar.SetStop(false);
// Will automatically set mLastPlayMode // Will automatically set mLastPlayMode
toolbar.PlayCurrentRegion(false); toolbar.PlayCurrentRegion(false);
@ -223,7 +210,7 @@ void OnPlayLooped(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
if( !MakeReadyToPlay(project, true) ) if( !MakeReadyToPlay(project) )
return; return;
// Now play in a loop // Now play in a loop
@ -247,11 +234,8 @@ void OnRecord(const CommandContext &context)
void OnRecord2ndChoice(const CommandContext &context) void OnRecord2ndChoice(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
wxCommandEvent evt;
evt.SetInt(1); // 0 is default, use 1 to set shift on, 2 to clear it
auto &controlToolBar = ControlToolBar::Get( project ); auto &controlToolBar = ControlToolBar::Get( project );
controlToolBar.OnRecord(evt); controlToolBar.OnRecord(true);
} }
void OnTimerRecord(const CommandContext &context) void OnTimerRecord(const CommandContext &context)
@ -793,7 +777,7 @@ void OnPlayCutPreview(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
if ( !MakeReadyToPlay(project, false, true) ) if ( !MakeReadyToPlay(project) )
return; return;
// Play with cut preview // Play with cut preview

View File

@ -99,6 +99,7 @@ BEGIN_EVENT_TABLE(ControlToolBar, ToolBar)
EVT_BUTTON(ID_REW_BUTTON, ControlToolBar::OnRewind) EVT_BUTTON(ID_REW_BUTTON, ControlToolBar::OnRewind)
EVT_BUTTON(ID_FF_BUTTON, ControlToolBar::OnFF) EVT_BUTTON(ID_FF_BUTTON, ControlToolBar::OnFF)
EVT_BUTTON(ID_PAUSE_BUTTON, ControlToolBar::OnPause) EVT_BUTTON(ID_PAUSE_BUTTON, ControlToolBar::OnPause)
EVT_IDLE(ControlToolBar::OnIdle)
END_EVENT_TABLE() END_EVENT_TABLE()
//Standard constructor //Standard constructor
@ -109,8 +110,6 @@ END_EVENT_TABLE()
ControlToolBar::ControlToolBar( AudacityProject &project ) ControlToolBar::ControlToolBar( AudacityProject &project )
: ToolBar(project, TransportBarID, _("Transport"), wxT("Control")) : ToolBar(project, TransportBarID, _("Transport"), wxT("Control"))
{ {
mPaused = false;
gPrefs->Read(wxT("/GUI/ErgonomicTransportButtons"), &mErgonomicTransportButtons, true); gPrefs->Read(wxT("/GUI/ErgonomicTransportButtons"), &mErgonomicTransportButtons, true);
mStrLocale = gPrefs->Read(wxT("/Locale/Language"), wxT("")); mStrLocale = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
@ -456,7 +455,8 @@ void ControlToolBar::ReCreateButtons()
if (recordDown) if (recordDown)
{ {
SetRecord(recordDown, recordShift); mRecord->SetAlternateIdx(recordShift ? 1 : 0);
mRecord->PushDown();
} }
EnableDisableButtons(); EnableDisableButtons();
@ -495,8 +495,8 @@ void ControlToolBar::EnableDisableButtons()
!(playing && !paused) !(playing && !paused)
); );
mStop->SetEnabled(CanStopAudioStream() && (playing || recording)); mStop->SetEnabled(CanStopAudioStream() && (playing || recording));
mRewind->SetEnabled(IsPauseDown() || (!playing && !recording)); mRewind->SetEnabled(paused || (!playing && !recording));
mFF->SetEnabled(tracks && (IsPauseDown() || (!playing && !recording))); mFF->SetEnabled(tracks && (paused || (!playing && !recording)));
mPause->SetEnabled(CanStopAudioStream()); mPause->SetEnabled(CanStopAudioStream());
} }
@ -514,46 +514,14 @@ void ControlToolBar::SetPlay(bool down, PlayAppearance appearance)
mPlay->SetAlternateIdx(0); mPlay->SetAlternateIdx(0);
} }
EnableDisableButtons(); EnableDisableButtons();
UpdateStatusBar( &mProject );
} }
void ControlToolBar::SetStop(bool down) void ControlToolBar::SetStop()
{ {
if (down) mStop->PushDown();
mStop->PushDown();
else {
if(FindFocus() == mStop)
mPlay->SetFocus();
mStop->PopUp();
}
EnableDisableButtons(); EnableDisableButtons();
} }
void ControlToolBar::SetRecord(bool down, bool altAppearance)
{
if (down)
{
mRecord->SetAlternateIdx(altAppearance ? 1 : 0);
mRecord->PushDown();
}
else
{
mRecord->SetAlternateIdx(0);
mRecord->PopUp();
}
EnableDisableButtons();
}
bool ControlToolBar::IsPauseDown() const
{
return mPause->IsDown();
}
bool ControlToolBar::IsRecordDown() const
{
return mRecord->IsDown();
}
int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
const AudioIOStartStreamOptions &options, const AudioIOStartStreamOptions &options,
PlayMode mode, PlayMode mode,
@ -561,6 +529,8 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
bool playWhiteSpace /* = false */) bool playWhiteSpace /* = false */)
// STRONG-GUARANTEE (for state of mCutPreviewTracks) // STRONG-GUARANTEE (for state of mCutPreviewTracks)
{ {
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
if (!CanStopAudioStream()) if (!CanStopAudioStream())
return -1; return -1;
@ -582,27 +552,10 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
if (backwards) if (backwards)
std::swap(t0, t1); std::swap(t0, t1);
{ projectAudioManager.SetLooping( mode == PlayMode::loopedPlay );
PlayAppearance appearance; projectAudioManager.SetCutting( mode == PlayMode::cutPreviewPlay );
switch( mode ) {
case PlayMode::cutPreviewPlay:
appearance = PlayAppearance::CutPreview; break;
case PlayMode::loopedPlay:
appearance = PlayAppearance::Looped; break;
default:
appearance = PlayAppearance::Straight; break;
}
SetPlay(true, appearance);
}
bool success = false; bool success = false;
auto cleanup = finally( [&] {
if (!success) {
SetPlay(false);
SetStop(false);
SetRecord(false);
}
} );
auto gAudioIO = AudioIO::Get(); auto gAudioIO = AudioIO::Get();
if (gAudioIO->IsBusy()) if (gAudioIO->IsBusy())
@ -738,8 +691,6 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
if (!success) if (!success)
return -1; return -1;
StartScrollingIfPreferred();
return token; return token;
} }
@ -771,26 +722,28 @@ void ControlToolBar::PlayCurrentRegion(bool looped /* = false */,
void ControlToolBar::OnKeyEvent(wxKeyEvent & event) void ControlToolBar::OnKeyEvent(wxKeyEvent & event)
{ {
// PRL: is this handler really ever reached? Is the ControlToolBar ever
// focused? Isn't there a global event filter that interprets the spacebar
// key (or other key chosen in preferences) and dispatches to DoPlayStop,
// according to CommandManager's table, before we come to this redundant
// function?
if (event.ControlDown() || event.AltDown()) { if (event.ControlDown() || event.AltDown()) {
event.Skip(); event.Skip();
return; return;
} }
auto gAudioIO = AudioIOBase::Get(); auto gAudioIO = AudioIOBase::Get();
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
// Does not appear to be needed on Linux. Perhaps on some other platform? // Does not appear to be needed on Linux. Perhaps on some other platform?
// If so, "!CanStopAudioStream()" should probably apply. // If so, "!CanStopAudioStream()" should probably apply.
if (event.GetKeyCode() == WXK_SPACE) { if (event.GetKeyCode() == WXK_SPACE) {
if (gAudioIO->IsStreamActive( if ( projectAudioManager.Playing() || projectAudioManager.Recording() ) {
ProjectAudioIO::Get( mProject ).GetAudioIOToken() SetStop();
)) {
SetPlay(false);
SetStop(true);
StopPlaying(); StopPlaying();
} }
else if (!gAudioIO->IsBusy()) { else if (!gAudioIO->IsBusy()) {
//SetPlay(true);// Not needed as done in PlayPlayRegion
SetStop(false);
PlayCurrentRegion(); PlayCurrentRegion();
} }
return; return;
@ -810,7 +763,6 @@ void ControlToolBar::OnPlay(wxCommandEvent & WXUNUSED(evt))
if (p) if (p)
ProjectWindow::Get( *p ).TP_DisplaySelection(); ProjectWindow::Get( *p ).TP_DisplaySelection();
auto cleanup = finally( [&]{ UpdateStatusBar(p); } );
PlayDefault(); PlayDefault();
} }
@ -818,7 +770,6 @@ void ControlToolBar::OnStop(wxCommandEvent & WXUNUSED(evt))
{ {
if (CanStopAudioStream()) { if (CanStopAudioStream()) {
StopPlaying(); StopPlaying();
UpdateStatusBar( &mProject );
} }
} }
@ -841,9 +792,8 @@ void ControlToolBar::PlayDefault()
void ControlToolBar::StopPlaying(bool stopStream /* = true*/) void ControlToolBar::StopPlaying(bool stopStream /* = true*/)
{ {
StopScrolling();
AudacityProject *project = &mProject; AudacityProject *project = &mProject;
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
if(project) { if(project) {
// Let scrubbing code do some appearance change // Let scrubbing code do some appearance change
@ -854,24 +804,33 @@ void ControlToolBar::StopPlaying(bool stopStream /* = true*/)
if (!CanStopAudioStream()) if (!CanStopAudioStream())
return; return;
mStop->PushDown();
auto gAudioIO = AudioIO::Get(); auto gAudioIO = AudioIO::Get();
SetStop(false); auto cleanup = finally( [&]{
projectAudioManager.SetStopping( false );
} );
if (stopStream && gAudioIO->IsBusy()) {
// flag that we are stopping
projectAudioManager.SetStopping( true );
// Allow UI to update for that
while( wxTheApp->ProcessIdle() )
;
}
if(stopStream) if(stopStream)
gAudioIO->StopStream(); gAudioIO->StopStream();
SetPlay(false);
SetRecord(false); projectAudioManager.SetLooping( false );
projectAudioManager.SetCutting( false );
#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
gAudioIO->AILADisable(); gAudioIO->AILADisable();
#endif #endif
mPause->PopUp(); projectAudioManager.SetPaused( false );
mPaused=false;
//Make sure you tell gAudioIO to unpause //Make sure you tell gAudioIO to unpause
gAudioIO->SetPaused(mPaused); gAudioIO->SetPaused( false );
ClearCutPreviewTracks(); ClearCutPreviewTracks();
@ -987,19 +946,20 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
// Here instead we reduplicate some logic (from CommandHandler) because it isn't // Here instead we reduplicate some logic (from CommandHandler) because it isn't
// normally used for buttons. // normally used for buttons.
// Code from CommandHandler start...
AudacityProject *p = &mProject;
bool altAppearance = mRecord->WasShiftDown(); bool altAppearance = mRecord->WasShiftDown();
if (evt.GetInt() == 1) // used when called by keyboard shortcut. Default (0) ignored. OnRecord( altAppearance );
altAppearance = true; }
if (evt.GetInt() == 2)
altAppearance = false;
void ControlToolBar::OnRecord(bool altAppearance)
// STRONG-GUARANTEE (for state of current project's tracks)
{
bool bPreferNewTrack; bool bPreferNewTrack;
gPrefs->Read("/GUI/PreferNewTrackRecord", &bPreferNewTrack, false); gPrefs->Read("/GUI/PreferNewTrackRecord", &bPreferNewTrack, false);
const bool appendRecord = (altAppearance == bPreferNewTrack); const bool appendRecord = (altAppearance == bPreferNewTrack);
// Code from CommandHandler start...
AudacityProject *p = &mProject;
if (p) { if (p) {
const auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion; const auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
double t0 = selectedRegion.t0(); double t0 = selectedRegion.t0();
@ -1075,6 +1035,8 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
bool altAppearance, bool altAppearance,
const AudioIOStartStreamOptions &options) const AudioIOStartStreamOptions &options)
{ {
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
CommandFlag flags = AlwaysEnabledFlag; // 0 means recalc flags. CommandFlag flags = AlwaysEnabledFlag; // 0 means recalc flags.
// NB: The call may have the side effect of changing flags. // NB: The call may have the side effect of changing flags.
@ -1087,27 +1049,12 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
// ...end of code from CommandHandler. // ...end of code from CommandHandler.
auto gAudioIO = AudioIO::Get(); auto gAudioIO = AudioIO::Get();
if (gAudioIO->IsBusy()) { if (gAudioIO->IsBusy())
if (!CanStopAudioStream() || 0 == gAudioIO->GetNumCaptureChannels())
mRecord->PopUp();
else
mRecord->PushDown();
return false; return false;
}
SetRecord(true, altAppearance); projectAudioManager.SetAppending( !altAppearance );
bool success = false; bool success = false;
auto cleanup = finally([&] {
if (!success) {
SetPlay(false);
SetStop(false);
SetRecord(false);
}
// Success or not:
UpdateStatusBar( &mProject );
});
auto transportTracks = tracks; auto transportTracks = tracks;
@ -1259,8 +1206,6 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
if (success) { if (success) {
ProjectAudioIO::Get( *p ).SetAudioIOToken(token); ProjectAudioIO::Get( *p ).SetAudioIOToken(token);
mBusyProject = p; mBusyProject = p;
StartScrollingIfPreferred();
} }
else { else {
CancelRecording(); CancelRecording();
@ -1277,21 +1222,14 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
void ControlToolBar::OnPause(wxCommandEvent & WXUNUSED(evt)) void ControlToolBar::OnPause(wxCommandEvent & WXUNUSED(evt))
{ {
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
if (!CanStopAudioStream()) { if (!CanStopAudioStream()) {
return; return;
} }
bool paused = !projectAudioManager.Paused();
if(mPaused) projectAudioManager.SetPaused( paused );
{
mPause->PopUp();
mPaused=false;
}
else
{
mPause->PushDown();
mPaused=true;
}
auto gAudioIO = AudioIO::Get(); auto gAudioIO = AudioIO::Get();
@ -1302,7 +1240,7 @@ void ControlToolBar::OnPause(wxCommandEvent & WXUNUSED(evt))
// Bug 1494 - Pausing a seek or scrub should just STOP as // Bug 1494 - Pausing a seek or scrub should just STOP as
// it is confusing to be in a paused scrub state. // it is confusing to be in a paused scrub state.
bool bStopInstead = mPaused && bool bStopInstead = paused &&
gAudioIO->IsScrubbing() && gAudioIO->IsScrubbing() &&
!scrubber.IsSpeedPlaying(); !scrubber.IsSpeedPlaying();
@ -1313,14 +1251,69 @@ void ControlToolBar::OnPause(wxCommandEvent & WXUNUSED(evt))
} }
if (gAudioIO->IsScrubbing()) if (gAudioIO->IsScrubbing())
scrubber.Pause(mPaused); scrubber.Pause(paused);
else else
#endif #endif
{ {
gAudioIO->SetPaused(mPaused); gAudioIO->SetPaused(paused);
}
}
void ControlToolBar::OnIdle(wxIdleEvent & event)
{
event.Skip();
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
if ( projectAudioManager.Paused() )
mPause->PushDown();
else
mPause->PopUp();
bool recording = projectAudioManager.Recording();
if (!recording) {
mRecord->PopUp();
mRecord->SetAlternateIdx( wxGetKeyState(WXK_SHIFT) ? 1 : 0 );
}
else {
mRecord->PushDown();
mRecord->SetAlternateIdx( projectAudioManager.Appending() ? 0 : 1 );
} }
UpdateStatusBar( &mProject ); bool playing = projectAudioManager.Playing();
if ( !(playing || Scrubber::Get(mProject).HasMark()) ) {
mPlay->PopUp();
mPlay->SetAlternateIdx(
wxGetKeyState(WXK_CONTROL)
? 2
: wxGetKeyState(WXK_SHIFT)
? 1
: 0
);
}
else {
mPlay->PushDown();
mPlay->SetAlternateIdx(
projectAudioManager.Cutting()
? 2
: projectAudioManager.Looping()
? 1
: 0
);
}
if ( recording || playing )
StartScrollingIfPreferred();
else
StopScrolling();
if ( projectAudioManager.Stopping() )
mStop->PushDown();
else
// push-downs of the stop button are only momentary and always pop up now
mStop->PopUp();
UpdateStatusBar();
EnableDisableButtons();
} }
void ControlToolBar::OnRewind(wxCommandEvent & WXUNUSED(evt)) void ControlToolBar::OnRewind(wxCommandEvent & WXUNUSED(evt))
@ -1409,6 +1402,7 @@ int ControlToolBar::WidthForStatusBar(wxStatusBar* const sb)
wxString ControlToolBar::StateForStatusBar() wxString ControlToolBar::StateForStatusBar()
{ {
wxString state; wxString state;
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
auto pProject = &mProject; auto pProject = &mProject;
auto scrubState = pProject auto scrubState = pProject
@ -1418,7 +1412,7 @@ wxString ControlToolBar::StateForStatusBar()
state = wxGetTranslation(scrubState); state = wxGetTranslation(scrubState);
else if (mPlay->IsDown()) else if (mPlay->IsDown())
state = wxGetTranslation(mStatePlay); state = wxGetTranslation(mStatePlay);
else if (mRecord->IsDown()) else if (projectAudioManager.Recording())
state = wxGetTranslation(mStateRecord); state = wxGetTranslation(mStateRecord);
else else
state = wxGetTranslation(mStateStop); state = wxGetTranslation(mStateStop);
@ -1434,9 +1428,9 @@ wxString ControlToolBar::StateForStatusBar()
return state; return state;
} }
void ControlToolBar::UpdateStatusBar(AudacityProject *pProject) void ControlToolBar::UpdateStatusBar()
{ {
GetProjectFrame( *pProject ) GetProjectFrame( mProject )
.GetStatusBar()->SetStatusText(StateForStatusBar(), stateStatusBarField); .GetStatusBar()->SetStatusText(StateForStatusBar(), stateStatusBarField);
} }
@ -1474,12 +1468,12 @@ void ControlToolBar::StartScrolling()
using Mode = ProjectWindow::PlaybackScroller::Mode; using Mode = ProjectWindow::PlaybackScroller::Mode;
const auto project = &mProject; const auto project = &mProject;
if (project) { if (project) {
auto gAudioIO = AudioIO::Get();
auto mode = Mode::Pinned; auto mode = Mode::Pinned;
#if 0 #if 0
// Enable these lines to pin the playhead right instead of center, // Enable these lines to pin the playhead right instead of center,
// when recording but not overdubbing. // when recording but not overdubbing.
auto gAudioIO = AudioIO::Get();
if (gAudioIO->GetNumCaptureChannels() > 0) { if (gAudioIO->GetNumCaptureChannels() > 0) {
// recording // recording

View File

@ -77,6 +77,7 @@ class ControlToolBar final : public ToolBar {
void OnPlay(wxCommandEvent & evt); void OnPlay(wxCommandEvent & evt);
void OnStop(wxCommandEvent & evt); void OnStop(wxCommandEvent & evt);
void OnRecord(wxCommandEvent & evt); void OnRecord(wxCommandEvent & evt);
void OnRecord(bool altAppearance);
bool DoRecord(AudacityProject &project, bool DoRecord(AudacityProject &project,
const TransportTracks &transportTracks, // If captureTracks is empty, then tracks are created const TransportTracks &transportTracks, // If captureTracks is empty, then tracks are created
double t0, double t1, double t0, double t1,
@ -84,6 +85,7 @@ class ControlToolBar final : public ToolBar {
const AudioIOStartStreamOptions &options); const AudioIOStartStreamOptions &options);
void OnFF(wxCommandEvent & evt); void OnFF(wxCommandEvent & evt);
void OnPause(wxCommandEvent & evt); void OnPause(wxCommandEvent & evt);
void OnIdle(wxIdleEvent & event);
// Choice among the appearances of the play button: // Choice among the appearances of the play button:
enum class PlayAppearance { enum class PlayAppearance {
@ -92,11 +94,7 @@ class ControlToolBar final : public ToolBar {
//These allow buttons to be controlled externally: //These allow buttons to be controlled externally:
void SetPlay(bool down, PlayAppearance appearance = PlayAppearance::Straight); void SetPlay(bool down, PlayAppearance appearance = PlayAppearance::Straight);
void SetStop(bool down); void SetStop();
void SetRecord(bool down, bool altAppearance = false);
bool IsPauseDown() const;
bool IsRecordDown() const;
// A project is only allowed to stop an audio stream that it owns. // A project is only allowed to stop an audio stream that it owns.
bool CanStopAudioStream () const; bool CanStopAudioStream () const;
@ -128,7 +126,6 @@ class ControlToolBar final : public ToolBar {
void RegenerateTooltips() override; void RegenerateTooltips() override;
int WidthForStatusBar(wxStatusBar* const); int WidthForStatusBar(wxStatusBar* const);
void UpdateStatusBar(AudacityProject *pProject);
// Starting and stopping of scrolling display // Starting and stopping of scrolling display
void StartScrollingIfPreferred(); void StartScrollingIfPreferred();
@ -141,6 +138,7 @@ class ControlToolBar final : public ToolBar {
PlayMode GetLastPlayMode() const { return mLastPlayMode; } PlayMode GetLastPlayMode() const { return mLastPlayMode; }
private: private:
void UpdateStatusBar();
static AButton *MakeButton( static AButton *MakeButton(
ControlToolBar *pBar, ControlToolBar *pBar,
@ -181,9 +179,6 @@ class ControlToolBar final : public ToolBar {
static AudacityProject *mBusyProject; static AudacityProject *mBusyProject;
// Maybe button state values shouldn't be duplicated in this toolbar?
bool mPaused; //Play or record is paused or not paused?
// Activate ergonomic order for transport buttons // Activate ergonomic order for transport buttons
bool mErgonomicTransportButtons; bool mErgonomicTransportButtons;

View File

@ -330,14 +330,12 @@ void Scrubber::MarkScrubStart(
mSeeking = seek; mSeeking = seek;
CheckMenuItems(); CheckMenuItems();
ctb.SetPlay(true, ControlToolBar::PlayAppearance::Straight );
// Commented out for Bug 1421 // Commented out for Bug 1421
// mSeeking // mSeeking
// ? ControlToolBar::PlayAppearance::Seek // ? ControlToolBar::PlayAppearance::Seek
// : ControlToolBar::PlayAppearance::Scrub); // : ControlToolBar::PlayAppearance::Scrub);
mScrubStartPosition = xx; mScrubStartPosition = xx;
ctb.UpdateStatusBar(mProject);
mCancelled = false; mCancelled = false;
} }
@ -674,8 +672,6 @@ void Scrubber::ContinueScrubbingUI()
// Show the correct status for seeking. // Show the correct status for seeking.
bool backup = mSeeking; bool backup = mSeeking;
mSeeking = seek; mSeeking = seek;
auto &ctb = ControlToolBar::Get( *mProject );
ctb.UpdateStatusBar(mProject);
mSeeking = backup; mSeeking = backup;
} }
@ -735,14 +731,6 @@ void Scrubber::StopScrubbing()
mDragging = false; mDragging = false;
mSeeking = false; mSeeking = false;
if (!IsScrubbing())
{
// Marked scrub start, but
// didn't really play, but did change button apperance
auto &ctb = ControlToolBar::Get( *mProject );
ctb.SetPlay(false, ControlToolBar::PlayAppearance::Straight);
}
AdornedRulerPanel::Get( *mProject ).DrawBothOverlays(); AdornedRulerPanel::Get( *mProject ).DrawBothOverlays();
CheckMenuItems(); CheckMenuItems();
} }
@ -872,9 +860,7 @@ void Scrubber::OnActivateOrDeactivateApp(wxActivateEvent &event)
// Pause if Pause down, or not scrubbing. // Pause if Pause down, or not scrubbing.
if (!mProject) if (!mProject)
Pause(true); Pause(true);
else if ( !ControlToolBar::Find( *mProject ) ) else if (ProjectAudioManager::Get( *mProject ).Paused())
Pause( true );
else if (ControlToolBar::Get( *mProject ).IsPauseDown())
Pause( true ); Pause( true );
else if (!IsScrubbing()) else if (!IsScrubbing())
Pause( true ); Pause( true );
@ -1107,12 +1093,6 @@ void Scrubber::OnScrubOrSeek(bool seek)
{ {
DoScrub(seek); DoScrub(seek);
if (HasMark()) {
// Show the correct status.
auto &ctb = ControlToolBar::Get( *mProject );
ctb.UpdateStatusBar(mProject);
}
mSeeking = seek; mSeeking = seek;
CheckMenuItems(); CheckMenuItems();