diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index ab514abc7..600f88c8a 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -86,7 +86,8 @@ static const std::pair SpecialCommands[] = { }; // end CLEANSPEECH remnant -MacroCommands::MacroCommands() +MacroCommands::MacroCommands( AudacityProject &project ) +: mExporter{ project } { ResetMacro(); @@ -574,12 +575,11 @@ bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate ) double endTime = GetEndTime(); if( endTime <= 0.0f ) return false; - AudacityProject *project = GetActiveProject(); if( bitrate <=0 ) { // 'No' bitrate given, use the current default. // Use Mp3Stereo to control if export is to a stereo or mono file - return mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime); + return mExporter.Process(numChannels, wxT("MP3"), Name, false, 0.0, endTime); } @@ -596,7 +596,7 @@ bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate ) } ); // Use Mp3Stereo to control if export is to a stereo or mono file - rc = mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime); + rc = mExporter.Process(numChannels, wxT("MP3"), Name, false, 0.0, endTime); return rc; } @@ -679,7 +679,7 @@ bool MacroCommands::ApplySpecialCommand( if (endTime <= 0.0f) { return false; } - return mExporter.Process(project, numChannels, wxT("WAV"), filename, false, 0.0, endTime); + return mExporter.Process(numChannels, wxT("WAV"), filename, false, 0.0, endTime); } else if (command == wxT("ExportOgg")) { #ifdef USE_LIBVORBIS filename.Replace(wxT(".mp3"), wxT(".ogg"), false); @@ -687,7 +687,7 @@ bool MacroCommands::ApplySpecialCommand( if (endTime <= 0.0f) { return false; } - return mExporter.Process(project, numChannels, wxT("OGG"), filename, false, 0.0, endTime); + return mExporter.Process(numChannels, wxT("OGG"), filename, false, 0.0, endTime); #else AudacityMessageBox( XO( "Ogg Vorbis support is not included in this build of Audacity")); @@ -700,7 +700,7 @@ bool MacroCommands::ApplySpecialCommand( if (endTime <= 0.0f) { return false; } - return mExporter.Process(project, numChannels, wxT("FLAC"), filename, false, 0.0, endTime); + return mExporter.Process(numChannels, wxT("FLAC"), filename, false, 0.0, endTime); #else AudacityMessageBox(XO( "FLAC support is not included in this build of Audacity")); diff --git a/src/BatchCommands.h b/src/BatchCommands.h index 40d7352ef..778668ca5 100644 --- a/src/BatchCommands.h +++ b/src/BatchCommands.h @@ -59,7 +59,7 @@ class MacroCommands final { const PluginID & ID, const CommandContext & context, unsigned flags ); // constructors and destructors - MacroCommands(); + MacroCommands( AudacityProject &project ); public: bool ApplyMacro( const MacroCommandsCatalog &catalog, const wxString & filename = {}); diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index c1a39e47f..94bd18bf9 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -80,10 +80,12 @@ BEGIN_EVENT_TABLE(ApplyMacroDialog, wxDialogWrapper) EVT_BUTTON(wxID_HELP, ApplyMacroDialog::OnHelp) END_EVENT_TABLE() -ApplyMacroDialog::ApplyMacroDialog(wxWindow * parent, bool bInherited): +ApplyMacroDialog::ApplyMacroDialog( + wxWindow * parent, AudacityProject &project, bool bInherited): wxDialogWrapper(parent, wxID_ANY, XO("Macros Palette"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) + , mMacroCommands{ project } , mCatalog( GetActiveProject() ) { //AudacityProject * p = GetActiveProject(); @@ -518,8 +520,9 @@ enum { }; /// Constructor -MacrosWindow::MacrosWindow(wxWindow * parent, bool bExpanded): - ApplyMacroDialog(parent, true) +MacrosWindow::MacrosWindow( + wxWindow * parent, AudacityProject &project, bool bExpanded): + ApplyMacroDialog(parent, project, true) { mbExpanded = bExpanded; auto Title = WindowTitle(); diff --git a/src/BatchProcessDialog.h b/src/BatchProcessDialog.h index 9fad0935f..da7859b6a 100644 --- a/src/BatchProcessDialog.h +++ b/src/BatchProcessDialog.h @@ -22,12 +22,14 @@ class wxListCtrl; class wxListEvent; class wxButton; class wxTextCtrl; +class AudacityProject; class ShuttleGui; class ApplyMacroDialog : public wxDialogWrapper { public: // constructors and destructors - ApplyMacroDialog(wxWindow * parent, bool bInherited=false); + ApplyMacroDialog( + wxWindow * parent, AudacityProject &project, bool bInherited=false); virtual ~ApplyMacroDialog(); public: // Populate methods NOT virtual. @@ -69,7 +71,8 @@ protected: class MacrosWindow final : public ApplyMacroDialog { public: - MacrosWindow(wxWindow * parent, bool bExpanded=true); + MacrosWindow( + wxWindow * parent, AudacityProject &project, bool bExpanded=true); ~MacrosWindow(); void UpdateDisplay( bool bExpanded ); diff --git a/src/ProjectFileManager.cpp b/src/ProjectFileManager.cpp index cb5eef0f0..59dd36b79 100644 --- a/src/ProjectFileManager.cpp +++ b/src/ProjectFileManager.cpp @@ -697,7 +697,7 @@ bool ProjectFileManager::SaveCopyWaveTracks(const FilePath & strProjectPathName, // Export all WaveTracks to OGG. bool bSuccess = true; - Exporter theExporter; + Exporter theExporter{ project }; wxFileName uniqueTrackFileName; for (auto pTrack : (trackRange + &Track::IsLeader)) { @@ -711,7 +711,7 @@ bool ProjectFileManager::SaveCopyWaveTracks(const FilePath & strProjectPathName, const auto startTime = channels.min( &Track::GetStartTime ); const auto endTime = channels.max( &Track::GetEndTime ); bSuccess = - theExporter.Process(&project, channels.size(), + theExporter.Process(channels.size(), fileFormat, uniqueTrackFileName.GetFullPath(), true, startTime, endTime); diff --git a/src/TimerRecordDialog.cpp b/src/TimerRecordDialog.cpp index 35d106fa6..4d428c2bd 100644 --- a/src/TimerRecordDialog.cpp +++ b/src/TimerRecordDialog.cpp @@ -357,11 +357,10 @@ would overwrite another project.\nPlease try again and select an original name." void TimerRecordDialog::OnAutoExportPathButton_Click(wxCommandEvent& WXUNUSED(event)) { - AudacityProject* pProject = &mProject; - Exporter eExporter; + Exporter eExporter{ mProject }; // Call the Exporter to set the options required - if (eExporter.SetAutoExportOptions(pProject)) { + if (eExporter.SetAutoExportOptions()) { // Populate the options so that we can destroy this instance of the Exporter m_fnAutoExportFile = eExporter.GetAutoExportFileName(); m_iAutoExportFormat = eExporter.GetAutoExportFormat(); @@ -644,10 +643,10 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) { // Do Automatic Export? if (m_bAutoExportEnabled) { - Exporter e; + Exporter e{ mProject }; MissingAliasFilesDialog::SetShouldShow(true); bExportOK = e.ProcessFromTimerRecording( - pProject, false, 0.0, TrackList::Get( *pProject ).GetEndTime(), + false, 0.0, TrackList::Get( *pProject ).GetEndTime(), m_fnAutoExportFile, m_iAutoExportFormat, m_iAutoExportSubFormat, m_iAutoExportFilterIndex); } diff --git a/src/commands/BatchEvalCommand.cpp b/src/commands/BatchEvalCommand.cpp index 696b6f51a..f11088d78 100644 --- a/src/commands/BatchEvalCommand.cpp +++ b/src/commands/BatchEvalCommand.cpp @@ -55,7 +55,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context) wxString macroName = GetString(wxT("MacroName")); if (!macroName.empty()) { - MacroCommands batch; + MacroCommands batch{ context.project }; batch.ReadMacro(macroName); return batch.ApplyMacro(catalog); } @@ -68,7 +68,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context) : iter->name.Msgid().Stripped(); // Create a Batch that will have just one command in it... - MacroCommands Batch; + MacroCommands Batch{ context.project }; bool bResult = Batch.ApplyCommandInBatchMode(friendly, cmdName, cmdParams, &context); // Relay messages, if any. wxString Message = Batch.GetMessage(); diff --git a/src/commands/ImportExportCommands.cpp b/src/commands/ImportExportCommands.cpp index 173cf36a3..a8fdcdef1 100644 --- a/src/commands/ImportExportCommands.cpp +++ b/src/commands/ImportExportCommands.cpp @@ -80,10 +80,9 @@ bool ExportCommand::Apply(const CommandContext & context) } wxString extension = mFileName.Mid(splitAt+1).MakeUpper(); - Exporter exporter; + Exporter exporter{ context.project }; - bool exportSuccess = exporter.Process(&context.project, - std::max(0, mnChannels), + bool exportSuccess = exporter.Process(std::max(0, mnChannels), extension, mFileName, true, t0, t1); diff --git a/src/export/Export.cpp b/src/export/Export.cpp index c78b26474..f4917432d 100644 --- a/src/export/Export.cpp +++ b/src/export/Export.cpp @@ -297,7 +297,8 @@ Exporter::RegisteredExportPlugin::RegisteredExportPlugin( sFactories().emplace_back( factory ); } -Exporter::Exporter() +Exporter::Exporter( AudacityProject &project ) +: mProject{ &project } { mMixerSpec = NULL; mBook = NULL; @@ -342,7 +343,7 @@ void Exporter::OnExtensionChanged(wxCommandEvent &evt) { void Exporter::OnHelp(wxCommandEvent& WXUNUSED(evt)) { - wxWindow * pWin = FindProjectFrame( GetActiveProject() ); + wxWindow * pWin = FindProjectFrame( mProject ); HelpSystem::ShowHelp(pWin, wxT("File_Export_Dialog"), true); } @@ -400,10 +401,9 @@ bool Exporter::DoEditMetadata(AudacityProject &project, return false; } -bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, double t1) +bool Exporter::Process(bool selectedOnly, double t0, double t1) { // Save parms - mProject = project; mSelectedOnly = selectedOnly; mT0 = t0; mT1 = t1; @@ -425,7 +425,7 @@ bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, d // Let user edit MetaData if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) { - if (!DoEditMetadata( *project, + if (!DoEditMetadata( *mProject, XO("Edit Metadata Tags"), XO("Exported Tags"), ProjectSettings::Get( *mProject ).GetShowId3Dialog())) { return false; @@ -446,12 +446,11 @@ bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, d return success; } -bool Exporter::Process(AudacityProject *project, unsigned numChannels, +bool Exporter::Process(unsigned numChannels, const FileExtension &type, const wxString & filename, bool selectedOnly, double t0, double t1) { // Save parms - mProject = project; mChannels = numChannels; mFilename = filename; mSelectedOnly = selectedOnly; @@ -1018,8 +1017,7 @@ void Exporter::OnFilterChanged(wxFileCtrlEvent & evt) mBook->ChangeSelection(index); } -bool Exporter::ProcessFromTimerRecording(AudacityProject *project, - bool selectedOnly, +bool Exporter::ProcessFromTimerRecording(bool selectedOnly, double t0, double t1, wxFileName fnFile, @@ -1028,7 +1026,6 @@ bool Exporter::ProcessFromTimerRecording(AudacityProject *project, int iFilterIndex) { // Save parms - mProject = project; mSelectedOnly = selectedOnly; mT0 = t0; mT1 = t1; @@ -1079,16 +1076,15 @@ wxFileName Exporter::GetAutoExportFileName() { return mFilename; } -bool Exporter::SetAutoExportOptions(AudacityProject *project) { +bool Exporter::SetAutoExportOptions() { mFormat = -1; - mProject = project; if( GetFilename()==false ) return false; // Let user edit MetaData if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) { - if (!DoEditMetadata( *project, + if (!DoEditMetadata( *mProject, XO("Edit Metadata Tags"), XO("Exported Tags"), ProjectSettings::Get(*mProject).GetShowId3Dialog())) { diff --git a/src/export/Export.h b/src/export/Export.h index 8b9cb4f80..d886e7d96 100644 --- a/src/export/Export.h +++ b/src/export/Export.h @@ -181,15 +181,15 @@ public: const TranslatableString &title, const TranslatableString &shortUndoDescription, bool force); - Exporter(); + Exporter( AudacityProject &project ); virtual ~Exporter(); void SetFileDialogTitle( const TranslatableString & DialogTitle ); void SetDefaultFormat( const FileExtension & Format ){ mFormatName = Format;}; - bool Process(AudacityProject *project, bool selectedOnly, + bool Process(bool selectedOnly, double t0, double t1); - bool Process(AudacityProject *project, unsigned numChannels, + bool Process(unsigned numChannels, const FileExtension &type, const wxString & filename, bool selectedOnly, double t0, double t1); @@ -199,15 +199,14 @@ public: const ExportPluginArray &GetPlugins(); // Auto Export from Timer Recording - bool ProcessFromTimerRecording(AudacityProject *project, - bool selectedOnly, + bool ProcessFromTimerRecording(bool selectedOnly, double t0, double t1, wxFileName fnFile, int iFormat, int iSubFormat, int iFilterIndex); - bool SetAutoExportOptions(AudacityProject *project); + bool SetAutoExportOptions(); int GetAutoExportFormat(); int GetAutoExportSubFormat(); int GetAutoExportFilterIndex(); diff --git a/src/export/ExportMultiple.cpp b/src/export/ExportMultiple.cpp index 0fb6b1368..86266b34b 100644 --- a/src/export/ExportMultiple.cpp +++ b/src/export/ExportMultiple.cpp @@ -131,6 +131,7 @@ END_EVENT_TABLE() ExportMultipleDialog::ExportMultipleDialog(AudacityProject *project) : wxDialogWrapper( &GetProjectFrame( *project ), wxID_ANY, XO("Export Multiple") ) +, mExporter{ *project } , mSelectionState{ SelectionState::Get( *project ) } { SetName(); diff --git a/src/menus/FileMenus.cpp b/src/menus/FileMenus.cpp index 86de831d4..7df55b5af 100644 --- a/src/menus/FileMenus.cpp +++ b/src/menus/FileMenus.cpp @@ -40,7 +40,7 @@ void DoExport( AudacityProject &project, const FileExtension & Format ) { auto &tracks = TrackList::Get( project ); - Exporter e; + Exporter e{ project }; MissingAliasFilesDialog::SetShouldShow(true); double t0 = 0.0; @@ -85,7 +85,7 @@ void DoExport( AudacityProject &project, const FileExtension & Format ) { // Do export with prompting. e.SetDefaultFormat(Format); - e.Process(&project, false, t0, t1); + e.Process(false, t0, t1); } else { @@ -94,7 +94,6 @@ void DoExport( AudacityProject &project, const FileExtension & Format ) // We really can proceed without prompting. int nChannels = MacroCommands::IsMono() ? 1 : 2; e.Process( - &project, // AudacityProject nChannels, // numChannels, Format, // type, filename, // filename, @@ -201,11 +200,11 @@ void OnExportSelection(const CommandContext &context) { auto &project = context.project; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; - Exporter e; + Exporter e{ project }; MissingAliasFilesDialog::SetShouldShow(true); e.SetFileDialogTitle( XO("Export Selected Audio") ); - e.Process(&project, true, selectedRegion.t0(), + e.Process(true, selectedRegion.t0(), selectedRegion.t1()); } diff --git a/src/menus/PluginMenus.cpp b/src/menus/PluginMenus.cpp index 6891d7fa9..d01a748dc 100644 --- a/src/menus/PluginMenus.cpp +++ b/src/menus/PluginMenus.cpp @@ -47,7 +47,7 @@ AudacityProject::AttachedWindows::RegisteredFactory sMacrosWindowKey{ []( AudacityProject &parent ) -> wxWeakRef< wxWindow > { auto &window = ProjectWindow::Get( parent ); return safenew MacrosWindow( - &window, true + &window, parent, true ); } }; @@ -543,7 +543,7 @@ void OnApplyMacroDirectly(const CommandContext &context ) auto &window = ProjectWindow::Get( project ); //wxLogDebug( "Macro was: %s", context.parameter); - ApplyMacroDialog dlg( &window ); + ApplyMacroDialog dlg( &window, project ); const auto &Name = context.parameter; // We used numbers previously, but macros could get renumbered, making