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 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 54 of file BatchCommands.cpp.

55: mProject{ project }
56, mExporter{ project }
57{
58 ResetMacro();
59
60 auto names = GetNames();
61 auto defaults = GetNamesOfDefaultMacros();
62
63 for( size_t i = 0;i<defaults.size();i++){
64 wxString name = defaults[i];
65 if ( ! make_iterator_range( names ).contains(name) ) {
69 }
70 }
71}
const TranslatableString name
Definition: Distortion.cpp:76
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:448
static TranslatableStrings names
Definition: TagsEditor.cpp:152
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 735 of file BatchCommands.cpp.

736{
737 mAbort = true;
738}

References mAbort.

◆ AddMacro()

bool MacroCommands::AddMacro ( const wxString &  macro)

Definition at line 265 of file BatchCommands.cpp.

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

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

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 745 of file BatchCommands.cpp.

746{
747 if (before == -1) {
748 before = (int)mCommandMacro.size();
749 }
750
751 mCommandMacro.insert(mCommandMacro.begin() + before, command);
752 mParamsMacro.insert(mParamsMacro.begin() + before, params);
753}
EffectDistortionSettings params
Definition: Distortion.cpp:77
CommandIDs mCommandMacro
wxArrayString mParamsMacro

References mCommandMacro, mParamsMacro, and params.

◆ AddToMacro() [2/2]

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

Definition at line 740 of file BatchCommands.cpp.

741{
742 AddToMacro(command, GetCurrentParamsFor(command), before);
743}
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 104 of file BatchCommands.h.

104{ 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 541 of file BatchCommands.cpp.

544{
545 // Test for an effect.
546 const PluginID & ID =
548 if (!ID.empty())
549 {
550 if( pContext )
551 return ApplyEffectCommand(
552 ID, friendlyCommand, command, params, *pContext);
553 const CommandContext context( mProject );
554 return ApplyEffectCommand(
555 ID, friendlyCommand, command, params, context);
556 }
557
558 AudacityProject *project = &mProject;
559 auto &manager = CommandManager::Get( *project );
560 if( pContext ){
562 manager, command, *pContext, AlwaysEnabledFlag, true ) )
563 return true;
564 pContext->Status( wxString::Format(
565 _("Your batch command of %s was not recognized."), friendlyCommand.Translation() ));
566 return false;
567 }
568 else
569 {
570 const CommandContext context( mProject );
572 manager, command, context, AlwaysEnabledFlag, true ) )
573 return true;
574 }
575
577 XO("Your batch command of %s was not recognized.")
578 .Format( friendlyCommand ) );
579
580 return false;
581}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
wxString PluginID
Definition: EffectManager.h:30
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
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:90
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
AUDACITY_DLL_API bool HandleTextualCommand(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)

References _, AlwaysEnabledFlag, ApplyEffectCommand(), AudacityMessageBox(), EffectManager::Get(), CommandManager::Get(), EffectManager::GetEffectByIdentifier(), CommandDispatch::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 583 of file BatchCommands.cpp.

587{
588 AudacityProject *project = &mProject;
589 auto &settings = ProjectSettings::Get( *project );
590 // Recalc flags and enable items that may have become enabled.
591 MenuManager::Get(*project).UpdateMenus(false);
592 // enter batch mode...
593 bool prevShowMode = settings.GetShowId3Dialog();
594 project->mBatchMode++;
595 auto cleanup = finally( [&] {
596 // exit batch mode...
597 settings.SetShowId3Dialog(prevShowMode);
598 project->mBatchMode--;
599 } );
600
601 return ApplyCommand( friendlyCommand, command, params, pContext );
602}
static Settings & settings()
Definition: TrackInfo.cpp:83
bool ApplyCommand(const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, CommandContext const *pContext=NULL)
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
void UpdateMenus(bool checkActive=true)
Definition: Menus.cpp:581
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 484 of file BatchCommands.cpp.

