diff --git a/src/ProjectFileManager.cpp b/src/ProjectFileManager.cpp index 2a5cc3092..cb5eef0f0 100644 --- a/src/ProjectFileManager.cpp +++ b/src/ProjectFileManager.cpp @@ -1620,7 +1620,7 @@ bool ProjectFileManager::Import( auto newTags = oldTags->Duplicate(); Tags::Set( project, newTags ); - bool success = Importer::Get().Import(fileName, + bool success = Importer::Get().Import(project, fileName, &TrackFactory::Get( project ), newTracks, newTags.get(), diff --git a/src/import/Import.cpp b/src/import/Import.cpp index 00de0bf2e..a42683a7e 100644 --- a/src/import/Import.cpp +++ b/src/import/Import.cpp @@ -409,13 +409,14 @@ std::unique_ptr Importer::CreateDefaultImportItem() } // returns number of tracks imported -bool Importer::Import(const FilePath &fName, +bool Importer::Import( AudacityProject &project, + const FilePath &fName, TrackFactory *trackFactory, TrackHolders &tracks, Tags *tags, TranslatableString &errorMessage) { - AudacityProject *pProj = GetActiveProject(); + AudacityProject *pProj = &project; auto cleanup = valueRestorer( pProj->mbBusyImporting, true ); const FileExtension extension{ fName.AfterLast(wxT('.')) }; @@ -589,7 +590,7 @@ bool Importer::Import(const FilePath &fName, { // Try to open the file with this plugin (probe it) wxLogMessage(wxT("Opening with %s"),plugin->GetPluginStringID()); - auto inFile = plugin->Open(fName); + auto inFile = plugin->Open(fName, pProj); if ( (inFile != NULL) && (inFile->GetStreamCount() > 0) ) { wxLogMessage(wxT("Open(%s) succeeded"), fName); diff --git a/src/import/Import.h b/src/import/Import.h index 58464584e..e06b464ad 100644 --- a/src/import/Import.h +++ b/src/import/Import.h @@ -22,6 +22,7 @@ class wxArrayString; class wxListBox; +class AudacityProject; class Tags; class TrackFactory; class Track; @@ -158,7 +159,8 @@ public: std::unique_ptr CreateDefaultImportItem(); // if false, the import failed and errorMessage will be set. - bool Import(const FilePath &fName, + bool Import( AudacityProject &project, + const FilePath &fName, TrackFactory *trackFactory, TrackHolders &tracks, Tags *tags, diff --git a/src/import/ImportFFmpeg.cpp b/src/import/ImportFFmpeg.cpp index bf0151b4b..fc13daabe 100644 --- a/src/import/ImportFFmpeg.cpp +++ b/src/import/ImportFFmpeg.cpp @@ -183,7 +183,8 @@ public: TranslatableString GetPluginFormatDescription() override; ///! Probes the file and opens it if appropriate - std::unique_ptr Open(const FilePath &Filename) override; + std::unique_ptr Open( + const FilePath &Filename, AudacityProject*) override; unsigned SequenceNumber() const override; }; @@ -291,7 +292,8 @@ TranslatableString FFmpegImportPlugin::GetPluginFormatDescription() return DESC; } -std::unique_ptr FFmpegImportPlugin::Open(const FilePath &filename) +std::unique_ptr FFmpegImportPlugin::Open( + const FilePath &filename, AudacityProject*) { auto handle = std::make_unique(filename); diff --git a/src/import/ImportFLAC.cpp b/src/import/ImportFLAC.cpp index f5d73ebed..3ac4bd803 100644 --- a/src/import/ImportFLAC.cpp +++ b/src/import/ImportFLAC.cpp @@ -135,7 +135,8 @@ class FLACImportPlugin final : public ImportPlugin wxString GetPluginStringID() override { return wxT("libflac"); } TranslatableString GetPluginFormatDescription() override; - std::unique_ptr Open(const FilePath &Filename) override; + std::unique_ptr Open( + const FilePath &Filename, AudacityProject*) override; unsigned SequenceNumber() const override; }; @@ -291,7 +292,8 @@ TranslatableString FLACImportPlugin::GetPluginFormatDescription() } -std::unique_ptr FLACImportPlugin::Open(const FilePath &filename) +std::unique_ptr FLACImportPlugin::Open( + const FilePath &filename, AudacityProject*) { // First check if it really is a FLAC file diff --git a/src/import/ImportGStreamer.cpp b/src/import/ImportGStreamer.cpp index fe5d1a305..8b75b853e 100644 --- a/src/import/ImportGStreamer.cpp +++ b/src/import/ImportGStreamer.cpp @@ -247,7 +247,8 @@ public: FileExtensions GetSupportedExtensions() override; ///! Probes the file and opens it if appropriate - std::unique_ptr Open(const wxString &Filename) override; + std::unique_ptr Open( + const wxString &Filename, AudacityProject*) override; unsigned SequenceNumber() const override; }; @@ -409,7 +410,8 @@ GStreamerImportPlugin::GetSupportedExtensions() // ---------------------------------------------------------------------------- // Open the file and return an importer "file handle" -std::unique_ptr GStreamerImportPlugin::Open(const wxString &filename) +std::unique_ptr GStreamerImportPlugin::Open( + const wxString &filename, AudacityProject*) { auto handle = std::make_unique(filename); diff --git a/src/import/ImportLOF.cpp b/src/import/ImportLOF.cpp index 2f8bbe9f4..1274ae29d 100644 --- a/src/import/ImportLOF.cpp +++ b/src/import/ImportLOF.cpp @@ -114,7 +114,8 @@ public: wxString GetPluginStringID() override { return wxT("lof"); } TranslatableString GetPluginFormatDescription() override; - std::unique_ptr Open(const FilePath &Filename) override; + std::unique_ptr Open( + const FilePath &Filename, AudacityProject *pProject) override; unsigned SequenceNumber() const override; }; @@ -123,7 +124,8 @@ public: class LOFImportFileHandle final : public ImportFileHandle { public: - LOFImportFileHandle(const FilePath & name, std::unique_ptr &&file); + LOFImportFileHandle( AudacityProject *pProject, + const FilePath & name, std::unique_ptr &&file); ~LOFImportFileHandle(); TranslatableString GetFileDescription() override; @@ -150,7 +152,7 @@ private: std::unique_ptr mTextFile; wxFileName mLOFFileName; /**< The name of the LOF file, which is used to interpret relative paths in it */ - AudacityProject *mProject{ GetActiveProject() }; + AudacityProject *mProject{}; // In order to know whether or not to create a NEW window bool windowCalledOnce{ false }; @@ -164,11 +166,12 @@ private: double scrollOffset{ 0 }; }; -LOFImportFileHandle::LOFImportFileHandle - (const FilePath & name, std::unique_ptr &&file) -: ImportFileHandle(name), - mTextFile(std::move(file)) +LOFImportFileHandle::LOFImportFileHandle( AudacityProject *pProject, + const FilePath & name, std::unique_ptr &&file) +: ImportFileHandle(name) + , mTextFile(std::move(file)) , mLOFFileName{name} + , mProject{ pProject } { } @@ -177,7 +180,8 @@ TranslatableString LOFImportPlugin::GetPluginFormatDescription() return DESC; } -std::unique_ptr LOFImportPlugin::Open(const FilePath &filename) +std::unique_ptr LOFImportPlugin::Open( + const FilePath &filename, AudacityProject *pProject) { // Check if it is a binary file { @@ -208,7 +212,8 @@ std::unique_ptr LOFImportPlugin::Open(const FilePath &filename if (!file->IsOpened()) return nullptr; - return std::make_unique(filename, std::move(file)); + return std::make_unique( + pProject, filename, std::move(file)); } TranslatableString LOFImportFileHandle::GetFileDescription() diff --git a/src/import/ImportMP3.cpp b/src/import/ImportMP3.cpp index b53626659..8b30a16a0 100644 --- a/src/import/ImportMP3.cpp +++ b/src/import/ImportMP3.cpp @@ -115,7 +115,8 @@ public: wxString GetPluginStringID() override { return wxT("libmad"); } TranslatableString GetPluginFormatDescription() override; - std::unique_ptr Open(const FilePath &Filename) override; + std::unique_ptr Open( + const FilePath &Filename, AudacityProject*) override; unsigned SequenceNumber() const override; }; @@ -177,7 +178,8 @@ TranslatableString MP3ImportPlugin::GetPluginFormatDescription() return DESC; } -std::unique_ptr MP3ImportPlugin::Open(const FilePath &Filename) +std::unique_ptr MP3ImportPlugin::Open( + const FilePath &Filename, AudacityProject*) { auto file = std::make_unique(Filename); diff --git a/src/import/ImportOGG.cpp b/src/import/ImportOGG.cpp index 95a9b01eb..a02ade9b5 100644 --- a/src/import/ImportOGG.cpp +++ b/src/import/ImportOGG.cpp @@ -89,7 +89,8 @@ public: wxString GetPluginStringID() override { return wxT("liboggvorbis"); } TranslatableString GetPluginFormatDescription() override; - std::unique_ptr Open(const FilePath &Filename) override; + std::unique_ptr Open( + const FilePath &Filename, AudacityProject*) override; unsigned SequenceNumber() const override; }; @@ -167,7 +168,8 @@ TranslatableString OggImportPlugin::GetPluginFormatDescription() return DESC; } -std::unique_ptr OggImportPlugin::Open(const FilePath &filename) +std::unique_ptr OggImportPlugin::Open( + const FilePath &filename, AudacityProject*) { // Suppress some compiler warnings about unused global variables in the library header wxUnusedVar(OV_CALLBACKS_DEFAULT); diff --git a/src/import/ImportPCM.cpp b/src/import/ImportPCM.cpp index 7f5f50a47..6df7c4033 100644 --- a/src/import/ImportPCM.cpp +++ b/src/import/ImportPCM.cpp @@ -87,7 +87,8 @@ public: wxString GetPluginStringID() override { return wxT("libsndfile"); } TranslatableString GetPluginFormatDescription() override; - std::unique_ptr Open(const FilePath &Filename) override; + std::unique_ptr Open( + const FilePath &Filename, AudacityProject*) override; unsigned SequenceNumber() const override; }; @@ -126,7 +127,8 @@ TranslatableString PCMImportPlugin::GetPluginFormatDescription() return DESC; } -std::unique_ptr PCMImportPlugin::Open(const FilePath &filename) +std::unique_ptr PCMImportPlugin::Open( + const FilePath &filename, AudacityProject*) { SF_INFO info; wxFile f; // will be closed when it goes out of scope diff --git a/src/import/ImportPlugin.h b/src/import/ImportPlugin.h index bd6dda329..faf660e34 100644 --- a/src/import/ImportPlugin.h +++ b/src/import/ImportPlugin.h @@ -52,6 +52,7 @@ but little else. #include "ImportRaw.h" // defines TrackHolders +class AudacityProject; class wxArrayString; class ProgressDialog; enum class ProgressResult : unsigned; @@ -92,7 +93,8 @@ public: // Open the given file, returning true if it is in a recognized // format, false otherwise. This puts the importer into the open // state. - virtual std::unique_ptr Open(const FilePath &Filename) = 0; + virtual std::unique_ptr Open( + const FilePath &Filename, AudacityProject*) = 0; virtual unsigned SequenceNumber() const = 0; diff --git a/src/import/ImportQT.cpp b/src/import/ImportQT.cpp index db286ba16..da75af54d 100644 --- a/src/import/ImportQT.cpp +++ b/src/import/ImportQT.cpp @@ -122,7 +122,8 @@ class QTImportPlugin final : public ImportPlugin wxString GetPluginStringID() override { return wxT("quicktime"); } TranslatableString GetPluginFormatDescription() override; - std::unique_ptr Open(const wxString & Filename) override; + std::unique_ptr Open( + const wxString & Filename, AudacityProject*) override; unsigned SequenceNumber() const override; @@ -180,7 +181,8 @@ TranslatableString QTImportPlugin::GetPluginFormatDescription() return DESC; } -std::unique_ptr QTImportPlugin::Open(const wxString & Filename) +std::unique_ptr QTImportPlugin::Open( + const wxString & Filename, AudacityProject*) { OSErr err; FSRef inRef;