Audacity 3.2.0
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
AUPImportFileHandle Class Referencefinal

An ImportFileHandle for AUP files (pre-AUP3) More...

Inheritance diagram for AUPImportFileHandle:
[legend]
Collaboration diagram for AUPImportFileHandle:
[legend]

Classes

struct  fileinfo
 
struct  node
 

Public Member Functions

 AUPImportFileHandle (const FilePath &name, AudacityProject *project)
 
 ~AUPImportFileHandle ()
 
TranslatableString GetFileDescription () override
 
ByteCount GetFileUncompressedBytes () override
 
ProgressResult Import (WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags) override
 
wxInt32 GetStreamCount () override
 
const TranslatableStringsGetStreamInfo () override
 
void SetStreamUsage (wxInt32 WXUNUSED(StreamID), bool WXUNUSED(Use)) override
 
bool Open ()
 
- Public Member Functions inherited from ImportFileHandle
 ImportFileHandle (const FilePath &filename)
 
virtual ~ImportFileHandle ()
 
void CreateProgress ()
 
virtual TranslatableString GetFileDescription ()=0
 
virtual ByteCount GetFileUncompressedBytes ()=0
 
virtual wxInt32 GetStreamCount ()=0
 
virtual const TranslatableStringsGetStreamInfo ()=0
 
virtual void SetStreamUsage (wxInt32 StreamID, bool Use)=0
 
virtual ProgressResult Import (WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags)=0
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Private Types

using stack = std::vector< struct node >
 
using BlockFileMap = std::map< wxString, std::pair< FilePath, std::shared_ptr< SampleBlock > > >
 

Private Member Functions

bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
void HandleXMLEndTag (const std::string_view &tag) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
bool HandleProject (XMLTagHandler *&handle)
 
bool HandleLabelTrack (XMLTagHandler *&handle)
 
bool HandleNoteTrack (XMLTagHandler *&handle)
 
bool HandleTimeTrack (XMLTagHandler *&handle)
 
bool HandleWaveTrack (XMLTagHandler *&handle)
 
bool HandleTags (XMLTagHandler *&handle)
 
bool HandleTag (XMLTagHandler *&handle)
 
bool HandleLabel (XMLTagHandler *&handle)
 
bool HandleWaveClip (XMLTagHandler *&handle)
 
bool HandleSequence (XMLTagHandler *&handle)
 
bool HandleWaveBlock (XMLTagHandler *&handle)
 
bool HandleEnvelope (XMLTagHandler *&handle)
 
bool HandleControlPoint (XMLTagHandler *&handle)
 
bool HandleSimpleBlockFile (XMLTagHandler *&handle)
 
bool HandleSilentBlockFile (XMLTagHandler *&handle)
 
bool HandlePCMAliasBlockFile (XMLTagHandler *&handle)
 
bool HandleImport (XMLTagHandler *&handle)
 
void AddFile (sampleCount len, sampleFormat format, const FilePath &blockFilename=wxEmptyString, const FilePath &audioFilename=wxEmptyString, sampleCount origin=0, int channel=0)
 
bool AddSilence (sampleCount len)
 
bool AddSamples (const FilePath &blockFilename, const FilePath &audioFilename, sampleCount len, sampleFormat format, sampleCount origin=0, int channel=0)
 
bool SetError (const TranslatableString &msg)
 
bool SetWarning (const TranslatableString &msg)
 

Private Attributes

AudacityProjectmProject
 
TagsmTags
 
