Audacity  2.2.2
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:
CommandDefinitionInterface IdentInterface ParamsInterface CompareAudioCommand DemoCommand DragCommand ExportCommand GetInfoCommand GetPreferenceCommand GetTrackInfoCommand HelpCommand ImportCommand MessageCommand OldStyleCommandType OpenProjectCommand SaveProjectCommand ScreenshotCommand SelectCommand SelectFrequenciesCommand SelectTimeCommand SelectTracksCommand SetLabelCommand SetPreferenceCommand SetProjectCommand SetTrackBase

Public Types

enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 

Public Member Functions

 AudacityCommand ()
 
virtual ~AudacityCommand ()
 
wxString GetPath () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () override
 
IdentInterfaceSymbol GetSymbol () override=0
 
virtual wxString GetDescription () override
 
virtual wxString ManualPage ()
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
virtual bool Apply (const CommandContext &WXUNUSED(context))
 
virtual bool Apply ()
 
bool ShowInterface (wxWindow *parent, bool forceModal=false)
 
virtual void SetHostUI (EffectUIHostInterface *WXUNUSED(host))
 
bool PopulateUI (wxWindow *parent)
 
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 wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
 
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 CommandDefinitionInterface
virtual ~CommandDefinitionInterface ()
 
- Public Member Functions inherited from IdentInterface
virtual ~IdentInterface ()
 
const wxString & GetTranslatedName ()
 
- Public Member Functions inherited from ParamsInterface
virtual ~ParamsInterface ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 

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

Member Enumeration Documentation

anonymous enum : long
Enumerator
DefaultMessageBoxStyle 

Definition at line 98 of file AudacityCommand.h.

Constructor & Destructor Documentation

AudacityCommand::AudacityCommand ( )

Definition at line 67 of file AudacityCommand.cpp.

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

68 {
69  mProgress = NULL;
70  mUIParent = NULL;
71  mUIDialog = NULL;
72  mUIDebug = false;
73  mIsBatch = false;
74  mNeedsInit = true;
75 }
wxWindow * mUIParent
wxDialog * mUIDialog
ProgressDialog * mProgress
AudacityCommand::~AudacityCommand ( )
virtual

Definition at line 77 of file AudacityCommand.cpp.

References mUIDialog.

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

Member Function Documentation

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

Definition at line 81 of file AudacityCommand.h.

Referenced by EffectUIHost::OnApply().

81 {return false;};
bool AudacityCommand::Apply ( )
virtual

Reimplemented in CompareAudioCommand.

Definition at line 89 of file AudacityCommand.cpp.

References GetActiveProject().

Referenced by DoAudacityCommand().

89  {
91  const CommandContext context( *pProj );
92  return Apply( context );
93 };
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
virtual bool Apply()
virtual bool AudacityCommand::CheckWhetherSkipAudacityCommand ( )
inlinevirtual

Definition at line 127 of file AudacityCommand.h.

Referenced by DoAudacityCommand().

127 { return false; }
wxDialog * AudacityCommand::CreateUI ( wxWindow *  parent,
AudacityCommand client 
)

Definition at line 131 of file AudacityCommand.cpp.

References IdentInterface::GetTranslatedName(), and safenew.

Referenced by ShowInterface().

132 {
134  parent, GetTranslatedName(), this}};
135 
136  if (dlg->Init())
137  {
138  // release() is safe because parent will own it
139  return dlg.release();
140  }
141  return NULL;
142 }
#define safenew
Definition: Audacity.h:230
const wxString & GetTranslatedName()
std::unique_ptr< T, Destroyer< T >> Destroy_ptr
Definition: MemoryX.h:835
Default dialog used for commands. Is populated using ShuttleGui.
bool AudacityCommand::DoAudacityCommand ( wxWindow *  parent,
const CommandContext context,
bool  shouldPrompt = true 
)

Definition at line 190 of file AudacityCommand.cpp.

References _(), Apply(), CheckWhetherSkipAudacityCommand(), End(), IdentInterface::GetTranslatedName(), Init(), mProgress, name, pdlgHideStopButton, PromptUser(), and valueRestorer().

Referenced by EffectManager::DoAudacityCommand().

