From 894f6f4f639a1a5fab93ed068bfde70bdfe3b086 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 19 Sep 2018 14:13:24 -0400 Subject: [PATCH] Remove SetLinked() and SetChannel() from importers --- src/Project.cpp | 7 +++++++ src/import/ImportFFmpeg.cpp | 23 ----------------------- src/import/ImportFLAC.cpp | 18 +----------------- src/import/ImportGStreamer.cpp | 8 -------- src/import/ImportMP3.cpp | 10 +--------- src/import/ImportOGG.cpp | 21 +-------------------- src/import/ImportPCM.cpp | 19 +------------------ src/import/ImportQT.cpp | 10 ---------- src/import/ImportRaw.cpp | 22 ++-------------------- 9 files changed, 13 insertions(+), 125 deletions(-) diff --git a/src/Project.cpp b/src/Project.cpp index ac496ed75..637dc7274 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -4177,10 +4177,17 @@ AudacityProject::AddImportedTracks(const wxString &fileName, // Must add all tracks first (before using Track::IsLeader) for (auto &group : newTracks) { + if (group.empty()) { + wxASSERT(false); + continue; + } + auto first = group.begin()->get(); + auto nChannels = group.size(); for (auto &uNewTrack : group) { auto newTrack = mTracks->Add(std::move(uNewTrack)); results.push_back(Track::Pointer(newTrack)); } + mTracks->GroupChannels(*first, nChannels); } newTracks.clear(); diff --git a/src/import/ImportFFmpeg.cpp b/src/import/ImportFFmpeg.cpp index e0352d801..a5aaf8923 100644 --- a/src/import/ImportFFmpeg.cpp +++ b/src/import/ImportFFmpeg.cpp @@ -523,31 +523,8 @@ ProgressResult FFmpegImportFileHandle::Import(TrackFactory *trackFactory, // There is a possibility that number of channels will change over time, but we do not have WaveTracks for NEW channels. Remember the number of channels and stick to it. sc->m_initialchannels = sc->m_stream->codec->channels; stream.resize(sc->m_stream->codec->channels); - int c = -1; for (auto &channel : stream) - { - ++c; - channel = trackFactory->NewWaveTrack(sc->m_osamplefmt, sc->m_stream->codec->sample_rate); - - if (sc->m_stream->codec->channels == 2) - { - switch (c) - { - case 0: - channel->SetChannel(Track::LeftChannel); - channel->SetLinked(true); - break; - case 1: - channel->SetChannel(Track::RightChannel); - break; - } - } - else - { - channel->SetChannel(Track::MonoChannel); - } - } } // Handles the start_time by creating silence. This may or may not be correct. diff --git a/src/import/ImportFLAC.cpp b/src/import/ImportFLAC.cpp index 2baf8aae2..739d56366 100644 --- a/src/import/ImportFLAC.cpp +++ b/src/import/ImportFLAC.cpp @@ -455,25 +455,9 @@ ProgressResult FLACImportFileHandle::Import(TrackFactory *trackFactory, mChannels.resize(mNumChannels); auto iter = mChannels.begin(); - for (size_t c = 0; c < mNumChannels; ++iter, ++c) { + for (size_t c = 0; c < mNumChannels; ++iter, ++c) *iter = trackFactory->NewWaveTrack(mFormat, mSampleRate); - if (mNumChannels == 2) { - switch (c) { - case 0: - iter->get()->SetChannel(Track::LeftChannel); - iter->get()->SetLinked(true); - break; - case 1: - iter->get()->SetChannel(Track::RightChannel); - break; - } - } - else { - iter->get()->SetChannel(Track::MonoChannel); - } - } - //Start OD bool useOD = false; diff --git a/src/import/ImportGStreamer.cpp b/src/import/ImportGStreamer.cpp index fbb9bd3d0..0a3a14110 100644 --- a/src/import/ImportGStreamer.cpp +++ b/src/import/ImportGStreamer.cpp @@ -789,14 +789,6 @@ GStreamerImportFileHandle::OnNewSample(GStreamContext *c, GstSample *sample) return; } } - - // Set to stereo if there's exactly 2 channels - if (c->mNumChannels == 2) - { - c->mChannels[0]->SetChannel(Track::LeftChannel); - c->mChannels[1]->SetChannel(Track::RightChannel); - c->mChannels[0]->SetLinked(true); - } } // Get the buffer for the sample...no need to release diff --git a/src/import/ImportMP3.cpp b/src/import/ImportMP3.cpp index 38ccad945..1feb77fb9 100644 --- a/src/import/ImportMP3.cpp +++ b/src/import/ImportMP3.cpp @@ -503,17 +503,9 @@ enum mad_flow output_cb(void *_data, auto format = QualityPrefs::SampleFormatChoice(); - for(auto &channel: data->channels) { + for(auto &channel: data->channels) channel = data->trackFactory->NewWaveTrack(format, samplerate); - channel->SetChannel(Track::MonoChannel); - } - /* special case: 2 channels is understood to be stereo */ - if(channels == 2) { - data->channels.begin()->get()->SetChannel(Track::LeftChannel); - data->channels.rbegin()->get()->SetChannel(Track::RightChannel); - data->channels.begin()->get()->SetLinked(true); - } data->numChannels = channels; } else { diff --git a/src/import/ImportOGG.cpp b/src/import/ImportOGG.cpp index aec1184a0..e51c542ea 100644 --- a/src/import/ImportOGG.cpp +++ b/src/import/ImportOGG.cpp @@ -259,27 +259,8 @@ ProgressResult OggImportFileHandle::Import( link.resize(vi->channels); - int c = -1; - for (auto &channel : link) { - ++c; - + for (auto &channel : link) channel = trackFactory->NewWaveTrack(mFormat, vi->rate); - - if (vi->channels == 2) { - switch (c) { - case 0: - channel->SetChannel(Track::LeftChannel); - channel->SetLinked(true); - break; - case 1: - channel->SetChannel(Track::RightChannel); - break; - } - } - else { - channel->SetChannel(Track::MonoChannel); - } - } } /* The number of bytes to get from the codec in each run */ diff --git a/src/import/ImportPCM.cpp b/src/import/ImportPCM.cpp index 6b3d21af1..68de4ef90 100644 --- a/src/import/ImportPCM.cpp +++ b/src/import/ImportPCM.cpp @@ -367,26 +367,9 @@ ProgressResult PCMImportFileHandle::Import(TrackFactory *trackFactory, NewChannelGroup channels(mInfo.channels); auto iter = channels.begin(); - for (int c = 0; c < mInfo.channels; ++iter, ++c) { + for (int c = 0; c < mInfo.channels; ++iter, ++c) *iter = trackFactory->NewWaveTrack(mFormat, mInfo.samplerate); - if (mInfo.channels > 1) - switch (c) { - case 0: - iter->get()->SetChannel(Track::LeftChannel); - break; - case 1: - iter->get()->SetChannel(Track::RightChannel); - break; - default: - iter->get()->SetChannel(Track::MonoChannel); - } - } - - if (mInfo.channels == 2) { - channels.begin()->get()->SetLinked(true); - } - auto fileTotalFrames = (sampleCount)mInfo.frames; // convert from sf_count_t auto maxBlockSize = channels.begin()->get()->GetMaxBlockSize(); diff --git a/src/import/ImportQT.cpp b/src/import/ImportQT.cpp index e805d0d49..34171ccd3 100644 --- a/src/import/ImportQT.cpp +++ b/src/import/ImportQT.cpp @@ -352,16 +352,6 @@ ProgressResult QTImportFileHandle::Import(TrackFactory *trackFactory, channel = trackFactory->NewWaveTrack( format ); channel->SetRate( desc.mSampleRate ); - - if (numchan == 2) { - if (c == 0) { - channel->SetChannel(Track::LeftChannel); - channel->SetLinked(true); - } - else if (c == 1) { - channel->SetChannel(Track::RightChannel); - } - } } do { diff --git a/src/import/ImportRaw.cpp b/src/import/ImportRaw.cpp index e363711d7..3c52a3c8d 100644 --- a/src/import/ImportRaw.cpp +++ b/src/import/ImportRaw.cpp @@ -205,28 +205,10 @@ void ImportRaw(wxWindow *parent, const wxString &fileName, channels.resize(numChannels); auto iter = channels.begin(); - for (decltype(numChannels) c = 0; c < numChannels; ++iter, ++c) { - const auto channel = - (*iter = trackFactory->NewWaveTrack(format, rate)).get(); - - if (numChannels > 1) - switch (c) { - case 0: - channel->SetChannel(Track::LeftChannel); - break; - case 1: - channel->SetChannel(Track::RightChannel); - break; - default: - channel->SetChannel(Track::MonoChannel); - } - } + for (decltype(numChannels) c = 0; c < numChannels; ++iter, ++c) + *iter = trackFactory->NewWaveTrack(format, rate); const auto firstChannel = channels.begin()->get(); - if (numChannels == 2) { - firstChannel->SetLinked(true); - } - auto maxBlockSize = firstChannel->GetMaxBlockSize(); SampleBuffer srcbuffer(maxBlockSize * numChannels, format);