Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
MacroCommands Class Referencefinal

Maintains the list of commands for batch/macro processing. See also MacrosWindow and ApplyMacroDialog. More...

#include <BatchCommands.h>

Collaboration diagram for MacroCommands:
[legend]

Public Member Functions

 MacroCommands (AudacityProject &project)
 
bool ApplyMacro (const MacroCommandsCatalog &catalog, const wxString &filename={})
 
bool ApplyCommand (const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, CommandContext const *pContext=NULL)
 
bool ApplyCommandInBatchMode (const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, CommandContext const *pContext=NULL)
 
bool ApplyEffectCommand (const PluginID &ID, const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, const CommandContext &Context)
 
bool ReportAndSkip (const TranslatableString &friendlyCommand, const wxString &params)
 
void AbortBatch ()
 
void ResetMacro ()
 
void RestoreMacro (const wxString &name)
 
wxString ReadMacro (const wxString &macro, wxWindow *parent=nullptr)
 
wxString WriteMacro (const wxString &macro, wxWindow *parent=nullptr)
 
bool AddMacro (const wxString &macro)
 
bool DeleteMacro (const wxString &name)
 
bool RenameMacro (const wxString &oldmacro, const wxString &newmacro)
 
void AddToMacro (const CommandID &command, int before=-1)
 
void AddToMacro (const CommandID &command, const wxString &params, int before=-1)
 
void DeleteFromMacro (int index)
 
CommandID GetCommand (int index)
 
wxString GetParams (int index)
 
int GetCount ()
 
wxString GetMessage ()
 
void AddToMessage (const wxString &msgIn)
 
bool IsFixed (const wxString &name)
 
void Split (const wxString &str, wxString &command, wxString &param)
 
wxString Join (const wxString &command, const wxString &param)
 

Static Public Member Functions

static bool DoAudacityCommand (const PluginID &ID, const CommandContext &context, unsigned flags)
 
static void MigrateLegacyChains ()
 
static wxArrayString GetNames ()
 
static wxArrayStringEx GetNamesOfDefaultMacros ()
 
static wxString GetCurrentParamsFor (const CommandID &command)
 
static wxString PromptForParamsFor (const CommandID &command, const wxString &params, wxWindow &parent)
 
static wxString PromptForPresetFor (const CommandID &command, const wxString &params, wxWindow *parent)
 

Private Attributes

AudacityProjectmProject
 
CommandIDs mCommandMacro
 
wxArrayString mParamsMacro
 
bool mAbort
 
wxString mMessage
 
Exporter mExporter
 
wxString mFileName
 

Detailed Description

Maintains the list of commands for batch/macro processing. See also MacrosWindow and ApplyMacroDialog.

Definition at line 56 of file BatchCommands.h.

Constructor & Destructor Documentation

◆ MacroCommands()

MacroCommands::MacroCommands ( AudacityProject project)

Definition at line 55 of file BatchCommands.cpp.

56: mProject{ project }
57, mExporter{ project }
58{
59 ResetMacro();
60
61 auto names = GetNames();
62 auto defaults = GetNamesOfDefaultMacros();
63
64 for( size_t i = 0;i<defaults.size();i++){
65 wxString name = defaults[i];
66 if ( ! make_iterator_range( names ).contains(name) ) {
70 }
71 }
72}
const TranslatableString name
Definition: Distortion.cpp:82
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:423
static TranslatableStrings names
Definition: TagsEditor.cpp:151
static wxArrayStringEx GetNamesOfDefaultMacros()
Exporter mExporter
static wxArrayString GetNames()
wxString WriteMacro(const wxString &macro, wxWindow *parent=nullptr)
bool AddMacro(const wxString &macro)
void RestoreMacro(const wxString &name)
AudacityProject & mProject

References AddMacro(), GetNames(), GetNamesOfDefaultMacros(), make_iterator_range(), name, names, ResetMacro(), RestoreMacro(), and WriteMacro().

Here is the call graph for this function:

Member Function Documentation

◆ AbortBatch()

void MacroCommands::AbortBatch ( )

Definition at line 788 of file BatchCommands.cpp.

789{
790 mAbort = true;
791}

References mAbort.

◆ AddMacro()

bool MacroCommands::AddMacro ( const wxString &  macro)

Definition at line 266 of file BatchCommands.cpp.

267{
268 // Build the filename
269 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
270
271 // Set the file name
272 wxTextFile tf(name.GetFullPath());
273
274 // Create it..Create will display errors
275 return tf.Create();
276}
FILES_API FilePath MacroDir()

References FileNames::MacroDir(), and name.

Referenced by MacroCommands(), and MacrosWindow::OnAdd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddToMacro() [1/2]

void MacroCommands::AddToMacro ( const CommandID command,
const wxString &  params,
int  before = -1 
)

