Audacity 3.2.0
Public Types | Public Member Functions | Protected Attributes | Private Attributes | List of all members
AudacityCommand Class Referenceabstract

Base class for command in Audacity. More...

#include <AudacityCommand.h>

Inheritance diagram for AudacityCommand:
[legend]
Collaboration diagram for AudacityCommand:
[legend]

Public Types

enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 

Public Member Functions

 AudacityCommand ()
 
virtual ~AudacityCommand ()
 
PluginPath GetPath () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
ComponentInterfaceSymbol GetSymbol () const override=0
 
virtual TranslatableString GetDescription () const override
 
virtual ManualPageID ManualPage ()
 
virtual bool IsBatchProcessing () const
 
virtual void SetBatchProcessing (bool start)
 
virtual bool Apply (const CommandContext &WXUNUSED(context))
 
bool ShowInterface (wxWindow *parent, bool forceModal=false)
 
wxDialog * CreateUI (wxWindow *parent, AudacityCommand *client)
 
bool SaveSettingsAsString (wxString &parms)
 
bool LoadSettingsFromString (const wxString &parms)
 
bool DoAudacityCommand (wxWindow *parent, const CommandContext &context, bool shouldPrompt=true)
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
virtual bool Init ()
 
virtual bool PromptUser (wxWindow *parent)
 
virtual bool CheckWhetherSkipAudacityCommand ()
 
virtual void End ()
 
virtual void PopulateOrExchange (ShuttleGui &WXUNUSED(S))
 
virtual bool TransferDataToWindow ()
 
virtual bool TransferDataFromWindow ()
 
virtual bool VisitSettings (SettingsVisitor &)
 
virtual bool VisitSettings (ConstSettingsVisitor &)
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Protected Attributes

ProgressDialogmProgress
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 

Private Attributes

bool mIsBatch
 
bool mNeedsInit
 

Detailed Description

Base class for command in Audacity.

Definition at line 38 of file AudacityCommand.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : long
Enumerator
DefaultMessageBoxStyle 

Definition at line 80 of file AudacityCommand.h.

80: long { DefaultMessageBoxStyle = wxOK | wxCENTRE };

Constructor & Destructor Documentation

◆ AudacityCommand()

AudacityCommand::AudacityCommand ( )

Definition at line 46 of file AudacityCommand.cpp.

47{
48 mProgress = NULL;
49 mUIParent = NULL;
50 mUIDialog = NULL;
51 mIsBatch = false;
52 mNeedsInit = true;
53}
wxDialog * mUIDialog
wxWindow * mUIParent
ProgressDialog * mProgress

References mIsBatch, mNeedsInit, mProgress, mUIDialog, and mUIParent.

◆ ~AudacityCommand()

AudacityCommand::~AudacityCommand ( )
virtual

Definition at line 55 of file AudacityCommand.cpp.

56{
57 if (mUIDialog)
58 mUIDialog->Close();
59}

References mUIDialog.

Member Function Documentation

◆ Apply()

virtual bool AudacityCommand::Apply ( const CommandContext WXUNUSEDcontext)
inlinevirtual

Definition at line 66 of file AudacityCommand.h.

66{ return false; }

Referenced by DoAudacityCommand().

Here is the caller graph for this function:

◆ CheckWhetherSkipAudacityCommand()

virtual bool AudacityCommand::CheckWhetherSkipAudacityCommand ( )
inlinevirtual

Definition at line 109 of file AudacityCommand.h.

109{ return false; }

Referenced by DoAudacityCommand().

Here is the caller graph for this function:

◆ CreateUI()

wxDialog * AudacityCommand::CreateUI ( wxWindow *  parent,
AudacityCommand client 
)

Definition at line 103 of file AudacityCommand.cpp.

104{
106 parent, GetName(), this}};
107
108 if (dlg->Init())
109 {
110 // release() is safe because parent will own it
111 return dlg.release();
112 }
113 return NULL;
114}
#define safenew
Definition: MemoryX.h:10
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:162
Default dialog used for commands. Is populated using ShuttleGui.
TranslatableString GetName() const

References ComponentInterface::GetName(), and safenew.

Referenced by ShowInterface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoAudacityCommand()

