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.
This commit is contained in:
Leland Lucius 2019-12-24 00:33:54 -06:00
parent 57350ff104
commit 036efda65e
2 changed files with 16 additions and 14 deletions

View File

@ -449,6 +449,10 @@ time warp info and AudioIOListener and whether the playback is looped.
#include <wx/intl.h>
#include <wx/debug.h>
#if defined(__WXMAC__) || defined(__WXMSW__)
#include <wx/power.h>
#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

View File

@ -16,10 +16,6 @@ Paul Licameli split from ProjectManager.cpp
#include <wx/frame.h>
#include <wx/statusbr.h>
#if defined(__WXMAC__) || defined(__WXMSW__)
#include <wx/power.h>
#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 );