Definition at line 798 of file BatchCommands.cpp.

799{
800 if (before == -1) {
801 before = (int)mCommandMacro.size();
802 }
803
804 mCommandMacro.insert(mCommandMacro.begin() + before, command);
805 mParamsMacro.insert(mParamsMacro.begin() + before, params);
806}
EffectDistortion::Params params
Definition: Distortion.cpp:83
CommandIDs mCommandMacro
wxArrayString mParamsMacro

References mCommandMacro, mParamsMacro, and params.

◆ AddToMacro() [2/2]

void MacroCommands::AddToMacro ( const CommandID command,
int  before = -1 
)

Definition at line 793 of file BatchCommands.cpp.

794{
795 AddToMacro(command, GetCurrentParamsFor(command), before);
796}
void AddToMacro(const CommandID &command, int before=-1)
static wxString GetCurrentParamsFor(const CommandID &command)

References AddToMacro(), and GetCurrentParamsFor().

Referenced by AddToMacro(), MacrosWindow::InsertCommandAt(), MacrosWindow::OnDown(), MacrosWindow::OnEditCommandParams(), MacrosWindow::OnUp(), and RestoreMacro().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddToMessage()

void MacroCommands::AddToMessage ( const wxString &  msgIn)
inline

Definition at line 107 of file BatchCommands.h.

107{ mMessage += msgIn;};
wxString mMessage

References mMessage.

◆ ApplyCommand()

bool MacroCommands::ApplyCommand ( const TranslatableString friendlyCommand,
const CommandID command,
const wxString &  params,
CommandContext const *  pContext = NULL 
)

Definition at line 594 of file BatchCommands.cpp.

