Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
LOFImportFileHandle Class Referencefinal

An ImportFileHandle for LOF data. More...

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

Public Member Functions

 LOFImportFileHandle (AudacityProject *pProject, const FilePath &name, std::unique_ptr< wxTextFile > &&file)
 
 ~LOFImportFileHandle ()
 
TranslatableString GetFileDescription () override
 
ByteCount GetFileUncompressedBytes () override
 
void Import (ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags, std::optional< LibFileFormats::AcidizerTags > &outAcidTags) override
 
FilePath GetFilename () const override
 
void Cancel () override
 
void Stop () override
 
wxInt32 GetStreamCount () override
 
const TranslatableStringsGetStreamInfo () override
 
void SetStreamUsage (wxInt32 WXUNUSED(StreamID), bool WXUNUSED(Use)) override
 
- Public Member Functions inherited from ImportFileHandle
virtual ~ImportFileHandle ()
 
virtual FilePath GetFilename () const =0
 
virtual TranslatableString GetErrorMessage () const
 
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 void Import (ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags, std::optional< LibFileFormats::AcidizerTags > &acidTags)=0
 
virtual void Cancel ()=0
 
virtual void Stop ()=0
 

Private Member Functions

void lofOpenFiles (wxString *ln)
 Processes a single line from a LOF text file, doing whatever is indicated on the line. More...
 
void doDurationAndScrollOffset ()
 

Private Attributes

std::unique_ptr< wxTextFile > mTextFile
 
const wxFileName mLOFFileName
 
AudacityProjectmProject {}
 
int nFilesInGroup { 0 }
 
bool callDurationFactor { false }
 
double durationFactor { 1 }
 
bool callScrollOffset { false }
 
double scrollOffset { 0 }
 

Additional Inherited Members

- Public Types inherited from ImportFileHandle
using ByteCount = unsigned long long
 

Detailed Description

An ImportFileHandle for LOF data.

Supports the opening of ".lof" files which are text files that contain a list of individual files to open in audacity in specific formats. Files may be file names (in the same directory as the LOF file), absolute paths or relative paths relative to the directory of the LOF file.