bool AudacityCommand::DoAudacityCommand ( wxWindow *  parent,
const CommandContext context,
bool  shouldPrompt = true 
)

Definition at line 159 of file AudacityCommand.cpp.

162{
163 // Note: Init may read parameters from preferences
164 if (!Init())
165 {
166 return false;
167 }
168
169 // Prompting will be bypassed when applying a command that has already
170 // been configured, e.g. repeating the last effect on a different selection.
171 // Prompting may call AudacityCommand::Preview
172 if (shouldPrompt && /*IsInteractive() && */!PromptUser(parent))
173 {
174 return false;
175 }
176
177 auto cleanup = finally( [&] {
178 End();
179 } );
180
181 bool returnVal = true;
182 bool skipFlag = CheckWhetherSkipAudacityCommand();
183 if (skipFlag == false)
184 {
185 auto name = GetName();
186 ProgressDialog progress{
187 name,
188 XO("Applying %s...").Format( name ),
190 };
191 auto vr = valueRestorer( mProgress, &progress );
192
193 returnVal = Apply(context);
194 }
195 return returnVal;
196}
const TranslatableString name
Definition: Distortion.cpp:76
XO("Cut/Copy/Paste")
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:251
@ pdlgHideStopButton
virtual bool Init()
virtual bool Apply(const CommandContext &WXUNUSED(context))
virtual bool PromptUser(wxWindow *parent)
virtual void End()
virtual bool CheckWhetherSkipAudacityCommand()
ProgressDialog Class.

References Apply(), CheckWhetherSkipAudacityCommand(), End(), ComponentInterface::GetName(), Init(), mProgress, name, pdlgHideStopButton, PromptUser(), valueRestorer(), and XO().

Referenced by EffectManager::DoAudacityCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ End()

virtual void AudacityCommand::End ( )
inlinevirtual

Definition at line 114 of file AudacityCommand.h.

114{;};

Referenced by DoAudacityCommand().

Here is the caller graph for this function:

◆ GetDescription()

virtual TranslatableString AudacityCommand::GetDescription ( ) const
inlineoverridevirtual

Implements ComponentInterface.

Reimplemented in CompareAudioCommand, DemoCommand, DragCommand, GetInfoCommand, GetTrackInfoCommand, HelpCommand, CommentCommand, ImportCommand, ExportCommand, MessageCommand, OpenProjectCommand, SaveProjectCommand, SaveCopyCommand, SaveLogCommand, ClearLogCommand, GetPreferenceCommand, SetPreferenceCommand, ScreenshotCommand, SelectTimeCommand, SelectFrequenciesCommand, SelectTracksCommand, SelectCommand, SetClipCommand, SetEnvelopeCommand, SetLabelCommand, SetProjectCommand, SetTrackStatusCommand, SetTrackAudioCommand, SetTrackVisualsCommand, and SetTrackCommand.

Definition at line 58 of file AudacityCommand.h.

59 {wxFAIL_MSG( "Implement a Description for this command");return XO("FAIL");};

References XO().

Referenced by EffectManager::GetCommandTip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPath()

PluginPath AudacityCommand::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 62 of file AudacityCommand.cpp.

#define BUILTIN_GENERIC_COMMAND_PREFIX
ComponentInterfaceSymbol GetSymbol() const override=0
const wxString & Internal() const

References BUILTIN_GENERIC_COMMAND_PREFIX, GetSymbol(), and ComponentInterfaceSymbol::Internal().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol AudacityCommand::GetSymbol ( ) const
overridepure virtual

◆ GetVendor()

VendorSymbol AudacityCommand::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 63 of file AudacityCommand.cpp.

63{ return XO("Audacity");}

References XO().

Here is the call graph for this function:

◆ GetVersion()

wxString AudacityCommand::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 64 of file AudacityCommand.cpp.

64{ return AUDACITY_VERSION_STRING;}

◆ Init()

bool AudacityCommand::Init ( )
virtual

Definition at line 67 of file AudacityCommand.cpp.

67 {
68 if( !mNeedsInit )
69 return true;
70 mNeedsInit = false;
71 ShuttleDefaults DefaultSettingShuttle;
72 return VisitSettings( DefaultSettingShuttle );
73}
virtual bool VisitSettings(SettingsVisitor &)
SettingsVisitor that sets parameters to their default values.

