mirror of
https://github.com/cookiengineer/audacity
synced 2026-04-01 03:54:47 +02:00
More exception-safety for recording...
... Do not call Autosave (which might fail) when recovering from exceptions in recording, but rely on the last good Autosave that happened during recording. If dropout labels are needed, then immediately modify the undo history item, but we can accept it if that modification fails. Also, be sure NOT to skip Autosave in all other places that push the undo history. Make Autosave the default unless otherwise specified. Finally removed one unnecessary call to Autosave.
This commit is contained in:
@@ -28,6 +28,7 @@ Paul Licameli split from ProjectManager.cpp
|
||||
#include "ProjectStatus.h"
|
||||
#include "TimeTrack.h"
|
||||
#include "TrackPanelAx.h"
|
||||
#include "UndoManager.h"
|
||||
#include "ViewInfo.h"
|
||||
#include "WaveTrack.h"
|
||||
#include "toolbars/ToolManager.h"
|
||||
@@ -870,38 +871,6 @@ void ProjectAudioManager::OnAudioIOStopRecording()
|
||||
// Only push state if we were capturing and not monitoring
|
||||
if (projectAudioIO.GetAudioIOToken() > 0)
|
||||
{
|
||||
auto &tracks = TrackList::Get( project );
|
||||
auto gAudioIO = AudioIO::Get();
|
||||
auto &intervals = gAudioIO->LostCaptureIntervals();
|
||||
if (intervals.size()) {
|
||||
// Make a track with labels for recording errors
|
||||
auto uTrack = TrackFactory::Get( project ).NewLabelTrack();
|
||||
auto pTrack = uTrack.get();
|
||||
tracks.Add( uTrack );
|
||||
/* i18n-hint: A name given to a track, appearing as its menu button.
|
||||
The translation should be short or else it will not display well.
|
||||
At most, about 11 Latin characters.
|
||||
Dropout is a loss of a short sequence of audio sample data from the
|
||||
recording */
|
||||
pTrack->SetName(_("Dropouts"));
|
||||
long counter = 1;
|
||||
for (auto &interval : intervals)
|
||||
pTrack->AddLabel(
|
||||
SelectedRegion{ interval.first,
|
||||
interval.first + interval.second },
|
||||
wxString::Format(wxT("%ld"), counter++));
|
||||
ShowWarningDialog(&window, wxT("DropoutDetected"), XO("\
|
||||
Recorded audio was lost at the labeled locations. Possible causes:\n\
|
||||
\n\
|
||||
Other applications are competing with Audacity for processor time\n\
|
||||
\n\
|
||||
You are saving directly to a slow external storage device\n\
|
||||
"
|
||||
),
|
||||
false,
|
||||
XXO("Turn off dropout detection"));
|
||||
}
|
||||
|
||||
auto &history = ProjectHistory::Get( project );
|
||||
|
||||
if (IsTimerRecordCancelled()) {
|
||||
@@ -910,13 +879,52 @@ You are saving directly to a slow external storage device\n\
|
||||
// Reset timer record
|
||||
ResetTimerRecordCancelled();
|
||||
}
|
||||
else
|
||||
else {
|
||||
// Add to history
|
||||
history.PushState(XO("Recorded Audio"), XO("Record"));
|
||||
}
|
||||
// We want this to have NOFAIL-GUARANTEE if we get here from exception
|
||||
// handling of recording, and that means we rely on the last autosave
|
||||
// successully committed to the database, not risking a failure
|
||||
history.PushState(XO("Recorded Audio"), XO("Record"),
|
||||
UndoPush::NOAUTOSAVE);
|
||||
|
||||
// Now we auto-save again to get the project to a "normal" state again.
|
||||
projectFileIO.AutoSave();
|
||||
// Now, we may add a label track to give information about
|
||||
// dropouts. We allow failure of this.
|
||||
auto &tracks = TrackList::Get( project );
|
||||
auto gAudioIO = AudioIO::Get();
|
||||
auto &intervals = gAudioIO->LostCaptureIntervals();
|
||||
if (intervals.size()) {
|
||||
// Make a track with labels for recording errors
|
||||
auto uTrack = TrackFactory::Get( project ).NewLabelTrack();
|
||||
auto pTrack = uTrack.get();
|
||||
tracks.Add( uTrack );
|
||||
/* i18n-hint: A name given to a track, appearing as its menu button.
|
||||
The translation should be short or else it will not display well.
|
||||
At most, about 11 Latin characters.
|
||||
Dropout is a loss of a short sequence of audio sample data from the
|
||||
recording */
|
||||
pTrack->SetName(_("Dropouts"));
|
||||
long counter = 1;
|
||||
for (auto &interval : intervals)
|
||||
pTrack->AddLabel(
|
||||
SelectedRegion{ interval.first,
|
||||
interval.first + interval.second },
|
||||
wxString::Format(wxT("%ld"), counter++));
|
||||
|
||||
history.ModifyState( true ); // this might fail and throw
|
||||
|
||||
ShowWarningDialog(&window, wxT("DropoutDetected"), XO("\
|
||||
Recorded audio was lost at the labeled locations. Possible causes:\n\
|
||||
\n\
|
||||
Other applications are competing with Audacity for processor time\n\
|
||||
\n\
|
||||
You are saving directly to a slow external storage device\n\
|
||||
"
|
||||
),
|
||||
false,
|
||||
XXO("Turn off dropout detection"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectAudioManager::OnAudioIONewBlockFiles(const WaveTrackArray *tracks)
|
||||
|
||||
Reference in New Issue
Block a user