diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index ba7997ab9..4141fe5a2 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -798,19 +798,22 @@ bool MacroCommands::ApplyCommand( const wxString &friendlyCommand, } bool MacroCommands::ApplyCommandInBatchMode( const wxString &friendlyCommand, - const wxString & command, const wxString ¶ms) + const wxString & command, const wxString ¶ms, + CommandContext const * pContext) { AudacityProject *project = GetActiveProject(); // Recalc flags and enable items that may have become enabled. project->UpdateMenus(false); // enter batch mode... bool prevShowMode = project->GetShowId3Dialog(); + project->mBatchMode++; auto cleanup = finally( [&] { // exit batch mode... project->SetShowId3Dialog(prevShowMode); + project->mBatchMode--; } ); - return ApplyCommand( friendlyCommand, command, params ); + return ApplyCommand( friendlyCommand, command, params, pContext ); } static int MacroReentryCount = 0; diff --git a/src/BatchCommands.h b/src/BatchCommands.h index 017ef2b85..943b1f9d2 100644 --- a/src/BatchCommands.h +++ b/src/BatchCommands.h @@ -60,7 +60,8 @@ class MacroCommands final { const wxString & command, const wxString & params, CommandContext const * pContext=NULL ); bool ApplyCommandInBatchMode( const wxString &friendlyCommand, - const wxString & command, const wxString ¶ms); + const wxString & command, const wxString ¶ms, + CommandContext const * pContext = NULL); bool ApplySpecialCommand( int iCommand, const wxString &friendlyCommand, const wxString & command, const wxString & params); @@ -72,10 +73,10 @@ class MacroCommands final { void AbortBatch(); // Utility functions for the special commands. - wxString BuildCleanFileName(const wxString &fileName, const wxString &extension); + static wxString BuildCleanFileName(const wxString &fileName, const wxString &extension); bool WriteMp3File( const wxString & Name, int bitrate ); double GetEndTime(); - bool IsMono(); + static bool IsMono(); // These commands do not depend on the command list. static void MigrateLegacyChains(); diff --git a/src/Menus.cpp b/src/Menus.cpp index fffaf2648..f6e9ac0ba 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -4957,10 +4957,37 @@ void AudacityProject::OnExportMIDI(const CommandContext &WXUNUSED(context) ){ void AudacityProject::OnExport(const wxString & Format ) { Exporter e; - e.SetDefaultFormat( Format ); wxGetApp().SetMissingAliasedFileWarningShouldShow(true); - e.Process(this, false, 0.0, mTracks->GetEndTime()); + double t0 = 0.0; + double t1 = mTracks->GetEndTime(); + + // Prompt for file name and/or extension? + bool bPromptingRequired = (mBatchMode == 0) || mFileName.IsEmpty() || Format.IsEmpty(); + + if (bPromptingRequired) { + e.SetDefaultFormat(Format); + e.Process(this, false, 0.0, mTracks->GetEndTime()); + } + else { + // We're in batch mode, and we have an mFileName and Format. + wxString extension = "."; + extension += Format; + extension.MakeLower(); + + wxString filename = MacroCommands::BuildCleanFileName(mFileName, extension); + + int nChannels = MacroCommands::IsMono() ? 1 : 2; + e.Process( + this, // AudacityProject + nChannels, // numChannels, + Format, // type, + filename, // filename, + false, // selectedOnly, + t0, // t0 + t1 // t1 + ); + } } void AudacityProject::OnExportAudio(const CommandContext &WXUNUSED(context) ){ OnExport("");} diff --git a/src/Project.h b/src/Project.h index 0127d15b3..828883b0f 100644 --- a/src/Project.h +++ b/src/Project.h @@ -706,6 +706,7 @@ private: wxString mHelpPref; wxString mSoloPref; bool mbBusyImporting{ false }; // used to fix bug 584 + int mBatchMode{ 0 };// 0 menas not, >0 means in batch mode. void SetNormalizedWindowState(wxRect pSizeAndLocation) { mNormalizedWindowState = pSizeAndLocation; } wxRect GetNormalizedWindowState() const { return mNormalizedWindowState; } diff --git a/src/commands/BatchEvalCommand.cpp b/src/commands/BatchEvalCommand.cpp index f943f1d02..5695417df 100644 --- a/src/commands/BatchEvalCommand.cpp +++ b/src/commands/BatchEvalCommand.cpp @@ -61,7 +61,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context) // Create a Batch that will have just one command in it... MacroCommands Batch; - bool bResult = Batch.ApplyCommand(friendly, cmdName, cmdParams, &context); + bool bResult = Batch.ApplyCommandInBatchMode(friendly, cmdName, cmdParams, &context); // Relay messages, if any. wxString Message = Batch.GetMessage(); if( !Message.IsEmpty() )