From e9d72ed6df067fa1f75e379e1e8b97ba6083095f Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 6 Nov 2020 07:44:39 -0500 Subject: [PATCH] Change handling of added tracks in ImportAup... ... Add them to the project, not a temporary array; revoke the addition if there is a failure. Preliminary for fixing bug 2570. --- src/import/ImportAUP.cpp | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/import/ImportAUP.cpp b/src/import/ImportAUP.cpp index fe4e2d8c9..58486e20e 100644 --- a/src/import/ImportAUP.cpp +++ b/src/import/ImportAUP.cpp @@ -206,7 +206,6 @@ private: std::map>>; BlockFileMap mFileMap; - ListOfTracks mTracks; WaveTrack *mWaveTrack; WaveClip *mClip; @@ -284,7 +283,16 @@ ProgressResult AUPImportFileHandle::Import(WaveTrackFactory *WXUNUSED(trackFacto auto &settings = ProjectSettings::Get(mProject); auto &selman = ProjectSelectionManager::Get(mProject); - auto cleanup = finally([this]{ mTracks.clear(); }); + auto oldNumTracks = tracks.size(); + auto cleanup = finally([this, &tracks, oldNumTracks]{ + if (mUpdateResult != ProgressResult::Success) { + // Revoke additions of tracks + while (oldNumTracks < tracks.size()) { + Track *lastTrack = *tracks.Any().rbegin(); + tracks.Remove(lastTrack); + } + } + }); bool isDirty = history.GetDirty() || !tracks.empty(); @@ -352,12 +360,8 @@ ProgressResult AUPImportFileHandle::Import(WaveTrackFactory *WXUNUSED(trackFacto processed += fi.len; } - - // Copy the tracks we just created into the project. - for (auto &track : mTracks) - { - tracks.Add(track); - } + + wxASSERT( mUpdateResult == ProgressResult::Success ); // If the active project is "dirty", then bypass the below updates as we don't // want to going changing things the user may have already set up. @@ -828,9 +832,7 @@ bool AUPImportFileHandle::HandleProject(XMLTagHandler *&handler) bool AUPImportFileHandle::HandleLabelTrack(XMLTagHandler *&handler) { - mTracks.push_back(std::make_shared()); - - handler = mTracks.back().get(); + handler = TrackList::Get(mProject).Add(std::make_shared()); return true; } @@ -838,9 +840,7 @@ bool AUPImportFileHandle::HandleLabelTrack(XMLTagHandler *&handler) bool AUPImportFileHandle::HandleNoteTrack(XMLTagHandler *&handler) { #if defined(USE_MIDI) - mTracks.push_back( std::make_shared()); - - handler = mTracks.back().get(); + handler = TrackList::Get(mProject).Add(std::make_shared()); return true; #else @@ -872,9 +872,8 @@ bool AUPImportFileHandle::HandleTimeTrack(XMLTagHandler *&handler) } auto &viewInfo = ViewInfo::Get( mProject ); - mTracks.push_back( std::make_shared(&viewInfo) ); - - handler = mTracks.back().get(); + handler = + TrackList::Get(mProject).Add(std::make_shared(&viewInfo)); return true; } @@ -882,11 +881,8 @@ bool AUPImportFileHandle::HandleTimeTrack(XMLTagHandler *&handler) bool AUPImportFileHandle::HandleWaveTrack(XMLTagHandler *&handler) { auto &trackFactory = WaveTrackFactory::Get(mProject); - mTracks.push_back(trackFactory.NewWaveTrack()); - - handler = mTracks.back().get(); - - mWaveTrack = static_cast(handler); + handler = mWaveTrack = + TrackList::Get(mProject).Add(trackFactory.NewWaveTrack()); // No active clip. In early versions of Audacity, there was a single // implied clip so we'll create a clip when the first "sequence" is