(In BNF) The syntax for an LOF file, denoted by <lof>:

  <lof> ::= [<window> | <file> | <#>]*
  <window> ::= window [<window-parameter>]* <newline>
  <window-parameter> ::= offset <time> | duration <time>
  <time> ::= [<digit>]+ [ . [<digit>]* ]
  <file> ::= file [<file-parameter>]* <newline>
  <file-parameter> ::= offset <time>
  <#> ::= <comment> <newline>

EXAMPLE LOF file:

  # everything following the hash character is ignored
  window # an initial window command is implicit and optional
  file "C:\folder1\sample1.wav"    # sample1.wav is displayed
  file "C:\sample2.wav" offset 5   # sample2 is displayed with a 5s offset
  File "C:\sample3.wav"            # sample3 is displayed with no offset
  File "foo.aiff" # foo is loaded from the same directory as the LOF file
  window offset 5 duration 10      # open a NEW window, zoom to display
  # 10 seconds total starting at 5 (ending at 15) seconds
  file "C:\sample3.wav" offset 2.5

SEMANTICS:

There are two commands: "window" creates a NEW window, and "file" appends a track to the current window and displays the file there. The first file is always placed in a NEW window, whether or not an initial "window" command is given.

Commands have optional keyword parameters that may be listed in any order. A parameter should only occur once per command. The "offset" parameter specifies a time offset. For windows, this is the leftmost time displayed in the window. For files, the offset is an amount by which the file is shifted in time before display (only enabled for audio; not midi). The offset is specified as an integer or decimal number of seconds, and the default value is zero.

Windows may also have a "duration" parameter, which specifies how much time should be displayed in the window. The default duration is equal to the duration of the longest track currently displayed.

Definition at line 113 of file ImportLOF.cpp.

Constructor & Destructor Documentation

◆ LOFImportFileHandle()

LOFImportFileHandle::LOFImportFileHandle ( AudacityProject pProject,
const FilePath name,
std::unique_ptr< wxTextFile > &&  file 
)

Definition at line 166 of file ImportLOF.cpp.

168: mTextFile(std::move(file))
170 , mProject{ pProject }
171{
172}
const TranslatableString name
Definition: Distortion.cpp:76
const wxFileName mLOFFileName
Definition: ImportLOF.cpp:150
std::unique_ptr< wxTextFile > mTextFile
Definition: ImportLOF.cpp:149
AudacityProject * mProject
Definition: ImportLOF.cpp:152

◆ ~LOFImportFileHandle()

LOFImportFileHandle::~LOFImportFileHandle ( )

Definition at line 534 of file ImportLOF.cpp.

535{
536}

Member Function Documentation

◆ Cancel()

void LOFImportFileHandle::Cancel ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 324 of file ImportLOF.cpp.

325{
326 //LOFImport delegates import to other plugins
327}

◆ doDurationAndScrollOffset()

void LOFImportFileHandle::doDurationAndScrollOffset ( )
private

Definition at line 508 of file ImportLOF.cpp.

509{
510 if (!mProject)
511 return;
512
514 bool doSomething = callDurationFactor || callScrollOffset;
515
517 {
518 double longestDuration = TrackList::Get(*mProject).GetEndTime();
519 Viewport::Get(*mProject).ZoomBy(longestDuration / durationFactor);
520 callDurationFactor = false;
521 }
522
524 {
526 callScrollOffset = false;
527 }
528
529 if (doSomething)
530 // Amend last undo state
531 ProjectHistory::Get( *mProject ).ModifyState(false);
532}
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
double GetEndTime() const
Return the greatest end time of the tracks, or 0 when no tracks.
Definition: Track.cpp:991
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
void ZoomBy(double multiplier)
Multiply the magnification; unchanged left edge time.
Definition: Viewport.cpp:510
void SetHorizontalThumb(double scrollto, bool doScroll=true)
Definition: Viewport.cpp:200
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:32

References callDurationFactor, callScrollOffset, durationFactor, ProjectHistory::Get(), TrackList::Get(), Viewport::Get(), TrackList::GetEndTime(), ProjectHistory::ModifyState(), mProject, scrollOffset, Viewport::SetHorizontalThumb(), and Viewport::ZoomBy().

Referenced by Import(), and lofOpenFiles().

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

◆ GetFileDescription()

TranslatableString LOFImportFileHandle::GetFileDescription ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 261 of file ImportLOF.cpp.

262{
263 return DESC;
264}
#define DESC
Definition: ImportLOF.cpp:90

References DESC.

◆ GetFilename()

FilePath LOFImportFileHandle::GetFilename ( ) const
overridevirtual

Implements ImportFileHandle.

Definition at line 319 of file ImportLOF.cpp.

320{
321 return mLOFFileName.GetFullPath();
322}

References mLOFFileName.

◆ GetFileUncompressedBytes()

auto LOFImportFileHandle::GetFileUncompressedBytes ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 266 of file ImportLOF.cpp.

267{
268 return 0;
269}

◆ GetStreamCount()

wxInt32 LOFImportFileHandle::GetStreamCount ( )
inlineoverridevirtual

Implements ImportFileHandle.

Definition at line 133 of file ImportLOF.cpp.

133{ return 1; }

◆ GetStreamInfo()

const TranslatableStrings & LOFImportFileHandle::GetStreamInfo ( )
inlineoverridevirtual

Implements ImportFileHandle.

Definition at line 135 of file ImportLOF.cpp.

136 {
137 static TranslatableStrings empty;
138 return empty;
139 }
std::vector< TranslatableString > TranslatableStrings

◆ Import()

void LOFImportFileHandle::Import ( ImportProgressListener progressListener,
WaveTrackFactory trackFactory,
TrackHolders outTracks,
Tags tags,
std::optional< LibFileFormats::AcidizerTags > &  outAcidTags 
)
overridevirtual

Implements ImportFileHandle.

Definition at line 271 of file ImportLOF.cpp.

274{
275 // Unlike other ImportFileHandle subclasses, this one never gives any tracks
276 // back to the caller.
277 // Instead, it recursively calls AudacityProject::Import for each file listed
278 // in the .lof file.
279 // Each importation creates a NEW undo state.
280 // If there is an error or exception during one of them, only that one's
281 // side effects are rolled back, and the rest of the import list is skipped.
282 // The file may have "window" directives that cause NEW AudacityProjects
283 // to be created, and the undo states are pushed onto the latest project.
284 // If a project is created but the first file import into it fails, destroy
285 // the project.
286
287 outTracks.clear();
288
289 wxASSERT(mTextFile->IsOpened());
290
291 if(mTextFile->Eof())
292 {
293 mTextFile->Close();
295 return;
296 }
297
298 wxString line = mTextFile->GetFirstLine();
299
300 while (!mTextFile->Eof())
301 {
302 lofOpenFiles(&line);
303 line = mTextFile->GetNextLine();
304 }
305
306 // for last line
307 lofOpenFiles(&line);
308
309 if(!mTextFile->Close())
310 {
312 return;
313 }
314 // set any duration/offset factors for last window, as all files were called
317}
virtual void OnImportResult(ImportResult result)=0
Used to report on import result for file handle passed as argument to OnImportFileOpened.
void lofOpenFiles(wxString *ln)
Processes a single line from a LOF text file, doing whatever is indicated on the line.
Definition: ImportLOF.cpp:344
void doDurationAndScrollOffset()
Definition: ImportLOF.cpp:508

References doDurationAndScrollOffset(), ImportProgressListener::Error, lofOpenFiles(), mTextFile, ImportProgressListener::OnImportResult(), and ImportProgressListener::Success.

Here is the call graph for this function:

◆ lofOpenFiles()

void LOFImportFileHandle::lofOpenFiles ( wxString *  ln)
private

Processes a single line from a LOF text file, doing whatever is indicated on the line.

This function should just return for lines it cannot deal with, and the caller will continue to the next line of the input file

Definition at line 344 of file ImportLOF.cpp.

345{
346 wxStringTokenizer tok(*ln, wxT(" "));
347 wxStringTokenizer temptok1(*ln, wxT("\""));
348 wxStringTokenizer temptok2(*ln, wxT(" "));
349 int tokenplace = 0;
350
351 wxString targetfile;
352 wxString tokenholder = tok.GetNextToken();
353
354
355 if (tokenholder.IsSameAs(wxT("window"), false))
356 {
357 // set any duration/offset factors for last window, as all files were called
359
360 if (nFilesInGroup > 0 )
361 // Cause a project to be created with the next import
362 mProject = nullptr;
363
364 nFilesInGroup = 0;
365
366 while (tok.HasMoreTokens())
367 {
368 tokenholder = tok.GetNextToken();
369
370 if (tokenholder.IsSameAs(wxT("offset"), false))
371 {
372 if (tok.HasMoreTokens())
373 tokenholder = tok.GetNextToken();
374
376 {
377 callScrollOffset = true;
378 }
379 else
380 {
382 /* i18n-hint: You do not need to translate "LOF" */
383 XO("Invalid window offset in LOF file."));
384 }
385
386 if (tok.HasMoreTokens())
387 tokenholder = tok.GetNextToken();
388 }
389
390 if (tokenholder.IsSameAs(wxT("duration"), false))
391 {
392 if (tok.HasMoreTokens())
393 tokenholder = tok.GetNextToken();
394
396 {
397 callDurationFactor = true;
398 }
399 else
400 {
402 /* i18n-hint: You do not need to translate "LOF" */
403 XO("Invalid duration in LOF file."));
404 }
405 } // End if statement
406
407 if (tokenholder == wxT("#"))
408 {
409 // # indicates comments; ignore line
410 tok = wxStringTokenizer(wxT(""), wxT(" "));
411 }
412 } // End while loop
413 } // End if statement handling "window" lines
414
415 else if (tokenholder.IsSameAs(wxT("file"), false))
416 {
418 // To identify filename and open it
419 tokenholder = temptok1.GetNextToken();
420 wxString targettoken = temptok1.GetNextToken();
421 targetfile = targettoken;
422
423 // If path is relative, make absolute path from LOF path
424 if(!wxIsAbsolutePath(targetfile)) {
425 wxFileName fName(targetfile);
426 fName.Normalize(wxPATH_NORM_ALL, mLOFFileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
427 if(fName.FileExists()) {
428 targetfile = fName.GetFullPath();
429 }
430 }
431
432 // Do recursive call to import
434 true /* addtohistory */, true /* reuseNonemptyProject */ );
435
436 // Set tok to right after filename
437 temptok2.SetString(targettoken);
438 tokenplace = temptok2.CountTokens();
439
440 for (int i = 0; i < tokenplace; i++)
441 tokenholder = tok.GetNextToken();
442
443 if (tok.HasMoreTokens())
444 {
445 tokenholder = tok.GetNextToken();
446
447 if (tokenholder == wxT("#"))
448 {
449 // # indicates comments; ignore line
450 tok = wxStringTokenizer(wxT(""), wxT(" "));
451 }
452
453 if (tokenholder.IsSameAs(wxT("offset"), false))
454 {
455 if (tok.HasMoreTokens())
456 tokenholder = tok.GetNextToken();
457 double offset;
458
459 // handle an "offset" specifier
460 if (!mProject)
461 // there was an import error,
462 // presumably with its own error message
463 ;
464 else if (Internat::CompatibleToDouble(tokenholder, &offset))
465 {
466 auto &tracks = TrackList::Get( *mProject );
467 auto t = *tracks.rbegin();
468
469 // t is now the last track in the project, unless the import of
470 // all tracks failed, in which case it will be null. In that
471 // case we return because we cannot offset a non-existent track.
472 if (t == NULL)
473 return;
474#ifdef USE_MIDI
475 if (targetfile.AfterLast(wxT('.')).IsSameAs(wxT("mid"), false) ||
476 targetfile.AfterLast(wxT('.')).IsSameAs(wxT("midi"), false))
477 {
478 ImportUtils::ShowMessageBox(XO("MIDI tracks cannot be offset individually, only audio files can be."));
479 }
480 else
481#endif
482 t->MoveTo(offset);
483
484 // Amend the undo transaction made by import
485 ProjectHistory::Get( *mProject ).ModifyState(false);
486 } // end of converting "offset" argument
487 else
488 {
490 /* i18n-hint: You do not need to translate "LOF" */
491 XO("Invalid track offset in LOF file."));
492 }
493 } // End if statement for "offset" parameters
494 } // End if statement (more tokens after file name)
495 } // End if statement "file" lines
496
497 else if (tokenholder == wxT("#"))
498 {
499 // # indicates comments; ignore line
500 tok = wxStringTokenizer(wxT(""), wxT(" "));
501 }
502 else
503 {
504 // Couldn't parse a line
505 }
506}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
const auto tracks
static void ShowMessageBox(const TranslatableString &message, const TranslatableString &caption=XO("Import Project"))
Definition: ImportUtils.cpp:43
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:109
static AudacityProject * OpenProject(AudacityProject *pGivenProject, const FilePath &fileNameArg, bool addtohistory, bool reuseNonemptyProject)
Open a file into an AudacityProject, returning the project, or nullptr for failure.

