1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-01-12 07:35:51 +01:00

Rewrite append-record onto only the proper number of channels

This commit is contained in:
Paul Licameli
2018-04-07 22:36:43 -04:00
parent b60fae4470
commit 9fcccd32ac

View File

@@ -1020,13 +1020,9 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
}
int recordingChannels = 0;
// These count channels sellected/existing skipping tracks that
// are too big for the number of channels left. e.g don't count a stereo
// track when only one channel left to record.
int selectedChannels = 0;
int existingChannels = 0;
double allt0 = t0;
WaveTrack *candidate{}, *selectedCandidate{};
if (appendRecord) {
recordingChannels = gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2);
@@ -1039,12 +1035,19 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
if (wt->GetEndTime() > allt0) {
allt0 = wt->GetEndTime();
}
int nChannelsThisTrack = wt->GetLinked() ? 2:1;
if( recordingChannels >= existingChannels + nChannelsThisTrack)
existingChannels += nChannelsThisTrack;
if (tt->GetSelected()) {
if( recordingChannels >= selectedChannels + nChannelsThisTrack)
selectedChannels += nChannelsThisTrack;
int nChannelsThisTrack = 1;
if (wt->GetLink()) {
if (wt->GetLinked())
nChannelsThisTrack = 2;
else
continue;
}
if( recordingChannels == nChannelsThisTrack) {
candidate = wt;
if (wt->GetSelected())
selectedCandidate = wt;
}
if (wt->GetSelected()) {
if (wt->GetEndTime() > t0) {
t0 = wt->GetEndTime();
}
@@ -1052,11 +1055,8 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
}
}
// Number of channels to record into is number selected, or all.
int nChannelsAvailable = ( selectedChannels > 0 ) ? selectedChannels : existingChannels;
// If that is not enough to record without losing a channel, flip over to
// recording to new tracks.
if( nChannelsAvailable < recordingChannels )
// candidate null implies selectedCandidate also null
if( !candidate )
appendRecord = false;
}
@@ -1065,7 +1065,7 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
// t0 is now: max(selection-start, end-of-selected-wavetracks)
// allt0 is: max(selection-start, end-of-all-tracks)
// Use end time of all wave tracks if none selected
if (selectedChannels == 0) {
if (!selectedCandidate) {
t0 = allt0;
}
@@ -1073,21 +1073,12 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
// Pad selected/all wave tracks to make them all the same length
// Remove recording tracks from the list of tracks for duplex ("overdub")
// playback.
for (Track *tt = it.First(); tt; tt = it.Next()) {
if (tt->GetKind() == Track::Wave &&
(tt->GetSelected() ||
(selectedChannels == 0)
)) {
auto wt = Track::Pointer<WaveTrack>(tt);
// Don't record into one track of a stereo track...
// We're in fact here refusing to record the last channel,
// if there are no more channels after it, into a stereo
// track - which comes to the same thing.
if( ((int)recordingTracks.size() >= recordingChannels -1) &&
wt->GetLinked() )
{ tt = it.Next();
continue;
}
auto tt = selectedCandidate ? selectedCandidate : candidate;
for (auto channel = tt; channel;
channel = static_cast<WaveTrack*>(
(channel->GetLinked()) ? channel->GetLink() : nullptr))
{
auto wt = Track::Pointer<WaveTrack>(channel);
if (duplex) {
auto end = playbackTracks.end();
@@ -1127,11 +1118,6 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
pending->Paste(t1, newTrack.get());
}
recordingTracks.push_back(pending);
// Don't record more channels than configured recording pref.
if( (int)recordingTracks.size() >= recordingChannels ){
break;
}
}
}
if (t1 <= p->GetSel0() && p->GetSel1() > p->GetSel0()) {