mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-20 14:20:06 +02:00
Bug2570: Save-compressed or -lossless files from 2.x should import
This commit is contained in:
parent
e9d72ed6df
commit
a8bc89e4c4
@ -48,6 +48,7 @@
|
|||||||
#include "../widgets/NumericTextCtrl.h"
|
#include "../widgets/NumericTextCtrl.h"
|
||||||
#include "../widgets/ProgressDialog.h"
|
#include "../widgets/ProgressDialog.h"
|
||||||
#include "../xml/XMLFileReader.h"
|
#include "../xml/XMLFileReader.h"
|
||||||
|
#include "../wxFileNameWrapper.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -134,6 +135,7 @@ private:
|
|||||||
bool HandleSimpleBlockFile(XMLTagHandler *&handle);
|
bool HandleSimpleBlockFile(XMLTagHandler *&handle);
|
||||||
bool HandleSilentBlockFile(XMLTagHandler *&handle);
|
bool HandleSilentBlockFile(XMLTagHandler *&handle);
|
||||||
bool HandlePCMAliasBlockFile(XMLTagHandler *&handle);
|
bool HandlePCMAliasBlockFile(XMLTagHandler *&handle);
|
||||||
|
bool HandleImport(XMLTagHandler *&handle);
|
||||||
|
|
||||||
// Called in first pass to collect information about blocks
|
// Called in first pass to collect information about blocks
|
||||||
void AddFile(sampleCount len,
|
void AddFile(sampleCount len,
|
||||||
@ -608,6 +610,10 @@ bool AUPImportFileHandle::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
{
|
{
|
||||||
success = HandlePCMAliasBlockFile(handler);
|
success = HandlePCMAliasBlockFile(handler);
|
||||||
}
|
}
|
||||||
|
else if (mCurrentTag.IsSameAs(wxT("import")))
|
||||||
|
{
|
||||||
|
success = HandleImport(handler);
|
||||||
|
}
|
||||||
|
|
||||||
if (!success || (handler && !handler->HandleXMLTag(tag, attrs)))
|
if (!success || (handler && !handler->HandleXMLTag(tag, attrs)))
|
||||||
{
|
{
|
||||||
@ -1338,6 +1344,81 @@ bool AUPImportFileHandle::HandlePCMAliasBlockFile(XMLTagHandler *&handler)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AUPImportFileHandle::HandleImport(XMLTagHandler *&handler)
|
||||||
|
{
|
||||||
|
// Adapted from ImportXMLTagHandler::HandleXMLTag as in version 2.4.2
|
||||||
|
if (!mAttrs || !(*mAttrs) || wxStrcmp(*mAttrs++, wxT("filename")))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
wxString strAttr = *mAttrs;
|
||||||
|
if (!XMLValueChecker::IsGoodPathName(strAttr))
|
||||||
|
{
|
||||||
|
// Maybe strAttr is just a fileName, not the full path. Try the project data directory.
|
||||||
|
wxFileNameWrapper fileName0{ mFilename };
|
||||||
|
fileName0.SetExt({});
|
||||||
|
wxFileNameWrapper fileName{
|
||||||
|
fileName0.GetFullPath() + wxT("_data"), strAttr };
|
||||||
|
if (XMLValueChecker::IsGoodFileName(strAttr, fileName.GetPath(wxPATH_GET_VOLUME)))
|
||||||
|
strAttr = fileName.GetFullPath();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogWarning(wxT("Could not import file: %s"), strAttr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &tracks = TrackList::Get(mProject);
|
||||||
|
auto oldNumTracks = tracks.size();
|
||||||
|
Track *pLast = nullptr;
|
||||||
|
if (oldNumTracks > 0)
|
||||||
|
pLast = *tracks.Any().rbegin();
|
||||||
|
|
||||||
|
// Guard this call so that C++ exceptions don't propagate through
|
||||||
|
// the expat library
|
||||||
|
GuardedCall(
|
||||||
|
[&] {
|
||||||
|
ProjectFileManager::Get( mProject ).Import(strAttr, false); },
|
||||||
|
[&] (AudacityException*) {}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (oldNumTracks == tracks.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Handle other attributes, now that we have the tracks.
|
||||||
|
// Apply them to all new wave tracks.
|
||||||
|
++mAttrs;
|
||||||
|
const wxChar** pAttr;
|
||||||
|
bool bSuccess = true;
|
||||||
|
|
||||||
|
auto range = tracks.Any();
|
||||||
|
if (pLast) {
|
||||||
|
range = range.StartingWith(pLast);
|
||||||
|
++range.first;
|
||||||
|
}
|
||||||
|
for (auto pTrack: range.Filter<WaveTrack>())
|
||||||
|
{
|
||||||
|
// Most of the "import" tag attributes are the same as for "wavetrack" tags,
|
||||||
|
// so apply them via WaveTrack::HandleXMLTag().
|
||||||
|
bSuccess = pTrack->HandleXMLTag(wxT("wavetrack"), mAttrs);
|
||||||
|
|
||||||
|
// "offset" tag is ignored in WaveTrack::HandleXMLTag except for legacy projects,
|
||||||
|
// so handle it here.
|
||||||
|
double dblValue;
|
||||||
|
pAttr = mAttrs;
|
||||||
|
while (*pAttr)
|
||||||
|
{
|
||||||
|
const wxChar *attr = *pAttr++;
|
||||||
|
const wxChar *value = *pAttr++;
|
||||||
|
const wxString strValue = value;
|
||||||
|
if (!wxStrcmp(attr, wxT("offset")) &&
|
||||||
|
XMLValueChecker::IsGoodString(strValue) &&
|
||||||
|
Internat::CompatibleToDouble(strValue, &dblValue))
|
||||||
|
pTrack->SetOffset(dblValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
void AUPImportFileHandle::AddFile(sampleCount len,
|
void AUPImportFileHandle::AddFile(sampleCount len,
|
||||||
sampleFormat format,
|
sampleFormat format,
|
||||||
const FilePath &filename /* = wxEmptyString */,
|
const FilePath &filename /* = wxEmptyString */,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user