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

Construct Exporter with project pointer, fewer GetActiveProject calls

This commit is contained in:
Paul Licameli 2019-05-21 20:16:20 -04:00
parent ece7bd888d
commit d23569ca10
13 changed files with 50 additions and 51 deletions

View File

@ -86,7 +86,8 @@ static const std::pair<TranslatableString, CommandID> SpecialCommands[] = {
}; };
// end CLEANSPEECH remnant // end CLEANSPEECH remnant
MacroCommands::MacroCommands() MacroCommands::MacroCommands( AudacityProject &project )
: mExporter{ project }
{ {
ResetMacro(); ResetMacro();
@ -574,12 +575,11 @@ bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate )
double endTime = GetEndTime(); double endTime = GetEndTime();
if( endTime <= 0.0f ) if( endTime <= 0.0f )
return false; return false;
AudacityProject *project = GetActiveProject();
if( bitrate <=0 ) if( bitrate <=0 )
{ {
// 'No' bitrate given, use the current default. // 'No' bitrate given, use the current default.
// Use Mp3Stereo to control if export is to a stereo or mono file // 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 // 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; return rc;
} }
@ -679,7 +679,7 @@ bool MacroCommands::ApplySpecialCommand(
if (endTime <= 0.0f) { if (endTime <= 0.0f) {
return false; 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")) { } else if (command == wxT("ExportOgg")) {
#ifdef USE_LIBVORBIS #ifdef USE_LIBVORBIS
filename.Replace(wxT(".mp3"), wxT(".ogg"), false); filename.Replace(wxT(".mp3"), wxT(".ogg"), false);
@ -687,7 +687,7 @@ bool MacroCommands::ApplySpecialCommand(
if (endTime <= 0.0f) { if (endTime <= 0.0f) {
return false; 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 #else
AudacityMessageBox( XO( AudacityMessageBox( XO(
"Ogg Vorbis support is not included in this build of Audacity")); "Ogg Vorbis support is not included in this build of Audacity"));
@ -700,7 +700,7 @@ bool MacroCommands::ApplySpecialCommand(
if (endTime <= 0.0f) { if (endTime <= 0.0f) {
return false; 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 #else
AudacityMessageBox(XO( AudacityMessageBox(XO(
"FLAC support is not included in this build of Audacity")); "FLAC support is not included in this build of Audacity"));

View File

@ -59,7 +59,7 @@ class MacroCommands final {
const PluginID & ID, const CommandContext & context, unsigned flags ); const PluginID & ID, const CommandContext & context, unsigned flags );
// constructors and destructors // constructors and destructors
MacroCommands(); MacroCommands( AudacityProject &project );
public: public:
bool ApplyMacro( const MacroCommandsCatalog &catalog, bool ApplyMacro( const MacroCommandsCatalog &catalog,
const wxString & filename = {}); const wxString & filename = {});

View File

@ -80,10 +80,12 @@ BEGIN_EVENT_TABLE(ApplyMacroDialog, wxDialogWrapper)
EVT_BUTTON(wxID_HELP, ApplyMacroDialog::OnHelp) EVT_BUTTON(wxID_HELP, ApplyMacroDialog::OnHelp)
END_EVENT_TABLE() END_EVENT_TABLE()
ApplyMacroDialog::ApplyMacroDialog(wxWindow * parent, bool bInherited): ApplyMacroDialog::ApplyMacroDialog(
wxWindow * parent, AudacityProject &project, bool bInherited):
wxDialogWrapper(parent, wxID_ANY, XO("Macros Palette"), wxDialogWrapper(parent, wxID_ANY, XO("Macros Palette"),
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, mMacroCommands{ project }
, mCatalog( GetActiveProject() ) , mCatalog( GetActiveProject() )
{ {
//AudacityProject * p = GetActiveProject(); //AudacityProject * p = GetActiveProject();
@ -518,8 +520,9 @@ enum {
}; };
/// Constructor /// Constructor
MacrosWindow::MacrosWindow(wxWindow * parent, bool bExpanded): MacrosWindow::MacrosWindow(
ApplyMacroDialog(parent, true) wxWindow * parent, AudacityProject &project, bool bExpanded):
ApplyMacroDialog(parent, project, true)
{ {
mbExpanded = bExpanded; mbExpanded = bExpanded;
auto Title = WindowTitle(); auto Title = WindowTitle();

View File

@ -22,12 +22,14 @@ class wxListCtrl;
class wxListEvent; class wxListEvent;
class wxButton; class wxButton;
class wxTextCtrl; class wxTextCtrl;
class AudacityProject;
class ShuttleGui; class ShuttleGui;
class ApplyMacroDialog : public wxDialogWrapper { class ApplyMacroDialog : public wxDialogWrapper {
public: public:
// constructors and destructors // constructors and destructors
ApplyMacroDialog(wxWindow * parent, bool bInherited=false); ApplyMacroDialog(
wxWindow * parent, AudacityProject &project, bool bInherited=false);
virtual ~ApplyMacroDialog(); virtual ~ApplyMacroDialog();
public: public:
// Populate methods NOT virtual. // Populate methods NOT virtual.
@ -69,7 +71,8 @@ protected:
class MacrosWindow final : public ApplyMacroDialog class MacrosWindow final : public ApplyMacroDialog
{ {
public: public:
MacrosWindow(wxWindow * parent, bool bExpanded=true); MacrosWindow(
wxWindow * parent, AudacityProject &project, bool bExpanded=true);
~MacrosWindow(); ~MacrosWindow();
void UpdateDisplay( bool bExpanded ); void UpdateDisplay( bool bExpanded );

View File

@ -697,7 +697,7 @@ bool ProjectFileManager::SaveCopyWaveTracks(const FilePath & strProjectPathName,
// Export all WaveTracks to OGG. // Export all WaveTracks to OGG.
bool bSuccess = true; bool bSuccess = true;
Exporter theExporter; Exporter theExporter{ project };
wxFileName uniqueTrackFileName; wxFileName uniqueTrackFileName;
for (auto pTrack : (trackRange + &Track::IsLeader)) 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 startTime = channels.min( &Track::GetStartTime );
const auto endTime = channels.max( &Track::GetEndTime ); const auto endTime = channels.max( &Track::GetEndTime );
bSuccess = bSuccess =
theExporter.Process(&project, channels.size(), theExporter.Process(channels.size(),
fileFormat, uniqueTrackFileName.GetFullPath(), true, fileFormat, uniqueTrackFileName.GetFullPath(), true,
startTime, endTime); startTime, endTime);

View File

@ -357,11 +357,10 @@ would overwrite another project.\nPlease try again and select an original name."
void TimerRecordDialog::OnAutoExportPathButton_Click(wxCommandEvent& WXUNUSED(event)) void TimerRecordDialog::OnAutoExportPathButton_Click(wxCommandEvent& WXUNUSED(event))
{ {
AudacityProject* pProject = &mProject; Exporter eExporter{ mProject };
Exporter eExporter;
// Call the Exporter to set the options required // 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 // Populate the options so that we can destroy this instance of the Exporter
m_fnAutoExportFile = eExporter.GetAutoExportFileName(); m_fnAutoExportFile = eExporter.GetAutoExportFileName();
m_iAutoExportFormat = eExporter.GetAutoExportFormat(); m_iAutoExportFormat = eExporter.GetAutoExportFormat();
@ -644,10 +643,10 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) {
// Do Automatic Export? // Do Automatic Export?
if (m_bAutoExportEnabled) { if (m_bAutoExportEnabled) {
Exporter e; Exporter e{ mProject };
MissingAliasFilesDialog::SetShouldShow(true); MissingAliasFilesDialog::SetShouldShow(true);
bExportOK = e.ProcessFromTimerRecording( bExportOK = e.ProcessFromTimerRecording(
pProject, false, 0.0, TrackList::Get( *pProject ).GetEndTime(), false, 0.0, TrackList::Get( *pProject ).GetEndTime(),
m_fnAutoExportFile, m_iAutoExportFormat, m_fnAutoExportFile, m_iAutoExportFormat,
m_iAutoExportSubFormat, m_iAutoExportFilterIndex); m_iAutoExportSubFormat, m_iAutoExportFilterIndex);
} }

View File

@ -55,7 +55,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context)
wxString macroName = GetString(wxT("MacroName")); wxString macroName = GetString(wxT("MacroName"));
if (!macroName.empty()) if (!macroName.empty())
{ {
MacroCommands batch; MacroCommands batch{ context.project };
batch.ReadMacro(macroName); batch.ReadMacro(macroName);
return batch.ApplyMacro(catalog); return batch.ApplyMacro(catalog);
} }
@ -68,7 +68,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context)
: iter->name.Msgid().Stripped(); : iter->name.Msgid().Stripped();
// Create a Batch that will have just one command in it... // 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); bool bResult = Batch.ApplyCommandInBatchMode(friendly, cmdName, cmdParams, &context);
// Relay messages, if any. // Relay messages, if any.
wxString Message = Batch.GetMessage(); wxString Message = Batch.GetMessage();

View File

@ -80,10 +80,9 @@ bool ExportCommand::Apply(const CommandContext & context)
} }
wxString extension = mFileName.Mid(splitAt+1).MakeUpper(); wxString extension = mFileName.Mid(splitAt+1).MakeUpper();
Exporter exporter; Exporter exporter{ context.project };
bool exportSuccess = exporter.Process(&context.project, bool exportSuccess = exporter.Process(std::max(0, mnChannels),
std::max(0, mnChannels),
extension, mFileName, extension, mFileName,
true, t0, t1); true, t0, t1);

View File

@ -297,7 +297,8 @@ Exporter::RegisteredExportPlugin::RegisteredExportPlugin(
sFactories().emplace_back( factory ); sFactories().emplace_back( factory );
} }
Exporter::Exporter() Exporter::Exporter( AudacityProject &project )
: mProject{ &project }
{ {
mMixerSpec = NULL; mMixerSpec = NULL;
mBook = NULL; mBook = NULL;
@ -342,7 +343,7 @@ void Exporter::OnExtensionChanged(wxCommandEvent &evt) {
void Exporter::OnHelp(wxCommandEvent& WXUNUSED(evt)) void Exporter::OnHelp(wxCommandEvent& WXUNUSED(evt))
{ {
wxWindow * pWin = FindProjectFrame( GetActiveProject() ); wxWindow * pWin = FindProjectFrame( mProject );
HelpSystem::ShowHelp(pWin, wxT("File_Export_Dialog"), true); HelpSystem::ShowHelp(pWin, wxT("File_Export_Dialog"), true);
} }
@ -400,10 +401,9 @@ bool Exporter::DoEditMetadata(AudacityProject &project,
return false; return false;
} }
bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, double t1) bool Exporter::Process(bool selectedOnly, double t0, double t1)
{ {
// Save parms // Save parms
mProject = project;
mSelectedOnly = selectedOnly; mSelectedOnly = selectedOnly;
mT0 = t0; mT0 = t0;
mT1 = t1; mT1 = t1;
@ -425,7 +425,7 @@ bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, d
// Let user edit MetaData // Let user edit MetaData
if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) { if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
if (!DoEditMetadata( *project, if (!DoEditMetadata( *mProject,
XO("Edit Metadata Tags"), XO("Exported Tags"), XO("Edit Metadata Tags"), XO("Exported Tags"),
ProjectSettings::Get( *mProject ).GetShowId3Dialog())) { ProjectSettings::Get( *mProject ).GetShowId3Dialog())) {
return false; return false;
@ -446,12 +446,11 @@ bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, d
return success; return success;
} }
bool Exporter::Process(AudacityProject *project, unsigned numChannels, bool Exporter::Process(unsigned numChannels,
const FileExtension &type, const wxString & filename, const FileExtension &type, const wxString & filename,
bool selectedOnly, double t0, double t1) bool selectedOnly, double t0, double t1)
{ {
// Save parms // Save parms
mProject = project;
mChannels = numChannels; mChannels = numChannels;
mFilename = filename; mFilename = filename;
mSelectedOnly = selectedOnly; mSelectedOnly = selectedOnly;
@ -1018,8 +1017,7 @@ void Exporter::OnFilterChanged(wxFileCtrlEvent & evt)
mBook->ChangeSelection(index); mBook->ChangeSelection(index);
} }
bool Exporter::ProcessFromTimerRecording(AudacityProject *project, bool Exporter::ProcessFromTimerRecording(bool selectedOnly,
bool selectedOnly,
double t0, double t0,
double t1, double t1,
wxFileName fnFile, wxFileName fnFile,
@ -1028,7 +1026,6 @@ bool Exporter::ProcessFromTimerRecording(AudacityProject *project,
int iFilterIndex) int iFilterIndex)
{ {
// Save parms // Save parms
mProject = project;
mSelectedOnly = selectedOnly; mSelectedOnly = selectedOnly;
mT0 = t0; mT0 = t0;
mT1 = t1; mT1 = t1;
@ -1079,16 +1076,15 @@ wxFileName Exporter::GetAutoExportFileName() {
return mFilename; return mFilename;
} }
bool Exporter::SetAutoExportOptions(AudacityProject *project) { bool Exporter::SetAutoExportOptions() {
mFormat = -1; mFormat = -1;
mProject = project;
if( GetFilename()==false ) if( GetFilename()==false )
return false; return false;
// Let user edit MetaData // Let user edit MetaData
if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) { if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
if (!DoEditMetadata( *project, if (!DoEditMetadata( *mProject,
XO("Edit Metadata Tags"), XO("Edit Metadata Tags"),
XO("Exported Tags"), XO("Exported Tags"),
ProjectSettings::Get(*mProject).GetShowId3Dialog())) { ProjectSettings::Get(*mProject).GetShowId3Dialog())) {

View File

@ -181,15 +181,15 @@ public:
const TranslatableString &title, const TranslatableString &title,
const TranslatableString &shortUndoDescription, bool force); const TranslatableString &shortUndoDescription, bool force);
Exporter(); Exporter( AudacityProject &project );
virtual ~Exporter(); virtual ~Exporter();
void SetFileDialogTitle( const TranslatableString & DialogTitle ); void SetFileDialogTitle( const TranslatableString & DialogTitle );
void SetDefaultFormat( const FileExtension & Format ){ mFormatName = Format;}; void SetDefaultFormat( const FileExtension & Format ){ mFormatName = Format;};
bool Process(AudacityProject *project, bool selectedOnly, bool Process(bool selectedOnly,
double t0, double t1); double t0, double t1);
bool Process(AudacityProject *project, unsigned numChannels, bool Process(unsigned numChannels,
const FileExtension &type, const wxString & filename, const FileExtension &type, const wxString & filename,
bool selectedOnly, double t0, double t1); bool selectedOnly, double t0, double t1);
@ -199,15 +199,14 @@ public:
const ExportPluginArray &GetPlugins(); const ExportPluginArray &GetPlugins();
// Auto Export from Timer Recording // Auto Export from Timer Recording
bool ProcessFromTimerRecording(AudacityProject *project, bool ProcessFromTimerRecording(bool selectedOnly,
bool selectedOnly,
double t0, double t0,
double t1, double t1,
wxFileName fnFile, wxFileName fnFile,
int iFormat, int iFormat,
int iSubFormat, int iSubFormat,
int iFilterIndex); int iFilterIndex);
bool SetAutoExportOptions(AudacityProject *project); bool SetAutoExportOptions();
int GetAutoExportFormat(); int GetAutoExportFormat();
int GetAutoExportSubFormat(); int GetAutoExportSubFormat();
int GetAutoExportFilterIndex(); int GetAutoExportFilterIndex();

View File

@ -131,6 +131,7 @@ END_EVENT_TABLE()
ExportMultipleDialog::ExportMultipleDialog(AudacityProject *project) ExportMultipleDialog::ExportMultipleDialog(AudacityProject *project)
: wxDialogWrapper( &GetProjectFrame( *project ), : wxDialogWrapper( &GetProjectFrame( *project ),
wxID_ANY, XO("Export Multiple") ) wxID_ANY, XO("Export Multiple") )
, mExporter{ *project }
, mSelectionState{ SelectionState::Get( *project ) } , mSelectionState{ SelectionState::Get( *project ) }
{ {
SetName(); SetName();

View File

@ -40,7 +40,7 @@ void DoExport( AudacityProject &project, const FileExtension & Format )
{ {
auto &tracks = TrackList::Get( project ); auto &tracks = TrackList::Get( project );
Exporter e; Exporter e{ project };
MissingAliasFilesDialog::SetShouldShow(true); MissingAliasFilesDialog::SetShouldShow(true);
double t0 = 0.0; double t0 = 0.0;
@ -85,7 +85,7 @@ void DoExport( AudacityProject &project, const FileExtension & Format )
{ {
// Do export with prompting. // Do export with prompting.
e.SetDefaultFormat(Format); e.SetDefaultFormat(Format);
e.Process(&project, false, t0, t1); e.Process(false, t0, t1);
} }
else else
{ {
@ -94,7 +94,6 @@ void DoExport( AudacityProject &project, const FileExtension & Format )
// We really can proceed without prompting. // We really can proceed without prompting.
int nChannels = MacroCommands::IsMono() ? 1 : 2; int nChannels = MacroCommands::IsMono() ? 1 : 2;
e.Process( e.Process(
&project, // AudacityProject
nChannels, // numChannels, nChannels, // numChannels,
Format, // type, Format, // type,
filename, // filename, filename, // filename,
@ -201,11 +200,11 @@ void OnExportSelection(const CommandContext &context)
{ {
auto &project = context.project; auto &project = context.project;
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion; auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
Exporter e; Exporter e{ project };
MissingAliasFilesDialog::SetShouldShow(true); MissingAliasFilesDialog::SetShouldShow(true);
e.SetFileDialogTitle( XO("Export Selected Audio") ); e.SetFileDialogTitle( XO("Export Selected Audio") );
e.Process(&project, true, selectedRegion.t0(), e.Process(true, selectedRegion.t0(),
selectedRegion.t1()); selectedRegion.t1());
} }

View File

@ -47,7 +47,7 @@ AudacityProject::AttachedWindows::RegisteredFactory sMacrosWindowKey{
[]( AudacityProject &parent ) -> wxWeakRef< wxWindow > { []( AudacityProject &parent ) -> wxWeakRef< wxWindow > {
auto &window = ProjectWindow::Get( parent ); auto &window = ProjectWindow::Get( parent );
return safenew MacrosWindow( return safenew MacrosWindow(
&window, true &window, parent, true
); );
} }
}; };
@ -543,7 +543,7 @@ void OnApplyMacroDirectly(const CommandContext &context )
auto &window = ProjectWindow::Get( project ); auto &window = ProjectWindow::Get( project );
//wxLogDebug( "Macro was: %s", context.parameter); //wxLogDebug( "Macro was: %s", context.parameter);
ApplyMacroDialog dlg( &window ); ApplyMacroDialog dlg( &window, project );
const auto &Name = context.parameter; const auto &Name = context.parameter;
// We used numbers previously, but macros could get renumbered, making // We used numbers previously, but macros could get renumbered, making