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

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

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

Definition at line 75 of file AudacityCommand.cpp.

References mUIDialog.

76 {
77  if (mUIDialog)
78  mUIDialog->Close();
79 }
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 87 of file AudacityCommand.cpp.

References GetActiveProject().

Referenced by DoAudacityCommand().

87  {
89  const CommandContext context( *pProj );
90  return Apply( context );
91 };
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 129 of file AudacityCommand.cpp.

References IdentInterface::GetTranslatedName(), and safenew.

Referenced by ShowInterface().

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

Definition at line 188 of file AudacityCommand.cpp.

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

Referenced by EffectManager::DoAudacityCommand().

191 {
192  // Note: Init may read parameters from preferences
193  if (!Init())
194  {
195  return false;
196  }
197 
198  // Prompting will be bypassed when applying a command that has already
199  // been configured, e.g. repeating the last effect on a different selection.
200  // Prompting may call AudacityCommand::Preview
201  if (shouldPrompt && /*IsInteractive() && */!PromptUser(parent))
202  {
203  return false;
204  }
205 
206  auto cleanup = finally( [&] {
207  End();
208  } );
209 
210  bool returnVal = true;
211  bool skipFlag = CheckWhetherSkipAudacityCommand();
212  if (skipFlag == false)
213  {
214  auto name = GetTranslatedName();
215  ProgressDialog progress{
216  name,
217  wxString::Format(_("Applying %s..."), name),
219  };
220  auto vr = valueRestorer( mProgress, &progress );
221 
222  returnVal = Apply(context);
223  }
224  return returnVal;
225 }
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:494
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 142 of file AudacityCommand.cpp.

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

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

143 {
144  CommandParameters eap;
145 
147  {
148  return false;
149  }
150 
152  S.mpEap = &eap;
153  bool bResult = DefineParams( S );
154  wxASSERT_MSG( bResult, "You did not define DefineParameters() for this command" );
155  static_cast<void>(bResult); // fix unused variable warning in release mode
156 
157  return eap.GetParameters(parms);
158 }
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 82 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 83 of file AudacityCommand.cpp.

References XO.

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

Implements IdentInterface.

Definition at line 84 of file AudacityCommand.cpp.

References AUDACITY_VERSION_STRING.

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

Definition at line 93 of file AudacityCommand.cpp.

References ParamsInterface::DefineParams(), and mNeedsInit.

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

93  {
94  if( !mNeedsInit )
95  return true;
96  mNeedsInit = false;
97  ShuttleDefaults DefaultSettingShuttle;
98  return DefineParams( DefaultSettingShuttle );
99 }
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 247 of file AudacityCommand.cpp.

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

Referenced by SetAutomationParameters().

248 {
249  wxString title;
250  if (titleStr.empty())
251  title = GetTranslatedName();
252  else
253  title = wxString::Format(_("%s: %s"), GetTranslatedName(), titleStr);
254  return AudacityMessageBox(message, title, style, mUIParent);
255 }
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 228 of file AudacityCommand.cpp.

References IsBatchProcessing(), and ShowInterface().

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

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

Definition at line 160 of file AudacityCommand.cpp.

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

Referenced by EffectManager::SetEffectParameters().

161 {
162  wxString preset = parms;
163 
164  CommandParameters eap(parms);
166 
167  S.SetForWriting( &eap );
168  bool bResult = DefineParams( S );
169  wxASSERT_MSG( bResult, "You did not define DefineParameters() for this command" );
170  static_cast<void>(bResult); // fix unused variable warning in release mode
171  if (!S.bOK)
172  {
174  wxString::Format(
175  _("%s: Could not load settings below. Default settings will be used.\n\n%s"),
177  preset
178  )
179  );
180 
181  // fror now always succeed, so that we can prompt the user.
182  return true;
183  }
184 
185  return TransferDataToWindow();
186 }
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 101 of file AudacityCommand.cpp.

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

Referenced by PromptUser().

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

Definition at line 240 of file AudacityCommand.cpp.

References mUIParent.

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

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

Definition at line 233 of file AudacityCommand.cpp.

References mUIParent.

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

234 {
235  if (mUIParent && !mUIParent->TransferDataToWindow())
236  return false;
237  return true;
238 }
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: