Audacity 3.2.0
NyquistBase.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 NyquistBase.h
6
7 Dominic Mazzoni
8
9**********************************************************************/
10#pragma once
11
12#include "FileNames.h"
13#include "SampleCount.h"
14#include "StatefulEffect.h"
16
17class wxArrayString;
18class wxFileName;
19class wxCheckBox;
20class wxTextCtrl;
21
23
24#define NYQUISTEFFECTS_VERSION wxT("1.0.0.0")
25#define NYQUIST_WORKER_ID wxT("Nyquist Worker")
26#define UNINITIALIZED_CONTROL ((double)99999999.99)
27
29{
39};
40
42{
43public:
44 NyqControl() = default;
45 NyqControl(const NyqControl&) = default;
46 NyqControl& operator=(const NyqControl&) = default;
47 // NyqControl( NyqControl && ) = default;
48 // NyqControl &operator = ( NyqControl && ) = default;
49
50 int type;
51 wxString var;
52 wxString name;
53 wxString label;
54 std::vector<EnumValueSymbol> choices;
56 wxString valStr;
57 wxString lowStr;
58 wxString highStr;
59 double val;
60 double low;
61 double high;
62 int ticks;
63};
64
66{
67 // other settings, for the Nyquist prompt; else null
69 bool proxyDebug { false };
70 std::vector<NyqControl> controls;
71
72 // Other fields, to do
73};
74
75class NYQUIST_EFFECTS_API NyquistBase :
76 public EffectWithSettings<NyquistSettings, StatefulEffect>
77{
78public:
79 struct NYQUIST_EFFECTS_API GetEffectHook :
81 GetEffectHook, std::unique_ptr<NyquistBase>(const wxString& pluginId)>
82 {
83 };
84
85 struct NYQUIST_EFFECTS_API GetDisplaysHook :
87 GetDisplaysHook,
88 std::vector<WaveChannelSubViewType>(const WaveTrack*)>
89 {
90 };
91
92 struct NYQUIST_EFFECTS_API ShowDebugOutputHook :
94 ShowDebugOutputHook, void(
95 const TranslatableString& title,
96 const TranslatableString& message)>
97 {
98 };
99
100 struct NYQUIST_EFFECTS_API ExecFromMainHook :
101 GlobalHook<ExecFromMainHook, void(wxString* pIn, wxString* pOut)>
102 {
103 };
104
105 struct YieldIfNeededHook : GlobalHook<YieldIfNeededHook, void()>
106 {
107 };
108
112 NyquistBase(const wxString& fName);
113 virtual ~NyquistBase();
114
115 // ComponentInterface implementation
116
117 PluginPath GetPath() const override;
118 ComponentInterfaceSymbol GetSymbol() const override;
119 VendorSymbol GetVendor() const override;
120 wxString GetVersion() const override;
121 TranslatableString GetDescription() const override;
122
123 ManualPageID ManualPage() const override;
124 FilePath HelpPage() const override;
125
126 // EffectDefinitionInterface implementation
127
128 EffectType GetType() const override;
129 EffectType GetClassification() const override;
130 EffectFamilySymbol GetFamily() const override;
131 bool IsInteractive() const override;
132 bool IsDefault() const override;
133 bool EnablesDebug() const override;
134
135 bool SaveSettings(
136 const EffectSettings& settings, CommandParameters& parms) const override;
137 bool LoadSettings(
138 const CommandParameters& parms, EffectSettings& settings) const override;
139 bool
140 DoLoadSettings(const CommandParameters& parms, EffectSettings& settings);
141
142 bool
143 VisitSettings(SettingsVisitor& visitor, EffectSettings& settings) override;
144 bool VisitSettings(
145 ConstSettingsVisitor& visitor,
146 const EffectSettings& settings) const override;
147 int
148 SetLispVarsFromParameters(const CommandParameters& parms, bool bTestOnly);
149
150 // Effect implementation
151
152 bool Init() override;
153 bool Process(EffectInstance& instance, EffectSettings& settings) override;
154
155 // NyquistBase implementation
156 // For Nyquist Workbench support
157 void RedirectOutput();
158 void SetCommand(const wxString& cmd);
159 void Continue();
160 void Break();
161 void Stop();
162
163 bool IsOk();
164
165private:
166 static int mReentryCount;
167 // NyquistBase implementation
168
169 struct NyxContext;
170 bool ProcessOne(NyxContext& nyxContext, EffectOutputTracks* pOutputs);
171
173 {
174 return mInitError;
175 }
176
177 static FilePaths GetNyquistSearchPath();
178
179 static wxString NyquistToWxString(const char* nyqString);
180 wxString EscapeString(const wxString& inStr);
181 static std::vector<EnumValueSymbol> ParseChoice(const wxString& text);
182
183 FileExtensions ParseFileExtensions(const wxString& text);
184 FileNames::FileType ParseFileType(const wxString& text);
185 FileNames::FileTypes ParseFileTypes(const wxString& text);
186
187 static void StaticOutputCallback(int c, void* userdata);
188 static void StaticOSCallback(void* userdata);
189
190 void OutputCallback(int c);
191 void OSCallback();
192
193 void ParseFile();
194
195protected:
196 bool ParseCommand(const wxString& cmd);
197
198private:
199 bool ParseProgram(wxInputStream& stream);
201 {
202 bool sl { false };
203 bool q { false };
204 int paren { 0 };
205 wxString tok;
207
208 bool Tokenize(
209 const wxString& line, bool eof, size_t trimStart, size_t trimEnd);
210 };
211 bool Parse(Tokenizer& tokenizer, const wxString& line, bool eof, bool first);
212
213 static TranslatableString UnQuoteMsgid(
214 const wxString& s, bool allowParens = true,
215 wxString* pExtraString = nullptr);
216 static wxString UnQuote(
217 const wxString& s, bool allowParens = true,
218 wxString* pExtraString = nullptr);
219
220protected:
221 static double GetCtrlValue(const wxString& s);
222 static void resolveFilePath(wxString& path, FileExtension extension = {});
223 bool validatePath(wxString path);
224 wxString ToTimeFormat(double t);
225
226private:
227 std::pair<bool, FilePath> CheckHelpPage() const;
228
229protected:
230 wxString mXlispPath;
231
232 wxFileName
234 wxDateTime mFileModified;
235
236 bool mStop;
237 bool mBreak;
238 bool mCont;
239
242 bool mTrace; // True when *tracenable* or *sal-traceback* are enabled
243 bool mIsSal;
251 const bool mIsPrompt;
252 bool mOK;
254 wxString mInputCmd; // history: exactly what the user typed
255 wxString mParameters; // The parameters of to be fed to a nested prompt
256 wxString mCmd; // the command to be processed
259 mPromptName; // If a prompt, we need to remember original name.
263 // Version number of the specific plug-in (not to be confused with mVersion)
264 // For shipped plug-ins this will be the same as the Audacity release version
265 // when the plug-in was last modified.
268 wxString mManPage; // ONLY use if a help page exists in the manual.
269 wxString mHelpFile;
273 EffectType mPromptType; // If a prompt, need to remember original type.
274
276 bool mDebugButton; // Set to false to disable Debug button.
277
278 bool mDebug; // When true, debug window is shown.
283
284 int mVersion; // Syntactic version of Nyquist plug-in (not to be confused
285 // with mReleaseVersion)
286public:
287 std::vector<NyqControl> mControls;
288
289protected:
294 unsigned mCount;
296
297 wxArrayString mCategories;
298
299 wxString mProps;
301
304
306};
EffectType
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
NyqControlType
Definition: NyquistBase.h:29
@ NYQ_CTRL_STRING
Definition: NyquistBase.h:32
@ NYQ_CTRL_TEXT
Definition: NyquistBase.h:36
@ NYQ_CTRL_TIME
Definition: NyquistBase.h:37
@ NYQ_CTRL_INT_TEXT
Definition: NyquistBase.h:34
@ NYQ_CTRL_INT
Definition: NyquistBase.h:30
@ NYQ_CTRL_CHOICE
Definition: NyquistBase.h:33
@ NYQ_CTRL_FLOAT_TEXT
Definition: NyquistBase.h:35
@ NYQ_CTRL_FILE
Definition: NyquistBase.h:38
@ NYQ_CTRL_FLOAT
Definition: NyquistBase.h:31
wxString FilePath
Definition: Project.h:21
@ Continue
Save was not handled by the extension.
static Settings & settings()
Definition: TrackInfo.cpp:51
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.
Use this object to copy the input tracks to tentative outputTracks.
std::vector< FileType > FileTypes
Definition: FileNames.h:75
Global function-valued variable, adding a convenient Call()
A control on a NyquistDialog.
Definition: NyquistBase.h:42
wxString highStr
Definition: NyquistBase.h:58
double high
Definition: NyquistBase.h:61
NyqControl & operator=(const NyqControl &)=default
wxString label
Definition: NyquistBase.h:53
wxString name
Definition: NyquistBase.h:52
wxString var
Definition: NyquistBase.h:51
NyqControl(const NyqControl &)=default
NyqControl()=default
std::vector< EnumValueSymbol > choices
Definition: NyquistBase.h:54
wxString valStr
Definition: NyquistBase.h:56
double low
Definition: NyquistBase.h:60
double val
Definition: NyquistBase.h:59
FileNames::FileTypes fileTypes
Definition: NyquistBase.h:55
wxString lowStr
Definition: NyquistBase.h:57
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class.
Definition: NyquistBase.h:77
wxString mHelpFile
Definition: NyquistBase.h:269
const bool mIsPrompt
Definition: NyquistBase.h:251
bool mHelpFileExists
Definition: NyquistBase.h:270
bool mCompiler
Definition: NyquistBase.h:241
wxString mInputCmd
Definition: NyquistBase.h:254
wxString mParameters
Definition: NyquistBase.h:255
bool mFoundType
Definition: NyquistBase.h:240
TranslatableString mCopyright
Definition: NyquistBase.h:267
wxString mProps
Definition: NyquistBase.h:299
TranslatableString mInitError
Definition: NyquistBase.h:253
TranslatableString mPromptName
Definition: NyquistBase.h:259
static int mReentryCount
Definition: NyquistBase.h:166
wxArrayString mCategories
Definition: NyquistBase.h:297
unsigned mNumSelectedChannels
Definition: NyquistBase.h:295
EffectType mType
Definition: NyquistBase.h:272
wxString mCmd
Definition: NyquistBase.h:256
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: NyquistBase.h:233
wxDateTime mFileModified
When the script was last modified on disk.
Definition: NyquistBase.h:234
bool mRedirectOutput
Definition: NyquistBase.h:279
wxString mManPage
Definition: NyquistBase.h:268
TranslatableString mAction
Definition: NyquistBase.h:260
unsigned mCount
Definition: NyquistBase.h:294
TranslatableString mDebugOutput
Definition: NyquistBase.h:282
wxString mXlispPath
Definition: NyquistBase.h:230
TranslatableString mReleaseVersion
Definition: NyquistBase.h:266
bool mRestoreSplits
Definition: NyquistBase.h:302
wxString mDebugOutputStr
Definition: NyquistBase.h:281
bool mProjectChanged
Definition: NyquistBase.h:280
bool mExternal
Definition: NyquistBase.h:244
EffectType mPromptType
Definition: NyquistBase.h:273
TranslatableString mAuthor
Definition: NyquistBase.h:262
TranslatableString mInfo
Definition: NyquistBase.h:261
bool mIsSpectral
Definition: NyquistBase.h:245
bool mDebugButton
Definition: NyquistBase.h:276
bool mEnablePreview
Definition: NyquistBase.h:275
std::vector< NyqControl > mControls
Definition: NyquistBase.h:287
bool mFirstInGroup
Definition: NyquistBase.h:292
wxString mPerTrackProps
Definition: NyquistBase.h:300
double mOutputTime
Definition: NyquistBase.h:293
TranslatableString mName
Name of the Effect (untranslated)
Definition: NyquistBase.h:257
sampleCount mMaxLen
Definition: NyquistBase.h:290
FilePath mHelpPage
Definition: NyquistBase.h:271
const TranslatableString & InitializationError() const
Definition: NyquistBase.h:172
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Holds a msgid for the translation catalog; may also bind format arguments.
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Externalized state of a plug-in.
wxArrayStringEx tokens
Definition: NyquistBase.h:206
std::vector< NyqControl > controls
Definition: NyquistBase.h:70
EffectSettings proxySettings
Definition: NyquistBase.h:68