Audacity  3.0.3
Nyquist.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Nyquist.h
6 
7  Dominic Mazzoni
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_EFFECT_NYQUIST__
12 #define __AUDACITY_EFFECT_NYQUIST__
13 
14 #include "../Effect.h"
15 #include "FileNames.h"
16 
17 #include "nyx.h"
18 
19 class wxArrayString;
20 class wxFileName;
21 class wxCheckBox;
22 class wxTextCtrl;
23 
24 #define NYQUISTEFFECTS_VERSION wxT("1.0.0.0")
25 
27 {
37 };
38 
40 {
41 public:
42  NyqControl() = default;
43  NyqControl( const NyqControl& ) = default;
44  NyqControl &operator = ( const NyqControl & ) = default;
45  //NyqControl( NyqControl && ) = default;
46  //NyqControl &operator = ( NyqControl && ) = default;
47 
48  int type;
49  wxString var;
50  wxString name;
51  wxString label;
52  std::vector<EnumValueSymbol> choices;
54  wxString valStr;
55  wxString lowStr;
56  wxString highStr;
57  double val;
58  double low;
59  double high;
60  int ticks;
61 };
62 
63 
64 class AUDACITY_DLL_API NyquistEffect final : public Effect
65 {
66 public:
67 
71  NyquistEffect(const wxString &fName);
72  virtual ~NyquistEffect();
73 
74  // ComponentInterface implementation
75 
76  PluginPath GetPath() override;
78  VendorSymbol GetVendor() override;
79  wxString GetVersion() override;
81 
82  ManualPageID ManualPage() override;
83  FilePath HelpPage() override;
84 
85  // EffectDefinitionInterface implementation
86 
87  EffectType GetType() override;
88  EffectType GetClassification() override;
89  EffectFamilySymbol GetFamily() override;
90  bool IsInteractive() override;
91  bool IsDefault() override;
92 
93  // EffectClientInterface implementation
94 
95  bool DefineParams( ShuttleParams & S ) override;
96  bool GetAutomationParameters(CommandParameters & parms) override;
97  bool SetAutomationParameters(CommandParameters & parms) override;
98  int SetLispVarsFromParameters(CommandParameters & parms, bool bTestOnly);
99 
100  // Effect implementation
101 
102  bool Init() override;
103  bool CheckWhetherSkipEffect() override;
104  bool Process() override;
105  bool ShowInterface( wxWindow &parent,
106  const EffectDialogFactory &factory, bool forceModal = false) override;
107  void PopulateOrExchange(ShuttleGui & S) override;
108  bool TransferDataToWindow() override;
109  bool TransferDataFromWindow() override;
110 
111  // NyquistEffect implementation
112  // For Nyquist Workbench support
113  void RedirectOutput();
114  void SetCommand(const wxString &cmd);
115  void Continue();
116  void Break();
117  void Stop();
118 
119 private:
120  static int mReentryCount;
121  // NyquistEffect implementation
122 
123  bool ProcessOne();
124 
125  void BuildPromptWindow(ShuttleGui & S);
126  void BuildEffectWindow(ShuttleGui & S);
127 
128  bool TransferDataToPromptWindow();
129  bool TransferDataToEffectWindow();
130 
131  bool TransferDataFromPromptWindow();
132  bool TransferDataFromEffectWindow();
133 
134  bool IsOk();
135  const TranslatableString &InitializationError() const { return mInitError; }
136 
137  static FilePaths GetNyquistSearchPath();
138 
139  static wxString NyquistToWxString(const char *nyqString);
140  wxString EscapeString(const wxString & inStr);
141  static std::vector<EnumValueSymbol> ParseChoice(const wxString & text);
142 
143  FileExtensions ParseFileExtensions(const wxString & text);
144  FileNames::FileType ParseFileType(const wxString & text);
145  FileNames::FileTypes ParseFileTypes(const wxString & text);
146 
147  static int StaticGetCallback(float *buffer, int channel,
148  int64_t start, int64_t len, int64_t totlen,
149  void *userdata);
150  static int StaticPutCallback(float *buffer, int channel,
151  int64_t start, int64_t len, int64_t totlen,
152  void *userdata);
153  static void StaticOutputCallback(int c, void *userdata);
154  static void StaticOSCallback(void *userdata);
155 
156  int GetCallback(float *buffer, int channel,
157  int64_t start, int64_t len, int64_t totlen);
158  int PutCallback(float *buffer, int channel,
159  int64_t start, int64_t len, int64_t totlen);
160  void OutputCallback(int c);
161  void OSCallback();
162 
163  void ParseFile();
164  bool ParseCommand(const wxString & cmd);
165  bool ParseProgram(wxInputStream & stream);
166  struct Tokenizer {
167  bool sl { false };
168  bool q { false };
169  int paren{ 0 };
170  wxString tok;
172 
173  bool Tokenize(
174  const wxString &line, bool eof,
175  size_t trimStart, size_t trimEnd);
176  };
177  bool Parse(Tokenizer &tokenizer, const wxString &line, bool eof, bool first);
178 
179  static TranslatableString UnQuoteMsgid(const wxString &s, bool allowParens = true,
180  wxString *pExtraString = nullptr);
181  static wxString UnQuote(const wxString &s, bool allowParens = true,
182  wxString *pExtraString = nullptr);
183  double GetCtrlValue(const wxString &s);
184 
185  void OnLoad(wxCommandEvent & evt);
186  void OnSave(wxCommandEvent & evt);
187  void OnDebug(wxCommandEvent & evt);
188 
189  void OnText(wxCommandEvent & evt);
190  void OnSlider(wxCommandEvent & evt);
191  void OnChoice(wxCommandEvent & evt);
192  void OnTime(wxCommandEvent & evt);
193  void OnFileButton(wxCommandEvent & evt);
194 
195  void resolveFilePath(wxString & path, FileExtension extension = {});
196  bool validatePath(wxString path);
197  wxString ToTimeFormat(double t);
198 
199 private:
200 
201  wxString mXlispPath;
202 
203  wxFileName mFileName;
204  wxDateTime mFileModified;
205 
206  bool mStop;
207  bool mBreak;
208  bool mCont;
209 
211  bool mCompiler;
212  bool mTrace; // True when *tracenable* or *sal-traceback* are enabled
213  bool mIsSal;
214  bool mExternal;
216  bool mIsTool;
221  bool mIsPrompt;
222  bool mOK;
224  wxString mInputCmd; // history: exactly what the user typed
225  wxString mParameters; // The parameters of to be fed to a nested prompt
226  wxString mCmd; // the command to be processed
228  TranslatableString mPromptName; // If a prompt, we need to remember original name.
232  // Version number of the specific plug-in (not to be confused with mVersion)
233  // For shipped plug-ins this will be the same as the Audacity release version
234  // when the plug-in was last modified.
237  wxString mManPage; // ONLY use if a help page exists in the manual.
238  wxString mHelpFile;
241  EffectType mPromptType; // If a prompt, need to remember original type.
242 
244  bool mDebugButton; // Set to false to disable Debug button.
245 
246  bool mDebug; // When true, debug window is shown.
249  wxString mDebugOutputStr;
251 
252  int mVersion; // Syntactic version of Nyquist plug-in (not to be confused with mReleaseVersion)
253  std::vector<NyqControl> mControls;
254 
255  unsigned mCurNumChannels;
256  WaveTrack *mCurTrack[2];
257  sampleCount mCurStart[2];
262  double mOutputTime;
263  unsigned mCount;
265  double mProgressIn;
266  double mProgressOut;
267  double mProgressTot;
268  double mScale;
269 
270  using Buffer = std::unique_ptr<float[]>;
271  Buffer mCurBuffer[2];
272  sampleCount mCurBufferStart[2];
273  size_t mCurBufferLen[2];
274 
275  WaveTrack *mOutputTrack[2];
276 
277  wxArrayString mCategories;
278 
279  wxString mProps;
280  wxString mPerTrackProps;
281 
284 
285  wxTextCtrl *mCommandText;
286 
287  std::exception_ptr mpException {};
288 
289  DECLARE_EVENT_TABLE()
290 
291  friend class NyquistEffectsModule;
292 };
293 
295 {
296 public:
297  NyquistOutputDialog(wxWindow * parent, wxWindowID id,
298  const TranslatableString & title,
299  const TranslatableString & prompt,
300  const TranslatableString &message);
301 
302 private:
303  void OnOk(wxCommandEvent & event);
304 
305 private:
306  DECLARE_EVENT_TABLE()
307 };
308 
309 
310 #endif
Effect::GetAutomationParameters
bool GetAutomationParameters(CommandParameters &parms) override
Definition: Effect.cpp:534
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
CommandParameters
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
Definition: EffectAutomationParameters.h:67
NyquistEffect::mTrackIndex
int mTrackIndex
Definition: Nyquist.h:260
NyquistEffect::mMaxLen
sampleCount mMaxLen
Definition: Nyquist.h:259
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
NyquistEffect::mXlispPath
wxString mXlispPath
Definition: Nyquist.h:201
NyquistEffect::mProgressIn
double mProgressIn
Definition: Nyquist.h:265
Effect::IsInteractive
bool IsInteractive() override
Definition: Effect.cpp:205
NyquistEffect::mInputCmd
wxString mInputCmd
Definition: Nyquist.h:224
Effect::ManualPage
virtual ManualPageID ManualPage()
Definition: Effect.cpp:1172
NyquistEffect::mStop
bool mStop
Definition: Nyquist.h:206
NyquistEffect::mTrace
bool mTrace
Definition: Nyquist.h:212
NyquistEffect::mHelpFileExists
bool mHelpFileExists
Definition: Nyquist.h:239
NYQ_CTRL_STRING
@ NYQ_CTRL_STRING
Definition: Nyquist.h:30
NyquistEffect
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class.
Definition: Nyquist.h:65
Effect::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: Effect.cpp:1916
NyquistEffect::mInitError
TranslatableString mInitError
Definition: Nyquist.h:223
NyquistEffect::mBreak
bool mBreak
Definition: Nyquist.h:207
NyquistEffect::InitializationError
const TranslatableString & InitializationError() const
Definition: Nyquist.h:135
NyquistEffect::mEnablePreview
bool mEnablePreview
Definition: Nyquist.h:243
Effect
Base class for many of the effects in Audacity.
Definition: Effect.h:72
NyqControl::lowStr
wxString lowStr
Definition: Nyquist.h:55
PluginPath
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
NyquistEffectsModule
Definition: LoadNyquist.h:22
NyquistEffect::mDebug
bool mDebug
Definition: Nyquist.h:246
NyquistEffect::mFirstInGroup
bool mFirstInGroup
Definition: Nyquist.h:261
NyqControlType
NyqControlType
Definition: Nyquist.h:27
Effect::SetAutomationParameters
bool SetAutomationParameters(CommandParameters &parms) override
Definition: Effect.cpp:544
NyquistEffect::Tokenizer::tok
wxString tok
Definition: Nyquist.h:170
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
NyquistEffect::mDebugOutput
TranslatableString mDebugOutput
Definition: Nyquist.h:250
NyquistEffect::mCont
bool mCont
Definition: Nyquist.h:208
NYQ_CTRL_FILE
@ NYQ_CTRL_FILE
Definition: Nyquist.h:36
NyquistEffect::mCategories
wxArrayString mCategories
Definition: Nyquist.h:277
NyqControl::choices
std::vector< EnumValueSymbol > choices
Definition: Nyquist.h:52
NyquistEffect::mParameters
wxString mParameters
Definition: Nyquist.h:225
NyqControl::high
double high
Definition: Nyquist.h:59
NyquistEffect::mRestoreSplits
bool mRestoreSplits
Definition: Nyquist.h:282
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
NyquistEffect::mFileModified
wxDateTime mFileModified
When the script was last modified on disk.
Definition: Nyquist.h:204
Effect::TransferDataFromWindow
virtual bool TransferDataFromWindow()
Definition: Effect.cpp:1921
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
NyqControl::val
double val
Definition: Nyquist.h:57
NyquistEffect::mReleaseVersion
TranslatableString mReleaseVersion
Definition: Nyquist.h:235
NyquistEffect::mType
EffectType mType
Definition: Nyquist.h:240
NyquistEffect::mNumSelectedChannels
unsigned mNumSelectedChannels
Definition: Nyquist.h:264
NyquistEffect::mIsSpectral
bool mIsSpectral
Definition: Nyquist.h:215
NYQ_CTRL_TIME
@ NYQ_CTRL_TIME
Definition: Nyquist.h:35
NyquistEffect::mInfo
TranslatableString mInfo
Definition: Nyquist.h:230
NyqControl::highStr
wxString highStr
Definition: Nyquist.h:56
FileExtension
wxString FileExtension
File extension, not including any leading dot.
Definition: Identifier.h:224
NyquistEffect::Tokenizer
Definition: Nyquist.h:166
NyquistEffect::Buffer
std::unique_ptr< float[]> Buffer
Definition: Nyquist.h:270
NyquistEffect::mPerTrackProps
wxString mPerTrackProps
Definition: Nyquist.h:280
NyquistEffect::mName
TranslatableString mName
Name of the Effect (untranslated)
Definition: Nyquist.h:227
NyquistEffect::mScale
double mScale
Definition: Nyquist.h:268
Effect::PopulateOrExchange
virtual void PopulateOrExchange(ShuttleGui &S)
Definition: Effect.cpp:1911
FilePath
wxString FilePath
Definition: Project.h:20
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:817
NyquistEffect::mControls
std::vector< NyqControl > mControls
Definition: Nyquist.h:253
NyquistEffect::mProjectChanged
bool mProjectChanged
Definition: Nyquist.h:248
NYQ_CTRL_INT
@ NYQ_CTRL_INT
Definition: Nyquist.h:28
NyqControl::operator=
NyqControl & operator=(const NyqControl &)=default
NyquistEffect::mProgressOut
double mProgressOut
Definition: Nyquist.h:266
NyquistEffect::mCopyright
TranslatableString mCopyright
Definition: Nyquist.h:236
NyquistEffect::mCompiler
bool mCompiler
Definition: Nyquist.h:211
Effect::GetType
EffectType GetType() override
Definition: Effect.cpp:133
NyquistEffect::mIsSal
bool mIsSal
Definition: Nyquist.h:213
Effect::CheckWhetherSkipEffect
virtual bool CheckWhetherSkipEffect()
Definition: Effect.h:299
NyquistEffect::mPromptName
TranslatableString mPromptName
Definition: Nyquist.h:228
NyqControl::ticks
int ticks
Definition: Nyquist.h:60
NyquistEffect::mPromptType
EffectType mPromptType
Definition: Nyquist.h:241
NyquistEffect::mAction
TranslatableString mAction
Definition: Nyquist.h:229
NyquistEffect::mIsPrompt
bool mIsPrompt
Definition: Nyquist.h:221
NyqControl::type
int type
Definition: Nyquist.h:48
anonymous_namespace{LogWindow.cpp}::OnSave
void OnSave(wxCommandEvent &e)
NyqControl
A control on a NyquistDialog.
Definition: Nyquist.h:40
Effect::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: Effect.cpp:153
NyquistEffect::mFileName
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: Nyquist.h:203
NYQ_CTRL_TEXT
@ NYQ_CTRL_TEXT
Definition: Nyquist.h:34
EffectClientInterface::EffectDialogFactory
std::function< wxDialog *(wxWindow &parent, EffectHostInterface *, EffectUIClientInterface *) > EffectDialogFactory
Definition: EffectInterface.h:190
NyquistEffect::mIsTool
bool mIsTool
Definition: Nyquist.h:216
NyquistEffect::mHelpFile
wxString mHelpFile
Definition: Nyquist.h:238
NyquistEffect::OnDebug
void OnDebug(wxCommandEvent &evt)
NyquistEffect::mManPage
wxString mManPage
Definition: Nyquist.h:237
EffectDefinitionInterface::GetClassification
virtual EffectType GetClassification()
Definition: EffectInterface.h:83
NyquistEffect::mProgressTot
double mProgressTot
Definition: Nyquist.h:267
Effect::Init
virtual bool Init()
Definition: Effect.cpp:1351
Effect::GetVendor
VendorSymbol GetVendor() override
Definition: Effect.cpp:163
NYQ_CTRL_FLOAT
@ NYQ_CTRL_FLOAT
Definition: Nyquist.h:29
wxDialogWrapper
Definition: wxPanelWrapper.h:81
NyquistEffect::mRedirectOutput
bool mRedirectOutput
Definition: Nyquist.h:247
NyquistEffect::mFoundType
bool mFoundType
Definition: Nyquist.h:210
title
static const auto title
Definition: NoUpdatesAvailableDialog.cpp:22
Effect::GetFamily
EffectFamilySymbol GetFamily() override
Definition: Effect.cpp:193
TaggedIdentifier< ManualPageIDTag >
NyqControl::name
wxString name
Definition: Nyquist.h:50
NyquistEffect::mMergeClips
int mMergeClips
Definition: Nyquist.h:283
Effect::GetDescription
TranslatableString GetDescription() override
Definition: Effect.cpp:183
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
NyquistOutputDialog
Dialog used with NyquistEffect.
Definition: Nyquist.h:295
Effect::GetPath
PluginPath GetPath() override
Definition: Effect.cpp:143
NyqControl::low
double low
Definition: Nyquist.h:58
NYQ_CTRL_FLOAT_TEXT
@ NYQ_CTRL_FLOAT_TEXT
Definition: Nyquist.h:33
FileNames.h
Effect::IsDefault
bool IsDefault() override
Definition: Effect.cpp:215
NyquistEffect::mCurLen
sampleCount mCurLen
Definition: Nyquist.h:258
NyqControl::fileTypes
FileNames::FileTypes fileTypes
Definition: Nyquist.h:53
Effect::HelpPage
virtual FilePath HelpPage()
Definition: Effect.cpp:1177
NyquistEffect::mOK
bool mOK
Definition: Nyquist.h:222
NyqControl::valStr
wxString valStr
Definition: Nyquist.h:54
NyquistEffect::mProps
wxString mProps
Definition: Nyquist.h:279
NYQ_CTRL_CHOICE
@ NYQ_CTRL_CHOICE
Definition: Nyquist.h:31
NyqControl::label
wxString label
Definition: Nyquist.h:51
NyquistEffect::Tokenizer::tokens
wxArrayStringEx tokens
Definition: Nyquist.h:171
NyquistEffect::mCount
unsigned mCount
Definition: Nyquist.h:263
FileNames::FileTypes
std::vector< FileType > FileTypes
Definition: FileNames.h:76
NyquistEffect::mExternal
bool mExternal
Definition: Nyquist.h:214
NyquistEffect::mCmd
wxString mCmd
Definition: Nyquist.h:226
NyquistEffect::mAuthor
TranslatableString mAuthor
Definition: Nyquist.h:231
NyquistEffect::mDebugOutputStr
wxString mDebugOutputStr
Definition: Nyquist.h:249
NyquistEffect::NyquistEffect
NyquistEffect(const wxString &fName)
NyquistEffect::mVersion
int mVersion
Definition: Nyquist.h:252
EffectType
EffectType
Definition: EffectInterface.h:55
NyqControl::var
wxString var
Definition: Nyquist.h:49
Effect::ShowInterface
bool ShowInterface(wxWindow &parent, const EffectDialogFactory &factory, bool forceModal=false) override
Definition: Effect.cpp:481
ComponentInterface::DefineParams
virtual bool DefineParams(ShuttleParams &WXUNUSED(S))
Definition: ComponentInterface.h:85
NyquistEffect::mCommandText
wxTextCtrl * mCommandText
Definition: Nyquist.h:285
Effect::GetVersion
wxString GetVersion() override
Definition: Effect.cpp:173
NyqControl::NyqControl
NyqControl(const NyqControl &)=default
NyquistEffect::mDebugButton
bool mDebugButton
Definition: Nyquist.h:244
Effect::Process
virtual bool Process()
Definition: Effect.cpp:1371
FileNames::FileType
Definition: FileNames.h:52
NyquistEffect::mReentryCount
static int mReentryCount
Definition: Nyquist.h:120
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
NyquistEffect::mCurNumChannels
unsigned mCurNumChannels
Definition: Nyquist.h:255
NyquistEffect::mOutputTime
double mOutputTime
Definition: Nyquist.h:262
NYQ_CTRL_INT_TEXT
@ NYQ_CTRL_INT_TEXT
Definition: Nyquist.h:32
NyqControl::NyqControl
NyqControl()=default