1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-18 00:50:52 +02:00

Update Play button appearance in idle time...

... so most calls to ControlToolBar::SetPlay are removed.  One remains in
TransportMenus, which will not be problematic for untangling dependencies,
and one remains where the toolbar remakes its own buttons.

But the routines that start and stop the streams, importantly, don't use it.
This commit is contained in:
Paul Licameli 2019-07-01 10:30:54 -04:00
parent cac04e9fb8
commit 830f772625
5 changed files with 62 additions and 45 deletions

View File

@ -192,6 +192,18 @@ 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 bool ProjectAudioManager::Recording() const
{ {
auto gAudioIO = AudioIO::Get(); auto gAudioIO = AudioIO::Get();
@ -265,7 +277,6 @@ 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(true); //Pushes stop down toolbar.SetStop(true); //Pushes stop down
// change the selection // change the selection
@ -321,7 +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); toolbar.SetStop(false);
// Will automatically set mLastPlayMode // Will automatically set mLastPlayMode

View File

@ -36,16 +36,22 @@ public:
void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; } void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; }
bool Paused() const { return mPaused; } bool Paused() const { return mPaused; }
bool Playing() const;
// Whether recording into this project (not just into some project) is // Whether recording into this project (not just into some project) is
// active // active
bool Recording() const; bool Recording() const;
// Whether the last attempt to start recording requested appending to tracks // Whether the last attempt to start recording requested appending to tracks
bool Appending() const { return mAppending; } bool Appending() const { return mAppending; }
bool Looping() const { return mLooping; }
bool Cutting() const { return mCutting; }
void SetPaused( bool value ) { mPaused = value; } void SetPaused( bool value ) { mPaused = value; }
void SetAppending( bool value ) { mAppending = value; } void SetAppending( bool value ) { mAppending = value; }
void SetLooping( bool value ) { mLooping = value; }
void SetCutting( bool value ) { mCutting = value; }
private: private:
// Audio IO callback methods // Audio IO callback methods
@ -63,6 +69,8 @@ private:
bool mPaused{ false }; bool mPaused{ false };
bool mAppending{ false }; bool mAppending{ false };
bool mLooping{ false };
bool mCutting{ false };
}; };
AudioIOStartStreamOptions DefaultPlayOptions( AudacityProject &project ); AudioIOStartStreamOptions DefaultPlayOptions( AudacityProject &project );

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,6 +52,7 @@ 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(true); //Pushes stop down
toolbar.OnStop(evt); toolbar.OnStop(evt);
@ -65,11 +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); toolbar.SetStop(false);
return true; return true;
@ -97,7 +92,6 @@ 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(true); //Pushes stop down toolbar.SetStop(true); //Pushes stop down
toolbar.StopPlaying(); toolbar.StopPlaying();
} }
@ -116,7 +110,6 @@ 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(true); //Pushes stop down otherToolbar.SetStop(true); //Pushes stop down
otherToolbar.StopPlaying(); otherToolbar.StopPlaying();
} }
@ -126,7 +119,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); toolbar.SetStop(false);
// Will automatically set mLastPlayMode // Will automatically set mLastPlayMode
@ -135,7 +127,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); toolbar.SetStop(false);
// Will automatically set mLastPlayMode // Will automatically set mLastPlayMode
@ -223,7 +214,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
@ -790,7 +781,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

@ -535,6 +535,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;
@ -556,23 +558,12 @@ 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( [&] { auto cleanup = finally( [&] {
if (!success) { if (!success) {
SetPlay(false);
SetStop(false); SetStop(false);
} }
} ); } );
@ -744,25 +735,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()
)) {
SetPlay(false);
SetStop(true); SetStop(true);
StopPlaying(); StopPlaying();
} }
else if (!gAudioIO->IsBusy()) { else if (!gAudioIO->IsBusy()) {
//SetPlay(true);// Not needed as done in PlayPlayRegion
SetStop(false); SetStop(false);
PlayCurrentRegion(); PlayCurrentRegion();
} }
@ -833,7 +827,9 @@ void ControlToolBar::StopPlaying(bool stopStream /* = true*/)
SetStop(false); SetStop(false);
if(stopStream) if(stopStream)
gAudioIO->StopStream(); gAudioIO->StopStream();
SetPlay(false);
projectAudioManager.SetLooping( false );
projectAudioManager.SetCutting( false );
#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
gAudioIO->AILADisable(); gAudioIO->AILADisable();
@ -1068,7 +1064,6 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
bool success = false; bool success = false;
auto cleanup = finally([&] { auto cleanup = finally([&] {
if (!success) { if (!success) {
SetPlay(false);
SetStop(false); SetStop(false);
} }
}); });
@ -1296,6 +1291,28 @@ void ControlToolBar::OnIdle(wxIdleEvent & event)
mRecord->PushDown(); mRecord->PushDown();
mRecord->SetAlternateIdx( projectAudioManager.Appending() ? 0 : 1 ); mRecord->SetAlternateIdx( projectAudioManager.Appending() ? 0 : 1 );
} }
if ( !(projectAudioManager.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
);
}
UpdateStatusBar(); UpdateStatusBar();
EnableDisableButtons(); EnableDisableButtons();

View File

@ -330,7 +330,6 @@ 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
@ -732,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();
} }