193 {
194  // Note: Init may read parameters from preferences
195  if (!Init())
196  {
197  return false;
198  }
199 
200  // Prompting will be bypassed when applying a command that has already
201  // been configured, e.g. repeating the last effect on a different selection.
202  // Prompting may call AudacityCommand::Preview
203  if (shouldPrompt && /*IsInteractive() && */!PromptUser(parent))
204  {
205  return false;
206  }
207 
208  auto cleanup = finally( [&] {
209  End();
210  } );
211 
212  bool returnVal = true;
213  bool skipFlag = CheckWhetherSkipAudacityCommand();
214  if (skipFlag == false)
215  {
216  auto name = GetTranslatedName();
217  ProgressDialog progress{
218  name,
219  wxString::Format(_("Applying %s..."), name),
221  };
222  auto vr = valueRestorer( mProgress, &progress );
223 
224  returnVal = Apply(context);
225  }
226  return returnVal;
227 }
virtual bool CheckWhetherSkipAudacityCommand()
virtual bool PromptUser(wxWindow *parent)
virtual void End()
ProgressDialog Class.
ProgressDialog * mProgress
virtual bool Init()
const wxString & GetTranslatedName()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
ValueRestorer< T > valueRestorer(T &var)
Definition: MemoryX.h:896
const wxChar * name
Definition: Distortion.cpp:94
virtual bool Apply()
virtual void AudacityCommand::End ( )
inlinevirtual

Definition at line 132 of file AudacityCommand.h.

Referenced by DoAudacityCommand().

132 {;};
bool AudacityCommand::GetAutomationParameters ( wxString &  parms)
virtual

Definition at line 144 of file AudacityCommand.cpp.

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

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

145 {
146  CommandParameters eap;
147 
149  {
150  return false;
151  }
152 
154  S.mpEap = &eap;
155  bool bResult = DefineParams( S );
156  wxASSERT_MSG( bResult, "You did not define DefineParameters() for this command" );
157  static_cast<void>(bResult); // fix unused variable warning in release mode
158 
159  return eap.GetParameters(parms);
160 }
Shuttle that gets parameter values into a string.
Definition: Shuttle.h:87
wxDialog * mUIDialog
CommandParameters * mpEap
Definition: Shuttle.h:65
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
bool GetParameters(wxString &parms)
virtual bool DefineParams(ShuttleParams &WXUNUSED(S))
virtual bool TransferDataFromWindow()
virtual wxString AudacityCommand::GetDescription ( )
inlineoverridevirtual
wxString AudacityCommand::GetPath ( )
overridevirtual

Implements IdentInterface.

Definition at line 84 of file AudacityCommand.cpp.

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

#define BUILTIN_GENERIC_COMMAND_PREFIX
IdentInterfaceSymbol GetSymbol() override=0
const wxString & Internal() const
IdentInterfaceSymbol AudacityCommand::GetSymbol ( )
overridepure virtual
IdentInterfaceSymbol AudacityCommand::GetVendor ( )
overridevirtual

Implements IdentInterface.

Definition at line 85 of file AudacityCommand.cpp.

References XO.

85 { return XO("Audacity");}
#define XO(s)
Definition: Internat.h:33
wxString AudacityCommand::GetVersion ( )
overridevirtual

Implements IdentInterface.

Definition at line 86 of file AudacityCommand.cpp.

References AUDACITY_VERSION_STRING.

86 { return AUDACITY_VERSION_STRING;}
#define AUDACITY_VERSION_STRING
Definition: Audacity.h:81
bool AudacityCommand::Init ( )
virtual

Definition at line 95 of file AudacityCommand.cpp.

References ParamsInterface::DefineParams(), and mNeedsInit.

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

95  {
96  if( !mNeedsInit )
97  return true;
98  mNeedsInit = false;
99  ShuttleDefaults DefaultSettingShuttle;
100  return DefineParams( DefaultSettingShuttle );
101 }
Shuttle that sets parameters to their default values.
Definition: Shuttle.h:151
virtual bool DefineParams(ShuttleParams &WXUNUSED(S))
virtual bool AudacityCommand::IsBatchProcessing ( )
inlinevirtual

Definition at line 78 of file AudacityCommand.h.

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

78 { return mIsBatch;}
virtual wxString AudacityCommand::ManualPage ( )
inlinevirtual
int AudacityCommand::MessageBox ( const wxString &  message,
long  style = DefaultMessageBoxStyle,
const wxString &  titleStr = wxString{} 
)

Definition at line 249 of file AudacityCommand.cpp.

References _(), AudacityMessageBox(), IdentInterface::GetTranslatedName(), and mUIParent.

Referenced by SetAutomationParameters().

250 {
251  wxString title;
252  if (titleStr.empty())
253  title = GetTranslatedName();
254  else
255  title = wxString::Format(_("%s: %s"), GetTranslatedName(), titleStr);
256  return AudacityMessageBox(message, title, style, mUIParent);
257 }
wxWindow * mUIParent
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
const wxString & GetTranslatedName()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
virtual void AudacityCommand::PopulateOrExchange ( ShuttleGui WXUNUSEDS)
inlinevirtual

Definition at line 133 of file AudacityCommand.h.

Referenced by _(), and AudacityCommandDialog::PopulateOrExchange().

133 {return;};
bool AudacityCommand::PopulateUI ( wxWindow *  parent)
bool AudacityCommand::PromptUser ( wxWindow *  parent)
virtual

