Audacity  3.0.3
Public Types | Public Member Functions | Static 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 }
 
using VetoDialogHook = bool(*)(wxDialog *)
 

Public Member Functions

 AudacityCommand ()
 
virtual ~AudacityCommand ()
 
PluginPath GetPath () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
ComponentInterfaceSymbol GetSymbol () override=0
 
virtual TranslatableString GetDescription () override
 
virtual ManualPageID ManualPage ()
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
virtual bool Apply (const CommandContext &WXUNUSED(context))
 
bool ShowInterface (wxWindow *parent, bool forceModal=false)
 
virtual void SetHostUI (EffectUIHostInterface *WXUNUSED(host))
 
wxDialog * CreateUI (wxWindow *parent, AudacityCommand *client)
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (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 ()
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 

Static Public Member Functions

static VetoDialogHook SetVetoDialogHook (VetoDialogHook hook)
 

Protected Attributes

ProgressDialogmProgress
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 

Private Attributes

bool mIsBatch
 
bool mUIDebug
 
bool mNeedsInit
 

Detailed Description

Base class for command in Audacity.

Definition at line 39 of file AudacityCommand.h.

Member Typedef Documentation

◆ VetoDialogHook

using AudacityCommand::VetoDialogHook = bool (*) ( wxDialog* )

Definition at line 51 of file AudacityCommand.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : long
Enumerator
DefaultMessageBoxStyle 

Definition at line 87 of file AudacityCommand.h.

87 : long { DefaultMessageBoxStyle = wxOK | wxCENTRE };

Constructor & Destructor Documentation

◆ AudacityCommand()

AudacityCommand::AudacityCommand ( )

Definition at line 67 of file AudacityCommand.cpp.

68 {
69  mProgress = NULL;
70  mUIParent = NULL;
71  mUIDialog = NULL;
72  mUIDebug = false;
73  mIsBatch = false;
74  mNeedsInit = true;
75 }

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

◆ ~AudacityCommand()

AudacityCommand::~AudacityCommand ( )
virtual

Definition at line 77 of file AudacityCommand.cpp.

78 {
79  if (mUIDialog)
80  mUIDialog->Close();
81 }

References mUIDialog.

Member Function Documentation

◆ Apply()

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

Definition at line 72 of file AudacityCommand.h.

72 {return false;};

Referenced by DoAudacityCommand(), and EffectUIHost::OnApply().

Here is the caller graph for this function:

◆ CheckWhetherSkipAudacityCommand()

virtual bool AudacityCommand::CheckWhetherSkipAudacityCommand ( )
inlinevirtual

Definition at line 116 of file AudacityCommand.h.

116 { return false; }

Referenced by DoAudacityCommand().

Here is the caller graph for this function:

◆ CreateUI()

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

Definition at line 126 of file AudacityCommand.cpp.

127 {
129  parent, GetName(), this}};
130 
131  if (dlg->Init())
132  {
133  // release() is safe because parent will own it
134  return dlg.release();
135  }
136  return NULL;
137 }

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 182 of file AudacityCommand.cpp.

185 {
186  // Note: Init may read parameters from preferences
187  if (!Init())
188  {
189  return false;
190  }
191 
192  // Prompting will be bypassed when applying a command that has already
193  // been configured, e.g. repeating the last effect on a different selection.
194  // Prompting may call AudacityCommand::Preview
195  if (shouldPrompt && /*IsInteractive() && */!PromptUser(parent))
196  {
197  return false;
198  }
199 
200  auto cleanup = finally( [&] {
201  End();
202  } );
203 
204  bool returnVal = true;
205  bool skipFlag = CheckWhetherSkipAudacityCommand();
206  if (skipFlag == false)
207  {
208  auto name = GetName();
209  ProgressDialog progress{
210  name,
211  XO("Applying %s...").Format( name ),
213  };
214  auto vr = valueRestorer( mProgress, &progress );
215 
216  returnVal = Apply(context);
217  }
218  return returnVal;
219 }

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 121 of file AudacityCommand.h.

121 {;};

