18#define wxLOG_COMPONENT "MacroCommands"
24#include <wx/datetime.h>
27#include <wx/textfile.h>
63 for(
size_t i = 0;i<defaults.size();i++){
64 wxString
name = defaults[i];
95 AddToMacro(
wxT(
"Select"),
wxT(
"Start=\"0\" End=\"1\" RelativeTo=\"ProjectEnd\"") );
140 wxFD_OPEN | wxRESIZE_BORDER,
145 return wxEmptyString;
148 wxFileName check(
fn);
149 check.SetPath(
name.GetPath());
150 if (check.FileExists())
153 XO(
"Macro %s already exists. Would you like to replace it?").
Format(check.GetName()),
157 return wxEmptyString;
165 wxTextFile tf(
name.GetFullPath());
169 if (!tf.IsOpened()) {
171 return wxEmptyString;
175 int lines = tf.GetLineCount();
177 for (
int i = 0; i < lines; i++) {
180 int splitAt = tf[i].Find(
wxT(
':'));
186 wxString cmd = tf[i].Left(splitAt).Strip(wxString::both);
187 wxString parm = tf[i].Mid(splitAt + 1).Strip(wxString::trailing);
203 return name.GetName();
219 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
224 return wxEmptyString;
231 wxTextFile tf(
name.GetFullPath());
241 if (!tf.IsOpened()) {
243 return wxEmptyString;
251 for (
int i = 0; i < lines; i++) {
262 return name.GetName();
271 wxTextFile tf(
name.GetFullPath());
283 auto result = wxRemoveFile(
name.GetFullPath());
287 wxRemoveFile(oldPath.GetFullPath());
299 return wxRenameFile(oname.GetFullPath(), nname.GetFullPath());
316 if (!command.empty())
317 commands.push_back( {
318 { command, plug.GetSymbol().Msgid() },
320 XO(
"Effect") :
XO(
"Menu Command (With Parameters)")
328 std::vector<bool> vExcludeFromMacros;
331 manager.GetAllCommandLabels(mLabels, vExcludeFromMacros,
true);
332 manager.GetAllCommandNames(mNames,
true);
334 const bool english = wxGetLocale()->GetCanonicalName().StartsWith(
wxT(
"en"));
336 for(
size_t i=0; i<mNames.size(); i++) {
337 if( !vExcludeFromMacros[i] ){
338 auto label = mLabels[i];
352 squashed.Replace(
" ",
"" );
357 suffix = squashed.length() < wxMin( 18, mNames[i].GET().length());
373 if (mNames[i] ==
"Close")
382 XO(
"Menu Command (No Parameters)")
394 b.name.StrippedTranslation(); };
395 std::stable_sort(commands.begin(), commands.end(), less);
401 b.name.StrippedTranslation(); };
403 commands.begin(), commands.end(), std::back_inserter(
mCommands), equal);
408 -> Entries::const_iterator
410 const auto less = [](
const Entry &entryA,
const Entry &entryB)
412 entryB.name.StrippedTranslation(); };
413 auto range = std::equal_range(
416 if (range.first != range.second) {
417 wxASSERT_MSG( range.first + 1 == range.second,
418 "Non-unique user-visible command name" );
427 -> Entries::const_iterator
430 return std::find_if(
begin(),
end(),
432 {
return entry.name.Internal() == commandId; });
441 return wxEmptyString;
453 return wxEmptyString;
469 return wxEmptyString;
489 static_cast<void>(command);
510 XO(
"\"%s\" requires one or more tracks to be selected.").
Format(friendlyCommand));
552 ID, friendlyCommand, command,
params, *pContext);
555 ID, friendlyCommand, command,
params, context);
564 pContext->
Status( wxString::Format(
565 _(
"Your batch command of %s was not recognized."), friendlyCommand.
Translation() ));
577 XO(
"Your batch command of %s was not recognized.")
578 .
Format( friendlyCommand ) );
593 bool prevShowMode =
settings.GetShowId3Dialog();
595 auto cleanup =
finally( [&] {
597 settings.SetShowId3Dialog(prevShowMode);
631 wxString
name =
gPrefs->Read(
wxT(
"/Batch/ActiveMacro"), wxEmptyString);
634 longDesc =
XO(
"Applied Macro");
635 shortDesc =
XO(
"Apply Macro");
639 longDesc =
XO(
"Applied Macro '%s'").Format(
name);
640 shortDesc =
XO(
"Apply '%s'").Format(
name);
655 if (macroReentryCount == 1 && !res && proj) {
660 history.RollbackState();
665 history.PopState( elem.
state ); } );
666 undoManager.AbandonRedo();
675 gPrefs->Read(
wxT(
"/EnableMacroTracing"), &trace,
false);
678 wxLogLevel prevLevel = wxLog::GetComponentLevel(
"");
680 wxLog::SetComponentLevel(
"", wxLOG_FatalError);
688 const auto friendly = (iter == catalog.
end())
697 before = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
703 auto after = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
704 wxLogMessage(
wxT(
"Macro line #%ld took %s : %s:%s"),
706 (after - before).
Format(
wxT(
"%H:%M:%S.%l")),
717 wxLog::SetComponentLevel(
"", prevLevel);
777 gPrefs->Read(
wxT(
"/Batch/Debug"), &bDebug,
false);
785 XO(
"Apply %s with parameter(s)\n\n%s")
792 XO(
"Apply %s").
Format( friendlyCommand ),
800 static bool done =
false;
814 wxDir::GetAllFiles(oldDir, &files,
wxT(
"*.txt"), wxDIR_FILES);
819 for (
const auto &file : files) {
820 auto name = wxFileName{file}.GetFullName();
821 newDir.SetFullName(
name);
822 const auto newPath = newDir.GetFullPath();
823 if (!wxFileExists(newPath))
841 for (i = 0; i < files.size(); i++) {
843 names.push_back(ff.GetName());
870 splitAt =
str.Find(
wxT(
':'));
875 command =
str.Mid(0, splitAt);
876 param =
str.Mid(splitAt + 1);
883 return command +
wxT(
": ") + param;
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...
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static const auto MP3Conversion
static const auto FadeEnds
static int MacroReentryCount
constexpr CommandFlag AlwaysEnabledFlag
EffectDistortionSettings params
const TranslatableString name
std::vector< CommandID > CommandIDs
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
@ PluginTypeAudacityCommand
static ProjectFileIORegistry::AttributeWriterEntry entry
static const AttachedProjectObjects::RegisteredFactory manager
EffectReverbSettings preset
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)
declares abstract base class Track, TrackList, and iterators over TrackList
static Settings & settings()
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
virtual void Status(const wxString &message, bool bFlush=false) const
static CommandManager & Get(AudacityProject &project)
const wxString StrippedTranslation() const
EffectManager is the class that handles effects and effect categories.
CommandID GetCommandIdentifier(const PluginID &ID)
BatchProcessingScope SetBatchProcessing(const PluginID &ID)
Begin a scope that ends when the returned object is destroyed.
static EffectManager & Get()
wxString GetPreset(const PluginID &ID, const wxString ¶ms, wxWindow *parent)
wxString GetEffectParameters(const PluginID &ID)
const PluginID & GetEffectByIdentifier(const CommandID &strTarget)
FILES_API const FileType TextFiles
Entries::const_iterator ByCommandId(const CommandID &commandId) const
Entries::const_iterator end() const
std::vector< Entry > Entries
MacroCommandsCatalog(const AudacityProject *project)
Entries::const_iterator ByFriendlyName(const TranslatableString &friendlyName) const
static wxArrayStringEx GetNamesOfDefaultMacros()
static wxString PromptForPresetFor(const CommandID &command, const wxString ¶ms, wxWindow *parent)
bool IsFixed(const wxString &name)
void AddToMacro(const CommandID &command, int before=-1)
bool ApplyEffectCommand(const PluginID &ID, const TranslatableString &friendlyCommand, const CommandID &command, const wxString ¶ms, const CommandContext &Context)
bool ApplyCommand(const TranslatableString &friendlyCommand, const CommandID &command, const wxString ¶ms, CommandContext const *pContext=NULL)
wxString GetParams(int index)
void DeleteFromMacro(int index)
wxArrayString mParamsMacro
wxString Join(const wxString &command, const wxString ¶m)
static wxString GetCurrentParamsFor(const CommandID &command)
static void MigrateLegacyChains()
bool RenameMacro(const wxString &oldmacro, const wxString &newmacro)
CommandID GetCommand(int index)
static wxArrayString GetNames()
bool DeleteMacro(const wxString &name)
bool ReportAndSkip(const TranslatableString &friendlyCommand, const wxString ¶ms)
void Split(const wxString &str, wxString &command, wxString ¶m)
wxString WriteMacro(const wxString ¯o, wxWindow *parent=nullptr)
bool ApplyMacro(const MacroCommandsCatalog &catalog, const wxString &filename={})
static wxString PromptForParamsFor(const CommandID &command, const wxString ¶ms, wxWindow &parent)
bool AddMacro(const wxString ¯o)
MacroCommands(AudacityProject &project)
wxString ReadMacro(const wxString ¯o, wxWindow *parent=nullptr)
void RestoreMacro(const wxString &name)
AudacityProject & mProject
bool ApplyCommandInBatchMode(const TranslatableString &friendlyCommand, const CommandID &command, const wxString ¶ms, CommandContext const *pContext=NULL)
PluginType GetPluginType() const
PluginManager maintains a list of all plug ins. That covers modules, effects, generators,...
Range PluginsOfType(int type)
const PluginDescriptor * GetPlugin(const PluginID &ID) const
static PluginManager & Get()
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static ProjectSettings & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.
TranslatableString & Strip(unsigned options=MenuCodes) &
TranslatableString & Join(TranslatableString arg, const wxString &separator={}) &
Append another translatable string.
wxString Translation() const
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object
static UndoManager & Get(AudacityProject &project)
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
AUDACITY_DLL_API bool DoAudacityCommand(const PluginID &ID, const CommandContext &context, unsigned flags)
AUDACITY_DLL_API bool HandleTextualCommand(CommandManager &commandManager, const CommandID &Str, const CommandContext &context, CommandFlag flags, bool alwaysEnabled)
AUDACITY_DLL_API bool DoEffect(const PluginID &ID, const CommandContext &context, unsigned flags)
'Repeat Last Effect'.
AUDACITY_DLL_API DialogFactoryResults DialogFactory(wxWindow &parent, EffectPlugin &host, EffectUIServices &client, EffectSettingsAccess &access)
FILES_API FilePath MacroDir()
FILES_API bool DoCopyFile(const FilePath &file1, const FilePath &file2, bool overwrite=true)
FILES_API FilePath LegacyChainDir()
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
bool SelectAllIfNoneAndAllowed(AudacityProject &project)
ComponentInterfaceSymbol name
Holds one item with description and time range for the UndoManager.