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, AudacityProject &project)
 
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 57 of file BatchCommands.cpp.

59{
60 ResetMacro();
61
62 auto names = GetNames();
63 auto defaults = GetNamesOfDefaultMacros();
64
65 for( size_t i = 0;i<defaults.size();i++){
66 wxString name = defaults[i];
67 if ( ! make_iterator_range( names ).contains(name) ) {
71 }
72 }
73}
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: IteratorX.h:210
wxString name
Definition: TagsEditor.cpp:166
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 770 of file BatchCommands.cpp.

771{
772 mAbort = true;
773}

References mAbort.

◆ AddMacro()

bool MacroCommands::AddMacro ( const wxString &  macro)

Definition at line 267 of file BatchCommands.cpp.

268{
269 // Build the filename
270 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
271
272 // Set the file name
273 wxTextFile tf(name.GetFullPath());
274
275 // Create it..Create will display errors
276 return tf.Create();
277}
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 780 of file BatchCommands.cpp.

781{
782 if (before == -1) {
783 before = (int)mCommandMacro.size();
784 }
785
786 mCommandMacro.insert(mCommandMacro.begin() + before, command);
787 mParamsMacro.insert(mParamsMacro.begin() + before, params);
788}
EffectDistortionSettings params
CommandIDs mCommandMacro
wxArrayString mParamsMacro

References mCommandMacro, mParamsMacro, and params.

◆ AddToMacro() [2/2]

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

Definition at line 775 of file BatchCommands.cpp.

776{
777 AddToMacro(command, GetCurrentParamsFor(command), before);
778}
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 116 of file BatchCommands.h.

116{ 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 579 of file BatchCommands.cpp.

582{
583 // Test for an effect.
585 if (!ID.empty())
586 {
587 if( pContext )
588 return ApplyEffectCommand(
589 ID, friendlyCommand, command, params, *pContext);
590 const CommandContext context( mProject );
591 return ApplyEffectCommand(
592 ID, friendlyCommand, command, params, context);
593 }
594
595 if (pContext) {
596 assert(&pContext->project == &GetProject());
598 command, *pContext, AlwaysEnabledFlag, true ) )
599 return true;
600 pContext->Status( wxString::Format(
601 _("Your batch command of %s was not recognized."), friendlyCommand.Translation() ));
602 return false;
603 }
604 else
605 {
606 const CommandContext context( mProject );
608 command, context, AlwaysEnabledFlag, true ) )
609 return true;
610 }
611
613 XO("Your batch command of %s was not recognized.")
614 .Format( friendlyCommand ) );
615
616 return false;
617}
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,...
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
const PluginID & GetByCommandIdentifier(const CommandID &strTarget)
static PluginManager & Get()
wxString Translation() const
AUDACITY_DLL_API bool HandleTextualCommand(const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)

References _, AlwaysEnabledFlag, ApplyEffectCommand(), AudacityMessageBox(), PluginManager::Get(), PluginManager::GetByCommandIdentifier(), 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 619 of file BatchCommands.cpp.

623{
624 assert(!pContext || &pContext->project == &GetProject());
627 // Recalc flags and enable items that may have become enabled.
628 CommandManager::Get(*project).UpdateMenus(false);
629 // enter batch mode...
630 project->mBatchMode++;
631 auto cleanup = finally( [&] {
632 // exit batch mode...
633 project->mBatchMode--;
634 } );
635
636 return ApplyCommand( friendlyCommand, command, params, pContext );
637}
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 523 of file BatchCommands.cpp.

527{
528 static_cast<void>(command);//compiler food.
529
530 //Possibly end processing here, if in batch-debug
531 if( ReportAndSkip(friendlyCommand, params))
532 return true;
533
535 if (!plug)
536 return false;
537
539
540 // IF nothing selected, THEN select everything depending
541 // on preferences setting.
542 // (most effects require that you have something selected).
544 {
546 {
548 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
549 XO("\"%s\" requires one or more tracks to be selected.").Format(friendlyCommand));
550 return false;
551 }
552 }
553
554 bool res = false;
555
557
558 // transfer the parameters to the effect...
559 if (EffectAndCommandPluginManager::Get().SetEffectParameters(ID, params))
560 {
562 // and apply the effect...
564 Context,
568 else
569 // and apply the effect...
570 res = EffectUI::DoEffect(
571 ID, Context.project,
574 }
575
576 return res;
577}
@ PluginTypeAudacityCommand
AudacityProject & project
static EffectAndCommandPluginManager & Get()
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
AUDACITY_DLL_API bool DoAudacityCommand(const PluginID &ID, const CommandContext &context, unsigned flags)
bool DoEffect(const PluginID &ID, AudacityProject &project, unsigned flags)
Definition: DoEffect.cpp:30
bool SelectAllIfNoneAndAllowed(AudacityProject &project)

References AudacityMessageBox(), CommandDispatch::DoAudacityCommand(), EffectUI::DoEffect(), PluginManager::Get(), EffectAndCommandPluginManager::Get(), PluginManager::GetPlugin(), PluginDescriptor::GetPluginType(), EffectManager::kConfigured, EffectManager::kDontRepeatLast, EffectManager::kSkipState, mProject, params, PluginTypeAudacityCommand, CommandContext::project, project, ReportAndSkip(), SelectUtilities::SelectAllIfNoneAndAllowed(), EffectAndCommandPluginManager::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 643 of file BatchCommands.cpp.

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

791{
792 if (index < 0 || index >= (int)mCommandMacro.size()) {
793 return;
794 }
795
796 mCommandMacro.erase( mCommandMacro.begin() + index );
797 mParamsMacro.erase( mParamsMacro.begin() + index );
798}

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

280{
281 // Build the filename
282 wxFileName name(FileNames::MacroDir(), macro, wxT("txt"));
283
284 // Delete it...wxRemoveFile will display errors
285 auto result = wxRemoveFile(name.GetFullPath());
286
287 // Delete any legacy chain that it shadowed
288 auto oldPath = wxFileName{ FileNames::LegacyChainDir(), macro, wxT("txt") };
289 wxRemoveFile(oldPath.GetFullPath()); // Don't care about this return value
290
291 return result;
292}
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 103 of file BatchCommands.cpp.

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

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

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

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

447{
449 if (ID.empty())
450 {
451 return wxEmptyString; // effect not found.
452 }
453
455}
wxString GetEffectParameters(const PluginID &ID)

References PluginManager::Get(), EffectAndCommandPluginManager::Get(), PluginManager::GetByCommandIdentifier(), and EffectAndCommandPluginManager::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 115 of file BatchCommands.h.

115{ return mMessage;};

References mMessage.

◆ GetNames()

wxArrayString MacroCommands::GetNames ( )
static

Definition at line 866 of file BatchCommands.cpp.

867{
869
870 wxArrayString names;
871 FilePaths files;
872 wxDir::GetAllFiles(FileNames::MacroDir(), &files, wxT("*.txt"), wxDIR_FILES);
873 size_t i;
874
875 wxFileName ff;
876 for (i = 0; i < files.size(); i++) {
877 ff = (files[i]);
878 names.push_back(ff.GetName());
879 }
880
881 std::sort( names.begin(), names.end() );
882
883 return names;
884}
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 78 of file BatchCommands.cpp.

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

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

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

887{
888 auto defaults = GetNamesOfDefaultMacros();
889 if( make_iterator_range( defaults ).contains( name ) )
890 return true;
891 return false;
892}

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

917{
918 return command + wxT(": ") + param;
919}

References wxT().

Here is the call graph for this function:

◆ MigrateLegacyChains()

void MacroCommands::MigrateLegacyChains ( )
static

Definition at line 833 of file BatchCommands.cpp.

834{
835 static bool done = false;
836 if (!done) {
837 // Check once per session at most
838
839 // Copy chain files from the old Chains into the new Macros directory,
840 // but only if like-named files are not already present in Macros.
841
842 // Leave the old copies in place, in case a user wants to go back to
843 // an old Audacity version. They will have their old chains intact, but
844 // won't have any edits they made to the copy that now lives in Macros
845 // which old Audacity will not read.
846
847 const auto oldDir = FileNames::LegacyChainDir();
848 FilePaths files;
849 wxDir::GetAllFiles(oldDir, &files, wxT("*.txt"), wxDIR_FILES);
850
851 // add a dummy path component to be overwritten by SetFullName
852 wxFileName newDir{ FileNames::MacroDir(), wxT("x") };
853
854 for (const auto &file : files) {
855 auto name = wxFileName{file}.GetFullName();
856 newDir.SetFullName(name);
857 const auto newPath = newDir.GetFullPath();
858 if (!wxFileExists(newPath))
859 FileNames::DoCopyFile(file, newPath);
860 }
861 done = true;
862 }
863 // To do: use std::once
864}
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,
AudacityProject project 
)
static

Definition at line 457 of file BatchCommands.cpp.

459{
461 if (ID.empty())
462 return wxEmptyString; // effect not found
463
464 wxString res = params;
466 if (EffectAndCommandPluginManager::Get().SetEffectParameters(ID, params))
467 {
468 auto dialogInvoker =
469 [&](
471 std::shared_ptr<EffectInstance>& pInstance) -> bool {
472 const auto pServices = dynamic_cast<EffectUIServices*>(&effect);
473 return pServices && pServices->ShowHostInterface(effect,
475 pInstance,
476 *std::make_shared<SimpleEffectSettingsAccess>(settings),
477 effect.IsBatchProcessing() ) != 0;
478 };
480 ID, project, std::move(dialogInvoker)))
482 }
483 return res;
484}
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
bool PromptUser(const PluginID &ID, AudacityProject &project, DialogInvoker dialogInvoker)
Shows an effect or command dialog so the user can specify settings for later.
Base class for many of the effects in Audacity.
Definition: Effect.h:26
bool IsBatchProcessing() const override
Definition: Effect.cpp:295
virtual int ShowHostInterface(EffectBase &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
AUDACITY_DLL_API DialogFactoryResults DialogFactory(wxWindow &parent, EffectBase &host, EffectUIServices &client, EffectSettingsAccess &access)
Definition: EffectUI.cpp:1112
Externalized state of a plug-in.

References EffectUI::DialogFactory(), PluginManager::Get(), EffectAndCommandPluginManager::Get(), PluginManager::GetByCommandIdentifier(), EffectAndCommandPluginManager::GetEffectParameters(), GetProjectFrame(), Effect::IsBatchProcessing(), params, project, EffectAndCommandPluginManager::PromptUser(), EffectAndCommandPluginManager::SetBatchProcessing(), settings(), and EffectUIServices::ShowHostInterface().

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

487{
489 if (ID.empty())
490 {
491 return wxEmptyString; // effect not found.
492 }
493
495 [parent](
496 EffectPlugin& effect,
497 const wxString& preset) -> std::optional<wxString> {
498 EffectPresetsDialog dlg(parent, &effect);
499 dlg.Layout();
500 dlg.Fit();
501 dlg.SetSize(dlg.GetMinSize());
502 dlg.CenterOnParent();
503 dlg.SetSelected(preset);
504
505 if (dlg.ShowModal())
506 return std::make_optional(dlg.GetSelected());
507 else
508 return {};
509 };
510 wxString preset =
511 EffectManager::Get().GetPreset(ID, params, std::move(dialog));
512
513 // Preset will be empty if the user cancelled the dialog, so return the original
514 // parameter value.
515 if (preset.empty())
516 {
517 return params;
518 }
519
520 return preset;
521}
ReverbSettings preset
Definition: ReverbBase.cpp:25
std::function< std::optional< wxString >(EffectPlugin &, const wxString &preset)> EffectPresetDialog
Definition: EffectManager.h:86
wxString GetPreset(const PluginID &ID, const wxString &params, EffectPresetDialog)
static EffectManager & Get()
Factory of instances of an effect.
Definition: EffectPlugin.h:36

References EffectManager::Get(), PluginManager::Get(), PluginManager::GetByCommandIdentifier(), EffectManager::GetPreset(), EffectPresetsDialog::GetSelected(), params, preset, and EffectPresetsDialog::SetSelected().

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

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

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

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

810{
811 int bDebug;
812 gPrefs->Read(wxT("/Batch/Debug"), &bDebug, 0);
813 if( bDebug == 0 )
814 return false;
815
816 //TODO: Add a cancel button to these, and add the logic so that we can abort.
817 if( !params.empty() )
818 {
820 XO("Apply %s with parameter(s)\n\n%s")
821 .Format( friendlyCommand, params ),
822 XO("Test Mode"));
823 }
824 else
825 {
827 XO("Apply %s").Format( friendlyCommand ),
828 XO("Test Mode"));
829 }
830 return true;
831}

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

801{
802 mCommandMacro.clear();
803 mParamsMacro.clear();
804}

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

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

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

895{
896 int splitAt;
897
898 command.Empty();
899 param.Empty();
900
901 if (str.empty()) {
902 return;
903 }
904
905 splitAt = str.Find(wxT(':'));
906 if (splitAt < 0) {
907 return;
908 }
909
910 command = str.Mid(0, splitAt);
911 param = str.Mid(splitAt + 1);
912
913 return;
914}
#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 208 of file BatchCommands.cpp.

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

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

Referenced by AbortBatch(), and ApplyMacro().

◆ mCommandMacro

CommandIDs MacroCommands::mCommandMacro
private

◆ mFileName

wxString MacroCommands::mFileName
private

Definition at line 131 of file BatchCommands.h.

Referenced by ApplyMacro().

◆ mMessage

wxString MacroCommands::mMessage
private

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