struct {
mProjectAttrs
 
std::vector< fileinfomFiles
 
sampleCount mTotalSamples
 
sampleFormat mFormat
 
unsigned long mNumChannels
 
stack mHandlers
 
std::string mParentTag
 
std::string mCurrentTag
 
AttributesList mAttrs
 
wxFileName mProjDir
 
BlockFileMap mFileMap
 
WaveTrackmWaveTrack
 
WaveClipmClip
 
std::vector< WaveClip * > mClips
 
ProgressResult mUpdateResult
 
TranslatableString mErrorMsg
 

Additional Inherited Members

- Public Types inherited from ImportFileHandle
using ProgressResult = BasicUI::ProgressResult
 
using ByteCount = unsigned long long
 
- Static Public Member Functions inherited from ImportFileHandle
static sampleFormat ChooseFormat (sampleFormat effectiveFormat)
 Choose appropriate format, which will not be narrower than the specified one. More...
 
- Protected Member Functions inherited from ImportFileHandle
std::shared_ptr< WaveTrackNewWaveTrack (WaveTrackFactory &trackFactory, sampleFormat effectiveFormat, double rate)
 Build a wave track with appropriate format, which will not be narrower than the specified one. More...
 
- Protected Attributes inherited from ImportFileHandle
FilePath mFilename
 
std::unique_ptr< ProgressDialogmProgress
 

Detailed Description

An ImportFileHandle for AUP files (pre-AUP3)

Definition at line 88 of file ImportAUP.cpp.

Member Typedef Documentation

◆ BlockFileMap

using AUPImportFileHandle::BlockFileMap = std::map<wxString, std::pair<FilePath, std::shared_ptr<SampleBlock> >>
private

Definition at line 213 of file ImportAUP.cpp.

◆ stack

using AUPImportFileHandle::stack = std::vector<struct node>
private

Definition at line 119 of file ImportAUP.cpp.

Constructor & Destructor Documentation

◆ AUPImportFileHandle()

AUPImportFileHandle::AUPImportFileHandle ( const FilePath name,
AudacityProject project 
)

Definition at line 284 of file ImportAUP.cpp.

286: ImportFileHandle(fileName),
287 mProject(*project)
288{
289}
AudacityProject & mProject
Definition: ImportAUP.cpp:164
ImportFileHandle(const FilePath &filename)

◆ ~AUPImportFileHandle()

AUPImportFileHandle::~AUPImportFileHandle ( )

Definition at line 291 of file ImportAUP.cpp.

292{
293}

Member Function Documentation

◆ AddFile()

void AUPImportFileHandle::AddFile ( sampleCount  len,
sampleFormat  format,
const FilePath blockFilename = wxEmptyString,
const FilePath audioFilename = wxEmptyString,
sampleCount  origin = 0,
int  channel = 0 
)
private

Definition at line 1409 of file ImportAUP.cpp.

1415{
1416 fileinfo fi = {};
1417 fi.track = mWaveTrack;
1418 fi.clip = mClip;
1419 fi.blockFile = blockFilename;
1420 fi.audioFile = audioFilename;
1421 fi.len = len;
1422 fi.format = format,
1423 fi.origin = origin,
1424 fi.channel = channel;
1425
1426 mFiles.push_back(fi);
1427
1428 mTotalSamples += len;
1429}
int format
Definition: ExportPCM.cpp:53
WaveTrack * mWaveTrack
Definition: ImportAUP.cpp:217
sampleCount mTotalSamples
Definition: ImportAUP.cpp:202
std::vector< fileinfo > mFiles
Definition: ImportAUP.cpp:201

References AUPImportFileHandle::fileinfo::audioFile, AUPImportFileHandle::fileinfo::blockFile, AUPImportFileHandle::fileinfo::channel, AUPImportFileHandle::fileinfo::clip, format, AUPImportFileHandle::fileinfo::format, AUPImportFileHandle::fileinfo::len, mClip, mFiles, mTotalSamples, mWaveTrack, AUPImportFileHandle::fileinfo::origin, and AUPImportFileHandle::fileinfo::track.

Referenced by HandlePCMAliasBlockFile(), HandleSilentBlockFile(), and HandleSimpleBlockFile().

Here is the caller graph for this function:

◆ AddSamples()

bool AUPImportFileHandle::AddSamples ( const FilePath blockFilename,
const FilePath audioFilename,
sampleCount  len,
sampleFormat  format,
sampleCount  origin = 0,
int  channel = 0 
)
private

Definition at line 1449 of file ImportAUP.cpp.

1455{
1456 auto pClip = mClip ? mClip : mWaveTrack->RightmostOrNewClip();
1457 auto &pBlock = mFileMap[wxFileNameFromPath(blockFilename)].second;
1458 if (pBlock) {
1459 // Replicate the sharing of blocks
1460 pClip->AppendSharedBlock( pBlock );
1461 return true;
1462 }
1463
1464 // Third party library has its own type alias, check it before
1465 // adding origin + size_t
1466 static_assert(sizeof(sampleCount::type) <= sizeof(sf_count_t),
1467 "Type sf_count_t is too narrow to hold a sampleCount");
1468
1469 SF_INFO info;
1470 memset(&info, 0, sizeof(info));
1471
1472 wxFile f; // will be closed when it goes out of scope
1473 SNDFILE *sf = nullptr;
1474 bool success = false;
1475
1476#ifndef UNCAUGHT_EXCEPTIONS_UNAVAILABLE
1477 const auto uncaughtExceptionsCount = std::uncaught_exceptions();
1478#endif
1479
1480 auto cleanup = finally([&]
1481 {
1482 // Do this before any throwing might happen
1483 if (sf)
1484 {
1485 SFCall<int>(sf_close, sf);
1486 }
1487
1488 if (!success)
1489 {
1490 SetWarning(XO("Error while processing %s\n\nInserting silence.").Format(audioFilename));
1491
1492 // If we are unwinding for an exception, don't do another
1493 // potentially throwing operation
1494#ifdef UNCAUGHT_EXCEPTIONS_UNAVAILABLE
1495 if (!std::uncaught_exception())
1496#else
1497 if (uncaughtExceptionsCount == std::uncaught_exceptions())
1498#endif
1499 // If this does throw, let that propagate, don't guard the call
1500 AddSilence(len);
1501 }
1502 });
1503
1504 if (!f.Open(audioFilename))
1505 {
1506 SetWarning(XO("Failed to open %s").Format(audioFilename));
1507
1508 return true;
1509 }
1510
1511 // Even though there is an sf_open() that takes a filename, use the one that
1512 // takes a file descriptor since wxWidgets can open a file with a Unicode name and
1513 // libsndfile can't (under Windows).
1514 sf = SFCall<SNDFILE*>(sf_open_fd, f.fd(), SFM_READ, &info, FALSE);
1515 if (!sf)
1516 {
1517 SetWarning(XO("Failed to open %s").Format(audioFilename));
1518
1519 return true;
1520 }
1521
1522 if (origin > 0)
1523 {
1524 if (SFCall<sf_count_t>(sf_seek, sf, origin.as_long_long(), SEEK_SET) < 0)
1525 {
1526 SetWarning(XO("Failed to seek to position %lld in %s")
1527 .Format(origin.as_long_long(), audioFilename));
1528
1529 return true;
1530 }
1531 }
1532
1533 sf_count_t cnt = len.as_size_t();
1534 int channels = info.channels;
1535
1536 wxASSERT(channels >= 1);
1537 wxASSERT(channel < channels);
1538
1539 SampleBuffer buffer(cnt, format);
1540 samplePtr bufptr = buffer.ptr();
1541
1542 size_t framesRead = 0;
1543
1544 // These cases preserve the logic formerly in BlockFile.cpp,
1545 // which was deleted at commit 98d1468.
1546 if (channels == 1 && format == int16Sample && sf_subtype_is_integer(info.format))
1547 {
1548 // If both the src and dest formats are integer formats,
1549 // read integers directly from the file, conversions not needed
1550 framesRead = SFCall<sf_count_t>(sf_readf_short, sf, (short *) bufptr, cnt);
1551 }
1552 else if (channels == 1 && format == int24Sample && sf_subtype_is_integer(info.format))
1553 {
1554 framesRead = SFCall<sf_count_t>(sf_readf_int, sf, (int *) bufptr, cnt);
1555 if (framesRead != cnt)
1556 {
1557 SetWarning(XO("Unable to read %lld samples from %s")
1558 .Format(cnt, audioFilename));
1559
1560 return true;
1561 }
1562
1563 // libsndfile gave us the 3 byte sample in the 3 most
1564 // significant bytes -- we want it in the 3 least
1565 // significant bytes.
1566 int *intPtr = (int *) bufptr;
1567 for (size_t i = 0; i < framesRead; i++)
1568 {
1569 intPtr[i] = intPtr[i] >> 8;
1570 }
1571 }
1572 else if (format == int16Sample && !sf_subtype_more_than_16_bits(info.format))
1573 {
1574 // Special case: if the file is in 16-bit (or less) format,
1575 // and the calling method wants 16-bit data, go ahead and
1576 // read 16-bit data directly. This is a pretty common
1577 // case, as most audio files are 16-bit.
1578 SampleBuffer temp(cnt * channels, int16Sample);
1579 short *tmpptr = (short *) temp.ptr();
1580
1581 framesRead = SFCall<sf_count_t>(sf_readf_short, sf, tmpptr, cnt);
1582 if (framesRead != cnt)
1583 {
1584 SetWarning(XO("Unable to read %lld samples from %s")
1585 .Format(cnt, audioFilename));
1586
1587 return true;
1588 }
1589
1590 for (size_t i = 0; i < framesRead; i++)
1591 {
1592 ((short *)bufptr)[i] = tmpptr[(channels * i) + channel];
1593 }
1594 }
1595 else
1596 {
1597 /*
1598 Therefore none of the three cases above:
1599 !(channels == 1 && format == int16Sample && sf_subtype_is_integer(info.format))
1600 &&
1601 !(channels == 1 && format == int24Sample && sf_subtype_is_integer(info.format))
1602 &&
1603 !(format == int16Sample && !sf_subtype_more_than_16_bits(info.format))
1604
1605 So format is not 16 bits with wider file format (third conjunct),
1606 but still maybe it is 24 bits with float file format (second conjunct).
1607 */
1608
1609 // Otherwise, let libsndfile handle the conversion and
1610 // scaling, and pass us normalized data as floats. We can
1611 // then convert to whatever format we want.
1612 SampleBuffer tmpbuf(cnt * channels, floatSample);
1613 float *tmpptr = (float *) tmpbuf.ptr();
1614
1615 framesRead = SFCall<sf_count_t>(sf_readf_float, sf, tmpptr, cnt);
1616 if (framesRead != cnt)
1617 {
1618 SetWarning(XO("Unable to read %lld samples from %s")
1619 .Format(cnt, audioFilename));
1620
1621 return true;
1622 }
1623
1624 /*
1625 Dithering will happen in CopySamples if format is 24 bits.
1626 Should that be done?
1627
1628 Either the file is an ordinary simple block file -- and presumably the
1629 track was saved specifying a matching format, so format is float and
1630 there is no dithering.
1631
1632 Or else this is the very unusual case of an .auf file, importing PCM data
1633 on demand. The destination format is narrower, requiring dither, only
1634 if the user also specified a narrow format for the track. In such a
1635 case, dithering is right.
1636 */
1637 CopySamples((samplePtr)(tmpptr + channel),
1639 bufptr,
1640 format,
1641 framesRead,
1642 gHighQualityDither /* high quality by default */,
1643 channels /* source stride */);
1644 }
1645
1646 wxASSERT(mClip || mWaveTrack);
1647
1648 // Add the samples to the clip/track
1649 if (pClip)
1650 {
1651 pBlock = pClip->AppendNewBlock(bufptr, format, cnt);
1652 }
1653
1654 // Let the finally block know everything is good
1655 success = true;
1656
1657 return true;
1658}
bool sf_subtype_is_integer(unsigned int format)
bool sf_subtype_more_than_16_bits(unsigned int format)
XO("Cut/Copy/Paste")
DitherType gHighQualityDither
void CopySamples(constSamplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, size_t len, DitherType ditherType, unsigned int srcStride, unsigned int dstStride)
Copy samples from any format to any other format; apply dithering only if narrowing the format.
char * samplePtr
Definition: SampleFormat.h:55
BlockFileMap mFileMap
Definition: ImportAUP.cpp:215
bool SetWarning(const TranslatableString &msg)
Definition: ImportAUP.cpp:1675
bool AddSilence(sampleCount len)
Definition: ImportAUP.cpp:1431
Abstract base class used in importing a file.
WaveClip * RightmostOrNewClip()
Get access to the last (rightmost) clip, or create a clip, if there is not already one.
Definition: WaveTrack.cpp:2252
long long as_long_long() const
Definition: SampleCount.h:48
long long type
Definition: SampleCount.h:21
size_t as_size_t() const
Definition: SampleCount.cpp:16

References AddSilence(), sampleCount::as_long_long(), sampleCount::as_size_t(), CopySamples(), floatSample, format, gHighQualityDither, int16Sample, int24Sample, mClip, mFileMap, mWaveTrack, SampleBuffer::ptr(), WaveTrack::RightmostOrNewClip(), SetWarning(), sf_subtype_is_integer(), sf_subtype_more_than_16_bits(), and XO().

Referenced by Import().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddSilence()

bool AUPImportFileHandle::AddSilence ( sampleCount  len)
private

Definition at line 1431 of file ImportAUP.cpp.

1432{
1433 wxASSERT(mClip || mWaveTrack);
1434
1435 if (mClip)
1436 {
1438 }
1439 else if (mWaveTrack)
1440 {
1442 }
1443
1444 return true;
1445}
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:48
void InsertSilence(double t, double len, double *pEnvelopeValue=nullptr)
Definition: WaveClip.cpp:453
double GetPlayEndTime() const
Definition: WaveClip.cpp:899
void InsertSilence(double t, double len) override
Definition: WaveTrack.cpp:1462
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:1888

References WaveTrack::GetEndTime(), WaveClip::GetPlayEndTime(), WaveTrack::InsertSilence(), WaveClip::InsertSilence(), SampleTrack::LongSamplesToTime(), mClip, and mWaveTrack.

Referenced by AddSamples(), and Import().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFileDescription()

TranslatableString AUPImportFileHandle::GetFileDescription ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 295 of file ImportAUP.cpp.

296{
297 return DESC;
298}
#define DESC
Definition: ImportAUP.cpp:58

References DESC.

◆ GetFileUncompressedBytes()

auto AUPImportFileHandle::GetFileUncompressedBytes ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 300 of file ImportAUP.cpp.

301{
302 // TODO: Get Uncompressed byte count.
303 return 0;
304}

◆ GetStreamCount()

wxInt32 AUPImportFileHandle::GetStreamCount ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 489 of file ImportAUP.cpp.

490{
491 return 1;
492}

◆ GetStreamInfo()

const TranslatableStrings & AUPImportFileHandle::GetStreamInfo ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 494 of file ImportAUP.cpp.

495{
496 static TranslatableStrings empty;
497 return empty;
498}
std::vector< TranslatableString > TranslatableStrings

◆ HandleControlPoint()

bool AUPImportFileHandle::HandleControlPoint ( XMLTagHandler *&  handle)
private

Definition at line 1068 of file ImportAUP.cpp.

1069{
1070 struct node node = mHandlers.back();
1071
1072 if (mParentTag == "envelope")
1073 {
1074 // If an imported timetrack was bypassed, then we want to bypass the
1075 // control points as well. (See HandleTimeTrack and HandleEnvelope)
1076 if (node.handler)
1077 {
1078 Envelope *envelope = static_cast<Envelope *>(node.handler);
1079
1080 handler = envelope->HandleXMLChild(mCurrentTag);
1081 }
1082 }
1083
1084 return true;
1085}
std::string mParentTag
Definition: ImportAUP.cpp:208
std::string mCurrentTag
Definition: ImportAUP.cpp:209
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:72
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
Definition: Envelope.cpp:333

References cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, AUPImportFileHandle::node::handler, Envelope::HandleXMLChild(), mCurrentTag, mHandlers, and mParentTag.

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleEnvelope()

bool AUPImportFileHandle::HandleEnvelope ( XMLTagHandler *&  handle)
private

Definition at line 1036 of file ImportAUP.cpp.

1037{
1038 struct node node = mHandlers.back();
1039
1040 if (mParentTag == "timetrack")
1041 {
1042 // If an imported timetrack was bypassed, then we want to bypass the
1043 // envelope as well. (See HandleTimeTrack and HandleControlPoint)
1044 if (node.handler)
1045 {
1046 TimeTrack *timetrack = static_cast<TimeTrack *>(node.handler);
1047
1048 handler = timetrack->GetEnvelope();
1049 }
1050 }
1051 // Earlier versions of Audacity had a single implied waveclip, so for
1052 // these versions, we get or create the only clip in the track.
1053 else if (mParentTag == "wavetrack")
1054 {
1056 }
1057 // Nested wave clips are cut lines
1058 else if (mParentTag == "waveclip")
1059 {
1060 WaveClip *waveclip = static_cast<WaveClip *>(node.handler);
1061
1062 handler = waveclip->GetEnvelope();
1063 }
1064
1065 return true;
1066}
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:22
BoundedEnvelope * GetEnvelope()
Definition: TimeTrack.h:83
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:101
Envelope * GetEnvelope()
Definition: WaveClip.h:219

References TimeTrack::GetEnvelope(), WaveClip::GetEnvelope(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, AUPImportFileHandle::node::handler, mHandlers, mParentTag, mWaveTrack, and WaveTrack::RightmostOrNewClip().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleImport()

bool AUPImportFileHandle::HandleImport ( XMLTagHandler *&  handle)
private

Definition at line 1334 of file ImportAUP.cpp.

1335{
1336 // Adapted from ImportXMLTagHandler::HandleXMLTag as in version 2.4.2
1337 if (mAttrs.empty() || mAttrs.front().first != "filename")
1338 return false;
1339
1340 wxString strAttr = mAttrs.front().second.ToWString();
1341
1342 if (!XMLValueChecker::IsGoodPathName(strAttr))
1343 {
1344 // Maybe strAttr is just a fileName, not the full path. Try the project data directory.
1345 wxFileNameWrapper fileName0{ mFilename };
1346 fileName0.SetExt({});
1347 wxFileNameWrapper fileName{
1348 fileName0.GetFullPath() + wxT("_data"), strAttr };
1349 if (XMLValueChecker::IsGoodFileName(strAttr, fileName.GetPath(wxPATH_GET_VOLUME)))
1350 strAttr = fileName.GetFullPath();
1351 else
1352 {
1353 wxLogWarning(wxT("Could not import file: %s"), strAttr);
1354 return false;
1355 }
1356 }
1357
1358 auto &tracks = TrackList::Get(mProject);
1359 auto oldNumTracks = tracks.size();
1360 Track *pLast = nullptr;
1361 if (oldNumTracks > 0)
1362 pLast = *tracks.Any().rbegin();
1363
1364 // Guard this call so that C++ exceptions don't propagate through
1365 // the expat library
1367 [&] {
1368 ProjectFileManager::Get( mProject ).Import(strAttr, false); },
1369 [&] (AudacityException*) {}
1370 );
1371
1372 if (oldNumTracks == tracks.size())
1373 return false;
1374
1375 // Handle other attributes, now that we have the tracks.
1376 // Apply them to all new wave tracks.
1377 bool bSuccess = true;
1378
1379 auto range = tracks.Any();
1380 if (pLast) {
1381 range = range.StartingWith(pLast);
1382 ++range.first;
1383 }
1384
1385 mAttrs.erase(mAttrs.begin());
1386
1387 for (auto pTrack: range.Filter<WaveTrack>())
1388 {
1389 // Most of the "import" tag attributes are the same as for "wavetrack" tags,
1390 // so apply them via WaveTrack::HandleXMLTag().
1391 bSuccess = pTrack->HandleXMLTag("wavetrack", mAttrs);
1392
1393 // "offset" tag is ignored in WaveTrack::HandleXMLTag except for legacy projects,
1394 // so handle it here.
1395 double dblValue;
1396
1397 for (auto pair : mAttrs)
1398 {
1399 auto attr = pair.first;
1400 auto value = pair.second;
1401
1402 if (attr == "offset" && value.TryGet(dblValue))
1403 pTrack->SetOffset(dblValue);
1404 }
1405 }
1406 return bSuccess;
1407}
wxT("CloseDown"))
R GuardedCall(const F1 &body, const F2 &handler=F2::Default(), F3 delayedHandler=DefaultDelayedHandlerAction) noexcept(noexcept(handler(std::declval< AudacityException * >())) &&noexcept(handler(nullptr)) &&noexcept(std::function< void(AudacityException *)>{std::move(delayedHandler)}))
Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread...
AttributesList mAttrs
Definition: ImportAUP.cpp:210
Base class for exceptions specially processed by the application.
FilePath mFilename
Definition: ImportPlugin.h:163
bool Import(const FilePath &fileName, bool addToHistory=true)
static ProjectFileManager & Get(AudacityProject &project)
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:162
bool Any() const
Definition: Track.cpp:299
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:385
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
static bool IsGoodPathName(const FilePath &strPathName)
static bool IsGoodFileName(const FilePath &strFileName, const FilePath &strDirName={})