Definition at line 230 of file AudacityCommand.cpp.

References IsBatchProcessing(), and ShowInterface().

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

231 {
232  return ShowInterface(parent, IsBatchProcessing());
233 }
virtual bool IsBatchProcessing()
bool ShowInterface(wxWindow *parent, bool forceModal=false)
bool AudacityCommand::SetAutomationParameters ( const wxString &  parms)
virtual

Definition at line 162 of file AudacityCommand.cpp.

References _(), ShuttleSetAutomation::bOK, ParamsInterface::DefineParams(), IdentInterface::GetTranslatedName(), MessageBox(), ShuttleSetAutomation::SetForWriting(), and TransferDataToWindow().

Referenced by EffectManager::SetEffectParameters().

163 {
164  wxString preset = parms;
165 
166  CommandParameters eap(parms);
168 
169  S.SetForWriting( &eap );
170  bool bResult = DefineParams( S );
171  wxASSERT_MSG( bResult, "You did not define DefineParameters() for this command" );
172  static_cast<void>(bResult); // fix unused variable warning in release mode
173  if (!S.bOK)
174  {
176  wxString::Format(
177  _("%s: Could not load settings below. Default settings will be used.\n\n%s"),
179  preset
180  )
181  );
182 
183  // fror now always succeed, so that we can prompt the user.
184  return true;
185  }
186 
187  return TransferDataToWindow();
188 }
void SetForWriting(CommandParameters *pEap)
Definition: Shuttle.h:114
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
const wxString & GetTranslatedName()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
virtual bool DefineParams(ShuttleParams &WXUNUSED(S))
Shuttle that sets parameters to a value (from a string)
Definition: Shuttle.h:105
virtual bool TransferDataToWindow()
virtual void AudacityCommand::SetBatchProcessing ( bool  start)
inlinevirtual

Definition at line 79 of file AudacityCommand.h.

Referenced by EffectManager::SetBatchProcessing().

79 { mIsBatch = start;};
virtual void AudacityCommand::SetHostUI ( EffectUIHostInterface WXUNUSEDhost)
inlinevirtual

Definition at line 85 of file AudacityCommand.h.

85 {;};
bool AudacityCommand::ShowInterface ( wxWindow *  parent,
bool  forceModal = false 
)

Definition at line 103 of file AudacityCommand.cpp.

References CreateUI(), ScreenshotCommand::MayCapture(), mUIDialog, and valueRestorer().

Referenced by PromptUser().

104 {
105  if (mUIDialog)
106  {
107  if ( mUIDialog->Close(true) )
108  mUIDialog = nullptr;
109  return false;
110  }
111 
112  // mUIDialog is null
113  auto cleanup = valueRestorer( mUIDialog );
114 
115  mUIDialog = CreateUI(parent, this);
116  if (!mUIDialog)
117  return false;
118 
119  mUIDialog->Layout();
120  mUIDialog->Fit();
121  mUIDialog->SetMinSize(mUIDialog->GetSize());
122 
123  // The Screenshot command might be popping this dialog up, just to capture it.
125  return false;
126 
127  bool res = mUIDialog->ShowModal() != 0;
128  return res;
129 }
wxDialog * mUIDialog
wxDialog * CreateUI(wxWindow *parent, AudacityCommand *client)
ValueRestorer< T > valueRestorer(T &var)
Definition: MemoryX.h:896
static bool MayCapture(wxDialog *pDlg)
bool AudacityCommand::TransferDataFromWindow ( )
virtual

Definition at line 242 of file AudacityCommand.cpp.

References mUIParent.

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

243 {
244  if (mUIParent && (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow()))
245  return false;
246  return true;
247 }
wxWindow * mUIParent
bool AudacityCommand::TransferDataToWindow ( )
virtual

Definition at line 235 of file AudacityCommand.cpp.

References mUIParent.

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

236 {
237  if (mUIParent && !mUIParent->TransferDataToWindow())
238  return false;
239  return true;
240 }
wxWindow * mUIParent

Member Data Documentation

bool AudacityCommand::mIsBatch
private

Definition at line 146 of file AudacityCommand.h.

Referenced by AudacityCommand().

bool AudacityCommand::mNeedsInit
private

Definition at line 148 of file AudacityCommand.h.

Referenced by AudacityCommand(), and Init().

ProgressDialog* AudacityCommand::mProgress
protected

Definition at line 139 of file AudacityCommand.h.

Referenced by AudacityCommand(), and DoAudacityCommand().

bool AudacityCommand::mUIDebug
private

Definition at line 147 of file AudacityCommand.h.

Referenced by AudacityCommand().

wxDialog* AudacityCommand::mUIDialog
protected
wxWindow* AudacityCommand::mUIParent
protected
int AudacityCommand::mUIResultID
protected

Definition at line 143 of file AudacityCommand.h.


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