References callDurationFactor, callScrollOffset, Internat::CompatibleToDouble(), doDurationAndScrollOffset(), durationFactor, ProjectHistory::Get(), TrackList::Get(), mLOFFileName, ProjectHistory::ModifyState(), mProject, nFilesInGroup, ProjectManager::OpenProject(), scrollOffset, ImportUtils::ShowMessageBox(), tracks, wxT(), and XO().

Referenced by Import().

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

◆ SetStreamUsage()

void LOFImportFileHandle::SetStreamUsage ( wxInt32   WXUNUSEDStreamID,
bool   WXUNUSEDUse 
)
inlineoverride

Definition at line 141 of file ImportLOF.cpp.

142 {}

◆ Stop()

void LOFImportFileHandle::Stop ( )
overridevirtual

Implements ImportFileHandle.

Definition at line 329 of file ImportLOF.cpp.

330{
331 //LOFImport delegates import to other plugins
332}

Member Data Documentation

◆ callDurationFactor

bool LOFImportFileHandle::callDurationFactor { false }
private

Definition at line 158 of file ImportLOF.cpp.

Referenced by doDurationAndScrollOffset(), and lofOpenFiles().

◆ callScrollOffset

bool LOFImportFileHandle::callScrollOffset { false }
private

Definition at line 162 of file ImportLOF.cpp.

