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