From 7592227f149e6922074114794bc4fe4283a6fb74 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 22 May 2019 01:48:34 -0400 Subject: [PATCH 1/9] Remove uses of GetActiveProject in import --- src/ProjectFileManager.cpp | 2 +- src/import/Import.cpp | 7 ++++--- src/import/Import.h | 4 +++- src/import/ImportFFmpeg.cpp | 6 ++++-- src/import/ImportFLAC.cpp | 6 ++++-- src/import/ImportGStreamer.cpp | 6 ++++-- src/import/ImportLOF.cpp | 23 ++++++++++++++--------- src/import/ImportMP3.cpp | 6 ++++-- src/import/ImportOGG.cpp | 6 ++++-- src/import/ImportPCM.cpp | 6 ++++-- src/import/ImportPlugin.h | 4 +++- src/import/ImportQT.cpp | 6 ++++-- 12 files changed, 53 insertions(+), 29 deletions(-) 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; From ece7bd888d77b055e1c38f0c6752a676278e0807 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 1 Jan 2020 23:41:04 -0500 Subject: [PATCH 2/9] Eliminate GetActiveProject in TimerRecordDialog --- src/TimerRecordDialog.cpp | 16 +++++++++------- src/TimerRecordDialog.h | 7 ++++++- src/menus/TransportMenus.cpp | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/TimerRecordDialog.cpp b/src/TimerRecordDialog.cpp index aede521b9..35d106fa6 100644 --- a/src/TimerRecordDialog.cpp +++ b/src/TimerRecordDialog.cpp @@ -165,9 +165,11 @@ BEGIN_EVENT_TABLE(TimerRecordDialog, wxDialogWrapper) END_EVENT_TABLE() -TimerRecordDialog::TimerRecordDialog(wxWindow* parent, bool bAlreadySaved) +TimerRecordDialog::TimerRecordDialog( + wxWindow* parent, AudacityProject &project, bool bAlreadySaved) : wxDialogWrapper(parent, -1, XO("Audacity Timer Record"), wxDefaultPosition, wxDefaultSize, wxCAPTION) +, mProject{ project } { SetName(); @@ -329,7 +331,7 @@ void TimerRecordDialog::OnAutoSavePathButton_Click(wxCommandEvent& WXUNUSED(even if (fName.empty()) return; - AudacityProject* pProject = GetActiveProject(); + AudacityProject* pProject = &mProject; // If project already exists then abort - we do not allow users to overwrite an existing project // unless it is the current project. @@ -355,7 +357,7 @@ would overwrite another project.\nPlease try again and select an original name." void TimerRecordDialog::OnAutoExportPathButton_Click(wxCommandEvent& WXUNUSED(event)) { - AudacityProject* pProject = GetActiveProject(); + AudacityProject* pProject = &mProject; Exporter eExporter; // Call the Exporter to set the options required @@ -424,7 +426,7 @@ void TimerRecordDialog::OnOK(wxCommandEvent& WXUNUSED(event)) // We don't stop the user from starting the recording // as its possible that they plan to free up some // space before the recording begins - AudacityProject* pProject = GetActiveProject(); + AudacityProject* pProject = &mProject; auto &projectManager = ProjectManager::Get( *pProject ); // How many minutes do we have left on the disc? @@ -539,7 +541,7 @@ bool TimerRecordDialog::RemoveAllAutoSaveFiles() /// or if the post recording actions fail. int TimerRecordDialog::RunWaitDialog() { - AudacityProject* pProject = GetActiveProject(); + AudacityProject* pProject = &mProject; auto updateResult = ProgressResult::Success; @@ -620,7 +622,7 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) { // Finally, if there is no post-record action selected then we output // a dialog detailing what has been carried out instead. - AudacityProject* pProject = GetActiveProject(); + AudacityProject* pProject = &mProject; bool bSaveOK = false; bool bExportOK = false; @@ -930,7 +932,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S) S.StartMultiColumn(3, wxEXPAND); { TranslatableString sInitialValue; - AudacityProject* pProject = GetActiveProject(); + AudacityProject* pProject = &mProject; auto sSaveValue = pProject->GetFileName(); if (!sSaveValue.empty()) { m_fnAutoSaveFile.Assign(sSaveValue); diff --git a/src/TimerRecordDialog.h b/src/TimerRecordDialog.h index 3cbb8796e..5355afb46 100644 --- a/src/TimerRecordDialog.h +++ b/src/TimerRecordDialog.h @@ -38,6 +38,8 @@ enum TimerRecordCompletedActions { TR_ACTION_EXPORTED = 0x00000002 }; +class AudacityProject; + class TimerRecordPathCtrl final : public wxTextCtrl { // MY: Class that inherits from the wxTextCtrl class. @@ -64,7 +66,8 @@ public: class TimerRecordDialog final : public wxDialogWrapper { public: - TimerRecordDialog(wxWindow* parent, bool bAlreadySaved); + TimerRecordDialog( + wxWindow* parent, AudacityProject &project, bool bAlreadySaved); ~TimerRecordDialog(); void OnTimer(wxTimerEvent& event); @@ -114,6 +117,8 @@ private: ProgressResult PreActionDelay(int iActionIndex, TimerRecordCompletedActions eCompletedActions); private: + AudacityProject &mProject; + wxDateTime m_DateTime_Start; wxDateTime m_DateTime_End; wxTimeSpan m_TimeSpan_Duration; diff --git a/src/menus/TransportMenus.cpp b/src/menus/TransportMenus.cpp index fcf40adf8..ac672154f 100644 --- a/src/menus/TransportMenus.cpp +++ b/src/menus/TransportMenus.cpp @@ -326,7 +326,7 @@ void OnTimerRecord(const CommandContext &context) //and therefore remove the newly inserted track. TimerRecordDialog dialog( - &window, bProjectSaved); /* parent, project saved? */ + &window, project, bProjectSaved); /* parent, project, project saved? */ int modalResult = dialog.ShowModal(); if (modalResult == wxID_CANCEL) { From d23569ca1018ba793d7b2fb8f346a2777a405324 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 21 May 2019 20:16:20 -0400 Subject: [PATCH 3/9] Construct Exporter with project pointer, fewer GetActiveProject calls --- src/BatchCommands.cpp | 14 +++++++------- src/BatchCommands.h | 2 +- src/BatchProcessDialog.cpp | 9 ++++++--- src/BatchProcessDialog.h | 7 +++++-- src/ProjectFileManager.cpp | 4 ++-- src/TimerRecordDialog.cpp | 9 ++++----- src/commands/BatchEvalCommand.cpp | 4 ++-- src/commands/ImportExportCommands.cpp | 5 ++--- src/export/Export.cpp | 22 +++++++++------------- src/export/Export.h | 11 +++++------ src/export/ExportMultiple.cpp | 1 + src/menus/FileMenus.cpp | 9 ++++----- src/menus/PluginMenus.cpp | 4 ++-- 13 files changed, 50 insertions(+), 51 deletions(-) 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 From 83f7bc6b5c8b9c4abccafe3f1def52a271e39e66 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 21 May 2019 10:53:09 -0400 Subject: [PATCH 4/9] Eliminate some uses of GetActiveProject... ... where there was already a project at hand --- src/commands/SetTrackInfoCommand.cpp | 2 +- src/menus/TrackMenus.cpp | 4 ++-- src/tracks/ui/Scrubbing.h | 3 +-- src/tracks/ui/TrackSelectHandle.cpp | 13 ++++++------- src/tracks/ui/TrackSelectHandle.h | 3 ++- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/commands/SetTrackInfoCommand.cpp b/src/commands/SetTrackInfoCommand.cpp index dd71463b9..fd83c57eb 100644 --- a/src/commands/SetTrackInfoCommand.cpp +++ b/src/commands/SetTrackInfoCommand.cpp @@ -398,7 +398,7 @@ bool SetTrackVisualsCommand::ApplyInner(const CommandContext & context, Track * mVZoomTop = c + ZOOMLIMIT / 2.0; } wt->SetDisplayBounds(mVZoomBottom, mVZoomTop); - auto &tp = TrackPanel::Get( *::GetActiveProject() ); + auto &tp = TrackPanel::Get( context.project ); tp.UpdateVRulers(); } diff --git a/src/menus/TrackMenus.cpp b/src/menus/TrackMenus.cpp index db98f788f..d497e626c 100644 --- a/src/menus/TrackMenus.cpp +++ b/src/menus/TrackMenus.cpp @@ -1029,10 +1029,10 @@ void OnScoreAlign(const CommandContext &context) params.mAudioStart, params.mAudioEnd) ); } else if (result == SA_CANCEL) { // wrong way to recover... - //GetActiveProject()->OnUndo(); // recover any changes to note track + //project.OnUndo(); // recover any changes to note track return; // no message when user cancels alignment } else { - //GetActiveProject()->OnUndo(); // recover any changes to note track + //project.OnUndo(); // recover any changes to note track AudacityMessageBox( XO("Internal error reported by alignment process.") ); } } diff --git a/src/tracks/ui/Scrubbing.h b/src/tracks/ui/Scrubbing.h index c36a4907f..852bcf6ec 100644 --- a/src/tracks/ui/Scrubbing.h +++ b/src/tracks/ui/Scrubbing.h @@ -26,7 +26,6 @@ Paul Licameli split from TrackPanel.cpp #include "../../../include/audacity/Types.h" class AudacityProject; -extern AudacityProject *GetActiveProject(); class TranslatableString; // Conditionally compile either a separate thead, or else use a timer in the main @@ -127,7 +126,7 @@ public: // Convenience wrapper for the above template void Thunk(wxCommandEvent &) - { (this->*pfn)(*GetActiveProject()); } + { (this->*pfn)(*mProject); } // A string to put in the leftmost part of the status bar // when scrub or seek is in progress, or else empty. diff --git a/src/tracks/ui/TrackSelectHandle.cpp b/src/tracks/ui/TrackSelectHandle.cpp index dc3985c58..c0fa049bb 100644 --- a/src/tracks/ui/TrackSelectHandle.cpp +++ b/src/tracks/ui/TrackSelectHandle.cpp @@ -96,7 +96,7 @@ UIHandle::Result TrackSelectHandle::Click result |= Cancelled; else { mRearrangeCount = 0; - CalculateRearrangingThresholds(event); + CalculateRearrangingThresholds(event, pProject); } SelectUtilities::DoListSelection(*pProject, @@ -135,7 +135,7 @@ UIHandle::Result TrackSelectHandle::Drag // JH: if we moved up or down, recalculate the thresholds and make sure the // track is fully on-screen. - CalculateRearrangingThresholds(event); + CalculateRearrangingThresholds(event, pProject); result |= EnsureVisible | RefreshAll; return result; @@ -154,7 +154,7 @@ HitTestPreview TrackSelectHandle::Preview ::MakeCursor(wxCURSOR_HAND, RearrangeCursorXpm, 16, 16); const bool unsafe = - ProjectAudioIO::Get( *GetActiveProject() ).IsAudioActive(); + ProjectAudioIO::Get( *project ).IsAudioActive(); return { message, (unsafe @@ -176,12 +176,11 @@ HitTestPreview TrackSelectHandle::Preview } UIHandle::Result TrackSelectHandle::Release -(const TrackPanelMouseEvent &, AudacityProject *, wxWindow *) +(const TrackPanelMouseEvent &, AudacityProject *project, wxWindow *) { // If we're releasing, surely we are dragging a track? wxASSERT( mpTrack ); if (mRearrangeCount != 0) { - AudacityProject *const project = ::GetActiveProject(); ProjectHistory::Get( *project ).PushState( /* i18n-hint: will substitute name of track for %s */ ( mRearrangeCount < 0 ? XO("Moved '%s' up") : XO("Moved '%s' down") ) @@ -207,13 +206,13 @@ UIHandle::Result TrackSelectHandle::Cancel(AudacityProject *pProject) /// Figure out how far the user must drag the mouse up or down /// before the track will swap with the one above or below -void TrackSelectHandle::CalculateRearrangingThresholds(const wxMouseEvent & event) +void TrackSelectHandle::CalculateRearrangingThresholds( + const wxMouseEvent & event, AudacityProject *project) { // JH: this will probably need to be tweaked a bit, I'm just // not sure what formula will have the best feel for the // user. - AudacityProject *const project = ::GetActiveProject(); auto &tracks = TrackList::Get( *project ); if (tracks.CanMoveUp(mpTrack.get())) diff --git a/src/tracks/ui/TrackSelectHandle.h b/src/tracks/ui/TrackSelectHandle.h index cbca1a382..5817c792d 100644 --- a/src/tracks/ui/TrackSelectHandle.h +++ b/src/tracks/ui/TrackSelectHandle.h @@ -59,7 +59,8 @@ private: int mMoveDownThreshold {}; int mRearrangeCount {}; - void CalculateRearrangingThresholds(const wxMouseEvent & event); + void CalculateRearrangingThresholds( + const wxMouseEvent & event, AudacityProject *project); }; #endif From 914bb1dc95cc3e3335795478f272b018edf4331d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 21 May 2019 19:10:06 -0400 Subject: [PATCH 5/9] Remove some uses of GetActiveProject in src/effects --- src/effects/Equalization.cpp | 3 +-- src/effects/Equalization48x.cpp | 18 ++++++------------ src/effects/StereoToMono.cpp | 3 +-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index e6e9c3d7d..996fc62e4 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -1262,8 +1262,7 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t, sampleCount start, sampleCount len) { // create a NEW WaveTrack to hold all of the output, including 'tails' each end - AudacityProject *p = GetActiveProject(); - auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate()); + auto output = mFactory->NewWaveTrack(floatSample, t->GetRate()); wxASSERT(mM - 1 < windowSize); size_t L = windowSize - (mM - 1); //Process L samples at a go diff --git a/src/effects/Equalization48x.cpp b/src/effects/Equalization48x.cpp index ccd96d598..8b2b6c6bb 100644 --- a/src/effects/Equalization48x.cpp +++ b/src/effects/Equalization48x.cpp @@ -410,8 +410,7 @@ bool EffectEqualization48x::DeltaTrack( Floats buffer1{ trackBlockSize }; Floats buffer2{ trackBlockSize }; - AudacityProject *p = GetActiveProject(); - auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate()); + auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate()); auto originalLen = len; auto currentSample = start; @@ -633,8 +632,7 @@ bool EffectEqualization48x::ProcessOne1x(int count, WaveTrack * t, auto trackBlockSize = t->GetMaxBlockSize(); - AudacityProject *p = GetActiveProject(); - auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate()); + auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate()); mEffectEqualization->TrackProgress(count, 0.0); int subBufferSize=mBufferCount==8?(mSubBufferSize>>1):mSubBufferSize; // half the buffers if avx is active @@ -820,8 +818,7 @@ bool EffectEqualization48x::ProcessOne4x(int count, WaveTrack * t, auto trackBlockSize = t->GetMaxBlockSize(); - AudacityProject *p = GetActiveProject(); - auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate()); + auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate()); mEffectEqualization->TrackProgress(count, 0.0); auto bigRuns = len/(subBufferSize-mBlockSize); @@ -910,8 +907,7 @@ bool EffectEqualization48x::ProcessOne1x4xThreaded(int count, WaveTrack * t, for(int i=0;iGetRate()); + auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate()); auto trackBlockSize = t->GetMaxBlockSize(); mEffectEqualization->TrackProgress(count, 0.0); @@ -1156,8 +1152,7 @@ bool EffectEqualization48x::ProcessOne8x(int count, WaveTrack * t, auto trackBlockSize = t->GetMaxBlockSize(); - AudacityProject *p = GetActiveProject(); - auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate()); + auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate()); mEffectEqualization->TrackProgress(count, 0.0); int bigRuns=len/(mSubBufferSize-mBlockSize); @@ -1208,8 +1203,7 @@ bool EffectEqualization48x::ProcessOne8xThreaded(int count, WaveTrack * t, if(mThreadCount<=0 || blockCount<256) // dont do it without cores or big data return ProcessOne4x(count, t, start, len); - AudacityProject *p = GetActiveProject(); - auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate()); + auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate()); auto trackBlockSize = t->GetMaxBlockSize(); mEffectEqualization->TrackProgress(count, 0.0); diff --git a/src/effects/StereoToMono.cpp b/src/effects/StereoToMono.cpp index 1d585d437..34da98cc1 100644 --- a/src/effects/StereoToMono.cpp +++ b/src/effects/StereoToMono.cpp @@ -133,9 +133,8 @@ bool EffectStereoToMono::ProcessOne(int count) Floats rightBuffer{ idealBlockLen }; bool bResult = true; - AudacityProject *p = GetActiveProject(); auto outTrack = - TrackFactory::Get( *p ).NewWaveTrack(floatSample, mLeftTrack->GetRate()); + mFactory->NewWaveTrack(floatSample, mLeftTrack->GetRate()); while (index < mEnd) { bResult &= mLeftTrack->Get((samplePtr)leftBuffer.get(), floatSample, index, idealBlockLen); From e2539be53b8edc57113d7338af16e58f4efb9491 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 22 May 2019 07:42:08 -0400 Subject: [PATCH 6/9] WaveTrack::SyncLockAdjust doesn't need a factory to make a temp track --- src/WaveTrack.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index d403db207..7027d93d3 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -1098,11 +1098,8 @@ void WaveTrack::SyncLockAdjust(double oldT1, double newT1) else { // AWD: Could just use InsertSilence() on its own here, but it doesn't // follow EditClipCanMove rules (Paste() does it right) - AudacityProject *p = GetActiveProject(); - if (!p) - THROW_INCONSISTENCY_EXCEPTION; - auto &factory = TrackFactory::Get( *p ); - auto tmp = factory.NewWaveTrack( GetSampleFormat(), GetRate() ); + auto tmp = std::make_shared( + mDirManager, GetSampleFormat(), GetRate() ); tmp->InsertSilence(0.0, newT1 - oldT1); tmp->Flush(); From f85f4db70413c57b2fd1c71f0cba4ff3f06398f5 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 21 May 2019 21:04:18 -0400 Subject: [PATCH 7/9] Remove use of GetActiveProject in MacroCommandsDialog... ... instead pass into it the project pointer already given to ctor of MacrosWindow --- src/BatchCommandDialog.cpp | 5 +++-- src/BatchCommandDialog.h | 3 ++- src/BatchProcessDialog.cpp | 3 ++- src/BatchProcessDialog.h | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/BatchCommandDialog.cpp b/src/BatchCommandDialog.cpp index 8a571d649..bfb0ee07c 100644 --- a/src/BatchCommandDialog.cpp +++ b/src/BatchCommandDialog.cpp @@ -61,11 +61,12 @@ BEGIN_EVENT_TABLE(MacroCommandDialog, wxDialogWrapper) EVT_LIST_ITEM_SELECTED(CommandsListID, MacroCommandDialog::OnItemSelected) END_EVENT_TABLE(); -MacroCommandDialog::MacroCommandDialog(wxWindow * parent, wxWindowID id): +MacroCommandDialog::MacroCommandDialog( + wxWindow * parent, wxWindowID id, AudacityProject &project): wxDialogWrapper(parent, id, XO("Select Command"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxRESIZE_BORDER) - , mCatalog( GetActiveProject() ) + , mCatalog( &project ) { SetLabel(XO("Select Command")); // Provide visual label SetName(XO("Select Command")); // Provide audible label diff --git a/src/BatchCommandDialog.h b/src/BatchCommandDialog.h index 0f58c1408..ed6606a42 100644 --- a/src/BatchCommandDialog.h +++ b/src/BatchCommandDialog.h @@ -21,12 +21,13 @@ class wxTextCtrl; class wxListCtrl; class wxListEvent; class wxButton; +class AudacityProject; class ShuttleGui; class MacroCommandDialog final : public wxDialogWrapper { public: // constructors and destructors - MacroCommandDialog(wxWindow *parent, wxWindowID id); + MacroCommandDialog(wxWindow *parent, wxWindowID id, AudacityProject &project); void SetCommandAndParams(const CommandID &Command, const wxString &Params); public: CommandID mSelectedCommand; diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index 94bd18bf9..1b94b239c 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -523,6 +523,7 @@ enum { MacrosWindow::MacrosWindow( wxWindow * parent, AudacityProject &project, bool bExpanded): ApplyMacroDialog(parent, project, true) + , mProject{ project } { mbExpanded = bExpanded; auto Title = WindowTitle(); @@ -1063,7 +1064,7 @@ void MacrosWindow::InsertCommandAt(int item) return; } - MacroCommandDialog d(this, wxID_ANY); + MacroCommandDialog d(this, wxID_ANY, mProject); if (!d.ShowModal()) { Raise(); diff --git a/src/BatchProcessDialog.h b/src/BatchProcessDialog.h index da7859b6a..858f14a1f 100644 --- a/src/BatchProcessDialog.h +++ b/src/BatchProcessDialog.h @@ -121,6 +121,8 @@ private: void InsertCommandAt(int item); bool SaveChanges(); + AudacityProject &mProject; + wxButton *mRemove; wxButton *mRename; wxButton *mRestore; From c39718fa1f9258b7818515ad35ba9db51eea8619 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 21 May 2019 21:08:43 -0400 Subject: [PATCH 8/9] MacroCommands remembers a reference to project... ... Eliminating several GetActiveProject calls, notably including those where we construct a CommandContext for executing commands. --- src/BatchCommands.cpp | 26 +++++++++++++------------- src/BatchCommands.h | 5 ++++- src/menus/FileMenus.cpp | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index 600f88c8a..7db6ebe9c 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -87,7 +87,8 @@ static const std::pair SpecialCommands[] = { // end CLEANSPEECH remnant MacroCommands::MacroCommands( AudacityProject &project ) -: mExporter{ project } +: mProject{ project } +, mExporter{ project } { ResetMacro(); @@ -483,7 +484,7 @@ wxString MacroCommands::PromptForPresetFor(const CommandID & command, const wxSt double MacroCommands::GetEndTime() { - AudacityProject *project = GetActiveProject(); + AudacityProject *project = &mProject; if( project == NULL ) { //AudacityMessageBox( XO("No project to process!") ); @@ -495,9 +496,8 @@ double MacroCommands::GetEndTime() return endTime; } -bool MacroCommands::IsMono() +bool MacroCommands::IsMono( AudacityProject *project ) { - AudacityProject *project = GetActiveProject(); if( project == NULL ) { //AudacityMessageBox( XO("No project and no Audio to process!") ); @@ -568,7 +568,7 @@ wxString MacroCommands::BuildCleanFileName(const FilePath &fileName, bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate ) { //check if current project is mono or stereo unsigned numChannels = 2; - if (IsMono()) { + if (IsMono( &mProject )) { numChannels = 1; } @@ -622,10 +622,10 @@ bool MacroCommands::ApplySpecialCommand( if (ReportAndSkip(friendlyCommand, params)) return true; - AudacityProject *project = GetActiveProject(); + AudacityProject *project = &mProject; unsigned numChannels = 1; //used to switch between mono and stereo export - if (IsMono()) { + if (IsMono( &mProject )) { numChannels = 1; //export in mono } else { numChannels = 2; //export in stereo @@ -771,7 +771,7 @@ bool MacroCommands::ApplyEffectCommand( if (!plug) return false; - AudacityProject *project = GetActiveProject(); + AudacityProject *project = &mProject; // FIXME: for later versions may want to not select-all in batch mode. // IF nothing selected, THEN select everything @@ -861,12 +861,12 @@ bool MacroCommands::ApplyCommand( const TranslatableString &friendlyCommand, if( pContext ) return ApplyEffectCommand( ID, friendlyCommand, command, params, *pContext); - const CommandContext context( *GetActiveProject() ); + const CommandContext context( mProject ); return ApplyEffectCommand( ID, friendlyCommand, command, params, context); } - AudacityProject *project = GetActiveProject(); + AudacityProject *project = &mProject; auto &manager = CommandManager::Get( *project ); if( pContext ){ if( HandleTextualCommand( @@ -878,7 +878,7 @@ bool MacroCommands::ApplyCommand( const TranslatableString &friendlyCommand, } else { - const CommandContext context( *GetActiveProject() ); + const CommandContext context( mProject ); if( HandleTextualCommand( manager, command, context, AlwaysEnabledFlag, true ) ) return true; @@ -896,7 +896,7 @@ bool MacroCommands::ApplyCommandInBatchMode( const CommandID & command, const wxString ¶ms, CommandContext const * pContext) { - AudacityProject *project = GetActiveProject(); + AudacityProject *project = &mProject; auto &settings = ProjectSettings::Get( *project ); // Recalc flags and enable items that may have become enabled. MenuManager::Get(*project).UpdateMenus(false); @@ -931,7 +931,7 @@ bool MacroCommands::ApplyMacro( mFileName = filename; - AudacityProject *proj = GetActiveProject(); + AudacityProject *proj = &mProject; bool res = false; auto cleanup2 = finally( [&] { if (!res) { diff --git a/src/BatchCommands.h b/src/BatchCommands.h index 778668ca5..61ee72b6f 100644 --- a/src/BatchCommands.h +++ b/src/BatchCommands.h @@ -87,7 +87,7 @@ class MacroCommands final { const FileExtension &extension); bool WriteMp3File( const wxString & Name, int bitrate ); double GetEndTime(); - static bool IsMono(); + static bool IsMono( AudacityProject *project ); // These commands do not depend on the command list. static void MigrateLegacyChains(); @@ -123,6 +123,9 @@ class MacroCommands final { void Split(const wxString & str, wxString & command, wxString & param); wxString Join(const wxString & command, const wxString & param); +private: + AudacityProject &mProject; + CommandIDs mCommandMacro; wxArrayString mParamsMacro; bool mAbort; diff --git a/src/menus/FileMenus.cpp b/src/menus/FileMenus.cpp index 7df55b5af..b7c29e025 100644 --- a/src/menus/FileMenus.cpp +++ b/src/menus/FileMenus.cpp @@ -92,7 +92,7 @@ void DoExport( AudacityProject &project, const FileExtension & Format ) FileHistory::Global().AddFileToHistory(filename); // We're in batch mode, the file does not exist already. // We really can proceed without prompting. - int nChannels = MacroCommands::IsMono() ? 1 : 2; + int nChannels = MacroCommands::IsMono( &project ) ? 1 : 2; e.Process( nChannels, // numChannels, Format, // type, From a769cdfe1d4039e8179f49df9609b89f54c37704 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 22 May 2019 07:07:57 -0400 Subject: [PATCH 9/9] MacroCommandDialog remembers reference to project --- src/BatchCommandDialog.cpp | 2 +- src/BatchProcessDialog.cpp | 8 ++++---- src/BatchProcessDialog.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/BatchCommandDialog.cpp b/src/BatchCommandDialog.cpp index bfb0ee07c..976ff3b50 100644 --- a/src/BatchCommandDialog.cpp +++ b/src/BatchCommandDialog.cpp @@ -66,7 +66,7 @@ MacroCommandDialog::MacroCommandDialog( wxDialogWrapper(parent, id, XO("Select Command"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxRESIZE_BORDER) - , mCatalog( &project ) + , mCatalog{ &project } { SetLabel(XO("Select Command")); // Provide visual label SetName(XO("Select Command")); // Provide audible label diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index 1b94b239c..0fcecfb39 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -86,9 +86,9 @@ ApplyMacroDialog::ApplyMacroDialog( wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) , mMacroCommands{ project } - , mCatalog( GetActiveProject() ) + , mProject{ project } + , mCatalog( &project ) { - //AudacityProject * p = GetActiveProject(); mAbort = false; mbExpanded = false; if( bInherited ) @@ -332,7 +332,7 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) gPrefs->Write(wxT("/Batch/ActiveMacro"), name); gPrefs->Flush(); - AudacityProject *project = GetActiveProject(); + AudacityProject *project = &mProject; if (!TrackList::Get( *project ).empty()) { AudacityMessageBox( XO("Please save and close the current project first.") ); @@ -730,7 +730,7 @@ void MacrosWindow::AddItem(const CommandID &Action, const wxString &Params) void MacrosWindow::UpdateMenus() { // OK even on mac, as dialog is modal. - auto p = GetActiveProject(); + auto p = &mProject; MenuManager::Get(*p).RebuildMenuBar(*p); } diff --git a/src/BatchProcessDialog.h b/src/BatchProcessDialog.h index 858f14a1f..f1a4fb81f 100644 --- a/src/BatchProcessDialog.h +++ b/src/BatchProcessDialog.h @@ -63,6 +63,7 @@ class ApplyMacroDialog : public wxDialogWrapper { wxString mMacroBeingRenamed; protected: + AudacityProject &mProject; const MacroCommandsCatalog mCatalog; DECLARE_EVENT_TABLE()