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