MCPcopy Create free account
hub / github.com/audacity/audacity / Import

Method Import

libraries/lib-import-export/Import.cpp:487–858  ·  view source on GitHub ↗

returns number of tracks imported

Source from the content-addressed store, hash-verified

485
486// returns number of tracks imported
487bool Importer::Import(
488 AudacityProject& project, const FilePath& fName,
489 ImportProgressListener* importProgressListener,
490 WaveTrackFactory* trackFactory, TrackHolders& tracks, Tags* tags,
491 std::optional<LibFileFormats::AcidizerTags>& outAcidTags,
492 TranslatableString& errorMessage)
493{
494 AudacityProject *pProj = &project;
495 auto cleanup = valueRestorer( pProj->mbBusyImporting, true );
496
497 const FileExtension extension{ fName.AfterLast(wxT('.')) };
498
499 // Bug #2647: Peter has a Word 2000 .doc file that is recognized and imported by FFmpeg.
500 if (wxFileName(fName).GetExt() == wxT("doc")) {
501 errorMessage =
502 XO("\"%s\" \nis a not an audio file. \nAudacity cannot open this type of file.")
503 .Format( fName );
504 return false;
505 }
506
507 using ImportPluginPtrs = std::vector< ImportPlugin* >;
508
509 // This list is used to call plugins in correct order
510 ImportPluginPtrs importPlugins;
511
512 // This list is used to remember plugins that should have been compatible with the file.
513 ImportPluginPtrs compatiblePlugins;
514
515 // Not implemented (yet?)
516 wxString mime_type = wxT("*");
517
518 // First, add user-selected filter
519 bool usersSelectionOverrides;
520 gPrefs->Read(wxT("/ExtendedImport/OverrideExtendedImportByOpenFileDialogChoice"), &usersSelectionOverrides, false);
521
522 if (usersSelectionOverrides)
523 {
524 // If user explicitly selected a filter,
525 // then we should try importing via corresponding plugin first
526 wxString type = gPrefs->Read(wxT("/LastOpenType"),wxT(""));
527
528 wxLogDebug(wxT("LastOpenType is %s"),type);
529 wxLogDebug(wxT("OverrideExtendedImportByOpenFileDialogChoice is %i"),usersSelectionOverrides);
530
531 for (const auto &plugin : sImportPluginList())
532 {
533 if (plugin->GetPluginFormatDescription().Translation() == type )
534 {
535 // This plugin corresponds to user-selected filter, try it first.
536 wxLogDebug(wxT("Inserting %s"),plugin->GetPluginStringID());
537 importPlugins.insert(importPlugins.begin(), plugin);
538 }
539 }
540 }
541
542 wxLogMessage(wxT("File name is %s"), fName);
543 wxLogMessage(wxT("Mime type is %s"), mime_type.Lower());
544

Callers

nothing calls this directly

Calls 15

valueRestorerFunction · 0.85
MakeGenericProgressFunction · 0.85
YieldFunction · 0.85
VerbatimFunction · 0.85
TranslationMethod · 0.80
SupportsExtensionMethod · 0.80
wxFileNameClass · 0.70
statClass · 0.70
ReadMethod · 0.45
GetPluginStringIDMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected