mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-03 17:39:25 +02:00
Play and record now wait in Macros if a regions exists.
This commit is contained in:
parent
030f92c40b
commit
69859eebe4
@ -38,6 +38,103 @@
|
|||||||
// private helper classes and functions
|
// private helper classes and functions
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
void PlayCurrentRegionAndWait(const CommandContext &context,
|
||||||
|
bool looped = false,
|
||||||
|
bool cutpreview = false)
|
||||||
|
{
|
||||||
|
auto &project = context.project;
|
||||||
|
auto &projectAudioManager = ProjectAudioManager::Get(project);
|
||||||
|
|
||||||
|
const auto &playRegion = ViewInfo::Get(project).playRegion;
|
||||||
|
double t0 = playRegion.GetStart();
|
||||||
|
double t1 = playRegion.GetEnd();
|
||||||
|
|
||||||
|
projectAudioManager.PlayCurrentRegion(looped, cutpreview);
|
||||||
|
|
||||||
|
if (project.mBatchMode > 0 && t0 != t1) {
|
||||||
|
/* i18n-hint: This title appears on a dialog that indicates the progress
|
||||||
|
in doing something.*/
|
||||||
|
ProgressDialog progress(XO("Progress"), XO("Playing"), pdlgHideCancelButton);
|
||||||
|
auto gAudioIO = AudioIO::Get();
|
||||||
|
|
||||||
|
while (projectAudioManager.Playing()) {
|
||||||
|
ProgressResult result = progress.Update(gAudioIO->GetStreamTime() - t0, t1 - t0);
|
||||||
|
if (result != ProgressResult::Success) {
|
||||||
|
projectAudioManager.Stop();
|
||||||
|
if (result != ProgressResult::Stopped) {
|
||||||
|
context.Error(wxT("Playing interrupted"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wxMilliSleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayPlayRegionAndWait(const CommandContext &context,
|
||||||
|
const SelectedRegion &selectedRegion,
|
||||||
|
const AudioIOStartStreamOptions &options,
|
||||||
|
PlayMode mode)
|
||||||
|
{
|
||||||
|
auto &project = context.project;
|
||||||
|
auto &projectAudioManager = ProjectAudioManager::Get(project);
|
||||||
|
|
||||||
|
double t0 = selectedRegion.t0();
|
||||||
|
double t1 = selectedRegion.t1();
|
||||||
|
|
||||||
|
projectAudioManager.PlayPlayRegion(selectedRegion, options, mode);
|
||||||
|
|
||||||
|
if (project.mBatchMode > 0) {
|
||||||
|
/* i18n-hint: This title appears on a dialog that indicates the progress
|
||||||
|
in doing something.*/
|
||||||
|
ProgressDialog progress(XO("Progress"), XO("Playing"), pdlgHideCancelButton);
|
||||||
|
auto gAudioIO = AudioIO::Get();
|
||||||
|
|
||||||
|
while (projectAudioManager.Playing()) {
|
||||||
|
ProgressResult result = progress.Update(gAudioIO->GetStreamTime() - t0, t1 - t0);
|
||||||
|
if (result != ProgressResult::Success) {
|
||||||
|
projectAudioManager.Stop();
|
||||||
|
if (result != ProgressResult::Stopped) {
|
||||||
|
context.Error(wxT("Playing interrupted"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wxMilliSleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecordAndWait(const CommandContext &context, bool altAppearance)
|
||||||
|
{
|
||||||
|
auto &project = context.project;
|
||||||
|
auto &projectAudioManager = ProjectAudioManager::Get(project);
|
||||||
|
|
||||||
|
const auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
|
||||||
|
double t0 = selectedRegion.t0();
|
||||||
|
double t1 = selectedRegion.t1();
|
||||||
|
|
||||||
|
projectAudioManager.OnRecord(altAppearance);
|
||||||
|
|
||||||
|
if (project.mBatchMode > 0 && t1 != t0) {
|
||||||
|
/* i18n-hint: This title appears on a dialog that indicates the progress
|
||||||
|
in doing something.*/
|
||||||
|
ProgressDialog progress(XO("Progress"), XO("Recording"), pdlgHideCancelButton);
|
||||||
|
auto gAudioIO = AudioIO::Get();
|
||||||
|
|
||||||
|
while (projectAudioManager.Recording()) {
|
||||||
|
ProgressResult result = progress.Update(gAudioIO->GetStreamTime() - t0, t1 - t0);
|
||||||
|
if (result != ProgressResult::Success) {
|
||||||
|
projectAudioManager.Stop();
|
||||||
|
if (result != ProgressResult::Stopped) {
|
||||||
|
context.Error(wxT("Recording interrupted"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wxMilliSleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Should all these functions which involve
|
// TODO: Should all these functions which involve
|
||||||
// the toolbar actually move into ControlToolBar?
|
// the toolbar actually move into ControlToolBar?
|
||||||
|
|
||||||
@ -124,7 +221,7 @@ void DoStartPlaying(const CommandContext &context, bool looping = false)
|
|||||||
//Otherwise, start playing (assuming audio I/O isn't busy)
|
//Otherwise, start playing (assuming audio I/O isn't busy)
|
||||||
|
|
||||||
// Will automatically set mLastPlayMode
|
// Will automatically set mLastPlayMode
|
||||||
projectAudioManager.PlayCurrentRegion(looping);
|
PlayCurrentRegionAndWait(context, looping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +314,7 @@ void OnPlayLooped(const CommandContext &context)
|
|||||||
|
|
||||||
// Now play in a loop
|
// Now play in a loop
|
||||||
// Will automatically set mLastPlayMode
|
// Will automatically set mLastPlayMode
|
||||||
ProjectAudioManager::Get( project ).PlayCurrentRegion(true);
|
PlayCurrentRegionAndWait(context, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPause(const CommandContext &context)
|
void OnPause(const CommandContext &context)
|
||||||
@ -227,15 +324,14 @@ void OnPause(const CommandContext &context)
|
|||||||
|
|
||||||
void OnRecord(const CommandContext &context)
|
void OnRecord(const CommandContext &context)
|
||||||
{
|
{
|
||||||
ProjectAudioManager::Get( context.project ).OnRecord(false);
|
RecordAndWait(context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If first choice is record same track 2nd choice is record NEW track
|
// If first choice is record same track 2nd choice is record NEW track
|
||||||
// and vice versa.
|
// and vice versa.
|
||||||
void OnRecord2ndChoice(const CommandContext &context)
|
void OnRecord2ndChoice(const CommandContext &context)
|
||||||
{
|
{
|
||||||
auto &project = context.project;
|
RecordAndWait(context, true);
|
||||||
ProjectAudioManager::Get( project ).OnRecord(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTimerRecord(const CommandContext &context)
|
void OnTimerRecord(const CommandContext &context)
|
||||||
@ -611,9 +707,8 @@ void OnPlayOneSecond(const CommandContext &context)
|
|||||||
auto options = DefaultPlayOptions( project );
|
auto options = DefaultPlayOptions( project );
|
||||||
|
|
||||||
double pos = trackPanel.GetMostRecentXPos();
|
double pos = trackPanel.GetMostRecentXPos();
|
||||||
ProjectAudioManager::Get( project ).PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(pos - 0.5, pos + 0.5),
|
||||||
SelectedRegion(pos - 0.5, pos + 0.5), options,
|
options, PlayMode::oneSecondPlay);
|
||||||
PlayMode::oneSecondPlay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The idea for this function (and first implementation)
|
/// The idea for this function (and first implementation)
|
||||||
@ -662,8 +757,8 @@ void OnPlayToSelection(const CommandContext &context)
|
|||||||
|
|
||||||
auto playOptions = DefaultPlayOptions( project );
|
auto playOptions = DefaultPlayOptions( project );
|
||||||
|
|
||||||
ProjectAudioManager::Get( project ).PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t0, t1),
|
||||||
SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay);
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The next 4 functions provide a limited version of the
|
// The next 4 functions provide a limited version of the
|
||||||
@ -685,8 +780,8 @@ void OnPlayBeforeSelectionStart(const CommandContext &context)
|
|||||||
|
|
||||||
auto playOptions = DefaultPlayOptions( project );
|
auto playOptions = DefaultPlayOptions( project );
|
||||||
|
|
||||||
ProjectAudioManager::Get( project ).PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t0 - beforeLen, t0),
|
||||||
SelectedRegion(t0 - beforeLen, t0), playOptions, PlayMode::oneSecondPlay);
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPlayAfterSelectionStart(const CommandContext &context)
|
void OnPlayAfterSelectionStart(const CommandContext &context)
|
||||||
@ -704,16 +799,14 @@ void OnPlayAfterSelectionStart(const CommandContext &context)
|
|||||||
double afterLen;
|
double afterLen;
|
||||||
gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
|
gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
|
||||||
|
|
||||||
auto &projectAudioManager = ProjectAudioManager::Get( project );
|
|
||||||
auto playOptions = DefaultPlayOptions( project );
|
auto playOptions = DefaultPlayOptions( project );
|
||||||
|
|
||||||
if ( t1 - t0 > 0.0 && t1 - t0 < afterLen )
|
if ( t1 - t0 > 0.0 && t1 - t0 < afterLen )
|
||||||
projectAudioManager.PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t0, t1),
|
||||||
SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay);
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
else
|
else
|
||||||
projectAudioManager.PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t0, t0 + afterLen),
|
||||||
SelectedRegion(t0, t0 + afterLen), playOptions,
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
PlayMode::oneSecondPlay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPlayBeforeSelectionEnd(const CommandContext &context)
|
void OnPlayBeforeSelectionEnd(const CommandContext &context)
|
||||||
@ -731,19 +824,16 @@ void OnPlayBeforeSelectionEnd(const CommandContext &context)
|
|||||||
double beforeLen;
|
double beforeLen;
|
||||||
gPrefs->Read(wxT("/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0);
|
gPrefs->Read(wxT("/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0);
|
||||||
|
|
||||||
auto &projectAudioManager = ProjectAudioManager::Get( project );
|
|
||||||
auto playOptions = DefaultPlayOptions( project );
|
auto playOptions = DefaultPlayOptions( project );
|
||||||
|
|
||||||
if ( t1 - t0 > 0.0 && t1 - t0 < beforeLen )
|
if ( t1 - t0 > 0.0 && t1 - t0 < beforeLen )
|
||||||
projectAudioManager.PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t0, t1),
|
||||||
SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay);
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
else
|
else
|
||||||
projectAudioManager.PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t1 - beforeLen, t1),
|
||||||
SelectedRegion(t1 - beforeLen, t1), playOptions,
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
PlayMode::oneSecondPlay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnPlayAfterSelectionEnd(const CommandContext &context)
|
void OnPlayAfterSelectionEnd(const CommandContext &context)
|
||||||
{
|
{
|
||||||
auto &project = context.project;
|
auto &project = context.project;
|
||||||
@ -760,8 +850,8 @@ void OnPlayAfterSelectionEnd(const CommandContext &context)
|
|||||||
|
|
||||||
auto playOptions = DefaultPlayOptions( project );
|
auto playOptions = DefaultPlayOptions( project );
|
||||||
|
|
||||||
ProjectAudioManager::Get( project ).PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t1, t1 + afterLen),
|
||||||
SelectedRegion(t1, t1 + afterLen), playOptions, PlayMode::oneSecondPlay);
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPlayBeforeAndAfterSelectionStart
|
void OnPlayBeforeAndAfterSelectionStart
|
||||||
@ -782,17 +872,14 @@ void OnPlayBeforeAndAfterSelectionStart
|
|||||||
double afterLen;
|
double afterLen;
|
||||||
gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
|
gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
|
||||||
|
|
||||||
auto &projectAudioManager = ProjectAudioManager::Get( project );
|
|
||||||
auto playOptions = DefaultPlayOptions( project );
|
auto playOptions = DefaultPlayOptions( project );
|
||||||
|
|
||||||
if ( t1 - t0 > 0.0 && t1 - t0 < afterLen )
|
if ( t1 - t0 > 0.0 && t1 - t0 < afterLen )
|
||||||
projectAudioManager.PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t0 - beforeLen, t1),
|
||||||
SelectedRegion(t0 - beforeLen, t1), playOptions,
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
PlayMode::oneSecondPlay);
|
|
||||||
else
|
else
|
||||||
projectAudioManager.PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t0 - beforeLen, t0 + afterLen),
|
||||||
SelectedRegion(t0 - beforeLen, t0 + afterLen), playOptions,
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
PlayMode::oneSecondPlay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPlayBeforeAndAfterSelectionEnd
|
void OnPlayBeforeAndAfterSelectionEnd
|
||||||
@ -813,20 +900,16 @@ void OnPlayBeforeAndAfterSelectionEnd
|
|||||||
double afterLen;
|
double afterLen;
|
||||||
gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
|
gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
|
||||||
|
|
||||||
auto &projectAudioManager = ProjectAudioManager::Get( project );
|
|
||||||
auto playOptions = DefaultPlayOptions( project );
|
auto playOptions = DefaultPlayOptions( project );
|
||||||
|
|
||||||
if ( t1 - t0 > 0.0 && t1 - t0 < beforeLen )
|
if ( t1 - t0 > 0.0 && t1 - t0 < beforeLen )
|
||||||
projectAudioManager.PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t0, t1 + afterLen),
|
||||||
SelectedRegion(t0, t1 + afterLen), playOptions,
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
PlayMode::oneSecondPlay);
|
|
||||||
else
|
else
|
||||||
projectAudioManager.PlayPlayRegion(
|
PlayPlayRegionAndWait(context, SelectedRegion(t1 - beforeLen, t1 + afterLen),
|
||||||
SelectedRegion(t1 - beforeLen, t1 + afterLen), playOptions,
|
playOptions, PlayMode::oneSecondPlay);
|
||||||
PlayMode::oneSecondPlay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnPlayCutPreview(const CommandContext &context)
|
void OnPlayCutPreview(const CommandContext &context)
|
||||||
{
|
{
|
||||||
auto &project = context.project;
|
auto &project = context.project;
|
||||||
@ -835,9 +918,7 @@ void OnPlayCutPreview(const CommandContext &context)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Play with cut preview
|
// Play with cut preview
|
||||||
ProjectAudioManager::Get( project ).PlayCurrentRegion(
|
PlayCurrentRegionAndWait(context, false, true);
|
||||||
false, true
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPlayAtSpeed(const CommandContext &context)
|
void OnPlayAtSpeed(const CommandContext &context)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user