Audacity  2.2.2
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 <wx/button.h>
15 #include <wx/datetime.h>
16 #include <wx/dialog.h>
17 #include <wx/filename.h>
18 #include <wx/intl.h>
19 #include <wx/sizer.h>
20 #include <wx/slider.h>
21 #include <wx/stattext.h>
22 #include <wx/textbuf.h>
23 #include <wx/textctrl.h>
24 #include <wx/tokenzr.h>
25 
26 #include "../Effect.h"
27 
28 #include "nyx.h"
29 
30 #define NYQUISTEFFECTS_VERSION wxT("1.0.0.0")
31 /* i18n-hint: "Nyquist" is an embedded interpreted programming language in
32  Audacity, named in honor of the Swedish-American Harry Nyquist (or Nyqvist).
33  In the translations of this and other strings, you may transliterate the
34  name into another alphabet. */
35 #define NYQUISTEFFECTS_FAMILY ( IdentInterfaceSymbol{ XO("Nyquist") } )
36 
37 #define NYQUIST_EFFECTS_PROMPT_ID wxT("Nyquist Effects Prompt")
38 #define NYQUIST_TOOLS_PROMPT_ID wxT("Nyquist Tools Prompt")
39 #define NYQUIST_WORKER_ID wxT("Nyquist Worker")
40 
42 {
52 };
53 
55 {
56 public:
57  NyqControl() = default;
58  NyqControl( const NyqControl& ) = default;
59  NyqControl &operator = ( const NyqControl & ) = default;
60  //NyqControl( NyqControl && ) = default;
61  //NyqControl &operator = ( NyqControl && ) = default;
62 
63  int type;
64  wxString var;
65  wxString name;
66  wxString label;
67  std::vector<IdentInterfaceSymbol> choices;
68  wxString valStr;
69  wxString lowStr;
70  wxString highStr;
71  double val;
72  double low;
73  double high;
74  int ticks;
75 };
76 
77 
78 class AUDACITY_DLL_API NyquistEffect final : public Effect
79 {
80 public:
81 
85  NyquistEffect(const wxString &fName);
86  virtual ~NyquistEffect();
87 
88  // IdentInterface implementation
89 
90  wxString GetPath() override;
93  wxString GetVersion() override;
94  wxString GetDescription() override;
95 
96  wxString ManualPage() override;
97  wxString HelpPage() override;
98 
99  // EffectDefinitionInterface implementation
100 
101  EffectType GetType() override;
103  bool IsInteractive() override;
104  bool IsDefault() override;
105 
106  // EffectClientInterface implementation
107 
108  bool DefineParams( ShuttleParams & S ) override;
109  bool GetAutomationParameters(CommandParameters & parms) override;
110  bool SetAutomationParameters(CommandParameters & parms) override;
111 
112  // Effect implementation
113 
114  bool Init() override;
115  bool CheckWhetherSkipEffect() override;
116  bool Process() override;
117  bool ShowInterface(wxWindow *parent, bool forceModal = false) override;
118  void PopulateOrExchange(ShuttleGui & S) override;
119  bool TransferDataToWindow() override;
120  bool TransferDataFromWindow() override;
121 
122  // NyquistEffect implementation
123 
124  // For Nyquist Workbench support
125  void RedirectOutput();
126  void SetCommand(const wxString &cmd);
127  void Continue();
128  void Break();
129  void Stop();
130 
131 private:
132  // NyquistEffect implementation
133 
134  bool ProcessOne();
135 
136  void BuildPromptWindow(ShuttleGui & S);
137  void BuildEffectWindow(ShuttleGui & S);
138 
139  bool TransferDataToPromptWindow();
140  bool TransferDataToEffectWindow();
141 
142  bool TransferDataFromPromptWindow();
143  bool TransferDataFromEffectWindow();
144 
145  bool IsOk();
146  const wxString &InitializationError() const { return mInitError; }
147 
148  static wxArrayString GetNyquistSearchPath();
149 
150  static wxString NyquistToWxString(const char *nyqString);
151  wxString EscapeString(const wxString & inStr);
152  static std::vector<IdentInterfaceSymbol> ParseChoice(const wxString & text);
153 
154  static int StaticGetCallback(float *buffer, int channel,
155  long start, long len, long totlen,
156  void *userdata);
157  static int StaticPutCallback(float *buffer, int channel,
158  long start, long len, long totlen,
159  void *userdata);
160  static void StaticOutputCallback(int c, void *userdata);
161  static void StaticOSCallback(void *userdata);
162 
163  int GetCallback(float *buffer, int channel,
164  long start, long len, long totlen);
165  int PutCallback(float *buffer, int channel,
166  long start, long len, long totlen);
167  void OutputCallback(int c);
168  void OSCallback();
169 
170  void ParseFile();
171  bool ParseCommand(const wxString & cmd);
172  bool ParseProgram(wxInputStream & stream);
173  struct Tokenizer {
174  bool sl { false };
175  bool q { false };
176  int paren{ 0 };
177  wxString tok;
178  wxArrayString tokens;
179 
180  bool Tokenize(
181  const wxString &line, bool eof,
182  size_t trimStart, size_t trimEnd);
183  };
184  bool Parse(Tokenizer &tokenizer, const wxString &line, bool eof, bool first);
185 
186  static wxString UnQuote(const wxString &s, bool allowParens = true,
187  wxString *pExtraString = nullptr);
188  double GetCtrlValue(const wxString &s);
189 
190  void OnLoad(wxCommandEvent & evt);
191  void OnSave(wxCommandEvent & evt);
192  void OnDebug(wxCommandEvent & evt);
193 
194  void OnText(wxCommandEvent & evt);
195  void OnSlider(wxCommandEvent & evt);
196  void OnChoice(wxCommandEvent & evt);
197  void OnTime(wxCommandEvent & evt);
198  void OnFileButton(wxCommandEvent & evt);
199 
200  void resolveFilePath(wxString & path, wxString extension = "");
201  bool validatePath(wxString path);
202  wxString ToTimeFormat(double t);
203 
204 private:
205 
206  wxString mXlispPath;
207 
208  wxFileName mFileName;
209  wxDateTime mFileModified;
210 
211  bool mStop;
212  bool mBreak;
213  bool mCont;
214 
216  bool mCompiler;
217  bool mTrace; // True when *tracenable* or *sal-traceback* are enabled
218  bool mIsSal;
219  bool mExternal;
225  bool mIsPrompt;
226  bool mOK;
227  wxString mInitError;
228  wxString mInputCmd; // history: exactly what the user typed
229  wxString mCmd; // the command to be processed
230  wxString mName;
231  wxString mPromptName; // If a prompt, we need to remember original name.
232  wxString mAction; // translatable
233  wxString mInfo; // translatable
234  wxString mAuthor;
235  // Version number of the specific plug-in (not to be confused with mVersion)
236  // For shipped plug-ins this will be the same as the Audacity release version
237  // when the plug-in was last modified.
238  wxString mReleaseVersion;
239  wxString mCopyright;
240  wxString mManPage; // ONLY use if a help page exists in the manual.
241  wxString mHelpFile;
244  EffectType mPromptType; // If a prompt, need ot remember original type.
245 
247  bool mDebugButton; // Set to false to disable Debug button.
248 
249  bool mDebug; // When true, debug window is shown.
252  wxString mDebugOutput;
253 
254  int mVersion; // Syntactic version of Nyquist plug-in (not to be confused with mReleaseVersion)
255  std::vector<NyqControl> mControls;
256 
257  unsigned mCurNumChannels;
258  WaveTrack *mCurTrack[2];
259  sampleCount mCurStart[2];
264  double mOutputTime;
265  unsigned mCount;
267  double mProgressIn;
268  double mProgressOut;
269  double mProgressTot;
270  double mScale;
271 
272  SampleBuffer mCurBuffer[2];
273  sampleCount mCurBufferStart[2];
274  size_t mCurBufferLen[2];
275 
276  WaveTrack *mOutputTrack[2];
277 
278  wxArrayString mCategories;
279 
280  wxString mProps;
281  wxString mPerTrackProps;
282 
285 
286  wxTextCtrl *mCommandText;
287  wxCheckBox *mVersionCheckBox;
288 
289  std::exception_ptr mpException {};
290 
291  DECLARE_EVENT_TABLE()
292 
293  friend class NyquistEffectsModule;
294 };
295 
297 {
298 public:
299  NyquistOutputDialog(wxWindow * parent, wxWindowID id,
300  const wxString & title,
301  const wxString & prompt,
302  const wxString &message);
303 
304 private:
305  void OnOk(wxCommandEvent & event);
306 
307 private:
308  DECLARE_EVENT_TABLE()
309 };
310 
311 
312 #endif
EffectType mPromptType
Definition: Nyquist.h:244
wxString highStr
Definition: Nyquist.h:70
wxString mDebugOutput
Definition: Nyquist.h:252
IdentInterfaceSymbol GetFamilyId() override
Definition: Effect.cpp:208
bool mTrace
Definition: Nyquist.h:217
sampleCount mCurLen
Definition: Nyquist.h:260
double mProgressIn
Definition: Nyquist.h:267
bool mStop
Definition: Nyquist.h:211
std::vector< NyqControl > mControls
Definition: Nyquist.h:255
void OnSave(const CommandContext &context)
wxString mName
Name of the Effect (untranslated)
Definition: Nyquist.h:230
wxString mXlispPath
Definition: Nyquist.h:206
NyqControlType
Definition: Nyquist.h:41
virtual bool TransferDataFromWindow()
Definition: Effect.cpp:1881
bool mIsSal
Definition: Nyquist.h:218
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
bool mProjectChanged
Definition: Nyquist.h:251
wxString mHelpFile
Definition: Nyquist.h:241
unsigned mNumSelectedChannels
Definition: Nyquist.h:266
int type
Definition: Nyquist.h:63
NyqControl()=default
bool SetAutomationParameters(CommandParameters &parms) override
Definition: Effect.cpp:574
virtual bool Init()
Definition: Effect.cpp:1264
virtual bool TransferDataToWindow()
Definition: Effect.cpp:1876
wxString mManPage
Definition: Nyquist.h:240
wxTextCtrl * mCommandText
Definition: Nyquist.h:286
double mProgressOut
Definition: Nyquist.h:268
virtual wxString ManualPage()
Definition: Effect.cpp:1127
A control on a NyquistDialog.
Definition: Nyquist.h:54
bool mExternal
Definition: Nyquist.h:219
wxString valStr
Definition: Nyquist.h:68
bool mHelpFileExists
Definition: Nyquist.h:242
Base class for many of the effects in Audacity.
Definition: Effect.h:62
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class...
Definition: Nyquist.h:78
EffectType mType
Definition: Nyquist.h:243
virtual bool Process()
Definition: Effect.cpp:1290
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
wxString lowStr
Definition: Nyquist.h:69
wxString label
Definition: Nyquist.h:66
wxString GetDescription() override
Definition: Effect.cpp:198
wxArrayString tokens
Definition: Nyquist.h:178
wxString var
Definition: Nyquist.h:64
bool mDebugButton
Definition: Nyquist.h:247
wxString mPromptName
Definition: Nyquist.h:231
bool mBreak
Definition: Nyquist.h:212
double mOutputTime
Definition: Nyquist.h:264
EffectType GetType() override
Definition: Effect.cpp:148
int mVersion
Definition: Nyquist.h:254
wxString GetVersion() override
Definition: Effect.cpp:188
unsigned mCount
Definition: Nyquist.h:265
bool mFoundType
Definition: Nyquist.h:215
double low
Definition: Nyquist.h:72
wxDateTime mFileModified
When the script was last modified on disk.
Definition: Nyquist.h:209
double mScale
Definition: Nyquist.h:270
bool mFirstInGroup
Definition: Nyquist.h:263
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
IdentInterfaceSymbol GetSymbol() override
Definition: Effect.cpp:168
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
bool mCompiler
Definition: Nyquist.h:216
wxString name
Definition: Nyquist.h:65
std::vector< IdentInterfaceSymbol > choices
Definition: Nyquist.h:67
bool mIsSpectral
Definition: Nyquist.h:220
wxCheckBox * mVersionCheckBox
Definition: Nyquist.h:287
wxString mCmd
Definition: Nyquist.h:229
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
wxString mAction
Definition: Nyquist.h:232
Dialog used with NyquistEffect.
Definition: Nyquist.h:296
bool IsInteractive() override
Definition: Effect.cpp:220
bool mRestoreSplits
Definition: Nyquist.h:283
bool mCont
Definition: Nyquist.h:213
NyqControl & operator=(const NyqControl &)=default
wxString mCopyright
Definition: Nyquist.h:239
bool mRedirectOutput
Definition: Nyquist.h:250
bool GetAutomationParameters(CommandParameters &parms) override
Definition: Effect.cpp:564
IdentInterfaceSymbol GetVendor() override
Definition: Effect.cpp:178
const wxString & InitializationError() const
Definition: Nyquist.h:146
double val
Definition: Nyquist.h:71
bool IsDefault() override
Definition: Effect.cpp:230
wxString mProps
Definition: Nyquist.h:280
wxString mReleaseVersion
Definition: Nyquist.h:238
unsigned mCurNumChannels
Definition: Nyquist.h:257
EffectType
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: Nyquist.h:208
wxString mInputCmd
Definition: Nyquist.h:228
virtual bool DefineParams(ShuttleParams &WXUNUSED(S))
bool mIsPrompt
Definition: Nyquist.h:225
bool ShowInterface(wxWindow *parent, bool forceModal=false) override
Definition: Effect.cpp:514
bool mEnablePreview
Definition: Nyquist.h:246
int mTrackIndex
Definition: Nyquist.h:262
wxString mPerTrackProps
Definition: Nyquist.h:281
bool mDebug
Definition: Nyquist.h:249
wxString mInitError
Definition: Nyquist.h:227
double high
Definition: Nyquist.h:73
int mMergeClips
Definition: Nyquist.h:284
double mProgressTot
Definition: Nyquist.h:269
virtual void PopulateOrExchange(ShuttleGui &S)
Definition: Effect.cpp:1871
wxString mInfo
Definition: Nyquist.h:233
virtual bool CheckWhetherSkipEffect()
Definition: Effect.h:297
int ticks
Definition: Nyquist.h:74
sampleCount mMaxLen
Definition: Nyquist.h:261
wxString GetPath() override
Definition: Effect.cpp:158
wxArrayString mCategories
Definition: Nyquist.h:278
wxString mAuthor
Definition: Nyquist.h:234
virtual wxString HelpPage()
Definition: Effect.cpp:1132