From 69b044e3215335b1b88576e946e7c07a38a7bbe1 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Fri, 17 Apr 2015 16:31:01 -0500 Subject: [PATCH] Restore tracks if recording fails to start During an append record, silence may need to be added to the end of the existing track(s) to fill any gap between the end and the common recording start time. But, if the recording fails to start, this silence is left at the ends of the tracks. This change fixes that by making a copy of the tracks before recording starts and restoring the tracks from that copy if the start fails. --- src/toolbars/ControlToolBar.cpp | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/toolbars/ControlToolBar.cpp b/src/toolbars/ControlToolBar.cpp index 55a0b2621..af9f27d77 100644 --- a/src/toolbars/ControlToolBar.cpp +++ b/src/toolbars/ControlToolBar.cpp @@ -819,6 +819,7 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt) // If SHIFT key was down, the user wants append to tracks int recordingChannels = 0; + TrackList *tracksCopy = NULL; bool shifted = mRecord->WasShiftDown(); if (shifted) { bool sel = false; @@ -858,6 +859,16 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt) playbackTracks.Remove(wt); t1 = wt->GetEndTime(); if (t1 < t0) { + if (!tracksCopy) { + tracksCopy = new TrackList(); + TrackListIterator iter(t); + Track *trk = iter.First(); + while (trk) { + tracksCopy->Add(trk->Duplicate()); + trk = iter.Next(); + } + } + WaveTrack *newTrack = p->GetTrackFactory()->NewWaveTrack(); newTrack->InsertSilence(0.0, t0 - t1); newTrack->Flush(); @@ -923,10 +934,29 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt) if (success) { p->SetAudioIOToken(token); mBusyProject = p; + if (shifted && tracksCopy) { + tracksCopy->Clear(true); + delete tracksCopy; + } } else { - // msmeyer: Delete recently added tracks if opening stream fails - if (!shifted) { + if (shifted) { + // Restore the tracks to remove any inserted silence + if (tracksCopy) { + t->Clear(true); + TrackListIterator iter(tracksCopy); + Track *trk = iter.First(); + while (trk) + { + Track *tmp = trk; + trk = iter.RemoveCurrent(); + t->Add(tmp); + } + delete tracksCopy; + } + } + else { + // msmeyer: Delete recently added tracks if opening stream fails for (unsigned int i = 0; i < newRecordingTracks.GetCount(); i++) { t->Remove(newRecordingTracks[i]); delete newRecordingTracks[i];