diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index f0df449e9..fbbacadc6 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -161,11 +161,18 @@ void BatchProcessDialog::OnApplyToProject(wxCommandEvent & WXUNUSED(event)) long item = mChains->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + if (item == -1) { AudacityMessageBox(_("No chain selected")); return; } - wxString name = mChains->GetItemText(item); +} + +void BatchProcessDialog::ApplyChainToProject( int iChain, bool bHasGui ) +{ + wxString name = mChains->GetItemText(iChain); + if( name.IsEmpty() ) + return; wxDialog * pD = safenew wxDialogWrapper(this, wxID_ANY, GetTitle()); pD->SetName(pD->GetTitle()); @@ -197,7 +204,8 @@ void BatchProcessDialog::OnApplyToProject(wxCommandEvent & WXUNUSED(event)) // the 'Hide' converts us from a Modal into a regular dialog, // as far as closing is concerned. On Linux we can't close with // EndModal() anymore after this. - Hide(); + if( bHasGui ) + Hide(); gPrefs->Write(wxT("/Batch/ActiveChain"), name); gPrefs->Flush(); @@ -213,6 +221,10 @@ void BatchProcessDialog::OnApplyToProject(wxCommandEvent & WXUNUSED(event)) [this]{ return mBatchCommands.ApplyChain(); } ); } + if( !bHasGui ) + return; + + if (!success) { Show(); return; diff --git a/src/BatchProcessDialog.h b/src/BatchProcessDialog.h index 203371405..810824064 100644 --- a/src/BatchProcessDialog.h +++ b/src/BatchProcessDialog.h @@ -55,6 +55,9 @@ class BatchProcessDialog : public wxDialogWrapper { virtual wxString GetHelpPageName() {return "Tools_Menu#chains_compact_dialog";}; + void ApplyChainToProject( int iChain, bool bHasGui=true ); + + // These will be reused in the derived class... wxListCtrl *mList; wxListCtrl *mChains; diff --git a/src/Menus.cpp b/src/Menus.cpp index 86f35f0c1..c50677336 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -167,6 +167,10 @@ enum { #include "commands/CommandContext.h" #include "commands/ScreenshotCommand.h" + +#include "BatchCommands.h" + + // // Effects menu arrays // @@ -1193,6 +1197,8 @@ void AudacityProject::CreateMenusAndCommands() AudioIONotBusyFlag); c->AddItem(wxT("EditChains"), _("Edit C&hains..."), FN(OnEditChains)); + c->AddSeparator(); + PopulateChainsMenu( c, AudioIONotBusyFlag ); c->AddSeparator(); PopulateEffectsMenu(c, @@ -1698,6 +1704,22 @@ void AudacityProject::CreateMenusAndCommands() #endif } + + +void AudacityProject::PopulateChainsMenu( CommandManager* c, CommandFlag flags ) +{ + wxArrayString names = BatchCommands::GetNames(); + int i; + + for (i = 0; i < (int)names.GetCount(); i++) { + c->AddItem(wxString::Format("Chain%03i", i ), names[i], FN(OnApplyChainDirectly), + AudioIONotBusyFlag, + AudioIONotBusyFlag); + } + +} + + /// The effects come from a plug in list /// This code iterates through the list, adding effects into /// the menu. @@ -8457,6 +8479,18 @@ void AudacityProject::OnApplyChain(const CommandContext &WXUNUSED(context) ) ModifyUndoMenuItems(); } +void AudacityProject::OnApplyChainDirectly(const CommandContext &context ) +{ + //wxLogDebug( "Chain was: %s", context.parameter); + BatchProcessDialog dlg(this); + wxString Name = context.parameter; + long item=0; + // Take last three letters (of e.g. Chain007) and convert to a number. + Name.Mid( Name.Length() - 3 ).ToLong( &item, 10 ); + dlg.ApplyChainToProject( item, false ); + ModifyUndoMenuItems(); +} + void AudacityProject::OnEditChains(const CommandContext &WXUNUSED(context) ) { EditChainsDialog dlg(this); diff --git a/src/Menus.h b/src/Menus.h index ee97b6d26..dca0f49fe 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -24,7 +24,7 @@ private: void CreateMenusAndCommands(); - +void PopulateChainsMenu( CommandManager* c, CommandFlag flags ); void PopulateEffectsMenu(CommandManager *c, EffectType type, CommandFlag batchflags, CommandFlag realflags); void AddEffectMenuItems(CommandManager *c, @@ -494,6 +494,7 @@ void OnEffect(const CommandContext &context ); void OnRepeatLastEffect(const CommandContext &context ); bool DoAudacityCommand(const PluginID & ID, const CommandContext &, int flags); void OnApplyChain(const CommandContext &context ); +void OnApplyChainDirectly(const CommandContext &context ); void OnEditChains(const CommandContext &context ); void OnStereoToMono(const CommandContext &context ); void OnAudacityCommand(const CommandContext &context );