From 2d46db2c5fb149c09f6be4881945dc581b33aafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=A4nggi?= Date: Sat, 7 Mar 2020 05:35:21 +0100 Subject: [PATCH] Implement 2347 and 2348, Loop Play with next/previous Label 2347: Loop Play starts now at cursor position even if no time selection present 2348: Mode is preserved when using Next/Previous Label during Loop Play --- src/ProjectAudioManager.cpp | 14 +++++++++++--- src/menus/TransportMenus.cpp | 14 ++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/ProjectAudioManager.cpp b/src/ProjectAudioManager.cpp index 918738c99..aaaf87f3c 100644 --- a/src/ProjectAudioManager.cpp +++ b/src/ProjectAudioManager.cpp @@ -158,6 +158,7 @@ int ProjectAudioManager::PlayPlayRegion(const SelectedRegion &selectedRegion, #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR) double init_seek = 0.0; #endif +double loop_offset = 0.0; if (t1 == t0) { if (looped) { @@ -172,6 +173,8 @@ int ProjectAudioManager::PlayPlayRegion(const SelectedRegion &selectedRegion, } else { // loop the entire project + // Bug2347, loop playback from cursor position instead of project start + loop_offset = t0; t0 = tracks.GetStartTime(); t1 = tracks.GetEndTime(); } @@ -239,8 +242,12 @@ int ProjectAudioManager::PlayPlayRegion(const SelectedRegion &selectedRegion, } if (token != 0) { success = true; - ProjectAudioIO::Get( *p ).SetAudioIOToken(token); -#if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR) + ProjectAudioIO::Get(*p).SetAudioIOToken(token); + if (loop_offset != t0) { + // Bug 2347 + gAudioIO->SeekStream(loop_offset); + } +#if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR ) //AC: If init_seek was set, now's the time to make it happen. gAudioIO->SeekStream(init_seek); #endif @@ -1011,7 +1018,8 @@ TransportTracks ProjectAudioManager::GetAllPlaybackTracks( } // Stop playing or recording, if paused. -void ProjectAudioManager::StopIfPaused() +void ProjectAudioManager::StopIfPaused +() { if( AudioIOBase::Get()->IsPaused() ) Stop(); diff --git a/src/menus/TransportMenus.cpp b/src/menus/TransportMenus.cpp index 4f0906b94..8dc32faca 100644 --- a/src/menus/TransportMenus.cpp +++ b/src/menus/TransportMenus.cpp @@ -1,4 +1,5 @@ #include "../Audacity.h" + #include "../Experimental.h" #include "../AdornedRulerPanel.h" @@ -83,7 +84,7 @@ enum { POST_TIMER_RECORD_SHUTDOWN }; -void DoPlayStop(const CommandContext &context) +void DoPlayStop(const CommandContext &context, bool looping = false ) { auto &project = context.project; auto &projectAudioManager = ProjectAudioManager::Get( project ); @@ -123,14 +124,14 @@ void DoPlayStop(const CommandContext &context) //Otherwise, start playing (assuming audio I/O isn't busy) // Will automatically set mLastPlayMode - projectAudioManager.PlayCurrentRegion(false); + projectAudioManager.PlayCurrentRegion(looping); } } else if (!gAudioIO->IsBusy()) { //Otherwise, start playing (assuming audio I/O isn't busy) // Will automatically set mLastPlayMode - projectAudioManager.PlayCurrentRegion(false); + projectAudioManager.PlayCurrentRegion(looping); } } @@ -139,6 +140,7 @@ void DoMoveToLabel(AudacityProject &project, bool next) auto &tracks = TrackList::Get( project ); auto &trackFocus = TrackFocus::Get( project ); auto &window = ProjectWindow::Get( project ); + auto &projectAudioManager = ProjectAudioManager::Get(project); // Find the number of label tracks, and ptr to last track found auto trackRange = tracks.Any(); @@ -169,20 +171,20 @@ void DoMoveToLabel(AudacityProject &project, bool next) if (i >= 0) { const LabelStruct* label = lt->GetLabel(i); + bool looping = projectAudioManager.Looping(); if (ProjectAudioIO::Get( project ).IsAudioActive()) { DoPlayStop(project); // stop selectedRegion = label->selectedRegion; window.RedrawProject(); - DoPlayStop(project); // play + DoPlayStop(project, looping); // play } else { selectedRegion = label->selectedRegion; window.ScrollIntoView(selectedRegion.t0()); window.RedrawProject(); } - auto message = XO("%s %d of %d") - .Format( label->title, i + 1, lt->GetNumLabels() ); + .Format( label->title, i + 1, lt->GetNumLabels() ); trackFocus.MessageForScreenReader(message); } else {