488{
489 static_cast<void>(command);//compiler food.
490
491 //Possibly end processing here, if in batch-debug
492 if( ReportAndSkip(friendlyCommand, params))
493 return true;
494
496 if (!plug)
497 return false;
498
499 AudacityProject *project = &mProject;
500
501 // IF nothing selected, THEN select everything depending
502 // on preferences setting.
503 // (most effects require that you have something selected).
505 {
507 {
509 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
510 XO("\"%s\" requires one or more tracks to be selected.").Format(friendlyCommand));
511 return false;
512 }
513 }
514
515 bool res = false;
516
517 auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
518
519 // transfer the parameters to the effect...
520 if (EffectManager::Get().SetEffectParameters(ID, params))
521 {
523 // and apply the effect...
525 Context,
529 else
530 // and apply the effect...
531 res = EffectUI::DoEffect(ID,
532 Context,
536 }
537
538 return res;
539}
@ 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)
PluginType GetPluginType() const
const PluginDescriptor * GetPlugin(const PluginID &ID) const
static PluginManager & Get()
AUDACITY_DLL_API bool DoAudacityCommand(const PluginID &ID, const CommandContext &context, unsigned flags)
AUDACITY_DLL_API bool DoEffect(const PluginID &ID, const CommandContext &context, unsigned flags)
'Repeat Last Effect'.
Definition: EffectUI.cpp:1144
bool SelectAllIfNoneAndAllowed(AudacityProject &project)

References AudacityMessageBox(), CommandDispatch::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 608 of file BatchCommands.cpp.

610{
611 // Check for reentrant ApplyMacro commands.
612 // We'll allow 1 level of reentry, but not more.
613 // And we treat ignoring deeper levels as a success.
614 if (MacroReentryCount > 1) {
615 return true;
616 }
617
618 // Restore the reentry counter (to zero) when we exit.
619 auto cleanup1 = valueRestorer(MacroReentryCount);
621
622 AudacityProject *proj = &mProject;
623 bool res = false;
624
625 // Only perform this group on initial entry. They should not be done
626 // while recursing.
627 if (MacroReentryCount == 1) {
628 mFileName = filename;
629
630 TranslatableString longDesc, shortDesc;
631 wxString name = gPrefs->Read(wxT("/Batch/ActiveMacro"), wxEmptyString);
632 if (name.empty()) {
633 /* i18n-hint: active verb in past tense */
634 longDesc = XO("Applied Macro");
635 shortDesc = XO("Apply Macro");
636 }
637 else {
638 /* i18n-hint: active verb in past tense */
639 longDesc = XO("Applied Macro '%s'").Format(name);
640 shortDesc = XO("Apply '%s'").Format(name);
641 }
642
643 // Save the project state before making any changes. It will be rolled
644 // back if an error occurs.
645 // It also causes any calls to ModifyState (such as by simple
646 // view-changing commands) to append changes to this state, not to the
647 // previous state in history. See Bug 2076
648 if (proj) {
649 ProjectHistory::Get(*proj).PushState(longDesc, shortDesc);
650 }
651 }
652
653 // Upon exit of the top level apply, roll back the state if an error occurs.
654 auto cleanup2 = finally([&, macroReentryCount = MacroReentryCount] {
655 if (macroReentryCount == 1 && !res && proj) {
656 // Be sure that exceptions do not escape this destructor
657 GuardedCall([&]{
658 // Macro failed or was cancelled; revert to the previous state
659 auto &history = ProjectHistory::Get(*proj);
660 history.RollbackState();
661 // The added undo state is now vacuous. Remove it (Bug 2759)
662 auto &undoManager = UndoManager::Get(*proj);
663 undoManager.Undo(
664 [&]( const UndoStackElem &elem ){
665 history.PopState( elem.state ); } );
666 undoManager.AbandonRedo();
667 });
668 }
669 });
670
671 mAbort = false;
672
673 // Is tracing enabled?
674 bool trace;
675 gPrefs->Read(wxT("/EnableMacroTracing"), &trace, false);
676
677 // If so, then block most other messages while running the macro
678 wxLogLevel prevLevel = wxLog::GetComponentLevel("");
679 if (trace) {
680 wxLog::SetComponentLevel("", wxLOG_FatalError);
681 wxLog::SetComponentLevel(wxLOG_COMPONENT, wxLOG_Info);
682 }
683
684 size_t i = 0;
685 for (; i < mCommandMacro.size(); i++) {
686 const auto &command = mCommandMacro[i];
687 auto iter = catalog.ByCommandId(command);
688 const auto friendly = (iter == catalog.end())
689 ?
690 // uh oh, using GET to expose an internal name to the user!
691 // in default of any better friendly name
692 Verbatim( command.GET() )
693 : iter->name.Msgid().Stripped();
694
695 wxTimeSpan before;
696 if (trace) {
697 before = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
698 }
699
700 bool success = ApplyCommandInBatchMode(friendly, command, mParamsMacro[i]);
701
702 if (trace) {
703 auto after = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
704 wxLogMessage(wxT("Macro line #%ld took %s : %s:%s"),
705 i + 1,
706 (after - before).Format(wxT("%H:%M:%S.%l")),
707 command.GET(),
708 mParamsMacro[i]);
709 }
710
711 if (!success || mAbort)
712 break;
713 }
714
715 // Restore message level
716 if (trace) {
717 wxLog::SetComponentLevel("", prevLevel);
718 }
719
720 res = (i == mCommandMacro.size());
721 if (!res)
722 return false;
723
724 if (MacroReentryCount == 1) {
725 mFileName.Empty();
726
727 if (proj)
728 ProjectHistory::Get(*proj).ModifyState(true);
729 }
730
731 return true;
732}
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:251
FileConfig * gPrefs
Definition: Prefs.cpp:70
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:71
Holds one item with description and time range for the UndoManager.
Definition: UndoManager.h:117
UndoState state
Definition: UndoManager.h:128

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, wxT(), 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 755 of file BatchCommands.cpp.

