1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-15 07:01:18 +02:00

Import functions return containers of smart pointers to new tracks

This commit is contained in:
Paul Licameli
2016-03-02 12:52:13 -05:00
parent bc5519a0e2
commit 824ff647f8
16 changed files with 303 additions and 333 deletions

View File

@@ -94,8 +94,8 @@ public:
wxString GetFileDescription();
int GetFileUncompressedBytes();
int Import(TrackFactory *trackFactory, Track ***outTracks,
int *outNumTracks, Tags *tags);
int Import(TrackFactory *trackFactory, TrackHolders &outTracks,
Tags *tags) override;
wxInt32 GetStreamCount(){ return 1; }
@@ -318,10 +318,11 @@ How do you want to import the current file(s)?"), oldCopyPref == wxT("copy") ? _
}
int PCMImportFileHandle::Import(TrackFactory *trackFactory,
Track ***outTracks,
int *outNumTracks,
TrackHolders &outTracks,
Tags *tags)
{
outTracks.clear();
wxASSERT(mFile);
// Get the preference / warn the user about aliased files.
@@ -338,31 +339,31 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
CreateProgress();
WaveTrack **channels = new WaveTrack *[mInfo.channels];
TrackHolders channels(mInfo.channels);
int c;
for (c = 0; c < mInfo.channels; c++) {
channels[c] = trackFactory->NewWaveTrack(mFormat, mInfo.samplerate).release();
auto iter = channels.begin();
for (int c = 0; c < mInfo.channels; ++iter, ++c) {
*iter = trackFactory->NewWaveTrack(mFormat, mInfo.samplerate);
if (mInfo.channels > 1)
switch (c) {
case 0:
channels[c]->SetChannel(Track::LeftChannel);
iter->get()->SetChannel(Track::LeftChannel);
break;
case 1:
channels[c]->SetChannel(Track::RightChannel);
iter->get()->SetChannel(Track::RightChannel);
break;
default:
channels[c]->SetChannel(Track::MonoChannel);
iter->get()->SetChannel(Track::MonoChannel);
}
}
if (mInfo.channels == 2) {
channels[0]->SetLinked(true);
channels.begin()->get()->SetLinked(true);
}
sampleCount fileTotalFrames = (sampleCount)mInfo.frames;
sampleCount maxBlockSize = channels[0]->GetMaxBlockSize();
sampleCount maxBlockSize = channels.begin()->get()->GetMaxBlockSize();
int updateResult = false;
// If the format is not seekable, we must use 'copy' mode,
@@ -387,8 +388,9 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
if (i + blockLen > fileTotalFrames)
blockLen = fileTotalFrames - i;
for (c = 0; c < mInfo.channels; c++)
channels[c]->AppendAlias(mFilename, i, blockLen, c,useOD);
auto iter = channels.begin();
for (int c = 0; c < mInfo.channels; ++iter, ++c)
iter->get()->AppendAlias(mFilename, i, blockLen, c,useOD);
if (++updateCounter == 50) {
updateResult = mProgress->Update(i, fileTotalFrames);
@@ -403,9 +405,9 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
{
ODComputeSummaryTask* computeTask=new ODComputeSummaryTask;
bool moreThanStereo = mInfo.channels>2;
for (c = 0; c < mInfo.channels; c++)
for (const auto &channel : channels)
{
computeTask->AddWaveTrack(channels[c]);
computeTask->AddWaveTrack(channel.get());
if(moreThanStereo)
{
//if we have 3 more channels, they get imported on seperate tracks, so we add individual tasks for each.
@@ -454,7 +456,8 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
block = sf_readf_float(mFile, (float *)srcbuffer.ptr(), block);
if (block) {
for(c=0; c<mInfo.channels; c++) {
auto iter = channels.begin();
for(int c=0; c<mInfo.channels; ++iter, ++c) {
if (mFormat==int16Sample) {
for(int j=0; j<block; j++)
((short *)buffer.ptr())[j] =
@@ -466,7 +469,7 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
((float *)srcbuffer.ptr())[mInfo.channels*j+c];
}
channels[c]->Append(buffer.ptr(), (mFormat == int16Sample)?int16Sample:floatSample, block);
iter->get()->Append(buffer.ptr(), (mFormat == int16Sample)?int16Sample:floatSample, block);
}
framescompleted += block;
}
@@ -480,20 +483,13 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
}
if (updateResult == eProgressFailed || updateResult == eProgressCancelled) {
for (c = 0; c < mInfo.channels; c++)
delete channels[c];
delete[] channels;
return updateResult;
}
*outNumTracks = mInfo.channels;
*outTracks = new Track *[mInfo.channels];
for(c = 0; c < mInfo.channels; c++) {
channels[c]->Flush();
(*outTracks)[c] = channels[c];
}
delete[] channels;
for(const auto &channel : channels) {
channel->Flush();
}
outTracks.swap(channels);
const char *str;