From 036efda65ee793402408503703d8239d7c361c99 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Tue, 24 Dec 2019 00:33:54 -0600 Subject: [PATCH] Prevent system sleep at a different point Instead of only when recording (it broke monitoring), now Audacity will prevent the system from sleeping while any audio I/O is active. This might be a little strong-handed though and maybe should be a preference option. --- src/AudioIO.cpp | 16 ++++++++++++++++ src/ProjectAudioManager.cpp | 14 -------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 5b43c467e..96096123f 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -449,6 +449,10 @@ time warp info and AudioIOListener and whether the playback is looped. #include #include +#if defined(__WXMAC__) || defined(__WXMSW__) +#include +#endif + #include "MissingAliasFileDialog.h" #include "Mix.h" #include "Resample.h" @@ -1404,6 +1408,13 @@ bool AudioIO::StartPortAudioStream(const AudioIOStartStreamOptions &options, } #endif +#if defined(__WXMAC__) || defined(__WXMSW__) + // Don't want the system to sleep while audio I/O is active + if (mPortStreamV19 != NULL && mLastPaError == paNoError) { + wxPowerResource::Acquire(wxPOWER_RESOURCE_SCREEN, _("Audacity Audio")); + } +#endif + return (mLastPaError == paNoError); } @@ -2150,6 +2161,11 @@ void AudioIO::StopStream() ) return; +#if defined(__WXMAC__) || defined(__WXMSW__) + // Re-enable system sleep + wxPowerResource::Release(wxPOWER_RESOURCE_SCREEN); +#endif + if( mAudioThreadFillBuffersLoopRunning) { // PortAudio callback can use the information that we are stopping to fade diff --git a/src/ProjectAudioManager.cpp b/src/ProjectAudioManager.cpp index 3f0057f19..4b4f7e43e 100644 --- a/src/ProjectAudioManager.cpp +++ b/src/ProjectAudioManager.cpp @@ -16,10 +16,6 @@ Paul Licameli split from ProjectManager.cpp #include #include -#if defined(__WXMAC__) || defined(__WXMSW__) -#include -#endif - #include "AudioIO.h" #include "AutoRecovery.h" #include "CommonCommandFlags.h" @@ -811,11 +807,6 @@ void ProjectAudioManager::OnAudioIORate(int rate) void ProjectAudioManager::OnAudioIOStartRecording() { -#if defined(__WXMAC__) || defined(__WXMSW__) - // Don't want the system to sleep while recording - wxPowerResource::Acquire(wxPOWER_RESOURCE_SCREEN, _("Audacity recording")); -#endif - auto &projectFileIO = ProjectFileIO::Get( mProject ); // Before recording is started, auto-save the file. The file will have // empty tracks at the bottom where the recording will be put into @@ -825,11 +816,6 @@ void ProjectAudioManager::OnAudioIOStartRecording() // This is called after recording has stopped and all tracks have flushed. void ProjectAudioManager::OnAudioIOStopRecording() { -#if defined(__WXMAC__) || defined(__WXMSW__) - // Done recording, so allow sleeping again - wxPowerResource::Release(wxPOWER_RESOURCE_SCREEN); -#endif - auto &project = mProject; auto &dirManager = DirManager::Get( project ); auto &projectAudioIO = ProjectAudioIO::Get( project );