597{
598 // Test for an effect.
599 const PluginID & ID =
601 if (!ID.empty())
602 {
603 if( pContext )
604 return ApplyEffectCommand(
605 ID, friendlyCommand, command, params, *pContext);
606 const CommandContext context( mProject );
607 return ApplyEffectCommand(
608 ID, friendlyCommand, command, params, context);
609 }
610
611 AudacityProject *project = &mProject;
612 auto &manager = CommandManager::Get( *project );
613 if( pContext ){
615 manager, command, *pContext, AlwaysEnabledFlag, true ) )
616 return true;
617 pContext->Status( wxString::Format(
618 _("Your batch command of %s was not recognized."), friendlyCommand.Translation() ));
619 return false;
620 }
621 else
622 {
623 const CommandContext context( mProject );
625 manager, command, context, AlwaysEnabledFlag, true ) )
626 return true;
627 }
628
630 XO("Your batch command of %s was not recognized.")
631 .Format( friendlyCommand ) );
632
633 return false;
634}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
bool HandleTextualCommand(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:35
wxString PluginID
Definition: EffectManager.h:30
#define XO(s)
Definition: Internat.h:31
#define _(s)
Definition: Internat.h:75
static const AttachedProjectObjects::RegisteredFactory manager
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
static CommandManager & Get(AudacityProject &project)
static EffectManager & Get()
const PluginID & GetEffectByIdentifier(const CommandID &strTarget)
Abstract base class used in importing a file.
bool ApplyEffectCommand(const PluginID &ID, const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, const CommandContext &Context)
wxString Translation() const

References _, AlwaysEnabledFlag, ApplyEffectCommand(), AudacityMessageBox(), EffectManager::Get(), CommandManager::Get(), EffectManager::GetEffectByIdentifier(), HandleTextualCommand(), manager, mProject, params, CommandContext::Status(), TranslatableString::Translation(), and XO.

Referenced by ApplyCommandInBatchMode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyCommandInBatchMode()

bool MacroCommands::ApplyCommandInBatchMode ( const TranslatableString friendlyCommand,
const CommandID command,
const wxString &  params,
CommandContext const *  pContext = NULL 
)

Definition at line 636 of file BatchCommands.cpp.

640{
641 AudacityProject *project = &mProject;
642 auto &settings = ProjectSettings::Get( *project );
643 // Recalc flags and enable items that may have become enabled.
644 MenuManager::Get(*project).UpdateMenus(false);
645 // enter batch mode...
646 bool prevShowMode = settings.GetShowId3Dialog();
647 project->mBatchMode++;
648 auto cleanup = finally( [&] {
649 // exit batch mode...
650 settings.SetShowId3Dialog(prevShowMode);
651 project->mBatchMode--;
652 } );
653
654 return ApplyCommand( friendlyCommand, command, params, pContext );
655}
static Settings & settings()
Definition: TrackInfo.cpp:87
bool ApplyCommand(const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, CommandContext const *pContext=NULL)
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:71
void UpdateMenus(bool checkActive=true)
Definition: Menus.cpp:643
static ProjectSettings & Get(AudacityProject &project)

References ApplyCommand(), MenuManager::Get(), ProjectSettings::Get(), AudacityProject::mBatchMode, mProject, params, settings(), and MenuManager::UpdateMenus().

Referenced by ApplyMacro().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyEffectCommand()

bool MacroCommands::ApplyEffectCommand ( const PluginID ID,
const TranslatableString friendlyCommand,
const CommandID command,
const wxString &  params,
const CommandContext Context 
)

Definition at line 537 of file BatchCommands.cpp.

541{
542 static_cast<void>(command);//compiler food.
543
544 //Possibly end processing here, if in batch-debug
545 if( ReportAndSkip(friendlyCommand, params))
546 return true;
547
549 if (!plug)
550 return false;
551
552 AudacityProject *project = &mProject;
553
554 // IF nothing selected, THEN select everything depending
555 // on preferences setting.
556 // (most effects require that you have something selected).
558 {
560 {
562 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
563 XO("\"%s\" requires one or more tracks to be selected.").Format(friendlyCommand));
564 return false;
565 }
566 }
567
568 bool res = false;
569
570 auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
571
572 // transfer the parameters to the effect...
573 if (EffectManager::Get().SetEffectParameters(ID, params))
574 {
576 // and apply the effect...
577 res = DoAudacityCommand(ID,
578 Context,
582 else
583 // and apply the effect...
584 res = EffectUI::DoEffect(ID,
585 Context,
589 }
590
591 return res;
592}
@ PluginTypeAudacityCommand
BatchProcessingScope SetBatchProcessing(const PluginID &ID)
Begin a scope that ends when the returned object is destroyed.
bool ReportAndSkip(const TranslatableString &friendlyCommand, const wxString &params)
static bool DoAudacityCommand(const PluginID &ID, const CommandContext &context, unsigned flags)
PluginType GetPluginType() const
const PluginDescriptor * GetPlugin(const PluginID &ID) const
static PluginManager & Get()
AUDACITY_DLL_API bool DoEffect(const PluginID &ID, const CommandContext &context, unsigned flags)
'Repeat Last Effect'.
Definition: EffectUI.cpp:1329
bool SelectAllIfNoneAndAllowed(AudacityProject &project)

References AudacityMessageBox(), DoAudacityCommand(), EffectUI::DoEffect(), PluginManager::Get(), EffectManager::Get(), PluginManager::GetPlugin(), PluginDescriptor::GetPluginType(), EffectManager::kConfigured, EffectManager::kDontRepeatLast, EffectManager::kSkipState, mProject, params, PluginTypeAudacityCommand, ReportAndSkip(), SelectUtilities::SelectAllIfNoneAndAllowed(), EffectManager::SetBatchProcessing(), and XO.

Referenced by ApplyCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyMacro()

bool MacroCommands::ApplyMacro ( const MacroCommandsCatalog catalog,
const wxString &  filename = {} 
)

Definition at line 661 of file BatchCommands.cpp.

663{
664 // Check for reentrant ApplyMacro commands.
665 // We'll allow 1 level of reentry, but not more.
666 // And we treat ignoring deeper levels as a success.
667 if (MacroReentryCount > 1) {
668 return true;
669 }
670
671 // Restore the reentry counter (to zero) when we exit.
672 auto cleanup1 = valueRestorer(MacroReentryCount);
674
675 AudacityProject *proj = &mProject;
676 bool res = false;
677
678 // Only perform this group on initial entry. They should not be done
679 // while recursing.
680 if (MacroReentryCount == 1) {
681 mFileName = filename;
682
683 TranslatableString longDesc, shortDesc;
684 wxString name = gPrefs->Read(wxT("/Batch/ActiveMacro"), wxEmptyString);
685 if (name.empty()) {
686 /* i18n-hint: active verb in past tense */
687 longDesc = XO("Applied Macro");
688 shortDesc = XO("Apply Macro");
689 }
690 else {
691 /* i18n-hint: active verb in past tense */
692 longDesc = XO("Applied Macro '%s'").Format(name);
693 shortDesc = XO("Apply '%s'").Format(name);
694 }
695
696 // Save the project state before making any changes. It will be rolled
697 // back if an error occurs.
698 // It also causes any calls to ModifyState (such as by simple
699 // view-changing commands) to append changes to this state, not to the
700 // previous state in history. See Bug 2076
701 if (proj) {
702 ProjectHistory::Get(*proj).PushState(longDesc, shortDesc);
703 }
704 }
705
706 // Upon exit of the top level apply, roll back the state if an error occurs.
707 auto cleanup2 = finally([&, macroReentryCount = MacroReentryCount] {
708 if (macroReentryCount == 1 && !res && proj) {
709 // Be sure that exceptions do not escape this destructor
710 GuardedCall([&]{
711 // Macro failed or was cancelled; revert to the previous state
712 auto &history = ProjectHistory::Get(*proj);
713 history.RollbackState();
714 // The added undo state is now vacuous. Remove it (Bug 2759)
715 auto &undoManager = UndoManager::Get(*proj);
716 undoManager.Undo(
717 [&]( const UndoStackElem &elem ){
718 history.PopState( elem.state ); } );
719 undoManager.AbandonRedo();
720 });
721 }
722 });
723
724 mAbort = false;
725
726 // Is tracing enabled?
727 bool trace;
728 gPrefs->Read(wxT("/EnableMacroTracing"), &trace, false);
729
730 // If so, then block most other messages while running the macro
731 wxLogLevel prevLevel = wxLog::GetComponentLevel("");
732 if (trace) {
733 wxLog::SetComponentLevel("", wxLOG_FatalError);
734 wxLog::SetComponentLevel(wxLOG_COMPONENT, wxLOG_Info);
735 }
736
737 size_t i = 0;
738 for (; i < mCommandMacro.size(); i++) {
739 const auto &command = mCommandMacro[i];
740 auto iter = catalog.ByCommandId(command);
741 const auto friendly = (iter == catalog.end())
742 ?
743 // uh oh, using GET to expose an internal name to the user!
744 // in default of any better friendly name
745 Verbatim( command.GET() )
746 : iter->name.Msgid().Stripped();
747
748 wxTimeSpan before;
749 if (trace) {
750 before = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
751 }
752
753 bool success = ApplyCommandInBatchMode(friendly, command, mParamsMacro[i]);
754
755 if (trace) {
756 auto after = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
757 wxLogMessage(wxT("Macro line #%ld took %s : %s:%s"),
758 i + 1,
759 (after - before).Format(wxT("%H:%M:%S.%l")),
760 command.GET(),
761 mParamsMacro[i]);
762 }
763
764 if (!success || mAbort)
765 break;
766 }
767
768 // Restore message level
769 if (trace) {
770 wxLog::SetComponentLevel("", prevLevel);
771 }
772
773 res = (i == mCommandMacro.size());
774 if (!res)
775 return false;
776
777 if (MacroReentryCount == 1) {
778 mFileName.Empty();
779
780 if (proj)
781 ProjectHistory::Get(*proj).ModifyState(true);
782 }
783
784 return true;
785}
R GuardedCall(const F1 &body, const F2 &handler=F2::Default(), F3 delayedHandler=DefaultDelayedHandlerAction) noexcept(noexcept(handler(std::declval< AudacityException * >())) &&noexcept(handler(nullptr)) &&noexcept(std::function< void(AudacityException *)>{std::move(delayedHandler)}))
Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread...
#define wxLOG_COMPONENT
static int MacroReentryCount
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:226
FileConfig * gPrefs
Definition: Prefs.cpp:71
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Entries::const_iterator ByCommandId(const CommandID &commandId) const
Entries::const_iterator end() const
Definition: BatchCommands.h:48
wxString mFileName
bool ApplyCommandInBatchMode(const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, CommandContext const *pContext=NULL)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:67
Holds one item with description and time range for the UndoManager.
Definition: UndoManager.h:127
UndoState state
Definition: UndoManager.h:140

References ApplyCommandInBatchMode(), MacroCommandsCatalog::ByCommandId(), TranslatableString::empty(), MacroCommandsCatalog::end(), ProjectHistory::Get(), UndoManager::Get(), gPrefs, GuardedCall(), mAbort, MacroReentryCount, mCommandMacro, mFileName, ProjectHistory::ModifyState(), mParamsMacro, mProject, name, ProjectHistory::PushState(), UndoStackElem::state, TranslatableString::Stripped(), valueRestorer(), Verbatim(), wxLOG_COMPONENT, and XO.

Referenced by ApplyMacroDialog::ApplyMacroToProject(), and ApplyMacroDialog::OnApplyToFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeleteFromMacro()

void MacroCommands::DeleteFromMacro ( int  index)

Definition at line 808 of file BatchCommands.cpp.

809{
810 if (index < 0 || index >= (int)mCommandMacro.size()) {
811 return;
812 }
813
814 mCommandMacro.erase( mCommandMacro.begin() + index );
815 mParamsMacro.erase( mParamsMacro.begin() + index );
816}

References mCommandMacro, and mParamsMacro.

Referenced by MacrosWindow::OnDelete(), MacrosWindow::OnDown(), MacrosWindow::OnEditCommandParams(), and MacrosWindow::OnUp().

Here is the caller graph for this function:

◆ DeleteMacro()

bool MacroCommands::DeleteMacro ( const wxString &  name)

Definition at line 278 of file BatchCommands.cpp.

279{
280 // Build the filename
281 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
282
283 // Delete it...wxRemoveFile will display errors
284 auto result = wxRemoveFile(name.GetFullPath());
285
286 // Delete any legacy chain that it shadowed
287 auto oldPath = wxFileName{ FileNames::LegacyChainDir(), macro, wxT("txt") };
288 wxRemoveFile(oldPath.GetFullPath()); // Don't care about this return value
289
290 return result;
291}
FILES_API FilePath LegacyChainDir()

References FileNames::LegacyChainDir(), FileNames::MacroDir(), and name.

Referenced by MacrosWindow::OnRemove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoAudacityCommand()

bool MacroCommands::DoAudacityCommand ( const PluginID ID,
const CommandContext context,
unsigned  flags 
)
static

DoAudacityCommand() takes a PluginID and executes the associated command.

At the moment flags are used only to indicate whether to prompt for parameters

Definition at line 498 of file BatchCommands.cpp.

500{
501 auto &project = context.project;
502 auto &window = ProjectWindow::Get( project );
504 if (!plug)
505 return false;
506
507 if (flags & EffectManager::kConfigured)
508 {
509 ProjectAudioManager::Get( project ).Stop();
510// SelectAllIfNone();
511 }
512
514 bool success = em.DoAudacityCommand(ID,
515 context,
516 &window,
517 (flags & EffectManager::kConfigured) == 0);
518
519 if (!success)
520 return false;
521
522/*
523 if (em.GetSkipStateFlag())
524 flags = flags | OnEffectFlags::kSkipState;
525
526 if (!(flags & OnEffectFlags::kSkipState))
527 {
528 wxString shortDesc = em.GetCommandName(ID);
529 wxString longDesc = em.GetCommandDescription(ID);
530 PushState(longDesc, shortDesc);
531 }
532*/
533 window.RedrawProject();
534 return true;
535}
AudacityProject & project
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:48
bool DoAudacityCommand(const PluginID &ID, const CommandContext &, wxWindow *parent, bool shouldPrompt=true)
void Stop(bool stopStream=true)
static ProjectAudioManager & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)

References EffectManager::DoAudacityCommand(), PluginManager::Get(), EffectManager::Get(), ProjectAudioManager::Get(), ProjectWindow::Get(), PluginManager::GetPlugin(), EffectManager::kConfigured, CommandContext::project, and ProjectAudioManager::Stop().

Referenced by ApplyEffectCommand(), and PluginActions::Handler::OnAudacityCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCommand()

CommandID MacroCommands::GetCommand ( int  index)

Definition at line 102 of file BatchCommands.cpp.

103{
104 if (index < 0 || index >= (int)mCommandMacro.size()) {
105 return wxT("");
106 }
107
108 return mCommandMacro[index];
109}

References mCommandMacro.

Referenced by MacrosWindow::OnDown(), MacrosWindow::OnEditCommandParams(), MacrosWindow::OnUp(), and MacrosWindow::PopulateList().

Here is the caller graph for this function:

◆ GetCount()

int MacroCommands::GetCount ( )

Definition at line 120 of file BatchCommands.cpp.

121{
122 return (int)mCommandMacro.size();
123}

References mCommandMacro.

Referenced by MacrosWindow::PopulateList().

Here is the caller graph for this function:

◆ GetCurrentParamsFor()

wxString MacroCommands::GetCurrentParamsFor ( const CommandID command)
static

Definition at line 436 of file BatchCommands.cpp.

437{
438 const PluginID & ID =
440 if (ID.empty())
441 {
442 return wxEmptyString; // effect not found.
443 }
444
446}
wxString GetEffectParameters(const PluginID &ID)

References EffectManager::Get(), EffectManager::GetEffectByIdentifier(), and EffectManager::GetEffectParameters().

Referenced by AddToMacro(), and MacroCommandDialog::OnItemSelected().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMessage()

wxString MacroCommands::GetMessage ( )
inline

Definition at line 106 of file BatchCommands.h.

106{ return mMessage;};

References mMessage.

◆ GetNames()

wxArrayString MacroCommands::GetNames ( )
static

Definition at line 884 of file BatchCommands.cpp.

885{
887
888 wxArrayString names;
889 FilePaths files;
890 wxDir::GetAllFiles(FileNames::MacroDir(), &files, wxT("*.txt"), wxDIR_FILES);
891 size_t i;
892
893 wxFileName ff;
894 for (i = 0; i < files.size(); i++) {
895 ff = (files[i]);
896 names.push_back(ff.GetName());
897 }
898
899 std::sort( names.begin(), names.end() );
900
901 return names;
902}
static void MigrateLegacyChains()
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

References FileNames::MacroDir(), MigrateLegacyChains(), and names.

Referenced by MacroCommands(), ApplyMacroDialog::PopulateMacros(), and anonymous_namespace{PluginMenus.cpp}::PopulateMacrosMenu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNamesOfDefaultMacros()

wxArrayStringEx MacroCommands::GetNamesOfDefaultMacros ( )
static

Definition at line 77 of file BatchCommands.cpp.

78{
79 return {
80 MP3Conversion.Translation() ,
81 FadeEnds.Translation() ,
82 };
83}
static const auto MP3Conversion
static const auto FadeEnds

References FadeEnds, and MP3Conversion.

Referenced by IsFixed(), and MacroCommands().

Here is the caller graph for this function:

◆ GetParams()

wxString MacroCommands::GetParams ( int  index)

Definition at line 111 of file BatchCommands.cpp.

112{
113 if (index < 0 || index >= (int)mParamsMacro.size()) {
114 return wxT("");
115 }
116
117 return mParamsMacro[index];
118}

References mParamsMacro.

Referenced by MacrosWindow::OnDown(), MacrosWindow::OnEditCommandParams(), MacrosWindow::OnUp(), and MacrosWindow::PopulateList().

Here is the caller graph for this function:

◆ IsFixed()

bool MacroCommands::IsFixed ( const wxString &  name)

Definition at line 904 of file BatchCommands.cpp.

905{
906 auto defaults = GetNamesOfDefaultMacros();
907 if( make_iterator_range( defaults ).contains( name ) )
908 return true;
909 return false;
910}

References GetNamesOfDefaultMacros(), make_iterator_range(), and name.

Referenced by MacrosWindow::OnMacrosBeginEdit(), and MacrosWindow::ShowActiveMacro().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Join()

wxString MacroCommands::Join ( const wxString &  command,
const wxString &  param 
)

Definition at line 934 of file BatchCommands.cpp.

935{
936 return command + wxT(": ") + param;
937}

◆ MigrateLegacyChains()

void MacroCommands::MigrateLegacyChains ( )
static

Definition at line 851 of file BatchCommands.cpp.

852{
853 static bool done = false;
854 if (!done) {
855 // Check once per session at most
856
857 // Copy chain files from the old Chains into the new Macros directory,
858 // but only if like-named files are not already present in Macros.
859
860 // Leave the old copies in place, in case a user wants to go back to
861 // an old Audacity version. They will have their old chains intact, but
862 // won't have any edits they made to the copy that now lives in Macros
863 // which old Audacity will not read.
864
865 const auto oldDir = FileNames::LegacyChainDir();
866 FilePaths files;
867 wxDir::GetAllFiles(oldDir, &files, wxT("*.txt"), wxDIR_FILES);
868
869 // add a dummy path component to be overwritten by SetFullName
870 wxFileName newDir{ FileNames::MacroDir(), wxT("x") };
871
872 for (const auto &file : files) {
873 auto name = wxFileName{file}.GetFullName();
874 newDir.SetFullName(name);
875 const auto newPath = newDir.GetFullPath();
876 if (!wxFileExists(newPath))
877 FileNames::DoCopyFile(file, newPath);
878 }
879 done = true;
880 }
881 // To do: use std::once
882}
FILES_API bool DoCopyFile(const FilePath &file1, const FilePath &file2, bool overwrite=true)

References FileNames::DoCopyFile(), FileNames::LegacyChainDir(), FileNames::MacroDir(), and name.

Referenced by GetNames().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PromptForParamsFor()

wxString MacroCommands::PromptForParamsFor ( const CommandID command,
const wxString &  params,
wxWindow &  parent 
)
static

Definition at line 448 of file BatchCommands.cpp.

450{
451 const PluginID & ID =
453 if (ID.empty())
454 {
455 return wxEmptyString; // effect not found
456 }
457
458 wxString res = params;
459
460 auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
461
462 if (EffectManager::Get().SetEffectParameters(ID, params))
463 {
464 if (EffectManager::Get().PromptUser(ID, EffectUI::DialogFactory, parent))
465 {
467 }
468 }
469
470 return res;
471}
AUDACITY_DLL_API wxDialog * DialogFactory(wxWindow &parent, EffectPlugin &host, EffectUIClientInterface &client, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access)
Definition: EffectUI.cpp:1295

References EffectUI::DialogFactory(), EffectManager::Get(), EffectManager::GetEffectByIdentifier(), EffectManager::GetEffectParameters(), params, and EffectManager::SetBatchProcessing().

Referenced by MacrosWindow::OnEditCommandParams(), and MacroCommandDialog::OnEditParams().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PromptForPresetFor()

wxString MacroCommands::PromptForPresetFor ( const CommandID command,
const wxString &  params,
wxWindow *  parent 
)
static

Definition at line 473 of file BatchCommands.cpp.

474{
475 const PluginID & ID =
477 if (ID.empty())
478 {
479 return wxEmptyString; // effect not found.
480 }
481
482 wxString preset = EffectManager::Get().GetPreset(ID, params, parent);
483
484 // Preset will be empty if the user cancelled the dialog, so return the original
485 // parameter value.
486 if (preset.empty())
487 {
488 return params;
489 }
490
491 return preset;
492}
EffectReverbSettings preset
Definition: Reverb.cpp:46
wxString GetPreset(const PluginID &ID, const wxString &params, wxWindow *parent)

References EffectManager::Get(), EffectManager::GetEffectByIdentifier(), EffectManager::GetPreset(), params, and preset.

Referenced by MacroCommandDialog::OnUsePreset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadMacro()

wxString MacroCommands::ReadMacro ( const wxString &  macro,
wxWindow *  parent = nullptr 
)

Definition at line 125 of file BatchCommands.cpp.

126{
127 // Clear any previous macro
128 ResetMacro();
129
130 // Build the filename
131 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
132
133 // But, ask the user for the real name if we're importing
134 if (parent) {
135 FilePath fn = SelectFile(FileNames::Operation::_None,
136 XO("Import Macro"),
137 wxEmptyString,
138 name.GetName(),
139 wxT("txt"),
141 wxFD_OPEN | wxRESIZE_BORDER,
142 parent);
143
144 // User canceled...
145 if (fn.empty()) {
146 return wxEmptyString;
147 }
148
149 wxFileName check(fn);
150 check.SetPath(name.GetPath());
151 if (check.FileExists())
152 {
153 int id = AudacityMessageBox(
154 XO("Macro %s already exists. Would you like to replace it?").Format(check.GetName()),
155 XO("Import Macro"),
156 wxYES_NO);
157 if (id == wxNO) {
158 return wxEmptyString;
159 }
160 }
161
162 name.Assign(fn);
163 }
164
165 // Set the file name
166 wxTextFile tf(name.GetFullPath());
167
168 // Open and check
169 tf.Open();
170 if (!tf.IsOpened()) {
171 // wxTextFile will display any errors
172 return wxEmptyString;
173 }
174
175 // Load commands from the file
176 int lines = tf.GetLineCount();
177 if (lines > 0) {
178 for (int i = 0; i < lines; i++) {
179
180 // Find the command name terminator...ignore line if not found
181 int splitAt = tf[i].Find(wxT(':'));
182 if (splitAt < 0) {
183 continue;
184 }
185
186 // Parse and clean
187 wxString cmd = tf[i].Left(splitAt).Strip(wxString::both);
188 wxString parm = tf[i].Mid(splitAt + 1).Strip(wxString::trailing);
189
190 // Add to lists
191 mCommandMacro.push_back(cmd);
192 mParamsMacro.push_back(parm);
193 }
194 }
195
196 // Done with the file
197 tf.Close();
198
199 // Write to macro directory if importing
200 if (parent) {
201 return WriteMacro(name.GetName());
202 }
203
204 return name.GetName();
205}
wxString FilePath
Definition: Project.h:20
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
Definition: SelectFile.cpp:17
static const auto fn
FILES_API const FileType TextFiles
Definition: FileNames.h:74

References AudacityMessageBox(), fn, FileNames::MacroDir(), mCommandMacro, mParamsMacro, name, ResetMacro(), SelectFile(), FileNames::TextFiles, WriteMacro(), and XO.

Referenced by ApplyMacroDialog::ApplyMacroToProject(), ApplyMacroDialog::OnApplyToFiles(), MacrosWindow::OnImport(), and MacrosWindow::ShowActiveMacro().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RenameMacro()

bool MacroCommands::RenameMacro ( const wxString &  oldmacro,
const wxString &  newmacro 
)

Definition at line 293 of file BatchCommands.cpp.

294{
295 // Build the filenames
296 wxFileName oname(FileNames::MacroDir(), oldmacro, wxT("txt"));
297 wxFileName nname(FileNames::MacroDir(), newmacro, wxT("txt"));
298
299 // Rename it...wxRenameFile will display errors
300 return wxRenameFile(oname.GetFullPath(), nname.GetFullPath());
301}

References FileNames::MacroDir().

Referenced by MacrosWindow::OnMacrosEndEdit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReportAndSkip()

bool MacroCommands::ReportAndSkip ( const TranslatableString friendlyCommand,
const wxString &  params 
)

Definition at line 826 of file BatchCommands.cpp.

828{
829 int bDebug;
830 gPrefs->Read(wxT("/Batch/Debug"), &bDebug, false);
831 if( bDebug == 0 )
832 return false;
833
834 //TODO: Add a cancel button to these, and add the logic so that we can abort.
835 if( !params.empty() )
836 {
838 XO("Apply %s with parameter(s)\n\n%s")
839 .Format( friendlyCommand, params ),
840 XO("Test Mode"));
841 }
842 else
843 {
845 XO("Apply %s").Format( friendlyCommand ),
846 XO("Test Mode"));
847 }
848 return true;
849}