References Track::Any(), TrackList::Get(), ProjectFileManager::Get(), GuardedCall(), ProjectFileManager::Import(), XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodPathName(), mAttrs, ImportFileHandle::mFilename, mProject, and wxT().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleLabel()

bool AUPImportFileHandle::HandleLabel ( XMLTagHandler *&  handle)
private

Definition at line 999 of file ImportAUP.cpp.

1000{
1001 if (mParentTag != "labeltrack")
1002 {
1003 return false;
1004 }
1005
1006 // The parent handler also handles this tag
1007 handler = mHandlers.back().handler;
1008
1009 return true;
1010}

References cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, mHandlers, and mParentTag.

Referenced by HandleXMLTag().

Here is the caller graph for this function:

◆ HandleLabelTrack()

bool AUPImportFileHandle::HandleLabelTrack ( XMLTagHandler *&  handle)
private

Definition at line 864 of file ImportAUP.cpp.

865{
866 handler = TrackList::Get(mProject).Add(std::make_shared<LabelTrack>());
867
868 return true;
869}
TrackKind * Add(const std::shared_ptr< TrackKind > &t)
Definition: Track.h:1446

References TrackList::Add(), TrackList::Get(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, and mProject.

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleNoteTrack()

bool AUPImportFileHandle::HandleNoteTrack ( XMLTagHandler *&  handle)
private

Definition at line 871 of file ImportAUP.cpp.

872{
873#if defined(USE_MIDI)
874 handler = TrackList::Get(mProject).Add(std::make_shared<NoteTrack>());
875
876 return true;
877#else
879 XO("MIDI tracks found in project file, but this build of Audacity does not include MIDI support, bypassing track."),
880 XO("Project Import"),
881 wxOK | wxICON_EXCLAMATION | wxCENTRE,
883
884 return false;
885#endif
886}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...

References TrackList::Add(), AudacityMessageBox(), TrackList::Get(), GetProjectFrame(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, mProject, and XO().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandlePCMAliasBlockFile()

bool AUPImportFileHandle::HandlePCMAliasBlockFile ( XMLTagHandler *&  handle)
private

Definition at line 1251 of file ImportAUP.cpp.

1252{
1253 wxString summaryFilename;
1254 wxFileName filename;
1255 sampleCount start = 0;
1256 size_t len = 0;
1257 int channel = 0;
1258 wxString name;
1259
1260 for (auto pair : mAttrs)
1261 {
1262 auto attr = pair.first;
1263 auto value = pair.second;
1264
1265 if (CaseInsensitiveEquals(attr, "aliasfile"))
1266 {
1267 const wxString strValue = value.ToWString();
1268
1269 if (XMLValueChecker::IsGoodPathName(strValue))
1270 {
1271 filename.Assign(strValue);
1272 }
1273 else if (XMLValueChecker::IsGoodFileName(strValue, mProjDir.GetPath()))
1274 {
1275 // Allow fallback of looking for the file name, located in the data directory.
1276 filename.Assign(mProjDir.GetPath(), strValue);
1277 }
1278 else if (XMLValueChecker::IsGoodPathString(strValue))
1279 {
1280 // If the aliased file is missing, we failed XMLValueChecker::IsGoodPathName()
1281 // and XMLValueChecker::IsGoodFileName, because both do existence tests.
1282 SetWarning(XO("Missing alias file %s\n\nInserting silence instead.")
1283 .Format(strValue));
1284 }
1285 }
1286 else if (CaseInsensitiveEquals(attr, "summaryfile"))
1287 {
1288 summaryFilename = value.ToWString();
1289 }
1290 else if (CaseInsensitiveEquals(attr, "aliasstart"))
1291 {
1292 long long llValue;
1293 if (!value.TryGet(llValue) || (llValue < 0))
1294 {
1295 return SetError(XO("Missing or invalid pcmaliasblockfile 'aliasstart' attribute."));
1296 }
1297
1298 start = llValue;
1299 }
1300 else if (CaseInsensitiveEquals(attr, "aliaslen"))
1301 {
1302 long lValue;
1303 if (!value.TryGet(lValue) || (lValue <= 0))
1304 {
1305 return SetError(XO("Missing or invalid pcmaliasblockfile 'aliaslen' attribute."));
1306 }
1307
1308 len = lValue;
1309 }
1310 else if (CaseInsensitiveEquals(attr, "aliaschannel"))
1311 {
1312 long lValue;
1313 if (!value.TryGet(lValue) || (lValue < 0))
1314 {
1315 return SetError(XO("Missing or invalid pcmaliasblockfile 'aliaslen' attribute."));
1316 }
1317
1318 channel = lValue;
1319 }
1320 }
1321
1322 // Do not set the handler - already handled
1323
1324 if (filename.IsOk())
1325 AddFile(len, mFormat,
1326 summaryFilename, filename.GetFullPath(),
1327 start, channel);
1328 else
1329 AddFile(len, mFormat); // will add silence instead
1330
1331 return true;
1332}
const TranslatableString name
Definition: Distortion.cpp:76
sampleFormat mFormat
Definition: ImportAUP.cpp:204
wxFileName mProjDir
Definition: ImportAUP.cpp:212
bool SetError(const TranslatableString &msg)
Definition: ImportAUP.cpp:1660
void AddFile(sampleCount len, sampleFormat format, const FilePath &blockFilename=wxEmptyString, const FilePath &audioFilename=wxEmptyString, sampleCount origin=0, int channel=0)
Definition: ImportAUP.cpp:1409
static bool IsGoodPathString(const FilePath &str)
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
bool CaseInsensitiveEquals(const std::string_view &lhs, const std::string_view &rhsLower)
Definition: ImportAUP.cpp:228

References AddFile(), anonymous_namespace{ImportAUP.cpp}::CaseInsensitiveEquals(), XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodPathName(), XMLValueChecker::IsGoodPathString(), mAttrs, mFormat, mProjDir, name, SetError(), SetWarning(), and XO().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleProject()

bool AUPImportFileHandle::HandleProject ( XMLTagHandler *&  handle)
private

Definition at line 670 of file ImportAUP.cpp.

671{
672 auto &fileMan = ProjectFileManager::Get(mProject);
673 auto &window = GetProjectFrame(mProject);
674
675 int requiredTags = 0;
676
677 for (auto pair : mAttrs)
678 {
679 auto attr = pair.first;
680 auto value = pair.second;
681
682 double dValue;
683
684#define set(f, v) (mProjectAttrs.have ## f = true, mProjectAttrs.f = v)
685
686 // ViewInfo
687 if (attr == "vpos")
688 {
689 long lValue;
690 if (!value.TryGet(lValue) || (lValue < 0))
691 {
692 return SetError(XO("Invalid project 'vpos' attribute."));
693 }
694
695 set(vpos, (int) lValue);
696 }
697 else if (attr == "h")
698 {
699 if (!value.TryGet(dValue))
700 {
701 return SetError(XO("Invalid project 'h' attribute."));
702 }
703
704 set(h, dValue);
705 }
706 else if (attr == "zoom")
707 {
708 if (!value.TryGet(dValue) || (dValue < 0.0))
709 {
710 return SetError(XO("Invalid project 'zoom' attribute."));
711 }
712
713 set(zoom, dValue);
714 }
715 // Viewinfo.SelectedRegion
716 else if (attr == "sel0")
717 {
718 if (!value.TryGet(dValue))
719 {
720 return SetError(XO("Invalid project 'sel0' attribute."));
721 }
722
723 set(sel0, dValue);
724 }
725 else if (attr == "sel1")
726 {
727 if (!value.TryGet(dValue))
728 {
729 return SetError(XO("Invalid project 'sel1' attribute."));
730 }
731
732 set(sel1, dValue);
733 }
734#ifdef EXPERIMENTAL_SPECTRAL_EDITING
735 else if (attr == "selLow")
736 {
737 if (!value.TryGet(dValue) || (dValue < 0.0))
738 {
739 return SetError(XO("Invalid project 'selLow' attribute."));
740 }
741
742 set(selLow, dValue);
743 }
744 else if (attr == "selHigh")
745 {
746 if (!value.TryGet(dValue) || (dValue < 0.0))
747 {
748 return SetError(XO("Invalid project 'selHigh' attribute."));
749 }
750
751 set(selHigh, dValue);
752 }
753#endif
754 else if (attr == "version")
755 {
756 requiredTags++;
757 }
758
759 else if (attr == "audacityversion")
760 {
761 requiredTags++;
762 }
763 else if (attr == "projname")
764 {
765 requiredTags++;
766
768 wxString altname = mProjDir.GetName() + wxT("_data");
769 mProjDir.SetFullName(wxEmptyString);
770
771 wxString projName = value.ToWString();
772 bool found = false;
773
774 // First try to load the data files based on the _data dir given in the .aup file
775 if (!projName.empty())
776 {
777 mProjDir.AppendDir(projName);
778 if (!mProjDir.DirExists())
779 {
780 mProjDir.RemoveLastDir();
781 projName.clear();
782 }
783 }
784
785 // If that fails then try to use the filename of the .aup as the base directory
786 // This is because unzipped projects e.g. those that get transferred between mac-pc
787 // may have encoding issues and end up expanding the wrong filenames for certain
788 // international characters (such as capital 'A' with an umlaut.)
789 if (projName.empty())
790 {
791 projName = altname;
792 mProjDir.AppendDir(projName);
793 if (!mProjDir.DirExists())
794 {
795 projName.clear();
796 }
797 }
798
799 // No luck...complain and bail
800 if (projName.empty())
801 {
803 XO("Couldn't find the project data folder: \"%s\"").Format(value.ToWString()),
804 XO("Error Opening Project"),
805 wxOK | wxCENTRE,
806 &window);
807
808 return false;
809 }
810
811 // Collect and hash the file names within the project directory
812 wxArrayString files;
813 size_t cnt = wxDir::GetAllFiles(mProjDir.GetFullPath(),
814 &files,
815 "*.*");
816
817 for (const auto &fn : files)
818 {
819 mFileMap[wxFileNameFromPath(fn)] = {fn, {}};
820 }
821 }
822 else if (attr == "rate")
823 {
824 if (!value.TryGet(dValue) || (dValue < 0.0))
825 {
826 return SetError(XO("Invalid project 'selLow' attribute."));
827 }
828
829 set(rate, dValue);
830 }
831
832 else if (attr == "snapto")
833 {
834 set(snapto, (value.ToWString() == "on" ? true : false));
835 }
836
837 else if (attr == "selectionformat")
838 {
839 set(selectionformat, value.ToWString());
840 }
841
842 else if (attr == "frequencyformat")
843 {
844 set(frequencyformat, value.ToWString());
845 }
846
847 else if (attr == "bandwidthformat")
848 {
849 set(bandwidthformat, value.ToWString());
850 }
851#undef set
852 }
853
854 if (requiredTags < 3)
855 {
856 return false;
857 }
858
859 // Do not set the handler - already handled
860
861 return true;
862}
#define set(f, v)
static const auto fn

References AudacityMessageBox(), fn, ProjectFileManager::Get(), GetProjectFrame(), mAttrs, mFileMap, ImportFileHandle::mFilename, mProjDir, mProject, set, SetError(), wxT(), and XO().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleSequence()

bool AUPImportFileHandle::HandleSequence ( XMLTagHandler *&  handle)
private

Definition at line 1087 of file ImportAUP.cpp.

1088{
1089 struct node node = mHandlers.back();
1090
1091 WaveClip *waveclip = static_cast<WaveClip *>(node.handler);
1092
1093 // Earlier versions of Audacity had a single implied waveclip, so for
1094 // these versions, we get or create the only clip in the track.
1095 if (mParentTag == "wavetrack")
1096 {
1097 XMLTagHandler *dummy;
1098 HandleWaveClip(dummy);
1099 waveclip = mClip;
1100 }
1101
1102 for (auto pair : mAttrs)
1103 {
1104 auto attr = pair.first;
1105 auto value = pair.second;
1106
1107 if (attr == "maxsamples")
1108 {
1109 // This attribute is a sample count, so can be 64bit
1110 long long llvalue;
1111 if (!value.TryGet(llvalue) || (llvalue < 0))
1112 {
1113 return SetError(XO("Invalid sequence 'maxsamples' attribute."));
1114 }
1115
1116 // Dominic, 12/10/2006:
1117 // Let's check that maxsamples is >= 1024 and <= 64 * 1024 * 1024
1118 // - that's a pretty wide range of reasonable values.
1119 if ((llvalue < 1024) || (llvalue > 64 * 1024 * 1024))
1120 {
1121 return SetError(XO("Invalid sequence 'maxsamples' attribute."));
1122 }
1123 }
1124 else if (attr == "sampleformat")
1125 {
1126 // This attribute is a sample format, normal int
1127 long fValue;
1128 if (!value.TryGet(fValue) || (fValue < 0) || !Sequence::IsValidSampleFormat(fValue))
1129 {
1130 return SetError(XO("Invalid sequence 'sampleformat' attribute."));
1131 }
1132
1133 mFormat = (sampleFormat) fValue;
1135 }
1136 else if (attr == "numsamples")
1137 {
1138 // This attribute is a sample count, so can be 64bit
1139 long long llvalue;
1140 if (!value.TryGet(llvalue) || (llvalue < 0))
1141 {
1142 return SetError(XO("Invalid sequence 'numsamples' attribute."));
1143 }
1144 }
1145 }
1146
1147 // Do not set the handler - already handled
1148
1149 return true;
1150}
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
bool HandleWaveClip(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1012
bool ConvertToSampleFormat(sampleFormat format, const std::function< void(size_t)> &progressReport={})
Definition: Sequence.cpp:137
static bool IsValidSampleFormat(const int nValue)
true if nValue is one of the sampleFormat enum values
Definition: Sequence.cpp:1855
Sequence * GetSequence()
Definition: WaveClip.h:227
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42

References Sequence::ConvertToSampleFormat(), WaveClip::GetSequence(), AUPImportFileHandle::node::handler, HandleWaveClip(), Sequence::IsValidSampleFormat(), mAttrs, mClip, mFormat, mHandlers, mParentTag, SetError(), and XO().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleSilentBlockFile()

bool AUPImportFileHandle::HandleSilentBlockFile ( XMLTagHandler *&  handle)
private

Definition at line 1222 of file ImportAUP.cpp.

1223{
1224 FilePath filename;
1225 size_t len = 0;
1226
1227 for (auto pair : mAttrs)
1228 {
1229 auto attr = pair.first;
1230 auto value = pair.second;
1231
1232 if (attr == "len")
1233 {
1234 long lValue;
1235 if (!value.TryGet(lValue) || !(lValue > 0))
1236 {
1237 return SetError(XO("Missing or invalid silentblockfile 'len' attribute."));
1238 }
1239
1240 len = lValue;
1241 }
1242 }
1243
1244 // Do not set the handler - already handled
1245
1246 AddFile(len, mFormat);
1247
1248 return true;
1249}
wxString FilePath
Definition: Project.h:21

References AddFile(), mAttrs, mFormat, SetError(), and XO().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleSimpleBlockFile()

bool AUPImportFileHandle::HandleSimpleBlockFile ( XMLTagHandler *&  handle)
private

Definition at line 1175 of file ImportAUP.cpp.

1176{
1177 FilePath filename;
1178 size_t len = 0;
1179
1180 for (auto pair : mAttrs)
1181 {
1182 auto attr = pair.first;
1183 auto value = pair.second;
1184
1185 // Can't use XMLValueChecker::IsGoodFileName here, but do part of its test.
1186 if (CaseInsensitiveEquals(attr, "filename"))
1187 {
1188 const wxString strValue = value.ToWString();
1189
1191 {
1192 if (mFileMap.find(strValue) != mFileMap.end())
1193 {
1194 filename = mFileMap[strValue].first;
1195 }
1196 else
1197 {
1198 SetWarning(XO("Missing project file %s\n\nInserting silence instead.")
1199 .Format(strValue));
1200 }
1201 }
1202 }
1203 else if (attr == "len")
1204 {
1205 long lValue;
1206 if (!value.TryGet(lValue) || (lValue <= 0))
1207 {
1208 return SetError(XO("Missing or invalid simpleblockfile 'len' attribute."));
1209 }
1210
1211 len = lValue;
1212 }
1213 }
1214
1215 // Do not set the handler - already handled
1216
1217 AddFile(len, mFormat, filename, filename);
1218
1219 return true;
1220}
static bool IsGoodFileString(const FilePath &str)

References AddFile(), anonymous_namespace{ImportAUP.cpp}::CaseInsensitiveEquals(), XMLValueChecker::IsGoodFileString(), mAttrs, mFileMap, mFormat, SetError(), SetWarning(), and XO().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleTag()

bool AUPImportFileHandle::HandleTag ( XMLTagHandler *&  handle)
private

Definition at line 961 of file ImportAUP.cpp.

962{
963 if (mParentTag != "tags")
964 {
965 return false;
966 }
967
968 wxString n, v;
969
970 for (auto pair : mAttrs)
971 {
972 auto attr = pair.first;
973 auto value = pair.second;
974
975 if (attr == "name")
976 {
977 n = value.ToWString();
978 }
979 else if (attr == "value")
980 {
981 v = value.ToWString();
982 }
983 }
984
985 if (n == wxT("id3v2"))
986 {
987 // LLL: This is obsolete, but it must be handled and ignored.
988 }
989 else
990 {
991 mTags->SetTag(n, v);
992 }
993
994 // Do not set the handler - already handled
995
996 return true;
997}
void SetTag(const wxString &name, const wxString &value, const bool bSpecialTag=false)
Definition: Tags.cpp:441

References mAttrs, mParentTag, mTags, Tags::SetTag(), and wxT().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleTags()

bool AUPImportFileHandle::HandleTags ( XMLTagHandler *&  handle)
private

Definition at line 925 of file ImportAUP.cpp.

926{
927 wxString n;
928 wxString v;
929
930 // Support for legacy tags
931 for (auto pair : mAttrs)
932 {
933 auto attr = pair.first;
934 auto value = pair.second;
935
936 if (attr == "id3v2")
937 {
938 continue;
939 }
940 else if (attr == "track")
941 {
942 n = wxT("TRACKNUMBER");
943 }
944 else
945 {
946 n = std::string(attr);
947 n.MakeUpper();
948 }
949
950 v = value.ToWString();
951
952 if (!v.empty())
953 mTags->SetTag(n, value.ToWString());
954 }
955
956 // Do not set the handler - already handled
957
958 return true;
959}

References mAttrs, mTags, Tags::SetTag(), and wxT().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleTimeTrack()

bool AUPImportFileHandle::HandleTimeTrack ( XMLTagHandler *&  handle)
private

Definition at line 888 of file ImportAUP.cpp.

889{
890 auto &tracks = TrackList::Get(mProject);
891
892 // Bypass this timetrack if the project already has one
893 // (See HandleTimeEnvelope and HandleControlPoint also)
894 if (*tracks.Any<TimeTrack>().begin())
895 {
897 XO("The active project already has a time track and one was encountered in the project being imported, bypassing imported time track."),
898 XO("Project Import"),
899 wxOK | wxICON_EXCLAMATION | wxCENTRE,
901
902 return true;
903 }
904
905 handler =
906 TrackList::Get(mProject).Add(std::make_shared<TimeTrack>());
907
908 return true;
909}

References TrackList::Add(), AudacityMessageBox(), TrackList::Get(), GetProjectFrame(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, mProject, and XO().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleWaveBlock()

bool AUPImportFileHandle::HandleWaveBlock ( XMLTagHandler *&  handle)
private

Definition at line 1152 of file ImportAUP.cpp.

1153{
1154 for (auto pair : mAttrs)
1155 {
1156 auto attr = pair.first;
1157 auto value = pair.second;
1158
1159 if (attr == "start")
1160 {
1161 // making sure that values > 2^31 are OK because long clips will need them.
1162 long long llvalue;
1163 if (!value.TryGet(llvalue) || (llvalue < 0))
1164 {
1165 return SetError(XO("Unable to parse the waveblock 'start' attribute"));
1166 }
1167 }
1168 }
1169
1170 // Do not set the handler - already handled
1171
1172 return true;
1173}

References mAttrs, SetError(), and XO().

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleWaveClip()

bool AUPImportFileHandle::HandleWaveClip ( XMLTagHandler *&  handle)
private

Definition at line 1012 of file ImportAUP.cpp.

1013{
1014 struct node node = mHandlers.back();
1015
1016 if (mParentTag == "wavetrack")
1017 {
1018 WaveTrack *wavetrack = static_cast<WaveTrack *>(node.handler);
1019
1020 handler = wavetrack->CreateClip();
1021 }
1022 else if (mParentTag == "waveclip")
1023 {
1024 // Nested wave clips are cut lines
1025 WaveClip *waveclip = static_cast<WaveClip *>(node.handler);
1026
1027 handler = waveclip->HandleXMLChild(mCurrentTag);
1028 }
1029
1030 mClip = static_cast<WaveClip *>(handler);
1031 mClips.push_back(mClip);
1032
1033 return true;
1034}
std::vector< WaveClip * > mClips
Definition: ImportAUP.cpp:219
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
Definition: WaveClip.cpp:332
WaveClip * CreateClip(double offset=.0, const wxString &name=wxEmptyString)
Definition: WaveTrack.cpp:2232

References WaveTrack::CreateClip(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, AUPImportFileHandle::node::handler, WaveClip::HandleXMLChild(), mClip, mClips, mCurrentTag, mHandlers, and mParentTag.

Referenced by HandleSequence(), and HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleWaveTrack()

bool AUPImportFileHandle::HandleWaveTrack ( XMLTagHandler *&  handle)
private

Definition at line 911 of file ImportAUP.cpp.

912{
913 auto &trackFactory = WaveTrackFactory::Get(mProject);
915 TrackList::Get(mProject).Add(trackFactory.Create());
916
917 // No active clip. In early versions of Audacity, there was a single
918 // implied clip so we'll create a clip when the first "sequence" is
919 // found.
920 mClip = nullptr;
921
922 return true;
923}
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2606

References TrackList::Add(), TrackList::Get(), WaveTrackFactory::Get(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, mClip, mProject, and mWaveTrack.

Referenced by HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleXMLChild()

XMLTagHandler * AUPImportFileHandle::HandleXMLChild ( const std::string_view &  tag)
overrideprivatevirtual

Implements XMLTagHandler.

Definition at line 542 of file ImportAUP.cpp.

543{
544 return this;
545}

◆ HandleXMLEndTag()

void AUPImportFileHandle::HandleXMLEndTag ( const std::string_view &  tag)
overrideprivate

Definition at line 547 of file ImportAUP.cpp.

548{
550 {
551 return;
552 }
553
554 struct node node = mHandlers.back();
555
556 if (tag == "waveclip")
557 {
558 mClip = nullptr;
559 }
560
561 if (node.handler)
562 {
563 node.handler->HandleXMLEndTag(tag);
564 }
565
566 mHandlers.pop_back();
567
568 if (mHandlers.size())
569 {
570 node = mHandlers.back();
571 mParentTag = node.parent;
572 mCurrentTag = node.tag;
573 }
574}
ProgressResult mUpdateResult
Definition: ImportAUP.cpp:221
void HandleXMLEndTag(const std::string_view &tag) override
Definition: WaveClip.cpp:326

References AUPImportFileHandle::node::handler, XMLTagHandler::HandleXMLEndTag(), mClip, mCurrentTag, mHandlers, mParentTag, mUpdateResult, AUPImportFileHandle::node::parent, BasicUI::Success, and AUPImportFileHandle::node::tag.

Here is the call graph for this function:

◆ HandleXMLTag()

bool AUPImportFileHandle::HandleXMLTag ( const std::string_view &  tag,
const AttributesList attrs 
)
overrideprivatevirtual

Implements XMLTagHandler.

Definition at line 576 of file ImportAUP.cpp.

577{
579 {
580 return false;
581 }
582
584 mCurrentTag = std::string(tag);
585 mAttrs = attrs;
586
587 XMLTagHandler *handler = nullptr;
588 bool success = false;
589
590 if (mCurrentTag == "project" ||
591 mCurrentTag == "audacityproject")
592 {
593 success = HandleProject(handler);
594 }
595 else if (mCurrentTag == "labeltrack")
596 {
597 success = HandleLabelTrack(handler);
598 }
599 else if (mCurrentTag == "notetrack")
600 {
601 success = HandleNoteTrack(handler);
602 }
603 else if (mCurrentTag == "timetrack")
604 {
605 success = HandleTimeTrack(handler);
606 }
607 else if (mCurrentTag == "wavetrack")
608 {
609 success = HandleWaveTrack(handler);
610 }
611 else if (mCurrentTag == "tags")
612 {
613 success = HandleTags(handler);
614 }
615 else if (mCurrentTag == "tag")
616 {
617 success = HandleTag(handler);
618 }
619 else if (mCurrentTag == "label")
620 {
621 success = HandleLabel(handler);
622 }
623 else if (mCurrentTag == "waveclip")
624 {
625 success = HandleWaveClip(handler);
626 }
627 else if (mCurrentTag == "sequence")
628 {
629 success = HandleSequence(handler);
630 }
631 else if (mCurrentTag == "waveblock")
632 {
633 success = HandleWaveBlock(handler);
634 }
635 else if (mCurrentTag == "envelope")
636 {
637 success = HandleEnvelope(handler);
638 }
639 else if (mCurrentTag == "controlpoint")
640 {
641 success = HandleControlPoint(handler);
642 }
643 else if (mCurrentTag == "simpleblockfile")
644 {
646 }
647 else if (mCurrentTag == "silentblockfile")
648 {
650 }
651 else if (mCurrentTag == "pcmaliasblockfile")
652 {
654 }
655 else if (mCurrentTag == "import")
656 {
657 success = HandleImport(handler);
658 }
659
660 if (!success || (handler && !handler->HandleXMLTag(tag, attrs)))
661 {
662 return SetError(XO("Internal error in importer...tag not recognized"));
663 }
664
666
667 return true;
668}
bool HandlePCMAliasBlockFile(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1251
bool HandleProject(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:670
bool HandleSilentBlockFile(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1222
bool HandleLabel(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:999
bool HandleWaveBlock(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1152
bool HandleLabelTrack(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:864
bool HandleSequence(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1087
bool HandleWaveTrack(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:911
bool HandleNoteTrack(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:871
bool HandleTimeTrack(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:888
bool HandleControlPoint(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1068
bool HandleImport(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1334
bool HandleTag(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:961
bool HandleSimpleBlockFile(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1175
bool HandleTags(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:925
bool HandleEnvelope(XMLTagHandler *&handle)
Definition: ImportAUP.cpp:1036

References HandleControlPoint(), HandleEnvelope(), HandleImport(), HandleLabel(), HandleLabelTrack(), HandleNoteTrack(), HandlePCMAliasBlockFile(), HandleProject(), cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, HandleSequence(), HandleSilentBlockFile(), HandleSimpleBlockFile(), HandleTag(), HandleTags(), HandleTimeTrack(), HandleWaveBlock(), HandleWaveClip(), HandleWaveTrack(), mAttrs, mCurrentTag, mHandlers, mParentTag, mUpdateResult, SetError(), BasicUI::Success, and XO().

Here is the call graph for this function:

◆ Import()

ProgressResult AUPImportFileHandle::Import ( WaveTrackFactory trackFactory,
TrackHolders outTracks,
Tags tags 
)
overridevirtual

Implements ImportFileHandle.

Definition at line 306 of file ImportAUP.cpp.

309{
310 auto &history = ProjectHistory::Get(mProject);
311 auto &tracks = TrackList::Get(mProject);
312 auto &viewInfo = ViewInfo::Get(mProject);
315
316 auto oldNumTracks = tracks.size();
317 auto cleanup = finally([this, &tracks, oldNumTracks]{
319 // Revoke additions of tracks
320 while (oldNumTracks < tracks.size()) {
321 Track *lastTrack = *tracks.Any().rbegin();
322 tracks.Remove(lastTrack);
323 }
324 }
325 });
326
327 bool isDirty = history.GetDirty() || !tracks.empty();
328
329 mTotalSamples = 0;
330
331 mTags = tags;
332
334
336
337 XMLFileReader xmlFile;
338
339 bool success = xmlFile.Parse(this, mFilename);
340 if (!success)
341 {
343 XO("Couldn't import the project:\n\n%s").Format(xmlFile.GetErrorStr()),
344 XO("Import Project"),
345 wxOK | wxCENTRE,
347
348 return ProgressResult::Failed;
349 }
350
351 if (!mErrorMsg.empty())
352 {
353 // Error or warning
355 mErrorMsg,
356 XO("Import Project"),
357 wxOK | wxCENTRE,
359
360 if (mUpdateResult == ProgressResult::Failed)
361 {
362 // Error
363 return ProgressResult::Failed;
364 }
365 }
366
367 // If mUpdateResult had been changed, we would have returned already
369
370 sampleCount processed = 0;
371 for (auto fi : mFiles)
372 {
375 {
376 return mUpdateResult;
377 }
378
379 mClip = fi.clip;
380 mWaveTrack = fi.track;
381
382 if (fi.blockFile.empty())
383 {
384 AddSilence(fi.len);
385 }
386 else
387 {
388 AddSamples(fi.blockFile, fi.audioFile,
389 fi.len, fi.format, fi.origin, fi.channel);
390 }
391
392 processed += fi.len;
393 }
394
395 for (auto pClip : mClips)
396 pClip->UpdateEnvelopeTrackLen();
397
399
400 // If the active project is "dirty", then bypass the below updates as we don't
401 // want to going changing things the user may have already set up.
402 if (isDirty)
403 {
404 return mUpdateResult;
405 }
406
407 if (mProjectAttrs.haverate)
409
410 if (mProjectAttrs.havesnapto)
411 {
414 }
415
416 if (mProjectAttrs.haveselectionformat)
417 {
418 selman.AS_SetSelectionFormat(NumericConverterFormats::Lookup(
420 mProjectAttrs.selectionformat));
421 }
422
423 if (mProjectAttrs.haveaudiotimeformat)
424 {
425 selman.TT_SetAudioTimeFormat(NumericConverterFormats::Lookup(
427 mProjectAttrs.audiotimeformat));
428 }
429
430 if (mProjectAttrs.havefrequencyformat)
431 {
432 selman.SSBL_SetFrequencySelectionFormatName(
436 mProjectAttrs.frequencyformat));
437 }
438
439 if (mProjectAttrs.havebandwidthformat)
440 {
441 selman.SSBL_SetBandwidthSelectionFormatName(
445 mProjectAttrs.bandwidthformat));
446 }
447
448 // PRL: It seems this must happen after SetSnapTo
449 if (mProjectAttrs.havevpos)
450 {
451 viewInfo.vpos = mProjectAttrs.vpos;
452 }
453
454 if (mProjectAttrs.haveh)
455 {
456 viewInfo.h = mProjectAttrs.h;
457 }
458
459 if (mProjectAttrs.havezoom)
460 {
461 viewInfo.SetZoom(mProjectAttrs.zoom);
462 }
463
464 if (mProjectAttrs.havesel0)
465 {
466 viewInfo.selectedRegion.setT0(mProjectAttrs.sel0);
467 }
468
469 if (mProjectAttrs.havesel1)
470 {
471 viewInfo.selectedRegion.setT1(mProjectAttrs.sel1);
472 }
473
474#ifdef EXPERIMENTAL_SPECTRAL_EDITING
475 if (mProjectAttrs.haveselLow)
476 {
477 viewInfo.selectedRegion.setF0(mProjectAttrs.selLow);
478 }
479
480 if (mProjectAttrs.haveselHigh)
481 {
482 viewInfo.selectedRegion.setF1(mProjectAttrs.selHigh);
483 }
484#endif
485
486 return mUpdateResult;
487}
const NumericConverterType & NumericConverterType_BANDWIDTH()
const NumericConverterType & NumericConverterType_FREQUENCY()
const NumericConverterType & NumericConverterType_TIME()
static Settings & settings()
Definition: TrackInfo.cpp:83
TranslatableString mErrorMsg
Definition: ImportAUP.cpp:222
bool AddSamples(const FilePath &blockFilename, const FilePath &audioFilename, sampleCount len, sampleFormat format, sampleCount origin=0, int channel=0)
Definition: ImportAUP.cpp:1449
struct AUPImportFileHandle::@47 mProjectAttrs
static FormatterContext ProjectContext(const AudacityProject &project)
std::unique_ptr< ProgressDialog > mProgress
Definition: ImportPlugin.h:164
static ProjectHistory & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
void SetRate(double rate)
Definition: ProjectRate.cpp:58
static ProjectSelectionManager & Get(AudacityProject &project)
static ProjectSettings & Get(AudacityProject &project)
void SetSnapMode(SnapMode mode)
Definition: ProjectSnap.cpp:41
static ProjectSnap & Get(AudacityProject &project)
Definition: ProjectSnap.cpp:27
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
Reads a file and passes the results through an XMLTagHandler.
Definition: XMLFileReader.h:19
const TranslatableString & GetErrorStr() const
bool Parse(XMLTagHandler *baseHandler, const FilePath &fname)
NUMERIC_FORMATS_API NumericFormatSymbol Lookup(const FormatterContext &context, const NumericConverterType &type, const NumericFormatSymbol &formatIdentifier)
Looks up the format, returns Default for the type if the format is not registered.

References AddSamples(), AddSilence(), sampleCount::as_long_long(), AudacityMessageBox(), ImportFileHandle::CreateProgress(), TranslatableString::empty(), ProjectHistory::Get(), ProjectRate::Get(), ProjectSnap::Get(), ViewInfo::Get(), TrackList::Get(), ProjectSelectionManager::Get(), ProjectSettings::Get(), XMLFileReader::GetErrorStr(), GetProjectFrame(), NumericConverterFormats::Lookup(), mClip, mClips, mErrorMsg, ImportFileHandle::mFilename, mFiles, ImportFileHandle::mProgress, mProject, mProjectAttrs, mTags, mTotalSamples, mUpdateResult, mWaveTrack, NumericConverterType_BANDWIDTH(), NumericConverterType_FREQUENCY(), NumericConverterType_TIME(), XMLFileReader::Parse(), FormatterContext::ProjectContext(), ProjectRate::SetRate(), ProjectSnap::SetSnapMode(), settings(), SNAP_NEAREST, SNAP_OFF, BasicUI::Success, and XO().

Here is the call graph for this function:

◆ Open()

bool AUPImportFileHandle::Open ( )

Definition at line 504 of file ImportAUP.cpp.

505{
506 wxFFile ff(mFilename, wxT("rb"));
507 if (ff.IsOpened())
508 {
509 char buf[256];
510
511 int numRead = ff.Read(buf, sizeof(buf));
512
513 ff.Close();
514
515 buf[sizeof(buf) - 1] = '\0';
516
517 if (!wxStrncmp(buf, wxT("AudacityProject"), 15))
518 {
520 XO("This project was saved by Audacity version 1.0 or earlier. The format has\n"
521 "changed and this version of Audacity is unable to import the project.\n\n"
522 "Use a version of Audacity prior to v3.0.0 to upgrade the project and then\n"
523 "you may import it with this version of Audacity."),
524 XO("Import Project"),
525 wxOK | wxCENTRE,
527
528 return false;
529 }
530
531 if (wxStrncmp(buf, "<?xml", 5) == 0 &&
532 (wxStrstr(buf, "<audacityproject") ||
533 wxStrstr(buf, "<project") ))
534 {
535 return true;
536 }
537 }
538
539 return false;
540}

References AudacityMessageBox(), GetProjectFrame(), ImportFileHandle::mFilename, mProject, wxT(), and XO().

Here is the call graph for this function:

◆ SetError()

bool AUPImportFileHandle::SetError ( const TranslatableString msg)
private

Definition at line 1660 of file ImportAUP.cpp.

1661{
1662 wxLogError(msg.Debug());
1663
1665 {
1666 mErrorMsg = msg;
1667 }
1668
1669 // The only place where mUpdateResult is set during XML handling callbacks
1670 mUpdateResult = ProgressResult::Failed;
1671
1672 return false;
1673}
wxString Debug() const
Format as an English string for debugging logs and developers' eyes, not for end users.

References TranslatableString::Debug(), TranslatableString::empty(), mErrorMsg, mUpdateResult, and BasicUI::Success.

Referenced by HandlePCMAliasBlockFile(), HandleProject(), HandleSequence(), HandleSilentBlockFile(), HandleSimpleBlockFile(), HandleWaveBlock(), and HandleXMLTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetStreamUsage()

void AUPImportFileHandle::SetStreamUsage ( wxInt32   WXUNUSEDStreamID,
bool   WXUNUSEDUse 
)
override

Definition at line 500 of file ImportAUP.cpp.

501{
502}

◆ SetWarning()

bool AUPImportFileHandle::SetWarning ( const TranslatableString msg)
private

Definition at line 1675 of file ImportAUP.cpp.

1676{
1677 wxLogWarning(msg.Debug());
1678
1679 if (mErrorMsg.empty())
1680 {
1681 mErrorMsg = msg;
1682 }
1683
1684 return false;
1685}

References TranslatableString::Debug(), TranslatableString::empty(), and mErrorMsg.

Referenced by AddSamples(), HandlePCMAliasBlockFile(), and HandleSimpleBlockFile().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAttrs

AttributesList AUPImportFileHandle::mAttrs
private

◆ mClip

WaveClip* AUPImportFileHandle::mClip
private

◆ mClips

std::vector<WaveClip *> AUPImportFileHandle::mClips
private

Definition at line 219 of file ImportAUP.cpp.

Referenced by HandleWaveClip(), and Import().

◆ mCurrentTag

std::string AUPImportFileHandle::mCurrentTag
private

Definition at line 209 of file ImportAUP.cpp.

Referenced by HandleControlPoint(), HandleWaveClip(), HandleXMLEndTag(), and HandleXMLTag().

◆ mErrorMsg

TranslatableString AUPImportFileHandle::mErrorMsg
private

Definition at line 222 of file ImportAUP.cpp.

Referenced by Import(), SetError(), and SetWarning().

◆ mFileMap

BlockFileMap AUPImportFileHandle::mFileMap
private

Definition at line 215 of file ImportAUP.cpp.

Referenced by AddSamples(), HandleProject(), and HandleSimpleBlockFile().

◆ mFiles

std::vector<fileinfo> AUPImportFileHandle::mFiles
private

Definition at line 201 of file ImportAUP.cpp.

Referenced by AddFile(), and Import().

◆ mFormat

sampleFormat AUPImportFileHandle::mFormat
private

◆ mHandlers

stack AUPImportFileHandle::mHandlers
private

◆ mNumChannels

unsigned long AUPImportFileHandle::mNumChannels
private

Definition at line 205 of file ImportAUP.cpp.

◆ mParentTag

std::string AUPImportFileHandle::mParentTag
private

◆ mProjDir

wxFileName AUPImportFileHandle::mProjDir
private

Definition at line 212 of file ImportAUP.cpp.

Referenced by HandlePCMAliasBlockFile(), and HandleProject().

◆ mProject

AudacityProject& AUPImportFileHandle::mProject
private

◆ 

struct { ... } AUPImportFileHandle::mProjectAttrs

Referenced by Import().

◆ mTags

Tags* AUPImportFileHandle::mTags
private

Definition at line 165 of file ImportAUP.cpp.

Referenced by HandleTag(), HandleTags(), and Import().

◆ mTotalSamples

sampleCount AUPImportFileHandle::mTotalSamples
private

Definition at line 202 of file ImportAUP.cpp.

Referenced by AddFile(), and Import().

◆ mUpdateResult

ProgressResult AUPImportFileHandle::mUpdateResult
private

Definition at line 221 of file ImportAUP.cpp.

Referenced by HandleXMLEndTag(), HandleXMLTag(), Import(), and SetError().

◆ mWaveTrack

WaveTrack* AUPImportFileHandle::mWaveTrack
private

Definition at line 217 of file ImportAUP.cpp.

Referenced by AddFile(), AddSamples(), AddSilence(), HandleEnvelope(), HandleWaveTrack(), and Import().


The documentation for this class was generated from the following file: