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

729{
730 mAbort = true;
731}

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

739{
740 if (before == -1) {
741 before = (int)mCommandMacro.size();
742 }
743
744 mCommandMacro.insert(mCommandMacro.begin() + before, command);
745 mParamsMacro.insert(mParamsMacro.begin() + before, params);
746}
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 733 of file BatchCommands.cpp.

734{
735 AddToMacro(command, GetCurrentParamsFor(command), before);
736}
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 112 of file BatchCommands.h.

112{ 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 536 of file BatchCommands.cpp.

539{
540 // Test for an effect.
541 const PluginID & ID =
543 if (!ID.empty())
544 {
545 if( pContext )
546 return ApplyEffectCommand(
547 ID, friendlyCommand, command, params, *pContext);
548 const CommandContext context( mProject );
549 return ApplyEffectCommand(
550 ID, friendlyCommand, command, params, context);
551 }
552
553 if (pContext) {
554 assert(&pContext->project == &GetProject());
556 command, *pContext, AlwaysEnabledFlag, true ) )
557 return true;
558 pContext->Status( wxString::Format(
559 _("Your batch command of %s was not recognized."), friendlyCommand.Translation() ));
560 return false;
561 }
562 else
563 {
564 const CommandContext context( mProject );
566 command, context, AlwaysEnabledFlag, true ) )
567 return true;
568 }
569
571 XO("Your batch command of %s was not recognized.")
572 .Format( friendlyCommand ) );
573
574 return false;
575}
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:61
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 577 of file BatchCommands.cpp.

581{
582 assert(!pContext || &pContext->project == &GetProject());
585 // Recalc flags and enable items that may have become enabled.
586 CommandManager::Get(*project).UpdateMenus(false);
587 // enter batch mode...
588 project->mBatchMode++;
589 auto cleanup = finally( [&] {
590 // exit batch mode...
591 project->mBatchMode--;
592 } );
593
594 return ApplyCommand( friendlyCommand, command, params, pContext );
595}
static Settings & settings()
Definition: TrackInfo.cpp:69
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 479 of file BatchCommands.cpp.

483{
484 static_cast<void>(command);//compiler food.
485
486 //Possibly end processing here, if in batch-debug
487 if( ReportAndSkip(friendlyCommand, params))
488 return true;
489
491 if (!plug)
492 return false;
493
495
496 // IF nothing selected, THEN select everything depending
497 // on preferences setting.
498 // (most effects require that you have something selected).
500 {
502 {
504 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
505 XO("\"%s\" requires one or more tracks to be selected.").Format(friendlyCommand));
506 return false;
507 }
508 }
509
510 bool res = false;
511
512 auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
513
514 // transfer the parameters to the effect...
515 if (EffectManager::Get().SetEffectParameters(ID, params))
516 {
518 // and apply the effect...
520 Context,
524 else
525 // and apply the effect...
526 res = EffectUI::DoEffect(ID,
527 Context,
531 }
532
533 return res;
534}
@ 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:1148
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 601 of file BatchCommands.cpp.

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

749{
750 if (index < 0 || index >= (int)mCommandMacro.size()) {
751 return;
752 }
753
754 mCommandMacro.erase( mCommandMacro.begin() + index );
755 mParamsMacro.erase( mParamsMacro.begin() + index );
756}

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

431{
432 const PluginID & ID =
434 if (ID.empty())
435 {
436 return wxEmptyString; // effect not found.
437 }
438
440}
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 111 of file BatchCommands.h.

111{ return mMessage;};

References mMessage.

◆ GetNames()

wxArrayString MacroCommands::GetNames ( )
static

Definition at line 824 of file BatchCommands.cpp.

825{
827
828 wxArrayString names;
829 FilePaths files;
830 wxDir::GetAllFiles(FileNames::MacroDir(), &files, wxT("*.txt"), wxDIR_FILES);
831 size_t i;
832
833 wxFileName ff;
834 for (i = 0; i < files.size(); i++) {
835 ff = (files[i]);
836 names.push_back(ff.GetName());
837 }
838
839 std::sort( names.begin(), names.end() );
840
841 return names;
842}
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 61 of file BatchCommands.h.

61{ 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 844 of file BatchCommands.cpp.

845{
846 auto defaults = GetNamesOfDefaultMacros();
847 if( make_iterator_range( defaults ).contains( name ) )
848 return true;
849 return false;
850}

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

875{
876 return command + wxT(": ") + param;
877}

References wxT().

Here is the call graph for this function:

◆ MigrateLegacyChains()

void MacroCommands::MigrateLegacyChains ( )
static

Definition at line 791 of file BatchCommands.cpp.

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

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

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

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

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

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

759{
760 mCommandMacro.clear();
761 mParamsMacro.clear();
762}

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

853{
854 int splitAt;
855
856 command.Empty();
857 param.Empty();
858
859 if (str.empty()) {
860 return;
861 }
862
863 splitAt = str.Find(wxT(':'));
864 if (splitAt < 0) {
865 return;
866 }
867
868 command = str.Mid(0, splitAt);
869 param = str.Mid(splitAt + 1);
870
871 return;
872}
#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 124 of file BatchCommands.h.

Referenced by AbortBatch(), and ApplyMacro().

◆ mCommandMacro

CommandIDs MacroCommands::mCommandMacro
private

◆ mFileName

wxString MacroCommands::mFileName
private

Definition at line 127 of file BatchCommands.h.

Referenced by ApplyMacro().

◆ mMessage

wxString MacroCommands::mMessage
private

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