Referenced by doDurationAndScrollOffset(), and lofOpenFiles().

◆ durationFactor

double LOFImportFileHandle::durationFactor { 1 }
private

Definition at line 159 of file ImportLOF.cpp.

Referenced by doDurationAndScrollOffset(), and lofOpenFiles().

◆ mLOFFileName

const wxFileName LOFImportFileHandle::mLOFFileName
private

The name of the LOF file, which is used to interpret relative paths in it

Definition at line 150 of file ImportLOF.cpp.

Referenced by GetFilename(), and lofOpenFiles().

◆ mProject

AudacityProject* LOFImportFileHandle::mProject {}
private

Definition at line 152 of file ImportLOF.cpp.

Referenced by doDurationAndScrollOffset(), and lofOpenFiles().

◆ mTextFile

std::unique_ptr<wxTextFile> LOFImportFileHandle::mTextFile
private

Definition at line 149 of file ImportLOF.cpp.

Referenced by Import().

◆ nFilesInGroup

int LOFImportFileHandle::nFilesInGroup { 0 }
private

Definition at line 155 of file ImportLOF.cpp.

Referenced by lofOpenFiles().

◆ scrollOffset

double LOFImportFileHandle::scrollOffset { 0 }
private

Definition at line 163 of file ImportLOF.cpp.

Referenced by doDurationAndScrollOffset(), and lofOpenFiles().


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