mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Fix interaction of recording and undo...
... in case you also do things, concurrent with the recording, that affect the undo stack, either by pushing it (such as by changing the gain on one of the playing tracks, or making a label) or by "Modifying state" without a new undo item (such as when you change its size or mute or solo).
This commit is contained in:
parent
b2c69cb0f6
commit
c0f2782695
@ -2800,6 +2800,10 @@ void AudioIO::StopStream()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
AudacityProject *p = GetActiveProject();
|
||||
ControlToolBar *bar = p->GetControlToolBar();
|
||||
bar->CommitRecording();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -958,24 +958,11 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
|
||||
shifted = !shifted;
|
||||
|
||||
TrackList *trackList = p->GetTracks();
|
||||
auto pTracksCopy = TrackList::Create();
|
||||
auto &tracksCopy = *pTracksCopy;
|
||||
bool tracksCopied = false;
|
||||
|
||||
WaveTrackArray recordingTracks;
|
||||
|
||||
auto cleanup = finally( [&] {
|
||||
if (!success) {
|
||||
if (tracksCopied)
|
||||
// Restore the tracks to remove any inserted silence
|
||||
*trackList = std::move(tracksCopy);
|
||||
|
||||
if ( ! shifted ) {
|
||||
// msmeyer: Delete recently added tracks if opening stream fails
|
||||
for ( auto track : recordingTracks )
|
||||
trackList->Remove(track.get());
|
||||
}
|
||||
|
||||
SetPlay(false);
|
||||
SetStop(false);
|
||||
SetRecord(false);
|
||||
@ -1022,13 +1009,13 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
|
||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||
midiTracks = trackList->GetNoteTrackArray(false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
playbackTracks = WaveTrackConstArray();
|
||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||
midiTracks = NoteTrackArray();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// If SHIFT key was down, the user wants append to tracks
|
||||
int recordingChannels = 0;
|
||||
@ -1076,14 +1063,23 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
|
||||
t1 = wt->GetEndTime();
|
||||
// less than or equal, not just less than, to ensure a clip boundary.
|
||||
// when append recording.
|
||||
|
||||
// A function that copies all the non-sample data between
|
||||
// wave tracks; in case the track recorded to changes scale
|
||||
// type (for instance), during the recording.
|
||||
auto updater = [](Track &d, const Track &s){
|
||||
auto &dst = static_cast<WaveTrack&>(d);
|
||||
auto &src = static_cast<const WaveTrack&>(s);
|
||||
dst.Reinit(src);
|
||||
};
|
||||
|
||||
// Get a copy of the track to be appended, to be pushed into
|
||||
// undo history only later.
|
||||
auto pending = std::static_pointer_cast<WaveTrack>(
|
||||
p->GetTracks()->RegisterPendingChangedTrack(
|
||||
updater, wt.get() ) );
|
||||
|
||||
if (t1 <= t0) {
|
||||
if (!tracksCopied) {
|
||||
// Duplicate all tracks before modifying any of them.
|
||||
// The duplicates are used to restore state in case
|
||||
// of failure.
|
||||
tracksCopied = true;
|
||||
tracksCopy = *trackList;
|
||||
}
|
||||
|
||||
// Pad the recording track with silence, up to the
|
||||
// maximum time.
|
||||
@ -1091,10 +1087,10 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
|
||||
newTrack->SetWaveColorIndex( wt->GetWaveColorIndex() );
|
||||
newTrack->InsertSilence(0.0, t0 - t1);
|
||||
newTrack->Flush();
|
||||
wt->Clear(t1, t0);
|
||||
wt->Paste(t1, newTrack.get());
|
||||
pending->Clear(t1, t0);
|
||||
pending->Paste(t1, newTrack.get());
|
||||
}
|
||||
recordingTracks.push_back(wt);
|
||||
recordingTracks.push_back(pending);
|
||||
// Don't record more channels than configured recording pref.
|
||||
if( (int)recordingTracks.size() >= recordingChannels ){
|
||||
break;
|
||||
@ -1130,7 +1126,9 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
|
||||
wxString baseTrackName = recordingNameCustom? defaultRecordingTrackName : defaultTrackName;
|
||||
|
||||
for (int c = 0; c < recordingChannels; c++) {
|
||||
auto newTrack = p->GetTrackFactory()->NewWaveTrack();
|
||||
std::shared_ptr<WaveTrack> newTrack{
|
||||
p->GetTrackFactory()->NewWaveTrack().release()
|
||||
};
|
||||
|
||||
newTrack->SetOffset(t0);
|
||||
wxString nameSuffix = wxString(wxT(""));
|
||||
@ -1182,11 +1180,8 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
|
||||
newTrack->SetChannel( Track::MonoChannel );
|
||||
}
|
||||
|
||||
// Let the list hold the track, and keep a pointer to it
|
||||
recordingTracks.push_back(
|
||||
Track::Pointer<WaveTrack>(
|
||||
trackList->Add(
|
||||
std::move(newTrack))));
|
||||
p->GetTracks()->RegisterPendingNewTrack( newTrack );
|
||||
recordingTracks.push_back( newTrack );
|
||||
}
|
||||
}
|
||||
|
||||
@ -1212,6 +1207,8 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
|
||||
StartScrollingIfPreferred();
|
||||
}
|
||||
else {
|
||||
CancelRecording();
|
||||
|
||||
// Show error message if stream could not be opened
|
||||
ShowErrorDialog(this, _("Error"),
|
||||
_("Error opening sound device.\nTry changing the audio host, recording device and the project sample rate."),
|
||||
@ -1453,3 +1450,15 @@ void ControlToolBar::StopScrolling()
|
||||
project->GetPlaybackScroller().Activate
|
||||
(AudacityProject::PlaybackScroller::Mode::Off);
|
||||
}
|
||||
|
||||
void ControlToolBar::CommitRecording()
|
||||
{
|
||||
const auto project = GetActiveProject();
|
||||
project->GetTracks()->ApplyPendingTracks();
|
||||
}
|
||||
|
||||
void ControlToolBar::CancelRecording()
|
||||
{
|
||||
const auto project = GetActiveProject();
|
||||
project->GetTracks()->ClearPendingTracks();
|
||||
}
|
||||
|
@ -112,6 +112,12 @@ class ControlToolBar final : public ToolBar {
|
||||
void StartScrolling();
|
||||
void StopScrolling();
|
||||
|
||||
// Commit the addition of temporary recording tracks into the project
|
||||
void CommitRecording();
|
||||
|
||||
// Cancel the addition of temporary recording tracks into the project
|
||||
void CancelRecording();
|
||||
|
||||
private:
|
||||
|
||||
AButton *MakeButton(teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,
|
||||
|
Loading…
x
Reference in New Issue
Block a user