17#define wxLOG_COMPONENT "MacroCommands"
22#include <wx/datetime.h>
25#include <wx/textfile.h>
58 for(
size_t i = 0;i<defaults.size();i++){
59 wxString
name = defaults[i];
90 AddToMacro(
wxT(
"Select"),
wxT(
"Start=\"0\" End=\"1\" RelativeTo=\"ProjectEnd\"") );
135 wxFD_OPEN | wxRESIZE_BORDER,
140 return wxEmptyString;
143 wxFileName check(
fn);
144 check.SetPath(
name.GetPath());
145 if (check.FileExists())
148 XO(
"Macro %s already exists. Would you like to replace it?").
Format(check.GetName()),
152 return wxEmptyString;
160 wxTextFile tf(
name.GetFullPath());
164 if (!tf.IsOpened()) {
166 return wxEmptyString;
170 int lines = tf.GetLineCount();
172 for (
int i = 0; i < lines; i++) {
175 int splitAt = tf[i].Find(
wxT(
':'));
181 wxString cmd = tf[i].Left(splitAt).Strip(wxString::both);
182 wxString parm = tf[i].Mid(splitAt + 1).Strip(wxString::trailing);
198 return name.GetName();
214 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
219 return wxEmptyString;
226 wxTextFile tf(
name.GetFullPath());
236 if (!tf.IsOpened()) {
238 return wxEmptyString;
246 for (
int i = 0; i < lines; i++) {
257 return name.GetName();
266 wxTextFile tf(
name.GetFullPath());
278 auto result = wxRemoveFile(
name.GetFullPath());
282 wxRemoveFile(oldPath.GetFullPath());
294 return wxRenameFile(oname.GetFullPath(), nname.GetFullPath());
311 if (!command.empty())
312 commands.push_back( {
313 { command, plug.GetSymbol().Msgid() },
315 XO(
"Effect") :
XO(
"Menu Command (With Parameters)")
323 std::vector<bool> vExcludeFromMacros;
326 manager.GetAllCommandLabels(mLabels, vExcludeFromMacros,
true);
327 manager.GetAllCommandNames(mNames,
true);
329 const bool english = wxGetLocale()->GetCanonicalName().StartsWith(
wxT(
"en"));
331 for(
size_t i=0; i<mNames.size(); i++) {
332 if( !vExcludeFromMacros[i] ){
333 auto label = mLabels[i];
347 squashed.Replace(
" ",
"" );
352 suffix = squashed.length() < wxMin( 18, mNames[i].GET().length());
368 if (mNames[i] ==
"Close")
377 XO(
"Menu Command (No Parameters)")
389 b.name.StrippedTranslation(); };
390 std::stable_sort(commands.begin(), commands.end(), less);
396 b.name.StrippedTranslation(); };
398 commands.begin(), commands.end(), std::back_inserter(
mCommands), equal);
403 -> Entries::const_iterator
405 const auto less = [](
const Entry &entryA,
const Entry &entryB)
407 entryB.name.StrippedTranslation(); };
408 auto range = std::equal_range(
411 if (range.first != range.second) {
412 wxASSERT_MSG( range.first + 1 == range.second,
413 "Non-unique user-visible command name" );
422 -> Entries::const_iterator
425 return std::find_if(
begin(),
end(),
427 {
return entry.name.Internal() == commandId; });
436 return wxEmptyString;
448 return wxEmptyString;
464 return wxEmptyString;
484 static_cast<void>(command);
505 XO(
"\"%s\" requires one or more tracks to be selected.").
Format(friendlyCommand));
547 ID, friendlyCommand, command,
params, *pContext);
550 ID, friendlyCommand, command,
params, context);
558 pContext->
Status( wxString::Format(
559 _(
"Your batch command of %s was not recognized."), friendlyCommand.
Translation() ));
571 XO(
"Your batch command of %s was not recognized.")
572 .
Format( friendlyCommand ) );
589 auto cleanup =
finally( [&] {
627 longDesc =
XO(
"Applied Macro");
628 shortDesc =
XO(
"Apply Macro");
632 longDesc =
XO(
"Applied Macro '%s'").Format(
name);
633 shortDesc =
XO(
"Apply '%s'").Format(
name);
648 if (macroReentryCount == 1 && !res && proj) {
653 history.RollbackState();
658 history.PopState( elem.
state ); } );
659 undoManager.AbandonRedo();
671 wxLogLevel prevLevel = wxLog::GetComponentLevel(
"");
673 wxLog::SetComponentLevel(
"", wxLOG_FatalError);
681 const auto friendly = (iter == catalog.
end())
690 before = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
696 auto after = wxTimeSpan(0, 0, 0, wxGetUTCTimeMillis());
697 wxLogMessage(
wxT(
"Macro line #%ld took %s : %s:%s"),
699 (after - before).
Format(
wxT(
"%H:%M:%S.%l")),
710 wxLog::SetComponentLevel(
"", prevLevel);
778 XO(
"Apply %s with parameter(s)\n\n%s")
785 XO(
"Apply %s").
Format( friendlyCommand ),
793 static bool done =
false;
807 wxDir::GetAllFiles(oldDir, &files,
wxT(
"*.txt"), wxDIR_FILES);
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))
834 for (i = 0; i < files.size(); i++) {
836 names.push_back(ff.GetName());
863 splitAt =
str.Find(
wxT(
':'));
868 command =
str.Mid(0, splitAt);
869 param =
str.Mid(splitAt + 1);
876 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
static ProjectFileIORegistry::AttributeWriterEntry entry
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
@ PluginTypeAudacityCommand
audacity::BasicSettings * gPrefs
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
AudacityProject & project
static CommandManager & Get(AudacityProject &project)
void UpdateMenus(bool checkActive=true)
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=nullptr)
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)
bool ApplyCommandInBatchMode(const TranslatableString &friendlyCommand, const CommandID &command, const wxString ¶ms, CommandContext const *pContext=nullptr)
AudacityProject & GetProject()
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
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)
virtual bool Read(const wxString &key, bool *value) const =0
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(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, EffectBase &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()
bool SelectAllIfNoneAndAllowed(AudacityProject &project)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
ComponentInterfaceSymbol name
Holds one item with description and time range for the UndoManager.