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)
 
AudacityProjectGetProject ()
 
bool ApplyMacro (const MacroCommandsCatalog &catalog, const wxString &filename={})
 
bool ApplyCommand (const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, CommandContext const *pContext=nullptr)
 
bool ApplyCommandInBatchMode (const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, CommandContext const *pContext=nullptr)
 
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
 
wxString mFileName
 

Detailed Description

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

Definition at line 60 of file BatchCommands.h.

Constructor & Destructor Documentation

◆ MacroCommands()

MacroCommands::MacroCommands ( AudacityProject project)

Definition at line 50 of file BatchCommands.cpp.

52{
53 ResetMacro();
54
55 auto names = GetNames();
56 auto defaults = GetNamesOfDefaultMacros();
57
58 for( size_t i = 0;i<defaults.size();i++){
59 wxString name = defaults[i];
60 if ( ! make_iterator_range( names ).contains(name) ) {
64 }
65 }
66}
const TranslatableString name
Definition: Distortion.cpp:76
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: IteratorX.h:210
static TranslatableStrings names
Definition: TagsEditor.cpp:153
const auto project
static wxArrayStringEx GetNamesOfDefaultMacros()
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 737 of file BatchCommands.cpp.

738{
739 mAbort = true;
740}

References mAbort.

◆ AddMacro()

bool MacroCommands::AddMacro ( const wxString &  macro)

Definition at line 260 of file BatchCommands.cpp.

261{
262 // Build the filename
263 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
264
265 // Set the file name
266 wxTextFile tf(name.GetFullPath());
267
268 // Create it..Create will display errors
269 return tf.Create();
270}
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 747 of file BatchCommands.cpp.

748{
749 if (before == -1) {
750 before = (int)mCommandMacro.size();
751 }
752
753 mCommandMacro.insert(mCommandMacro.begin() + before, command);
754 mParamsMacro.insert(mParamsMacro.begin() + before, params);
755}
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 742 of file BatchCommands.cpp.

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

115{ mMessage += msgIn;};
wxString mMessage

References mMessage.

◆ ApplyCommand()

bool MacroCommands::ApplyCommand ( const TranslatableString friendlyCommand,
const CommandID command,
const wxString &  params,
CommandContext const *  pContext = nullptr 
)
Precondition
!pContext || &pContext->project == &GetProject()

Definition at line 545 of file BatchCommands.cpp.

548{
549 // Test for an effect.
550 const PluginID & ID =
552 if (!ID.empty())
553 {
554 if( pContext )
555 return ApplyEffectCommand(
556 ID, friendlyCommand, command, params, *pContext);
557 const CommandContext context( mProject );
558 return ApplyEffectCommand(
559 ID, friendlyCommand, command, params, context);
560 }
561
562 if (pContext) {
563 assert(&pContext->project == &GetProject());
565 command, *pContext, AlwaysEnabledFlag, true ) )
566 return true;
567 pContext->Status( wxString::Format(
568 _("Your batch command of %s was not recognized."), friendlyCommand.Translation() ));
569 return false;
570 }
571 else
572 {
573 const CommandContext context( mProject );
575 command, context, AlwaysEnabledFlag, true ) )
576 return true;
577 }
578
580 XO("Your batch command of %s was not recognized.")
581 .Format( friendlyCommand ) );
582
583 return false;
584}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
wxString PluginID
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
CommandContext provides additional information to an 'Apply()' command. It provides the 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)
AudacityProject & GetProject()
Definition: BatchCommands.h:64
wxString Translation() const
AUDACITY_DLL_API bool HandleTextualCommand(const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)

References _, AlwaysEnabledFlag, ApplyEffectCommand(), AudacityMessageBox(), EffectManager::Get(), EffectManager::GetEffectByIdentifier(), GetProject(), CommandDispatch::HandleTextualCommand(), mProject, params, CommandContext::project, 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 = nullptr 
)
Precondition
!pContext || &pContext->project == &GetProject()

Definition at line 586 of file BatchCommands.cpp.

590{
591 assert(!pContext || &pContext->project == &GetProject());
594 // Recalc flags and enable items that may have become enabled.
595 CommandManager::Get(*project).UpdateMenus(false);
596 // enter batch mode...
597 project->mBatchMode++;
598 auto cleanup = finally( [&] {
599 // exit batch mode...
600 project->mBatchMode--;
601 } );
602
603 return ApplyCommand( friendlyCommand, command, params, pContext );
604}
static Settings & settings()
Definition: TrackInfo.cpp:51
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static CommandManager & Get(AudacityProject &project)
void UpdateMenus(bool checkActive=true)
bool ApplyCommand(const TranslatableString &friendlyCommand, const CommandID &command, const wxString &params, CommandContext const *pContext=nullptr)
static ProjectSettings & Get(AudacityProject &project)

References ApplyCommand(), CommandManager::Get(), ProjectSettings::Get(), GetProject(), mProject, params, CommandContext::project, project, settings(), and CommandManager::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 488 of file BatchCommands.cpp.