Referenced by DoAudacityCommand().

Here is the caller graph for this function:

◆ GetAutomationParameters()

bool AudacityCommand::GetAutomationParameters ( wxString &  parms)
virtual

Definition at line 139 of file AudacityCommand.cpp.

140 {
141  CommandParameters eap;
142 
144  {
145  return false;
146  }
147 
149  S.mpEap = &eap;
150  bool bResult = DefineParams( S );
151  wxASSERT_MSG( bResult, "You did not define DefineParameters() for this command" );
152  static_cast<void>(bResult); // fix unused variable warning in release mode
153 
154  return eap.GetParameters(parms);
155 }

References ComponentInterface::DefineParams(), CommandParameters::GetParameters(), ShuttleParams::mpEap, mUIDialog, and TransferDataFromWindow().

Referenced by EffectManager::GetEffectParameters(), and EffectUIHost::OnApply().

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

◆ GetDescription()

virtual TranslatableString AudacityCommand::GetDescription ( )
inlineoverridevirtual

Implements ComponentInterface.

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

Definition at line 64 of file AudacityCommand.h.

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

References XO.

Referenced by EffectManager::GetCommandTip().

Here is the caller graph for this function:

◆ GetPath()

PluginPath AudacityCommand::GetPath ( )
overridevirtual

Implements ComponentInterface.

Definition at line 84 of file AudacityCommand.cpp.

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

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol AudacityCommand::GetSymbol ( )
overridepure virtual

◆ GetVendor()

VendorSymbol AudacityCommand::GetVendor ( )
overridevirtual

Implements ComponentInterface.

Definition at line 85 of file AudacityCommand.cpp.

85 { return XO("Audacity");}

References XO.

◆ GetVersion()

wxString AudacityCommand::GetVersion ( )
overridevirtual

Implements ComponentInterface.

Definition at line 86 of file AudacityCommand.cpp.

86 { return AUDACITY_VERSION_STRING;}

◆ Init()

bool AudacityCommand::Init ( )
virtual

Definition at line 89 of file AudacityCommand.cpp.

89  {
90  if( !mNeedsInit )
91  return true;
92  mNeedsInit = false;
93  ShuttleDefaults DefaultSettingShuttle;
94  return DefineParams( DefaultSettingShuttle );
95 }

References ComponentInterface::DefineParams(), and mNeedsInit.

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 ( )
inlinevirtual

Definition at line 69 of file AudacityCommand.h.

69 { return mIsBatch;}

Referenced by EffectUIHost::BuildButtonBar(), and PromptUser().

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 241 of file AudacityCommand.cpp.

244 {
245  auto title = titleStr.empty()
246  ? GetName()
247  : XO("%s: %s").Format( GetName(), titleStr );
248  return AudacityMessageBox(message, title, style, mUIParent);
249 }

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

Referenced by SetAutomationParameters().

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 122 of file AudacityCommand.h.

122 {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 222 of file AudacityCommand.cpp.

223 {
224  return ShowInterface(parent, IsBatchProcessing());
225 }

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:

◆ SetAutomationParameters()

bool AudacityCommand::SetAutomationParameters ( const wxString &  parms)
virtual

Definition at line 157 of file AudacityCommand.cpp.

158 {
159  wxString preset = parms;
160 
161  CommandParameters eap(parms);
163 
164  S.SetForWriting( &eap );
165  bool bResult = DefineParams( S );
166  wxASSERT_MSG( bResult, "You did not define DefineParameters() for this command" );
167  static_cast<void>(bResult); // fix unused variable warning in release mode
168  if (!S.bOK)
169  {
171  XO(
172 "%s: Could not load settings below. Default settings will be used.\n\n%s")
173  .Format( GetName(), preset ) );
174 
175  // fror now always succeed, so that we can prompt the user.
176  return true;
177  }
178 
179  return TransferDataToWindow();
180 }

References ShuttleSetAutomation::bOK, ComponentInterface::DefineParams(), ComponentInterface::GetName(), MessageBox(), ShuttleSetAutomation::SetForWriting(), TransferDataToWindow(), and XO.