756{
757 if (index < 0 || index >= (int)mCommandMacro.size()) {
758 return;
759 }
760
761 mCommandMacro.erase( mCommandMacro.begin() + index );
762 mParamsMacro.erase( mParamsMacro.begin() + index );
763}

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 277 of file BatchCommands.cpp.

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

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

Referenced by MacrosWindow::OnRemove().

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 101 of file BatchCommands.cpp.

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

References mCommandMacro, and wxT().

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

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

◆ GetCount()

int MacroCommands::GetCount ( )

Definition at line 119 of file BatchCommands.cpp.

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

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 435 of file BatchCommands.cpp.

436{
437 const PluginID & ID =
439 if (ID.empty())
440 {
441 return wxEmptyString; // effect not found.
442 }
443
445}
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 103 of file BatchCommands.h.

103{ return mMessage;};

References mMessage.

◆ GetNames()

wxArrayString MacroCommands::GetNames ( )
static

Definition at line 831 of file BatchCommands.cpp.

832{
834
835 wxArrayString names;
836 FilePaths files;
837 wxDir::GetAllFiles(FileNames::MacroDir(), &files, wxT("*.txt"), wxDIR_FILES);
838 size_t i;
839
840 wxFileName ff;
841 for (i = 0; i < files.size(); i++) {
842 ff = (files[i]);
843 names.push_back(ff.GetName());
844 }
845
846 std::sort( names.begin(), names.end() );
847
848 return names;
849}
static void MigrateLegacyChains()
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

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