492{
493 static_cast<void>(command);//compiler food.
494
495 //Possibly end processing here, if in batch-debug
496 if( ReportAndSkip(friendlyCommand, params))
497 return true;
498
500 if (!plug)
501 return false;
502
504
505 // IF nothing selected, THEN select everything depending
506 // on preferences setting.
507 // (most effects require that you have something selected).
509 {
511 {
513 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
514 XO("\"%s\" requires one or more tracks to be selected.").Format(friendlyCommand));
515 return false;
516 }
517 }
518
519 bool res = false;
520
521 auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
522
523 // transfer the parameters to the effect...
524 if (EffectManager::Get().SetEffectParameters(ID, params))
525 {
527 // and apply the effect...
529 Context,
533 else
534 // and apply the effect...
535 res = EffectUI::DoEffect(ID,
536 Context,
540 }
541
542 return res;
543}
@ 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:1149
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, project, 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 610 of file BatchCommands.cpp.

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

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

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

273{
274 // Build the filename
275 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
276
277 // Delete it...wxRemoveFile will display errors
278 auto result = wxRemoveFile(name.GetFullPath());
279
280 // Delete any legacy chain that it shadowed
281 auto oldPath = wxFileName{ FileNames::LegacyChainDir(), macro, wxT("txt") };
282 wxRemoveFile(oldPath.GetFullPath()); // Don't care about this return value
283
284 return result;
285}
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 96 of file BatchCommands.cpp.

97{
98 if (index < 0 || index >= (int)mCommandMacro.size()) {
99 return wxT("");
100 }
101
102 return mCommandMacro[index];
103}

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

115{
116 return (int)mCommandMacro.size();
117}

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

440{
441 const PluginID & ID =
443 if (ID.empty())
444 {
445 return wxEmptyString; // effect not found.
446 }
447
449}
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 114 of file BatchCommands.h.

114{ return mMessage;};

References mMessage.

◆ GetNames()

wxArrayString MacroCommands::GetNames ( )
static

Definition at line 833 of file BatchCommands.cpp.

834{
836
837 wxArrayString names;
838 FilePaths files;
839 wxDir::GetAllFiles(FileNames::MacroDir(), &files, wxT("*.txt"), wxDIR_FILES);
840 size_t i;
841
842 wxFileName ff;
843 for (i = 0; i < files.size(); i++) {
844 ff = (files[i]);
845 names.push_back(ff.GetName());
846 }
847
848 std::sort( names.begin(), names.end() );
849
850 return names;
851}
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 71 of file BatchCommands.cpp.

72{
73 return {
74 MP3Conversion.Translation() ,
75 FadeEnds.Translation() ,
76 };
77}
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 105 of file BatchCommands.cpp.

106{
107 if (index < 0 || index >= (int)mParamsMacro.size()) {
108 return wxT("");
109 }
110
111 return mParamsMacro[index];
112}

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:

◆ GetProject()

AudacityProject & MacroCommands::GetProject ( )
inline

Definition at line 64 of file BatchCommands.h.

64{ return mProject; }

References mProject.

Referenced by ApplyCommand(), and ApplyCommandInBatchMode().

Here is the caller graph for this function:

◆ IsFixed()

bool MacroCommands::IsFixed ( const wxString &  name)

Definition at line 853 of file BatchCommands.cpp.

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

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

884{
885 return command + wxT(": ") + param;
886}

References wxT().

Here is the call graph for this function:

◆ MigrateLegacyChains()

void MacroCommands::MigrateLegacyChains ( )
static

Definition at line 800 of file BatchCommands.cpp.

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

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

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

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

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

288{
289 // Build the filenames
290 wxFileName oname(FileNames::MacroDir(), oldmacro, wxT("txt"));
291 wxFileName nname(FileNames::MacroDir(), newmacro, wxT("txt"));
292
293 // Rename it...wxRenameFile will display errors
294 return wxRenameFile(oname.GetFullPath(), nname.GetFullPath());
295}

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

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

References AudacityMessageBox(), gPrefs, params, audacity::BasicSettings::Read(), 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 767 of file BatchCommands.cpp.

768{
769 mCommandMacro.clear();
770 mParamsMacro.clear();
771}

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

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

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

862{
863 int splitAt;
864
865 command.Empty();
866 param.Empty();
867
868 if (str.empty()) {
869 return;
870 }
871
872 splitAt = str.Find(wxT(':'));
873 if (splitAt < 0) {
874 return;
875 }
876
877 command = str.Mid(0, splitAt);
878 param = str.Mid(splitAt + 1);
879
880 return;
881}
#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 201 of file BatchCommands.cpp.

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

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 127 of file BatchCommands.h.

Referenced by AbortBatch(), and ApplyMacro().

◆ mCommandMacro

CommandIDs MacroCommands::mCommandMacro
private

◆ mFileName

wxString MacroCommands::mFileName
private

Definition at line 130 of file BatchCommands.h.

Referenced by ApplyMacro().

◆ mMessage

wxString MacroCommands::mMessage
private

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