References mNeedsInit, and VisitSettings().

Referenced by DoAudacityCommand(), EffectManager::GetAudacityCommand(), and EffectManager::SetEffectParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsBatchProcessing()

virtual bool AudacityCommand::IsBatchProcessing ( ) const
inlinevirtual

Definition at line 63 of file AudacityCommand.h.

63{ return mIsBatch; }

Referenced by PromptUser().

Here is the caller graph for this function:

◆ LoadSettingsFromString()

bool AudacityCommand::LoadSettingsFromString ( const wxString &  parms)

Definition at line 134 of file AudacityCommand.cpp.

135{
136 wxString preset = parms;
137
138 CommandParameters eap(parms);
140
141 S.SetForWriting( &eap );
142 bool bResult = VisitSettings( S );
143 wxASSERT_MSG( bResult, "You did not define DefineParameters() for this command" );
144 static_cast<void>(bResult); // fix unused variable warning in release mode
145 if (!S.bOK)
146 {
148 XO(
149"%s: Could not load settings below. Default settings will be used.\n\n%s")
150 .Format( GetName(), preset ) );
151
152 // fror now always succeed, so that we can prompt the user.
153 return true;
154 }
155
156 return TransferDataToWindow();
157}
EffectReverbSettings preset
Definition: Reverb.cpp:44
#define S(N)
Definition: ToChars.cpp:64
virtual bool TransferDataToWindow()
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
Abstract base class used in importing a file.
SettingsVisitor that sets parameters to a value (from a string)

References ComponentInterface::GetName(), MessageBox(), preset, S, TransferDataToWindow(), VisitSettings(), and XO().

Referenced by EffectManager::SetEffectParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ManualPage()

virtual ManualPageID AudacityCommand::ManualPage ( )
inlinevirtual

◆ MessageBox()

int AudacityCommand::MessageBox ( const TranslatableString message,
long  style = DefaultMessageBoxStyle,
const TranslatableString titleStr = {} 
)

Definition at line 228 of file AudacityCommand.cpp.

231{
232 auto title = titleStr.empty()
233 ? GetName()
234 : XO("%s: %s").Format( GetName(), titleStr );
235 return AudacityMessageBox(message, title, style, mUIParent);
236}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static const auto title

References AudacityMessageBox(), TranslatableString::empty(), ComponentInterface::GetName(), mUIParent, title, and XO().

Referenced by LoadSettingsFromString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PopulateOrExchange()

virtual void AudacityCommand::PopulateOrExchange ( ShuttleGui WXUNUSEDS)
inlinevirtual

Definition at line 115 of file AudacityCommand.h.

115{return;};

Referenced by AudacityCommandDialog::PopulateOrExchange().

Here is the caller graph for this function:

◆ PromptUser()

bool AudacityCommand::PromptUser ( wxWindow *  parent)
virtual

Reimplemented in ClearLogCommand.

Definition at line 199 of file AudacityCommand.cpp.

200{
201 return ShowInterface(parent, IsBatchProcessing());
202}
virtual bool IsBatchProcessing() const
bool ShowInterface(wxWindow *parent, bool forceModal=false)

References IsBatchProcessing(), and ShowInterface().

Referenced by DoAudacityCommand(), and EffectManager::PromptUser().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SaveSettingsAsString()

bool AudacityCommand::SaveSettingsAsString ( wxString &  parms)

Definition at line 116 of file AudacityCommand.cpp.

117{
119
121 {
122 return false;
123 }
124
126 S.mpEap = &eap;
127 bool bResult = VisitSettings( S );
128 wxASSERT_MSG( bResult, "You did not define DefineParameters() for this command" );
129 static_cast<void>(bResult); // fix unused variable warning in release mode
130
131 return eap.GetParameters(parms);
132}
virtual bool TransferDataFromWindow()
bool GetParameters(wxString &parms)
SettingsVisitor that gets parameter values into a string.

References CommandParameters::GetParameters(), mUIDialog, S, TransferDataFromWindow(), and VisitSettings().