Referenced by MacroCommands(), ApplyMacroDialog::PopulateMacros(), and anonymous_namespace{BatchProcessDialog.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 76 of file BatchCommands.cpp.

77{
78 return {
79 MP3Conversion.Translation() ,
80 FadeEnds.Translation() ,
81 };
82}
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 110 of file BatchCommands.cpp.

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

References mParamsMacro, and wxT().

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

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

◆ IsFixed()

bool MacroCommands::IsFixed ( const wxString &  name)

Definition at line 851 of file BatchCommands.cpp.

852{
853 auto defaults = GetNamesOfDefaultMacros();
854 if( make_iterator_range( defaults ).contains( name ) )
855 return true;
856 return false;
857}

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 881 of file BatchCommands.cpp.

882{
883 return command + wxT(": ") + param;
884}

References wxT().

Here is the call graph for this function:

◆ MigrateLegacyChains()

void MacroCommands::MigrateLegacyChains ( )
static

Definition at line 798 of file BatchCommands.cpp.

799{
800 static bool done = false;
801 if (!done) {
802 // Check once per session at most
803
804 // Copy chain files from the old Chains into the new Macros directory,
805 // but only if like-named files are not already present in Macros.
806
807 // Leave the old copies in place, in case a user wants to go back to
808 // an old Audacity version. They will have their old chains intact, but
809 // won't have any edits they made to the copy that now lives in Macros
810 // which old Audacity will not read.
811
812 const auto oldDir = FileNames::LegacyChainDir();
813 FilePaths files;
814 wxDir::GetAllFiles(oldDir, &files, wxT("*.txt"), wxDIR_FILES);
815
816 // add a dummy path component to be overwritten by SetFullName
817 wxFileName newDir{ FileNames::MacroDir(), wxT("x") };
818
819 for (const auto &file : files) {
820 auto name = wxFileName{file}.GetFullName();
821 newDir.SetFullName(name);
822 const auto newPath = newDir.GetFullPath();
823 if (!wxFileExists(newPath))
824 FileNames::DoCopyFile(file, newPath);
825 }
826 done = true;
827 }
828 // To do: use std::once
829}
FILES_API bool DoCopyFile(const FilePath &file1, const FilePath &file2, bool overwrite=true)

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

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 447 of file BatchCommands.cpp.

449{
450 const PluginID & ID =
452 if (ID.empty())
453 return wxEmptyString; // effect not found
454
455 wxString res = params;
456 auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
457 if (EffectManager::Get().SetEffectParameters(ID, params))
458 if (EffectManager::Get().PromptUser(ID, EffectUI::DialogFactory, parent))
460 return res;
461}
AUDACITY_DLL_API DialogFactoryResults DialogFactory(wxWindow &parent, EffectBase &host, EffectUIServices &client, EffectSettingsAccess &access)
Definition: EffectUI.cpp:1105

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 463 of file BatchCommands.cpp.

464{
465 const PluginID & ID =
467 if (ID.empty())
468 {
469 return wxEmptyString; // effect not found.
470 }
471
472 wxString preset = EffectManager::Get().GetPreset(ID, params, parent);
473
474 // Preset will be empty if the user cancelled the dialog, so return the original
475 // parameter value.
476 if (preset.empty())
477 {
478 return params;
479 }
480
481 return preset;
482}
EffectReverbSettings preset
Definition: Reverb.cpp:44
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 124 of file BatchCommands.cpp.

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

References AudacityMessageBox(), fn, FileNames::MacroDir(), mCommandMacro, mParamsMacro, name, ResetMacro(), SelectFile(), FileNames::TextFiles, WriteMacro(), wxT(), 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 292 of file BatchCommands.cpp.

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

References FileNames::MacroDir(), and wxT().

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 773 of file BatchCommands.cpp.

775{
776 int bDebug;
777 gPrefs->Read(wxT("/Batch/Debug"), &bDebug, false);
778 if( bDebug == 0 )
779 return false;
780
781 //TODO: Add a cancel button to these, and add the logic so that we can abort.
782 if( !params.empty() )
783 {
785 XO("Apply %s with parameter(s)\n\n%s")
786 .Format( friendlyCommand, params ),
787 XO("Test Mode"));
788 }
789 else
790 {
792 XO("Apply %s").Format( friendlyCommand ),
793 XO("Test Mode"));
794 }
795 return true;
796}

References AudacityMessageBox(), gPrefs, params, wxT(), 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 765 of file BatchCommands.cpp.

766{
767 mCommandMacro.clear();
768 mParamsMacro.clear();
769}

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 84 of file BatchCommands.cpp.

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

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

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 859 of file BatchCommands.cpp.

860{
861 int splitAt;
862
863 command.Empty();
864 param.Empty();
865
866 if (str.empty()) {
867 return;
868 }
869
870 splitAt = str.Find(wxT(':'));
871 if (splitAt < 0) {
872 return;
873 }
874
875 command = str.Mid(0, splitAt);
876 param = str.Mid(splitAt + 1);
877
878 return;
879}
#define str(a)

References str, and wxT().

Here is the call graph for this function:

◆ WriteMacro()

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

Definition at line 206 of file BatchCommands.cpp.

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

References fn, FileNames::MacroDir(), mCommandMacro, mParamsMacro, name, SelectFile(), FileNames::TextFiles, wxT(), 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 116 of file BatchCommands.h.

Referenced by AbortBatch(), and ApplyMacro().

◆ mCommandMacro

CommandIDs MacroCommands::mCommandMacro
private

◆ mExporter

Exporter MacroCommands::mExporter
private

Definition at line 119 of file BatchCommands.h.

◆ mFileName

wxString MacroCommands::mFileName
private

Definition at line 120 of file BatchCommands.h.

Referenced by ApplyMacro().

◆ mMessage

wxString MacroCommands::mMessage
private

Definition at line 117 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: