mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-02 17:09:26 +02:00
AUP3: Add better progress to AUP importer
This commit is contained in:
parent
e75ab6eaad
commit
25d9e1c387
@ -133,6 +133,11 @@ private:
|
|||||||
bool HandleSilentBlockFile(XMLTagHandler *&handle);
|
bool HandleSilentBlockFile(XMLTagHandler *&handle);
|
||||||
bool HandlePCMAliasBlockFile(XMLTagHandler *&handle);
|
bool HandlePCMAliasBlockFile(XMLTagHandler *&handle);
|
||||||
|
|
||||||
|
void AddFile(sampleCount len,
|
||||||
|
const FilePath &filename = wxEmptyString,
|
||||||
|
sampleCount origin = 0,
|
||||||
|
int channel = 0);
|
||||||
|
|
||||||
bool AddSilence(sampleCount len);
|
bool AddSilence(sampleCount len);
|
||||||
bool AddSamples(const FilePath &filename,
|
bool AddSamples(const FilePath &filename,
|
||||||
sampleCount len,
|
sampleCount len,
|
||||||
@ -169,6 +174,18 @@ private:
|
|||||||
} mProjectAttrs;
|
} mProjectAttrs;
|
||||||
#undef field
|
#undef field
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
WaveTrack *track;
|
||||||
|
WaveClip *clip;
|
||||||
|
FilePath path;
|
||||||
|
sampleCount len;
|
||||||
|
sampleCount origin;
|
||||||
|
int channel;
|
||||||
|
} fileinfo;
|
||||||
|
std::vector<fileinfo> mFiles;
|
||||||
|
sampleCount mTotalSamples;
|
||||||
|
|
||||||
sampleFormat mFormat;
|
sampleFormat mFormat;
|
||||||
unsigned long mSampleRate;
|
unsigned long mSampleRate;
|
||||||
unsigned long mNumChannels;
|
unsigned long mNumChannels;
|
||||||
@ -233,7 +250,6 @@ AUPImportFileHandle::AUPImportFileHandle(const FilePath &fileName,
|
|||||||
: ImportFileHandle(fileName),
|
: ImportFileHandle(fileName),
|
||||||
mProject(*project)
|
mProject(*project)
|
||||||
{
|
{
|
||||||
mUpdateResult = ProgressResult::Success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AUPImportFileHandle::~AUPImportFileHandle()
|
AUPImportFileHandle::~AUPImportFileHandle()
|
||||||
@ -263,10 +279,14 @@ ProgressResult AUPImportFileHandle::Import(TrackFactory *WXUNUSED(trackFactory),
|
|||||||
|
|
||||||
bool isDirty = history.GetDirty() || !tracks.empty();
|
bool isDirty = history.GetDirty() || !tracks.empty();
|
||||||
|
|
||||||
|
mTotalSamples = 0;
|
||||||
|
|
||||||
mTags = tags;
|
mTags = tags;
|
||||||
|
|
||||||
CreateProgress();
|
CreateProgress();
|
||||||
|
|
||||||
|
mUpdateResult = ProgressResult::Success;
|
||||||
|
|
||||||
XMLFileReader xmlFile;
|
XMLFileReader xmlFile;
|
||||||
|
|
||||||
bool success = xmlFile.Parse(this, mFilename);
|
bool success = xmlFile.Parse(this, mFilename);
|
||||||
@ -280,11 +300,37 @@ ProgressResult AUPImportFileHandle::Import(TrackFactory *WXUNUSED(trackFactory),
|
|||||||
wxOK | wxCENTRE,
|
wxOK | wxCENTRE,
|
||||||
&GetProjectFrame(mProject));
|
&GetProjectFrame(mProject));
|
||||||
|
|
||||||
return mUpdateResult;
|
return ProgressResult::Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sampleCount processed = 0;
|
||||||
|
for (auto fi : mFiles)
|
||||||
|
{
|
||||||
|
mUpdateResult = mProgress->Update(processed.as_long_long(), mTotalSamples.as_long_long());
|
||||||
|
if (mUpdateResult != ProgressResult::Success)
|
||||||
|
{
|
||||||
|
return mUpdateResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
mClip = fi.clip;
|
||||||
|
mWaveTrack = fi.track;
|
||||||
|
|
||||||
|
if (fi.path.empty())
|
||||||
|
{
|
||||||
|
AddSilence(fi.len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddSamples(fi.path, fi.len, fi.origin, fi.channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
processed += fi.len;
|
||||||
|
}
|
||||||
|
|
||||||
if (mUpdateResult == ProgressResult::Failed || mUpdateResult == ProgressResult::Cancelled)
|
if (mUpdateResult == ProgressResult::Failed || mUpdateResult == ProgressResult::Cancelled)
|
||||||
{
|
{
|
||||||
|
mTracks.clear();
|
||||||
|
|
||||||
return mUpdateResult;
|
return mUpdateResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,9 +602,7 @@ bool AUPImportFileHandle::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
|
|
||||||
mHandlers.push_back({mParentTag, mCurrentTag, handler});
|
mHandlers.push_back({mParentTag, mCurrentTag, handler});
|
||||||
|
|
||||||
mUpdateResult = mProgress->Update(9999);
|
return true;
|
||||||
|
|
||||||
return (mUpdateResult == ProgressResult::Success);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AUPImportFileHandle::HandleProject(XMLTagHandler *&handler)
|
bool AUPImportFileHandle::HandleProject(XMLTagHandler *&handler)
|
||||||
@ -1155,12 +1199,18 @@ bool AUPImportFileHandle::HandleSimpleBlockFile(XMLTagHandler *&handler)
|
|||||||
|
|
||||||
// Do not set the handler - already handled
|
// Do not set the handler - already handled
|
||||||
|
|
||||||
|
AddFile(len, filename);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
if (filename.empty())
|
if (filename.empty())
|
||||||
{
|
{
|
||||||
return AddSilence(len);
|
// return AddSilence(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return AddSamples(filename, len);
|
// return AddSamples(filename, len);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AUPImportFileHandle::HandleSilentBlockFile(XMLTagHandler *&handler)
|
bool AUPImportFileHandle::HandleSilentBlockFile(XMLTagHandler *&handler)
|
||||||
@ -1194,6 +1244,10 @@ bool AUPImportFileHandle::HandleSilentBlockFile(XMLTagHandler *&handler)
|
|||||||
|
|
||||||
// Do not set the handler - already handled
|
// Do not set the handler - already handled
|
||||||
|
|
||||||
|
AddFile(len);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
return AddSilence(len);
|
return AddSilence(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1269,6 +1323,10 @@ bool AUPImportFileHandle::HandlePCMAliasBlockFile(XMLTagHandler *&handler)
|
|||||||
|
|
||||||
// Do not set the handler - already handled
|
// Do not set the handler - already handled
|
||||||
|
|
||||||
|
AddFile(len, filename.GetFullPath(), start, channel);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
if (!filename.IsOk())
|
if (!filename.IsOk())
|
||||||
{
|
{
|
||||||
return AddSilence(len);
|
return AddSilence(len);
|
||||||
@ -1277,6 +1335,24 @@ bool AUPImportFileHandle::HandlePCMAliasBlockFile(XMLTagHandler *&handler)
|
|||||||
return AddSamples(filename.GetFullPath(), len, start, channel);
|
return AddSamples(filename.GetFullPath(), len, start, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AUPImportFileHandle::AddFile(sampleCount len,
|
||||||
|
const FilePath &filename /* = wxEmptyString */,
|
||||||
|
sampleCount origin /* = 0 */,
|
||||||
|
int channel /* = 0 */)
|
||||||
|
{
|
||||||
|
fileinfo fi = {};
|
||||||
|
fi.track = mWaveTrack;
|
||||||
|
fi.clip = mClip;
|
||||||
|
fi.path = filename;
|
||||||
|
fi.len = len;
|
||||||
|
fi.origin = origin,
|
||||||
|
fi.channel = channel;
|
||||||
|
|
||||||
|
mFiles.push_back(fi);
|
||||||
|
|
||||||
|
mTotalSamples += len;
|
||||||
|
}
|
||||||
|
|
||||||
bool AUPImportFileHandle::AddSilence(sampleCount len)
|
bool AUPImportFileHandle::AddSilence(sampleCount len)
|
||||||
{
|
{
|
||||||
wxASSERT(mClip || mWaveTrack);
|
wxASSERT(mClip || mWaveTrack);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user