1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Remove uses of GetActiveProject in import

This commit is contained in:
Paul Licameli 2019-05-22 01:48:34 -04:00
parent a1eeb528b7
commit 7592227f14
12 changed files with 53 additions and 29 deletions

View File

@ -1620,7 +1620,7 @@ bool ProjectFileManager::Import(
auto newTags = oldTags->Duplicate(); auto newTags = oldTags->Duplicate();
Tags::Set( project, newTags ); Tags::Set( project, newTags );
bool success = Importer::Get().Import(fileName, bool success = Importer::Get().Import(project, fileName,
&TrackFactory::Get( project ), &TrackFactory::Get( project ),
newTracks, newTracks,
newTags.get(), newTags.get(),

View File

@ -409,13 +409,14 @@ std::unique_ptr<ExtImportItem> Importer::CreateDefaultImportItem()
} }
// returns number of tracks imported // returns number of tracks imported
bool Importer::Import(const FilePath &fName, bool Importer::Import( AudacityProject &project,
const FilePath &fName,
TrackFactory *trackFactory, TrackFactory *trackFactory,
TrackHolders &tracks, TrackHolders &tracks,
Tags *tags, Tags *tags,
TranslatableString &errorMessage) TranslatableString &errorMessage)
{ {
AudacityProject *pProj = GetActiveProject(); AudacityProject *pProj = &project;
auto cleanup = valueRestorer( pProj->mbBusyImporting, true ); auto cleanup = valueRestorer( pProj->mbBusyImporting, true );
const FileExtension extension{ fName.AfterLast(wxT('.')) }; 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) // Try to open the file with this plugin (probe it)
wxLogMessage(wxT("Opening with %s"),plugin->GetPluginStringID()); wxLogMessage(wxT("Opening with %s"),plugin->GetPluginStringID());
auto inFile = plugin->Open(fName); auto inFile = plugin->Open(fName, pProj);
if ( (inFile != NULL) && (inFile->GetStreamCount() > 0) ) if ( (inFile != NULL) && (inFile->GetStreamCount() > 0) )
{ {
wxLogMessage(wxT("Open(%s) succeeded"), fName); wxLogMessage(wxT("Open(%s) succeeded"), fName);

View File

@ -22,6 +22,7 @@
class wxArrayString; class wxArrayString;
class wxListBox; class wxListBox;
class AudacityProject;
class Tags; class Tags;
class TrackFactory; class TrackFactory;
class Track; class Track;
@ -158,7 +159,8 @@ public:
std::unique_ptr<ExtImportItem> CreateDefaultImportItem(); std::unique_ptr<ExtImportItem> CreateDefaultImportItem();
// if false, the import failed and errorMessage will be set. // if false, the import failed and errorMessage will be set.
bool Import(const FilePath &fName, bool Import( AudacityProject &project,
const FilePath &fName,
TrackFactory *trackFactory, TrackFactory *trackFactory,
TrackHolders &tracks, TrackHolders &tracks,
Tags *tags, Tags *tags,

View File

@ -183,7 +183,8 @@ public:
TranslatableString GetPluginFormatDescription() override; TranslatableString GetPluginFormatDescription() override;
///! Probes the file and opens it if appropriate ///! Probes the file and opens it if appropriate
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override; std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override; unsigned SequenceNumber() const override;
}; };
@ -291,7 +292,8 @@ TranslatableString FFmpegImportPlugin::GetPluginFormatDescription()
return DESC; return DESC;
} }
std::unique_ptr<ImportFileHandle> FFmpegImportPlugin::Open(const FilePath &filename) std::unique_ptr<ImportFileHandle> FFmpegImportPlugin::Open(
const FilePath &filename, AudacityProject*)
{ {
auto handle = std::make_unique<FFmpegImportFileHandle>(filename); auto handle = std::make_unique<FFmpegImportFileHandle>(filename);

View File

@ -135,7 +135,8 @@ class FLACImportPlugin final : public ImportPlugin
wxString GetPluginStringID() override { return wxT("libflac"); } wxString GetPluginStringID() override { return wxT("libflac"); }
TranslatableString GetPluginFormatDescription() override; TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override; std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override; unsigned SequenceNumber() const override;
}; };
@ -291,7 +292,8 @@ TranslatableString FLACImportPlugin::GetPluginFormatDescription()
} }
std::unique_ptr<ImportFileHandle> FLACImportPlugin::Open(const FilePath &filename) std::unique_ptr<ImportFileHandle> FLACImportPlugin::Open(
const FilePath &filename, AudacityProject*)
{ {
// First check if it really is a FLAC file // First check if it really is a FLAC file

View File

@ -247,7 +247,8 @@ public:
FileExtensions GetSupportedExtensions() override; FileExtensions GetSupportedExtensions() override;
///! Probes the file and opens it if appropriate ///! Probes the file and opens it if appropriate
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override; std::unique_ptr<ImportFileHandle> Open(
const wxString &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override; unsigned SequenceNumber() const override;
}; };
@ -409,7 +410,8 @@ GStreamerImportPlugin::GetSupportedExtensions()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Open the file and return an importer "file handle" // Open the file and return an importer "file handle"
std::unique_ptr<ImportFileHandle> GStreamerImportPlugin::Open(const wxString &filename) std::unique_ptr<ImportFileHandle> GStreamerImportPlugin::Open(
const wxString &filename, AudacityProject*)
{ {
auto handle = std::make_unique<GStreamerImportFileHandle>(filename); auto handle = std::make_unique<GStreamerImportFileHandle>(filename);

View File

@ -114,7 +114,8 @@ public:
wxString GetPluginStringID() override { return wxT("lof"); } wxString GetPluginStringID() override { return wxT("lof"); }
TranslatableString GetPluginFormatDescription() override; TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override; std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject *pProject) override;
unsigned SequenceNumber() const override; unsigned SequenceNumber() const override;
}; };
@ -123,7 +124,8 @@ public:
class LOFImportFileHandle final : public ImportFileHandle class LOFImportFileHandle final : public ImportFileHandle
{ {
public: public:
LOFImportFileHandle(const FilePath & name, std::unique_ptr<wxTextFile> &&file); LOFImportFileHandle( AudacityProject *pProject,
const FilePath & name, std::unique_ptr<wxTextFile> &&file);
~LOFImportFileHandle(); ~LOFImportFileHandle();
TranslatableString GetFileDescription() override; TranslatableString GetFileDescription() override;
@ -150,7 +152,7 @@ private:
std::unique_ptr<wxTextFile> mTextFile; std::unique_ptr<wxTextFile> mTextFile;
wxFileName mLOFFileName; /**< The name of the LOF file, which is used to wxFileName mLOFFileName; /**< The name of the LOF file, which is used to
interpret relative paths in it */ interpret relative paths in it */
AudacityProject *mProject{ GetActiveProject() }; AudacityProject *mProject{};
// In order to know whether or not to create a NEW window // In order to know whether or not to create a NEW window
bool windowCalledOnce{ false }; bool windowCalledOnce{ false };
@ -164,11 +166,12 @@ private:
double scrollOffset{ 0 }; double scrollOffset{ 0 };
}; };
LOFImportFileHandle::LOFImportFileHandle LOFImportFileHandle::LOFImportFileHandle( AudacityProject *pProject,
(const FilePath & name, std::unique_ptr<wxTextFile> &&file) const FilePath & name, std::unique_ptr<wxTextFile> &&file)
: ImportFileHandle(name), : ImportFileHandle(name)
mTextFile(std::move(file)) , mTextFile(std::move(file))
, mLOFFileName{name} , mLOFFileName{name}
, mProject{ pProject }
{ {
} }
@ -177,7 +180,8 @@ TranslatableString LOFImportPlugin::GetPluginFormatDescription()
return DESC; return DESC;
} }
std::unique_ptr<ImportFileHandle> LOFImportPlugin::Open(const FilePath &filename) std::unique_ptr<ImportFileHandle> LOFImportPlugin::Open(
const FilePath &filename, AudacityProject *pProject)
{ {
// Check if it is a binary file // Check if it is a binary file
{ {
@ -208,7 +212,8 @@ std::unique_ptr<ImportFileHandle> LOFImportPlugin::Open(const FilePath &filename
if (!file->IsOpened()) if (!file->IsOpened())
return nullptr; return nullptr;
return std::make_unique<LOFImportFileHandle>(filename, std::move(file)); return std::make_unique<LOFImportFileHandle>(
pProject, filename, std::move(file));
} }
TranslatableString LOFImportFileHandle::GetFileDescription() TranslatableString LOFImportFileHandle::GetFileDescription()

View File

@ -115,7 +115,8 @@ public:
wxString GetPluginStringID() override { return wxT("libmad"); } wxString GetPluginStringID() override { return wxT("libmad"); }
TranslatableString GetPluginFormatDescription() override; TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override; std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override; unsigned SequenceNumber() const override;
}; };
@ -177,7 +178,8 @@ TranslatableString MP3ImportPlugin::GetPluginFormatDescription()
return DESC; return DESC;
} }
std::unique_ptr<ImportFileHandle> MP3ImportPlugin::Open(const FilePath &Filename) std::unique_ptr<ImportFileHandle> MP3ImportPlugin::Open(
const FilePath &Filename, AudacityProject*)
{ {
auto file = std::make_unique<wxFile>(Filename); auto file = std::make_unique<wxFile>(Filename);

View File

@ -89,7 +89,8 @@ public:
wxString GetPluginStringID() override { return wxT("liboggvorbis"); } wxString GetPluginStringID() override { return wxT("liboggvorbis"); }
TranslatableString GetPluginFormatDescription() override; TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override; std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override; unsigned SequenceNumber() const override;
}; };
@ -167,7 +168,8 @@ TranslatableString OggImportPlugin::GetPluginFormatDescription()
return DESC; return DESC;
} }
std::unique_ptr<ImportFileHandle> OggImportPlugin::Open(const FilePath &filename) std::unique_ptr<ImportFileHandle> OggImportPlugin::Open(
const FilePath &filename, AudacityProject*)
{ {
// Suppress some compiler warnings about unused global variables in the library header // Suppress some compiler warnings about unused global variables in the library header
wxUnusedVar(OV_CALLBACKS_DEFAULT); wxUnusedVar(OV_CALLBACKS_DEFAULT);

View File

@ -87,7 +87,8 @@ public:
wxString GetPluginStringID() override { return wxT("libsndfile"); } wxString GetPluginStringID() override { return wxT("libsndfile"); }
TranslatableString GetPluginFormatDescription() override; TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override; std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override; unsigned SequenceNumber() const override;
}; };
@ -126,7 +127,8 @@ TranslatableString PCMImportPlugin::GetPluginFormatDescription()
return DESC; return DESC;
} }
std::unique_ptr<ImportFileHandle> PCMImportPlugin::Open(const FilePath &filename) std::unique_ptr<ImportFileHandle> PCMImportPlugin::Open(
const FilePath &filename, AudacityProject*)
{ {
SF_INFO info; SF_INFO info;
wxFile f; // will be closed when it goes out of scope wxFile f; // will be closed when it goes out of scope

View File

@ -52,6 +52,7 @@ but little else.
#include "ImportRaw.h" // defines TrackHolders #include "ImportRaw.h" // defines TrackHolders
class AudacityProject;
class wxArrayString; class wxArrayString;
class ProgressDialog; class ProgressDialog;
enum class ProgressResult : unsigned; enum class ProgressResult : unsigned;
@ -92,7 +93,8 @@ public:
// Open the given file, returning true if it is in a recognized // Open the given file, returning true if it is in a recognized
// format, false otherwise. This puts the importer into the open // format, false otherwise. This puts the importer into the open
// state. // state.
virtual std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) = 0; virtual std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) = 0;
virtual unsigned SequenceNumber() const = 0; virtual unsigned SequenceNumber() const = 0;

View File

@ -122,7 +122,8 @@ class QTImportPlugin final : public ImportPlugin
wxString GetPluginStringID() override { return wxT("quicktime"); } wxString GetPluginStringID() override { return wxT("quicktime"); }
TranslatableString GetPluginFormatDescription() override; TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const wxString & Filename) override; std::unique_ptr<ImportFileHandle> Open(
const wxString & Filename, AudacityProject*) override;
unsigned SequenceNumber() const override; unsigned SequenceNumber() const override;
@ -180,7 +181,8 @@ TranslatableString QTImportPlugin::GetPluginFormatDescription()
return DESC; return DESC;
} }
std::unique_ptr<ImportFileHandle> QTImportPlugin::Open(const wxString & Filename) std::unique_ptr<ImportFileHandle> QTImportPlugin::Open(
const wxString & Filename, AudacityProject*)
{ {
OSErr err; OSErr err;
FSRef inRef; FSRef inRef;