mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Merge branch 'macros' into master
- Macros Dialog expand/shrink now optically stable. - Fade Ends macro now works (The ':' is in the right place) - Macros can call other macros, but only one deep, now. - MacroIDs are textual names now, not Macro007 - Macros Dialog expand/shrink saves the changes so they are not lost by resizing.
This commit is contained in:
commit
24ee14412f
@ -87,19 +87,13 @@ static const std::pair<const wxChar*, const wxChar*> SpecialCommands[] = {
|
|||||||
};
|
};
|
||||||
// end CLEANSPEECH remnant
|
// end CLEANSPEECH remnant
|
||||||
|
|
||||||
static const wxString MP3Conversion = wxT("MP3 Conversion");
|
|
||||||
static const wxString FadeEnds = wxT("Fade Ends");
|
|
||||||
|
|
||||||
MacroCommands::MacroCommands()
|
MacroCommands::MacroCommands()
|
||||||
{
|
{
|
||||||
mMessage = "";
|
mMessage = "";
|
||||||
ResetMacro();
|
ResetMacro();
|
||||||
|
|
||||||
wxArrayString names = GetNames();
|
wxArrayString names = GetNames();
|
||||||
|
wxArrayString defaults = GetNamesOfDefaultMacros();
|
||||||
wxArrayString defaults;
|
|
||||||
defaults.Add( MP3Conversion );
|
|
||||||
defaults.Add( FadeEnds );
|
|
||||||
|
|
||||||
for( size_t i = 0;i<defaults.Count();i++){
|
for( size_t i = 0;i<defaults.Count();i++){
|
||||||
wxString name = defaults[i];
|
wxString name = defaults[i];
|
||||||
@ -111,6 +105,18 @@ MacroCommands::MacroCommands()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const wxString MP3Conversion = wxT("MP3 Conversion");
|
||||||
|
static const wxString FadeEnds = wxT("Fade Ends");
|
||||||
|
|
||||||
|
|
||||||
|
wxArrayString MacroCommands::GetNamesOfDefaultMacros()
|
||||||
|
{
|
||||||
|
wxArrayString defaults;
|
||||||
|
defaults.Add( MP3Conversion );
|
||||||
|
defaults.Add( FadeEnds );
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
|
|
||||||
void MacroCommands::RestoreMacro(const wxString & name)
|
void MacroCommands::RestoreMacro(const wxString & name)
|
||||||
{
|
{
|
||||||
// TIDY-ME: Effects change their name with localisation.
|
// TIDY-ME: Effects change their name with localisation.
|
||||||
@ -120,11 +126,11 @@ void MacroCommands::RestoreMacro(const wxString & name)
|
|||||||
AddToMacro( wxT("Normalize") );
|
AddToMacro( wxT("Normalize") );
|
||||||
AddToMacro( wxT("ExportMP3") );
|
AddToMacro( wxT("ExportMP3") );
|
||||||
} else if (name == FadeEnds ){
|
} else if (name == FadeEnds ){
|
||||||
AddToMacro( wxT("Select: Start=\"0\" End=\"1\"") );
|
AddToMacro( wxT("Select"), wxT("Start=\"0\" End=\"1\"") );
|
||||||
AddToMacro( wxT("FadeIn") );
|
AddToMacro( wxT("FadeIn") );
|
||||||
AddToMacro( wxT("Select: Start=\"0\" End=\"1\" FromEnd=\"1\"") );
|
AddToMacro( wxT("Select"), wxT("Start=\"0\" End=\"1\" FromEnd=\"1\"") );
|
||||||
AddToMacro( wxT("FadeOut") );
|
AddToMacro( wxT("FadeOut") );
|
||||||
AddToMacro( wxT("Select: Start=\"0\" End=\"0\"") );
|
AddToMacro( wxT("Select"), wxT("Start=\"0\" End=\"0\"") );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,16 +751,27 @@ bool MacroCommands::ApplyCommandInBatchMode(const wxString & command, const wxSt
|
|||||||
return ApplyCommand( command, params );
|
return ApplyCommand( command, params );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int MacroReentryCount = 0;
|
||||||
// ApplyMacro returns true on success, false otherwise.
|
// ApplyMacro returns true on success, false otherwise.
|
||||||
// Any error reporting to the user in setting up the chain
|
// Any error reporting to the user in setting up the chain
|
||||||
// has already been done.
|
// has already been done.
|
||||||
bool MacroCommands::ApplyMacro(const wxString & filename)
|
bool MacroCommands::ApplyMacro(const wxString & filename)
|
||||||
{
|
{
|
||||||
|
// Check for reentrant ApplyMacro commands.
|
||||||
|
// We'll allow 1 level of reentry, but not more.
|
||||||
|
// And we treat ignoring deeper levels as a success.
|
||||||
|
if( MacroReentryCount > 1 )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Restore the reentry counter (to zero) when we exit.
|
||||||
|
auto cleanup1 = valueRestorer( MacroReentryCount);
|
||||||
|
MacroReentryCount++;
|
||||||
|
|
||||||
mFileName = filename;
|
mFileName = filename;
|
||||||
|
|
||||||
AudacityProject *proj = GetActiveProject();
|
AudacityProject *proj = GetActiveProject();
|
||||||
bool res = false;
|
bool res = false;
|
||||||
auto cleanup = finally( [&] {
|
auto cleanup2 = finally( [&] {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
if(proj) {
|
if(proj) {
|
||||||
// Macro failed or was cancelled; revert to the previous state
|
// Macro failed or was cancelled; revert to the previous state
|
||||||
@ -795,7 +812,8 @@ bool MacroCommands::ApplyMacro(const wxString & filename)
|
|||||||
|
|
||||||
if (!proj)
|
if (!proj)
|
||||||
return false;
|
return false;
|
||||||
proj->PushState(longDesc, shortDesc);
|
if( MacroReentryCount <= 1 )
|
||||||
|
proj->PushState(longDesc, shortDesc);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,13 +895,12 @@ wxArrayString MacroCommands::GetNames()
|
|||||||
|
|
||||||
bool MacroCommands::IsFixed(const wxString & name)
|
bool MacroCommands::IsFixed(const wxString & name)
|
||||||
{
|
{
|
||||||
if (name == MP3Conversion)
|
wxArrayString defaults = GetNamesOfDefaultMacros();
|
||||||
|
if( defaults.Index( name ) != wxNOT_FOUND )
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MacroCommands::Split(const wxString & str, wxString & command, wxString & param)
|
void MacroCommands::Split(const wxString & str, wxString & command, wxString & param)
|
||||||
{
|
{
|
||||||
int splitAt;
|
int splitAt;
|
||||||
|
@ -42,6 +42,7 @@ class MacroCommands final {
|
|||||||
|
|
||||||
// These commands do not depend on the command list.
|
// These commands do not depend on the command list.
|
||||||
static wxArrayString GetNames();
|
static wxArrayString GetNames();
|
||||||
|
static wxArrayString GetNamesOfDefaultMacros();
|
||||||
|
|
||||||
// A triple of user-visible name, internal string identifier and type/help string.
|
// A triple of user-visible name, internal string identifier and type/help string.
|
||||||
using CommandName = std::tuple<wxString, wxString, wxString>;
|
using CommandName = std::tuple<wxString, wxString, wxString>;
|
||||||
|
@ -123,6 +123,14 @@ void ApplyMacroDialog::PopulateOrExchange(ShuttleGui &S)
|
|||||||
S.Id(ExpandID).AddButton(_("&Expand"));
|
S.Id(ExpandID).AddButton(_("&Expand"));
|
||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
|
S.StartHorizontalLay(wxALIGN_RIGHT, false);
|
||||||
|
{
|
||||||
|
S.AddSpace( 40 );
|
||||||
|
S.AddPrompt( _("Apply Macro to:") );
|
||||||
|
S.Id(ApplyToProjectID).AddButton(_("&Project"));
|
||||||
|
S.Id(ApplyToFilesID).AddButton(_("&Files..."));
|
||||||
|
}
|
||||||
|
S.EndHorizontalLay();
|
||||||
|
|
||||||
S.StartStatic(_("&Select Macro"), true);
|
S.StartStatic(_("&Select Macro"), true);
|
||||||
{
|
{
|
||||||
@ -132,14 +140,8 @@ void ApplyMacroDialog::PopulateOrExchange(ShuttleGui &S)
|
|||||||
mMacros->InsertColumn(0, _("Macro"), wxLIST_FORMAT_LEFT);
|
mMacros->InsertColumn(0, _("Macro"), wxLIST_FORMAT_LEFT);
|
||||||
}
|
}
|
||||||
S.EndStatic();
|
S.EndStatic();
|
||||||
|
|
||||||
S.StartHorizontalLay(wxALIGN_RIGHT, false);
|
S.StartHorizontalLay(wxALIGN_RIGHT, false);
|
||||||
{
|
{
|
||||||
S.SetBorder(10);
|
|
||||||
S.AddPrompt( _("Apply Macro to:") );
|
|
||||||
S.Id(ApplyToProjectID).AddButton(_("&Project"));
|
|
||||||
S.Id(ApplyToFilesID).AddButton(_("&Files..."));
|
|
||||||
S.AddSpace( 40 );
|
|
||||||
S.AddStandardButtons( eCancelButton | eHelpButton);
|
S.AddStandardButtons( eCancelButton | eHelpButton);
|
||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
@ -190,6 +192,28 @@ void ApplyMacroDialog::OnApplyToProject(wxCommandEvent & WXUNUSED(event))
|
|||||||
ApplyMacroToProject( item );
|
ApplyMacroToProject( item );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString ApplyMacroDialog::MacroIdOfName( const wxString & MacroName )
|
||||||
|
{
|
||||||
|
wxString Temp = MacroName;
|
||||||
|
Temp.Replace(" ","");
|
||||||
|
Temp = wxString( "Macro_" ) + Temp;
|
||||||
|
return Temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply macro, given its ID.
|
||||||
|
// Does nothing if not found, rather than returning an error.
|
||||||
|
void ApplyMacroDialog::ApplyMacroToProject( const wxString & MacroID, bool bHasGui )
|
||||||
|
{
|
||||||
|
for( size_t i=0;i<mMacros->GetItemCount();i++){
|
||||||
|
wxString name = mMacros->GetItemText(i);
|
||||||
|
if( MacroIdOfName( name ) == MacroID ){
|
||||||
|
ApplyMacroToProject( i, bHasGui );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply macro, given its number in the list.
|
||||||
void ApplyMacroDialog::ApplyMacroToProject( int iMacro, bool bHasGui )
|
void ApplyMacroDialog::ApplyMacroToProject( int iMacro, bool bHasGui )
|
||||||
{
|
{
|
||||||
wxString name = mMacros->GetItemText(iMacro);
|
wxString name = mMacros->GetItemText(iMacro);
|
||||||
@ -501,9 +525,9 @@ MacrosWindow::MacrosWindow(wxWindow * parent, bool bExpanded):
|
|||||||
ApplyMacroDialog(parent, true)
|
ApplyMacroDialog(parent, true)
|
||||||
{
|
{
|
||||||
mbExpanded = bExpanded;
|
mbExpanded = bExpanded;
|
||||||
SetLabel(_("Macros")); // Provide visual label
|
SetLabel(_("Edit Macros")); // Provide visual label
|
||||||
SetName(_("Macros")); // Provide audible label
|
SetName(_("Edit Macros")); // Provide audible label
|
||||||
SetTitle(_("Macros"));
|
SetTitle(_("Edit Macros"));
|
||||||
|
|
||||||
mChanged = false;
|
mChanged = false;
|
||||||
mSelectedCommand = 0;
|
mSelectedCommand = 0;
|
||||||
@ -563,10 +587,18 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
|
|||||||
{
|
{
|
||||||
S.Prop(0).StartHorizontalLay(wxALIGN_RIGHT, false);
|
S.Prop(0).StartHorizontalLay(wxALIGN_RIGHT, false);
|
||||||
{
|
{
|
||||||
S.Id(ShrinkID).AddButton(_("&Shrink"));
|
S.Id(ShrinkID).AddButton(_("Shrin&k"));
|
||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
S.StartStatic(_("&Macros"),1);
|
S.StartHorizontalLay(wxALIGN_RIGHT, false);
|
||||||
|
{
|
||||||
|
S.AddSpace( 40 );
|
||||||
|
S.AddPrompt( _("Apply Macro to:") );
|
||||||
|
S.Id(ApplyToProjectID).AddButton(_("&Project"));
|
||||||
|
S.Id(ApplyToFilesID).AddButton(_("&Files..."));
|
||||||
|
}
|
||||||
|
S.EndHorizontalLay();
|
||||||
|
S.StartStatic(_("&Select Macros"),1);
|
||||||
{
|
{
|
||||||
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_SINGLE_SEL |
|
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_SINGLE_SEL |
|
||||||
wxLC_EDIT_LABELS);
|
wxLC_EDIT_LABELS);
|
||||||
@ -587,7 +619,7 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
|
|||||||
|
|
||||||
S.StartVerticalLay( 1 );
|
S.StartVerticalLay( 1 );
|
||||||
{
|
{
|
||||||
S.StartStatic(_("Ma&cro (Double-Click or press SPACE to edit)"), true);
|
S.StartStatic(_("&Macro (Double-Click or press SPACE to edit)"), true);
|
||||||
{
|
{
|
||||||
S.StartHorizontalLay(wxEXPAND,1);
|
S.StartHorizontalLay(wxEXPAND,1);
|
||||||
{
|
{
|
||||||
@ -620,10 +652,6 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
|
|||||||
S.EndStatic();
|
S.EndStatic();
|
||||||
S.StartHorizontalLay(wxALIGN_RIGHT, false);
|
S.StartHorizontalLay(wxALIGN_RIGHT, false);
|
||||||
{
|
{
|
||||||
S.AddPrompt( _("Apply Macro to:") );
|
|
||||||
S.Id(ApplyToProjectButtonID).AddButton(_("&Project"), wxALIGN_LEFT);
|
|
||||||
S.Id(ApplyToFilesButtonID).AddButton(_("&Files..."), wxALIGN_LEFT);
|
|
||||||
S.AddSpace( 40 );
|
|
||||||
S.AddStandardButtons( eOkButton | eCancelButton | eHelpButton);
|
S.AddStandardButtons( eOkButton | eCancelButton | eHelpButton);
|
||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
@ -684,6 +712,10 @@ void MacrosWindow::UpdateDisplay( bool bExpanded )
|
|||||||
{
|
{
|
||||||
if( bExpanded == mbExpanded )
|
if( bExpanded == mbExpanded )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if( !SaveChanges() )
|
||||||
|
return;
|
||||||
|
|
||||||
mbExpanded = bExpanded;
|
mbExpanded = bExpanded;
|
||||||
DestroyChildren();
|
DestroyChildren();
|
||||||
SetSizer( nullptr );
|
SetSizer( nullptr );
|
||||||
@ -692,10 +724,22 @@ void MacrosWindow::UpdateDisplay( bool bExpanded )
|
|||||||
mSelectedCommand = 0;
|
mSelectedCommand = 0;
|
||||||
SetMinSize( wxSize( 200,200 ));
|
SetMinSize( wxSize( 200,200 ));
|
||||||
|
|
||||||
|
// Get and set position for optical stability.
|
||||||
|
// Expanded and shrunk dialogs 'stay where they were'.
|
||||||
|
// That's OK , and what we want, even if we exapnd off-screen.
|
||||||
|
// We won't shrink to being off-screen, since the shrink button
|
||||||
|
// was clicked, so must have been on screen.
|
||||||
|
wxPoint p = GetPosition( );
|
||||||
if( mbExpanded )
|
if( mbExpanded )
|
||||||
Populate();
|
Populate();
|
||||||
else
|
else
|
||||||
ApplyMacroDialog::Populate();
|
ApplyMacroDialog::Populate();
|
||||||
|
SetPosition( p );
|
||||||
|
|
||||||
|
wxString Title = mbExpanded ? _("Edit Macros") : _("Apply Macro");
|
||||||
|
SetLabel( Title ); // Provide visual label
|
||||||
|
SetName( Title ); // Provide audible label
|
||||||
|
SetTitle( Title );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacrosWindow::OnExpand(wxCommandEvent &WXUNUSED(event))
|
void MacrosWindow::OnExpand(wxCommandEvent &WXUNUSED(event))
|
||||||
|
@ -56,7 +56,9 @@ class ApplyMacroDialog : public wxDialogWrapper {
|
|||||||
virtual wxString GetHelpPageName() {return "Tools_Menu#macros_compact_dialog";};
|
virtual wxString GetHelpPageName() {return "Tools_Menu#macros_compact_dialog";};
|
||||||
|
|
||||||
void PopulateMacros();
|
void PopulateMacros();
|
||||||
|
static wxString MacroIdOfName( const wxString & MacroName );
|
||||||
void ApplyMacroToProject( int iMacro, bool bHasGui=true );
|
void ApplyMacroToProject( int iMacro, bool bHasGui=true );
|
||||||
|
void ApplyMacroToProject( const wxString & MacroID, bool bHasGui=true );
|
||||||
|
|
||||||
|
|
||||||
// These will be reused in the derived class...
|
// These will be reused in the derived class...
|
||||||
|
@ -1713,7 +1713,8 @@ void AudacityProject::PopulateMacrosMenu( CommandManager* c, CommandFlag flags
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < (int)names.GetCount(); i++) {
|
for (i = 0; i < (int)names.GetCount(); i++) {
|
||||||
c->AddItem(wxString::Format("Macro%03i", i ), names[i], FN(OnApplyMacroDirectly),
|
wxString MacroID = ApplyMacroDialog::MacroIdOfName( names[i] );
|
||||||
|
c->AddItem(MacroID, names[i], FN(OnApplyMacroDirectly),
|
||||||
flags,
|
flags,
|
||||||
flags);
|
flags);
|
||||||
}
|
}
|
||||||
@ -6860,10 +6861,17 @@ void AudacityProject::OnApplyMacroDirectly(const CommandContext &context )
|
|||||||
//wxLogDebug( "Macro was: %s", context.parameter);
|
//wxLogDebug( "Macro was: %s", context.parameter);
|
||||||
ApplyMacroDialog dlg(this);
|
ApplyMacroDialog dlg(this);
|
||||||
wxString Name = context.parameter;
|
wxString Name = context.parameter;
|
||||||
|
|
||||||
|
// We used numbers previously, but macros could get renumbered, making
|
||||||
|
// macros containing macros unpredictable.
|
||||||
|
#ifdef MACROS_BY_NUMBERS
|
||||||
long item=0;
|
long item=0;
|
||||||
// Take last three letters (of e.g. Macro007) and convert to a number.
|
// Take last three letters (of e.g. Macro007) and convert to a number.
|
||||||
Name.Mid( Name.Length() - 3 ).ToLong( &item, 10 );
|
Name.Mid( Name.Length() - 3 ).ToLong( &item, 10 );
|
||||||
dlg.ApplyMacroToProject( item, false );
|
dlg.ApplyMacroToProject( item, false );
|
||||||
|
#else
|
||||||
|
dlg.ApplyMacroToProject( Name, false );
|
||||||
|
#endif
|
||||||
ModifyUndoMenuItems();
|
ModifyUndoMenuItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user