Referenced by EffectManager::GetEffectParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetBatchProcessing()

virtual void AudacityCommand::SetBatchProcessing ( bool  start)
inlinevirtual

Definition at line 64 of file AudacityCommand.h.

64{ mIsBatch = start; }

◆ ShowInterface()

bool AudacityCommand::ShowInterface ( wxWindow *  parent,
bool  forceModal = false 
)

Definition at line 75 of file AudacityCommand.cpp.

76{
77 if (mUIDialog)
78 {
79 if ( mUIDialog->Close(true) )
80 mUIDialog = nullptr;
81 return false;
82 }
83
84 // mUIDialog is null
85 auto cleanup = valueRestorer( mUIDialog );
86
87 mUIDialog = CreateUI(parent, this);
88 if (!mUIDialog)
89 return false;
90
91 mUIDialog->Layout();
92 mUIDialog->Fit();
93 mUIDialog->SetMinSize(mUIDialog->GetSize());
94
95 // The Screenshot command might be popping this dialog up, just to capture it.
97 return false;
98
99 bool res = mUIDialog->ShowModal() != 0;
100 return res;
101}
wxDialog * CreateUI(wxWindow *parent, AudacityCommand *client)
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.

References GlobalHook< VetoDialogHook, bool(wxDialog *) >::Call(), CreateUI(), mUIDialog, and valueRestorer().

Referenced by PromptUser().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TransferDataFromWindow()

bool AudacityCommand::TransferDataFromWindow ( )
virtual

Definition at line 211 of file AudacityCommand.cpp.

212{
213 if (mUIParent && (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow()))
214 return false;
215 return true;
216}

References mUIParent.

Referenced by SaveSettingsAsString().

Here is the caller graph for this function:

◆ TransferDataToWindow()

bool AudacityCommand::TransferDataToWindow ( )
virtual

Definition at line 204 of file AudacityCommand.cpp.

205{
206 if (mUIParent && !mUIParent->TransferDataToWindow())
207 return false;
208 return true;
209}

References mUIParent.

Referenced by LoadSettingsFromString().

Here is the caller graph for this function:

◆ VisitSettings() [1/2]

bool AudacityCommand::VisitSettings ( ConstSettingsVisitor )
virtual

◆ VisitSettings() [2/2]

bool AudacityCommand::VisitSettings ( SettingsVisitor )
virtual

Visit settings, if defined. false means no defined settings. Default implementation returns false

Reimplemented in CompareAudioCommand, DemoCommand, DragCommand, GetInfoCommand, GetTrackInfoCommand, HelpCommand, CommentCommand, ImportCommand, ExportCommand, MessageCommand, OpenProjectCommand, SaveProjectCommand, SaveCopyCommand, SaveLogCommand, ClearLogCommand, GetPreferenceCommand, SetPreferenceCommand, ScreenshotCommand, SelectTimeCommand, SelectFrequenciesCommand, SelectTracksCommand, SelectCommand, SetClipCommand, SetEnvelopeCommand, SetLabelCommand, SetProjectCommand, SetTrackStatusCommand, SetTrackAudioCommand, SetTrackVisualsCommand, and SetTrackCommand.

Definition at line 218 of file AudacityCommand.cpp.

219{
220 return false;
221}

Referenced by EffectManager::GetCommandDefinition(), Init(), LoadSettingsFromString(), and SaveSettingsAsString().

Here is the caller graph for this function:

Member Data Documentation

◆ mIsBatch

bool AudacityCommand::mIsBatch
private

Definition at line 134 of file AudacityCommand.h.

Referenced by AudacityCommand().

◆ mNeedsInit

bool AudacityCommand::mNeedsInit
private

Definition at line 135 of file AudacityCommand.h.

Referenced by AudacityCommand(), and Init().

◆ mProgress

ProgressDialog* AudacityCommand::mProgress
protected

Definition at line 128 of file AudacityCommand.h.

Referenced by AudacityCommand(), and DoAudacityCommand().

◆ mUIDialog

wxDialog* AudacityCommand::mUIDialog
protected

◆ mUIParent

wxWindow* AudacityCommand::mUIParent
protected

The documentation for this class was generated from the following files: