mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-17 16:50:26 +02:00
Do not use ControlToolBar's Record button as a state variable
This commit is contained in:
parent
923128731d
commit
cac04e9fb8
@ -192,6 +192,15 @@ void ProjectAudioManager::OnSoundActivationThreshold()
|
||||
}
|
||||
}
|
||||
|
||||
bool ProjectAudioManager::Recording() const
|
||||
{
|
||||
auto gAudioIO = AudioIO::Get();
|
||||
return
|
||||
gAudioIO->IsBusy() &&
|
||||
ControlToolBar::Get( mProject).CanStopAudioStream() &&
|
||||
gAudioIO->GetNumCaptureChannels() > 0;
|
||||
}
|
||||
|
||||
AudioIOStartStreamOptions
|
||||
DefaultPlayOptions( AudacityProject &project )
|
||||
{
|
||||
|
@ -36,8 +36,16 @@ public:
|
||||
void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; }
|
||||
|
||||
bool Paused() const { return mPaused; }
|
||||
|
||||
// Whether recording into this project (not just into some project) is
|
||||
// active
|
||||
bool Recording() const;
|
||||
|
||||
// Whether the last attempt to start recording requested appending to tracks
|
||||
bool Appending() const { return mAppending; }
|
||||
|
||||
void SetPaused( bool value ) { mPaused = value; }
|
||||
void SetAppending( bool value ) { mAppending = value; }
|
||||
|
||||
private:
|
||||
// Audio IO callback methods
|
||||
@ -54,6 +62,7 @@ private:
|
||||
bool mTimerRecordCanceled{ false };
|
||||
|
||||
bool mPaused{ false };
|
||||
bool mAppending{ false };
|
||||
};
|
||||
|
||||
AudioIOStartStreamOptions DefaultPlayOptions( AudacityProject &project );
|
||||
|
@ -455,7 +455,8 @@ void ControlToolBar::ReCreateButtons()
|
||||
|
||||
if (recordDown)
|
||||
{
|
||||
SetRecord(recordDown, recordShift);
|
||||
mRecord->SetAlternateIdx(recordShift ? 1 : 0);
|
||||
mRecord->PushDown();
|
||||
}
|
||||
|
||||
EnableDisableButtons();
|
||||
@ -527,26 +528,6 @@ void ControlToolBar::SetStop(bool down)
|
||||
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::IsRecordDown() const
|
||||
{
|
||||
return mRecord->IsDown();
|
||||
}
|
||||
|
||||
int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
|
||||
const AudioIOStartStreamOptions &options,
|
||||
PlayMode mode,
|
||||
@ -593,7 +574,6 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
|
||||
if (!success) {
|
||||
SetPlay(false);
|
||||
SetStop(false);
|
||||
SetRecord(false);
|
||||
}
|
||||
} );
|
||||
|
||||
@ -854,7 +834,6 @@ void ControlToolBar::StopPlaying(bool stopStream /* = true*/)
|
||||
if(stopStream)
|
||||
gAudioIO->StopStream();
|
||||
SetPlay(false);
|
||||
SetRecord(false);
|
||||
|
||||
#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
|
||||
gAudioIO->AILADisable();
|
||||
@ -1067,6 +1046,8 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
|
||||
bool altAppearance,
|
||||
const AudioIOStartStreamOptions &options)
|
||||
{
|
||||
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
|
||||
|
||||
CommandFlag flags = AlwaysEnabledFlag; // 0 means recalc flags.
|
||||
|
||||
// NB: The call may have the side effect of changing flags.
|
||||
@ -1079,22 +1060,16 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
|
||||
// ...end of code from CommandHandler.
|
||||
|
||||
auto gAudioIO = AudioIO::Get();
|
||||
if (gAudioIO->IsBusy()) {
|
||||
if (!CanStopAudioStream() || 0 == gAudioIO->GetNumCaptureChannels())
|
||||
mRecord->PopUp();
|
||||
else
|
||||
mRecord->PushDown();
|
||||
if (gAudioIO->IsBusy())
|
||||
return false;
|
||||
}
|
||||
|
||||
SetRecord(true, altAppearance);
|
||||
projectAudioManager.SetAppending( !altAppearance );
|
||||
|
||||
bool success = false;
|
||||
auto cleanup = finally([&] {
|
||||
if (!success) {
|
||||
SetPlay(false);
|
||||
SetStop(false);
|
||||
SetRecord(false);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1313,6 +1288,15 @@ void ControlToolBar::OnIdle(wxIdleEvent & event)
|
||||
else
|
||||
mPause->PopUp();
|
||||
|
||||
if (!projectAudioManager.Recording()) {
|
||||
mRecord->PopUp();
|
||||
mRecord->SetAlternateIdx( wxGetKeyState(WXK_SHIFT) ? 1 : 0 );
|
||||
}
|
||||
else {
|
||||
mRecord->PushDown();
|
||||
mRecord->SetAlternateIdx( projectAudioManager.Appending() ? 0 : 1 );
|
||||
}
|
||||
|
||||
UpdateStatusBar();
|
||||
EnableDisableButtons();
|
||||
}
|
||||
@ -1403,6 +1387,7 @@ int ControlToolBar::WidthForStatusBar(wxStatusBar* const sb)
|
||||
wxString ControlToolBar::StateForStatusBar()
|
||||
{
|
||||
wxString state;
|
||||
auto &projectAudioManager = ProjectAudioManager::Get( mProject );
|
||||
|
||||
auto pProject = &mProject;
|
||||
auto scrubState = pProject
|
||||
@ -1412,7 +1397,7 @@ wxString ControlToolBar::StateForStatusBar()
|
||||
state = wxGetTranslation(scrubState);
|
||||
else if (mPlay->IsDown())
|
||||
state = wxGetTranslation(mStatePlay);
|
||||
else if (mRecord->IsDown())
|
||||
else if (projectAudioManager.Recording())
|
||||
state = wxGetTranslation(mStateRecord);
|
||||
else
|
||||
state = wxGetTranslation(mStateStop);
|
||||
|
@ -95,9 +95,6 @@ class ControlToolBar final : public ToolBar {
|
||||
//These allow buttons to be controlled externally:
|
||||
void SetPlay(bool down, PlayAppearance appearance = PlayAppearance::Straight);
|
||||
void SetStop(bool down);
|
||||
void SetRecord(bool down, bool altAppearance = false);
|
||||
|
||||
bool IsRecordDown() const;
|
||||
|
||||
// A project is only allowed to stop an audio stream that it owns.
|
||||
bool CanStopAudioStream () const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user