Referenced by EffectManager::SetEffectParameters().

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 70 of file AudacityCommand.h.

70 { mIsBatch = start;};

Referenced by EffectManager::SetBatchProcessing().

Here is the caller graph for this function:

◆ SetHostUI()

virtual void AudacityCommand::SetHostUI ( EffectUIHostInterface WXUNUSEDhost)
inlinevirtual

Definition at line 75 of file AudacityCommand.h.

75 {;};

◆ SetVetoDialogHook()

auto AudacityCommand::SetVetoDialogHook ( VetoDialogHook  hook)
static

Definition at line 58 of file AudacityCommand.cpp.

60 {
61  auto &theHook = GetVetoDialogHook();
62  auto result = theHook;
63  theHook = hook;
64  return result;
65 }

References anonymous_namespace{AudacityCommand.cpp}::GetVetoDialogHook().

Referenced by ScreenshotCommand::ScreenshotCommand().

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

◆ ShowInterface()

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

Definition at line 97 of file AudacityCommand.cpp.

98 {
99  if (mUIDialog)
100  {
101  if ( mUIDialog->Close(true) )
102  mUIDialog = nullptr;
103  return false;
104  }
105 
106  // mUIDialog is null
107  auto cleanup = valueRestorer( mUIDialog );
108 
109  mUIDialog = CreateUI(parent, this);
110  if (!mUIDialog)
111  return false;
112 
113  mUIDialog->Layout();
114  mUIDialog->Fit();
115  mUIDialog->SetMinSize(mUIDialog->GetSize());
116 
117  // The Screenshot command might be popping this dialog up, just to capture it.
118  auto hook = GetVetoDialogHook();
119  if( hook && hook( mUIDialog ) )
120  return false;
121 
122  bool res = mUIDialog->ShowModal() != 0;
123  return res;
124 }

References CreateUI(), anonymous_namespace{AudacityCommand.cpp}::GetVetoDialogHook(), 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 234 of file AudacityCommand.cpp.

235 {
236  if (mUIParent && (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow()))
237  return false;
238  return true;
239 }

References mUIParent.

Referenced by GetAutomationParameters(), and EffectUIHost::TransferDataFromWindow().

Here is the caller graph for this function:

◆ TransferDataToWindow()

bool AudacityCommand::TransferDataToWindow ( )
virtual

Definition at line 227 of file AudacityCommand.cpp.

228 {
229  if (mUIParent && !mUIParent->TransferDataToWindow())
230  return false;
231  return true;
232 }

References mUIParent.

Referenced by SetAutomationParameters(), and EffectUIHost::TransferDataToWindow().

Here is the caller graph for this function:

Member Data Documentation

◆ mIsBatch

bool AudacityCommand::mIsBatch
private

Definition at line 135 of file AudacityCommand.h.

Referenced by AudacityCommand().

◆ mNeedsInit

bool AudacityCommand::mNeedsInit
private

Definition at line 137 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().

◆ mUIDebug

bool AudacityCommand::mUIDebug
private

Definition at line 136 of file AudacityCommand.h.

Referenced by AudacityCommand().

◆ mUIDialog

wxDialog* AudacityCommand::mUIDialog
protected

◆ mUIParent

wxWindow* AudacityCommand::mUIParent
protected

◆ mUIResultID

int AudacityCommand::mUIResultID
protected

Definition at line 132 of file AudacityCommand.h.