References AudacityMessageBox(), gPrefs, params, and XO.

Referenced by ApplyEffectCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetMacro()

void MacroCommands::ResetMacro ( )

Definition at line 818 of file BatchCommands.cpp.

819{
820 mCommandMacro.clear();
821 mParamsMacro.clear();
822}

References mCommandMacro, and mParamsMacro.

Referenced by MacroCommands(), ReadMacro(), and RestoreMacro().

Here is the caller graph for this function:

◆ RestoreMacro()

void MacroCommands::RestoreMacro ( const wxString &  name)

Definition at line 85 of file BatchCommands.cpp.

86{
87// TIDY-ME: Effects change their name with localisation.
88// Commands (at least currently) don't. Messy.
89 ResetMacro();
90 if (name == MP3Conversion.Translation() ){
91 AddToMacro( wxT("Normalize") );
92 AddToMacro( wxT("ExportMP3") );
93 } else if (name == FadeEnds.Translation() ){
94 AddToMacro( wxT("Select"), wxT("Start=\"0\" End=\"1\"") );
95 AddToMacro( wxT("FadeIn") );
96 AddToMacro( wxT("Select"), wxT("Start=\"0\" End=\"1\" RelativeTo=\"ProjectEnd\"") );
97 AddToMacro( wxT("FadeOut") );
98 AddToMacro( wxT("Select"), wxT("Start=\"0\" End=\"0\"") );
99 }
100}

