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