mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 08:09:32 +02:00
Construct Exporter with project pointer, fewer GetActiveProject calls
This commit is contained in:
parent
ece7bd888d
commit
d23569ca10
@ -86,7 +86,8 @@ static const std::pair<TranslatableString, CommandID> 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"));
|
||||
|
@ -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 = {});
|
||||
|
@ -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();
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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())) {
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user