The documentation for this class was generated from the following files:
AudacityCommand::mIsBatch
bool mIsBatch
Definition: AudacityCommand.h:135
ShuttleSetAutomation
Shuttle that sets parameters to a value (from a string)
Definition: Shuttle.h:106
CommandParameters
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
Definition: EffectAutomationParameters.h:67
TranslatableString::empty
bool empty() const
Definition: TranslatableString.h:72
valueRestorer
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:354
anonymous_namespace{AudacityCommand.cpp}::GetVetoDialogHook
AudacityCommand::VetoDialogHook & GetVetoDialogHook()
Definition: AudacityCommand.cpp:50
AudacityCommand::CheckWhetherSkipAudacityCommand
virtual bool CheckWhetherSkipAudacityCommand()
Definition: AudacityCommand.h:116
AudacityCommand::PromptUser
virtual bool PromptUser(wxWindow *parent)
Definition: AudacityCommand.cpp:222
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Definition: AudacityMessageBox.cpp:17
AudacityCommand::End
virtual void End()
Definition: AudacityCommand.h:121
pdlgHideStopButton
@ pdlgHideStopButton
Definition: ProgressDialog.h:38
Format
Abstract base class used in importing a file.
AudacityCommand::mUIParent
wxWindow * mUIParent
Definition: AudacityCommand.h:131
ShuttleDefaults
Shuttle that sets parameters to their default values.
Definition: Shuttle.h:131
XO
#define XO(s)
Definition: Internat.h:31
CommandParameters::GetParameters
bool GetParameters(wxString &parms)
Definition: EffectAutomationParameters.h:258
AudacityCommand::MessageBox
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
Definition: AudacityCommand.cpp:241
AudacityCommand::mUIDialog
wxDialog * mUIDialog
Definition: AudacityCommand.h:130
AudacityCommand::IsBatchProcessing
virtual bool IsBatchProcessing()
Definition: AudacityCommand.h:69
AudacityCommand::mNeedsInit
bool mNeedsInit
Definition: AudacityCommand.h:137
ShuttleParams::mpEap
CommandParameters * mpEap
Definition: Shuttle.h:66
ProgressDialog
ProgressDialog Class.
Definition: ProgressDialog.h:51
AudacityCommand::ShowInterface
bool ShowInterface(wxWindow *parent, bool forceModal=false)
Definition: AudacityCommand.cpp:97
ShuttleGetAutomation
Shuttle that gets parameter values into a string.
Definition: Shuttle.h:88
AudacityCommand::Apply
virtual bool Apply(const CommandContext &WXUNUSED(context))
Definition: AudacityCommand.h:72
AudacityCommand::GetSymbol
ComponentInterfaceSymbol GetSymbol() override=0
AudacityCommand::DefaultMessageBoxStyle
@ DefaultMessageBoxStyle
Definition: AudacityCommand.h:87
name
const TranslatableString name
Definition: Distortion.cpp:98
AudacityCommand::mProgress
ProgressDialog * mProgress
Definition: AudacityCommand.h:128
AudacityCommand::CreateUI
wxDialog * CreateUI(wxWindow *parent, AudacityCommand *client)
Definition: AudacityCommand.cpp:126
AudacityCommand::Init
virtual bool Init()
Definition: AudacityCommand.cpp:89
title
static const auto title
Definition: NoUpdatesAvailableDialog.cpp:22
AudacityCommandDialog
Default dialog used for commands. Is populated using ShuttleGui.
Definition: AudacityCommand.h:143
BUILTIN_GENERIC_COMMAND_PREFIX
#define BUILTIN_GENERIC_COMMAND_PREFIX
Definition: AudacityCommand.h:30
ComponentInterfaceSymbol::Internal
const wxString & Internal() const
Definition: ComponentInterfaceSymbol.h:55
ShuttleSetAutomation::bOK
bool bOK
Definition: Shuttle.h:108
ComponentInterface::GetName
TranslatableString GetName()
Definition: PluginManager.cpp:2083
Destroy_ptr
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:290
safenew
#define safenew
Definition: MemoryX.h:10
ComponentInterface::DefineParams
virtual bool DefineParams(ShuttleParams &WXUNUSED(S))
Definition: ComponentInterface.h:85
AudacityCommand::mUIDebug
bool mUIDebug
Definition: AudacityCommand.h:136
ShuttleSetAutomation::SetForWriting
void SetForWriting(CommandParameters *pEap)
Definition: Shuttle.h:114
AudacityCommand::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: AudacityCommand.cpp:227
AudacityCommand::TransferDataFromWindow
virtual bool TransferDataFromWindow()
Definition: AudacityCommand.cpp:234