References AddToMacro(), FadeEnds, MP3Conversion, name, and ResetMacro().

Referenced by MacroCommands(), and MacrosWindow::OnRestore().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Split()

void MacroCommands::Split ( const wxString &  str,
wxString &  command,
wxString &  param 
)

Definition at line 912 of file BatchCommands.cpp.

913{
914 int splitAt;
915
916 command.Empty();
917 param.Empty();
918
919 if (str.empty()) {
920 return;
921 }
922
923 splitAt = str.Find(wxT(':'));
924 if (splitAt < 0) {
925 return;
926 }
927
928 command = str.Mid(0, splitAt);
929 param = str.Mid(splitAt + 1);
930
931 return;
932}
#define str(a)

References str.

◆ WriteMacro()

wxString MacroCommands::WriteMacro ( const wxString &  macro,
wxWindow *  parent = nullptr 
)

Definition at line 207 of file BatchCommands.cpp.

208{
209 // Build the default filename
210 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
211
212 // But, ask the user for the real name if we're exporting
213 if (parent) {
214 FilePath fn = SelectFile(FileNames::Operation::_None,
215 XO("Export Macro"),
216 wxEmptyString,
217 name.GetName(),
218 wxT("txt"),
220 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
221 parent);
222
223 // User canceled...
224 if (fn.empty()) {
225 return wxEmptyString;
226 }
227
228 name.Assign(fn);
229 }
230
231 // Set the file name
232 wxTextFile tf(name.GetFullPath());
233
234 // Create the file (Create() doesn't leave the file open)
235 if (!tf.Exists()) {
236 tf.Create();
237 }
238
239 // Open it
240 tf.Open();
241
242 if (!tf.IsOpened()) {
243 // wxTextFile will display any errors
244 return wxEmptyString;
245 }
246
247 // Start with a clean slate
248 tf.Clear();
249
250 // Copy over the commands
251 int lines = mCommandMacro.size();
252 for (int i = 0; i < lines; i++) {
253 // using GET to serialize macro definition to a text file
254 tf.AddLine(mCommandMacro[i].GET() + wxT(":") + mParamsMacro[ i ]);
255 }
256
257 // Write the macro
258 tf.Write();
259
260 // Done with the file
261 tf.Close();
262
263 return name.GetName();
264}

References fn, FileNames::MacroDir(), mCommandMacro, mParamsMacro, name, SelectFile(), FileNames::TextFiles, and XO.

Referenced by MacrosWindow::ChangeOK(), MacroCommands(), MacrosWindow::OnExport(), ReadMacro(), and MacrosWindow::SaveChanges().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAbort

bool MacroCommands::mAbort
private

Definition at line 119 of file BatchCommands.h.

Referenced by AbortBatch(), and ApplyMacro().

◆ mCommandMacro

CommandIDs MacroCommands::mCommandMacro
private

◆ mExporter

Exporter MacroCommands::mExporter
private

Definition at line 122 of file BatchCommands.h.

◆ mFileName

wxString MacroCommands::mFileName
private

Definition at line 123 of file BatchCommands.h.

Referenced by ApplyMacro().

◆ mMessage

wxString MacroCommands::mMessage
private

Definition at line 120 of file BatchCommands.h.

Referenced by AddToMessage(), and GetMessage().

◆ mParamsMacro

wxArrayString MacroCommands::mParamsMacro
private

◆ mProject

AudacityProject& MacroCommands::mProject
private

The documentation for this class was generated from the following files: