Audacity  2.2.2
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
NyquistEffect Class Referencefinal

An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class. More...

#include <Nyquist.h>

Inheritance diagram for NyquistEffect:
Effect EffectClientInterface EffectUIClientInterface EffectHostInterface EffectDefinitionInterface ConfigClientInterface IdentInterface ParamsInterface

Classes

struct  Tokenizer
 

Public Member Functions

 NyquistEffect (const wxString &fName)
 
virtual ~NyquistEffect ()
 
wxString GetPath () override
 
IdentInterfaceSymbol GetSymbol () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () override
 
wxString GetDescription () override
 
wxString ManualPage () override
 
wxString HelpPage () override
 
EffectType GetType () override
 
IdentInterfaceSymbol GetFamilyId () override
 
bool IsInteractive () override
 
bool IsDefault () override
 
bool DefineParams (ShuttleParams &S) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool Init () override
 
bool CheckWhetherSkipEffect () override
 
bool Process () override
 
bool ShowInterface (wxWindow *parent, bool forceModal=false) override
 
void PopulateOrExchange (ShuttleGui &S) override
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
void RedirectOutput ()
 
void SetCommand (const wxString &cmd)
 
void Continue ()
 
void Break ()
 
void Stop ()
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 
bool SupportsAutomation () override
 
bool SetHost (EffectHostInterface *host) override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
bool IsReady () override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 
bool ProcessFinalize () override
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () override
 
bool LoadUserPreset (const wxString &name) override
 
bool SaveUserPreset (const wxString &name) override
 
wxArrayString GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (wxWindow *parent) override
 
bool IsGraphicalUI () override
 
bool ValidateUI () override
 
bool HideUI () override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets () override
 
void ImportPresets () override
 
bool HasOptions () override
 
void ShowOptions () override
 
double GetDefaultDuration () override
 
double GetDuration () override
 
NumericFormatId GetDurationFormat () override
 
virtual NumericFormatId GetSelectionFormat ()
 
void SetDuration (double duration) override
 
bool Apply () override
 
void Preview () override
 
wxDialog * CreateUI (wxWindow *parent, EffectUIClientInterface *client) override
 
wxString GetUserPresetsGroup (const wxString &name) override
 
wxString GetCurrentSettingsGroup () override
 
wxString GetFactoryDefaultsGroup () override
 
virtual wxString GetSavedStateGroup ()
 
bool HasSharedConfigGroup (const wxString &group) override
 
bool GetSharedConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const wxString &group) override
 
bool RemoveSharedConfig (const wxString &group, const wxString &key) override
 
bool HasPrivateConfigGroup (const wxString &group) override
 
bool GetPrivateConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const wxString &group) override
 
bool RemovePrivateConfig (const wxString &group, const wxString &key) override
 
virtual PluginID GetID ()
 
virtual bool Startup (EffectClientInterface *client)
 
virtual bool Startup ()
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (const wxString &parms)
 
virtual wxArrayString GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual wxString GetPreset (wxWindow *parent, const wxString &parms)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (wxWindow *parent, double projectRate, TrackList *list, TrackFactory *factory, SelectedRegion *selectedRegion, bool shouldPrompt=true)
 
bool Delegate (Effect &delegate, wxWindow *parent, bool shouldPrompt)
 
bool RealtimeAddProcessor (int group, unsigned chans, float rate)
 
size_t RealtimeProcess (int group, unsigned chans, float **inbuf, float **outbuf, size_t numSamples)
 
bool IsRealtimeActive ()
 
virtual bool IsHidden ()
 
int MessageBox (const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
- Public Member Functions inherited from IdentInterface
virtual ~IdentInterface ()
 
const wxString & GetTranslatedName ()
 
- Public Member Functions inherited from ParamsInterface
virtual ~ParamsInterface ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()
 
- Public Member Functions inherited from ConfigClientInterface
virtual ~ConfigClientInterface ()
 

Private Member Functions

bool ProcessOne ()
 
void BuildPromptWindow (ShuttleGui &S)
 
void BuildEffectWindow (ShuttleGui &S)
 
bool TransferDataToPromptWindow ()
 
bool TransferDataToEffectWindow ()
 
bool TransferDataFromPromptWindow ()
 
bool TransferDataFromEffectWindow ()
 
bool IsOk ()
 
const wxString & InitializationError () const
 
wxString EscapeString (const wxString &inStr)
 
int GetCallback (float *buffer, int channel, long start, long len, long totlen)
 
int PutCallback (float *buffer, int channel, long start, long len, long totlen)
 
void OutputCallback (int c)
 
void OSCallback ()
 
void ParseFile ()
 
bool ParseCommand (const wxString &cmd)
 
bool ParseProgram (wxInputStream &stream)
 
bool Parse (Tokenizer &tokenizer, const wxString &line, bool eof, bool first)
 
double GetCtrlValue (const wxString &s)
 
void OnLoad (wxCommandEvent &evt)
 
void OnSave (wxCommandEvent &evt)
 
void OnDebug (wxCommandEvent &evt)
 
void OnText (wxCommandEvent &evt)
 
void OnSlider (wxCommandEvent &evt)
 
void OnChoice (wxCommandEvent &evt)
 
void OnTime (wxCommandEvent &evt)
 
void OnFileButton (wxCommandEvent &evt)
 
void resolveFilePath (wxString &path, wxString extension="")
 
bool validatePath (wxString path)
 
wxString ToTimeFormat (double t)
 

Static Private Member Functions

static wxArrayString GetNyquistSearchPath ()
 
static wxString NyquistToWxString (const char *nyqString)
 
static std::vector
< IdentInterfaceSymbol
ParseChoice (const wxString &text)
 
static int StaticGetCallback (float *buffer, int channel, long start, long len, long totlen, void *userdata)
 
static int StaticPutCallback (float *buffer, int channel, long start, long len, long totlen, void *userdata)
 
static void StaticOutputCallback (int c, void *userdata)
 
static void StaticOSCallback (void *userdata)
 
static wxString UnQuote (const wxString &s, bool allowParens=true, wxString *pExtraString=nullptr)
 

Private Attributes

wxString mXlispPath
 
wxFileName mFileName
 Name of the Nyquist script file this effect is loaded from. More...
 
wxDateTime mFileModified
 When the script was last modified on disk. More...
 
bool mStop
 
bool mBreak
 
bool mCont
 
bool mFoundType
 
bool mCompiler
 
bool mTrace
 
bool mIsSal
 
bool mExternal
 
bool mIsSpectral
 
bool mIsPrompt
 
bool mOK
 
wxString mInitError
 
wxString mInputCmd
 
wxString mCmd
 
wxString mName
 Name of the Effect (untranslated) More...
 
wxString mAction
 
wxString mInfo
 
wxString mAuthor
 
wxString mCopyright
 
wxString mManPage
 
wxString mHelpFile
 
bool mHelpFileExists
 
EffectType mType
 
bool mEnablePreview
 
bool mDebugButton
 
bool mDebug
 
bool mRedirectOutput
 
bool mProjectChanged
 
wxString mDebugOutput
 
int mVersion
 
std::vector< NyqControlmControls
 
unsigned mCurNumChannels
 
WaveTrackmCurTrack [2]
 
sampleCount mCurStart [2]
 
sampleCount mCurLen
 
sampleCount mMaxLen
 
int mTrackIndex
 
bool mFirstInGroup
 
double mOutputTime
 
unsigned mCount
 
unsigned mNumSelectedChannels
 
double mProgressIn
 
double mProgressOut
 
double mProgressTot
 
double mScale
 
SampleBuffer mCurBuffer [2]
 
sampleCount mCurBufferStart [2]
 
size_t mCurBufferLen [2]
 
WaveTrackmOutputTrack [2]
 
wxArrayString mCategories
 
wxString mProps
 
wxString mPerTrackProps
 
bool mRestoreSplits
 
int mMergeClips
 
wxTextCtrl * mCommandText
 
wxCheckBox * mVersionCheckBox
 
std::exception_ptr mpException {}
 

Friends

class NyquistEffectsModule
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Protected Member Functions inherited from Effect
virtual bool PromptUser (wxWindow *parent)
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual int GetPass ()
 
virtual void End ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
virtual void Preview (bool dryOnly)
 
virtual bool EnableApply (bool enable=true)
 
virtual bool EnablePreview (bool enable=true)
 
virtual void EnableDebug (bool enable=true)
 
bool TotalProgress (double frac)
 
bool TrackProgress (int whichTrack, double frac, const wxString &=wxEmptyString)
 
bool TrackGroupProgress (int whichGroup, double frac, const wxString &=wxEmptyString)
 
int GetNumWaveTracks ()
 
int GetNumWaveGroups ()
 
void GetSamples (const WaveTrack *track, sampleCount *start, sampleCount *len)
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing ()
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void CopyInputTracks ()
 
void CopyInputTracks (int trackType)
 
std::shared_ptr
< AddedAnalysisTrack
AddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
TrackAddToOutputTracks (std::unique_ptr< Track > &&t)
 
TrackListinputTracks () const
 
- Protected Attributes inherited from Effect
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
SelectedRegionmpSelectedRegion {}
 
TrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
double mF0
 
double mF1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
sampleCount mSampleCnt
 
int mOutputTracksType
 

Detailed Description

An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class.

Definition at line 78 of file Nyquist.h.

Constructor & Destructor Documentation

NyquistEffect::NyquistEffect ( const wxString &  fName)
Parameters
fNameFile name of the Nyquist script defining this effect. If an empty string, then prompt the user for the Nyquist code to interpret.
NyquistEffect::~NyquistEffect ( )
virtual

Definition at line 186 of file Nyquist.cpp.

187 {
188 }

Member Function Documentation

void NyquistEffect::Break ( )

Definition at line 1533 of file Nyquist.cpp.

References mBreak.

1534 {
1535  mBreak = true;
1536 }
bool mBreak
Definition: Nyquist.h:212
void NyquistEffect::BuildEffectWindow ( ShuttleGui S)
private

Definition at line 2506 of file Nyquist.cpp.

References ShuttleGuiBase::AddButton(), ShuttleGuiBase::AddChoice(), ShuttleGuiBase::AddFixedText(), ShuttleGuiBase::AddPrompt(), ShuttleGuiBase::AddSlider(), ShuttleGui::AddSpace(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::AddUnits(), ShuttleGuiBase::AddWindow(), NumericTextCtrl::Options::AutoPos(), NyqControl::choices, ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndScroller(), ShuttleGuiBase::GetParent(), Effect::GetSelectionFormat(), NyqControl::high, ShuttleGui::Id(), ID_Choice, ID_FILE, ID_Slider, ID_Text, ID_Time, NyqControl::label, LocalizedStrings(), NyqControl::low, NyqControl::lowStr, mControls, NumericTextCtrl::Options::MenuEnabled(), min(), Effect::mProjectRate, NyqControl::name, NYQ_CTRL_CHOICE, NYQ_CTRL_FILE, NYQ_CTRL_FLOAT, NYQ_CTRL_FLOAT_TEXT, NYQ_CTRL_INT, NYQ_CTRL_INT_TEXT, NYQ_CTRL_STRING, NYQ_CTRL_TEXT, NYQ_CTRL_TIME, NumericTextCtrl::Options::ReadOnly(), resolveFilePath(), ShuttleGuiBase::SetSizeHints(), ShuttleGuiBase::SetStyle(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), ShuttleGuiBase::StartScroller(), NyqControl::ticks, NumericConverter::TIME, NyqControl::type, NyqControl::val, and NyqControl::valStr.

Referenced by PopulateOrExchange().

2507 {
2508  S.SetStyle(wxVSCROLL | wxTAB_TRAVERSAL);
2509  wxScrolledWindow *scroller = S.StartScroller(2);
2510  {
2511  S.StartMultiColumn(4);
2512  {
2513  for (size_t i = 0; i < mControls.size(); i++)
2514  {
2515  NyqControl & ctrl = mControls[i];
2516 
2517  if (ctrl.type == NYQ_CTRL_TEXT)
2518  {
2519  S.EndMultiColumn();
2520  S.StartHorizontalLay(wxALIGN_LEFT, 0);
2521  {
2522  S.AddSpace(0, 10);
2523  S.AddFixedText( ctrl.label, false );
2524  }
2525  S.EndHorizontalLay();
2526  S.StartMultiColumn(4);
2527  }
2528  else
2529  {
2530  wxString prompt = ctrl.name + wxT(":");
2531  S.AddPrompt(prompt);
2532 
2533  if (ctrl.type == NYQ_CTRL_STRING)
2534  {
2535  S.AddSpace(10, 10);
2536 
2537  wxTextCtrl *item = S.Id(ID_Text + i).AddTextBox( {}, wxT(""), 12);
2538  item->SetValidator(wxGenericValidator(&ctrl.valStr));
2539  item->SetName(prompt);
2540  }
2541  else if (ctrl.type == NYQ_CTRL_CHOICE)
2542  {
2543  S.AddSpace(10, 10);
2544 
2545  auto choices =
2546  LocalizedStrings(ctrl.choices.data(), ctrl.choices.size());
2547  S.Id(ID_Choice + i).AddChoice( {}, wxT(""), &choices);
2548  }
2549  else if (ctrl.type == NYQ_CTRL_TIME)
2550  {
2551  S.AddSpace(10, 10);
2552 
2553  const auto options = NumericTextCtrl::Options{}
2554  .AutoPos(true)
2555  .MenuEnabled(true)
2556  .ReadOnly(false);
2557 
2558  NumericTextCtrl *time = new
2559  NumericTextCtrl(S.GetParent(), (ID_Time + i),
2562  ctrl.val,
2563  mProjectRate,
2564  options);
2565  time->SetName(prompt);
2566  S.AddWindow(time, wxALIGN_LEFT | wxALL);
2567  }
2568  else if (ctrl.type == NYQ_CTRL_FILE)
2569  {
2570  S.AddSpace(10, 10);
2571 
2572  // Get default file extension if specified in wildcards
2573  wxString defaultExtension = "";
2574  size_t len = ctrl.lowStr.length();
2575  int characters = ctrl.lowStr.Find("*");
2576 
2577  if (characters != wxNOT_FOUND)
2578  {
2579  if (static_cast<int>(ctrl.lowStr.find("|", characters)) != wxNOT_FOUND)
2580  len = ctrl.lowStr.find("|", characters) - 1;
2581  if (static_cast<int>(ctrl.lowStr.find(";", characters)) != wxNOT_FOUND)
2582  len = std::min(static_cast<int>(len), static_cast<int>(ctrl.lowStr.find(";", characters)) - 1);
2583 
2584  defaultExtension = ctrl.lowStr.wxString::Mid(characters + 1, len - characters);
2585  }
2586  resolveFilePath(ctrl.valStr, defaultExtension);
2587 
2588  wxTextCtrl *item = S.Id(ID_Text+i).AddTextBox( {}, wxT(""), 40);
2589  item->SetValidator(wxGenericValidator(&ctrl.valStr));
2590  item->SetName(prompt);
2591 
2592  if (ctrl.label == wxEmptyString)
2593  ctrl.label = wxFileSelectorPromptStr;
2594  S.Id(ID_FILE + i).AddButton(ctrl.label, wxALIGN_LEFT);
2595  }
2596  else
2597  {
2598  // Integer or Real
2599  if (ctrl.type == NYQ_CTRL_INT_TEXT || ctrl.type == NYQ_CTRL_FLOAT_TEXT)
2600  {
2601  S.AddSpace(10, 10);
2602  }
2603 
2604  wxTextCtrl *item = S.Id(ID_Text+i).AddTextBox( {}, wxT(""),
2605  (ctrl.type == NYQ_CTRL_INT_TEXT ||
2606  ctrl.type == NYQ_CTRL_FLOAT_TEXT) ? 25 : 12);
2607  item->SetName(prompt);
2608 
2609  double range = ctrl.high - ctrl.low;
2610 
2611  if (ctrl.type == NYQ_CTRL_FLOAT || ctrl.type == NYQ_CTRL_FLOAT_TEXT)
2612  {
2613  // > 12 decimal places can cause rounding errors in display.
2614  FloatingPointValidator<double> vld(12, &ctrl.val);
2615  vld.SetRange(ctrl.low, ctrl.high);
2616 
2617  // Set number of decimal places
2618  auto style = range < 10 ? NumValidatorStyle::THREE_TRAILING_ZEROES :
2619  range < 100 ? NumValidatorStyle::TWO_TRAILING_ZEROES :
2620  NumValidatorStyle::ONE_TRAILING_ZERO;
2621  vld.SetStyle(style);
2622 
2623  item->SetValidator(vld);
2624  }
2625  else
2626  {
2627  IntegerValidator<double> vld(&ctrl.val);
2628  vld.SetRange((int) ctrl.low, (int) ctrl.high);
2629  item->SetValidator(vld);
2630  }
2631 
2632  if (ctrl.type == NYQ_CTRL_INT || ctrl.type == NYQ_CTRL_FLOAT)
2633  {
2634  S.SetStyle(wxSL_HORIZONTAL);
2635  S.Id(ID_Slider + i).AddSlider( {}, 0, ctrl.ticks, 0);
2636  S.SetSizeHints(150, -1);
2637  }
2638  }
2639 
2640  if (ctrl.type != NYQ_CTRL_FILE)
2641  {
2642  if (ctrl.type == NYQ_CTRL_CHOICE || ctrl.label.IsEmpty())
2643  {
2644  S.AddSpace(10, 10);
2645  }
2646  else
2647  {
2648  S.AddUnits(ctrl.label);
2649  }
2650  }
2651  }
2652  }
2653  }
2654  S.EndMultiColumn();
2655  }
2656  S.EndScroller();
2657 
2658  scroller->SetScrollRate(0, 20);
2659 
2660  // This fools NVDA into not saying "Panel" when the dialog gets focus
2661  scroller->SetName(wxT("\a"));
2662  scroller->SetLabel(wxT("\a"));
2663 }
NyquistEffect::OnText ID_Time
Definition: Nyquist.cpp:116
void SetSizeHints(int minX, int minY)
Used to modify an already placed Window.
Definition: ShuttleGui.cpp:194
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
int type
Definition: Nyquist.h:63
wxWindow * AddWindow(wxWindow *pWindow, int Flags=wxALIGN_CENTRE|wxALL)
Definition: ShuttleGui.cpp:288
wxArrayString LocalizedStrings(const IdentInterfaceSymbol strings[], size_t nStrings)
Definition: Internat.cpp:303
void EndMultiColumn()
A control on a NyquistDialog.
Definition: Nyquist.h:54
wxString valStr
Definition: Nyquist.h:68
wxString lowStr
Definition: Nyquist.h:69
wxString label
Definition: Nyquist.h:66
void EndScroller()
Definition: ShuttleGui.cpp:828
void EndHorizontalLay()
void AddUnits(const wxString &Prompt)
Left aligned text string.
Definition: ShuttleGui.cpp:260
void AddPrompt(const wxString &Prompt)
Right aligned text string.
Definition: ShuttleGui.cpp:239
ID_Text
Definition: Nyquist.cpp:112
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:795
double low
Definition: Nyquist.h:72
wxWindow * GetParent()
Definition: ShuttleGui.h:294
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Options & MenuEnabled(bool value)
wxChoice * AddChoice(const wxString &Prompt, const wxString &Selected, const wxArrayString *pChoices)
Definition: ShuttleGui.cpp:371
ShuttleGui & Id(int id)
void SetStyle(int Style)
Definition: ShuttleGui.h:287
wxString name
Definition: Nyquist.h:65
std::vector< IdentInterfaceSymbol > choices
Definition: Nyquist.h:67
void resolveFilePath(wxString &path, wxString extension="")
Definition: Nyquist.cpp:2906
void AddFixedText(const wxString &Str, bool bCenter=false)
Definition: ShuttleGui.cpp:397
int min(int a, int b)
double mProjectRate
Definition: Effect.h:453
double val
Definition: Nyquist.h:71
Options & ReadOnly(bool value)
virtual NumericFormatId GetSelectionFormat()
Definition: Effect.cpp:737
Options & AutoPos(bool value)
wxSizerItem * AddSpace(int width, int height)
double high
Definition: Nyquist.h:73
wxButton * AddButton(const wxString &Text, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:341
int ticks
Definition: Nyquist.h:74
wxSlider * AddSlider(const wxString &Prompt, int pos, int Max, int Min=0)
Definition: ShuttleGui.cpp:497
void NyquistEffect::BuildPromptWindow ( ShuttleGui S)
private

Definition at line 2470 of file Nyquist.cpp.

References _(), ShuttleGuiBase::AddButton(), ShuttleGuiBase::AddCheckBox(), ShuttleGui::AddSpace(), ShuttleGuiBase::AddTextWindow(), ShuttleGuiBase::AddVariableText(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndVerticalLay(), ShuttleGui::Id(), ID_Load, ID_Save, mCommandText, mVersion, mVersionCheckBox, ShuttleGuiBase::SetStretchyCol(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), and ShuttleGuiBase::StartVerticalLay().

Referenced by PopulateOrExchange().

2471 {
2472  S.StartVerticalLay();
2473  {
2474  S.StartMultiColumn(3, wxEXPAND);
2475  {
2476  S.SetStretchyCol(1);
2477 
2478  S.AddVariableText(_("Enter Nyquist Command: "));
2479 
2480  S.AddSpace(1, 1);
2481 
2482  mVersionCheckBox = S.AddCheckBox(_("&Use legacy (version 3) syntax."),
2483  (mVersion == 3) ? wxT("true") : wxT("false"));
2484  }
2485  S.EndMultiColumn();
2486 
2487  S.StartHorizontalLay(wxEXPAND, 1);
2488  {
2489  mCommandText = S.AddTextWindow(wxT(""));
2490  mCommandText->SetMinSize(wxSize(500, 200));
2491  }
2492  S.EndHorizontalLay();
2493 
2494  S.StartHorizontalLay(wxALIGN_CENTER, 0);
2495  {
2496  S.Id(ID_Load).AddButton(_("&Load"));
2497  S.Id(ID_Save).AddButton(_("&Save"));
2498  }
2499  S.EndHorizontalLay();
2500  }
2501  S.EndVerticalLay();
2502 
2503  mCommandText->SetFocus();
2504 }
wxTextCtrl * mCommandText
Definition: Nyquist.h:280
void EndMultiColumn()
void EndHorizontalLay()
void EndVerticalLay()
int mVersion
Definition: Nyquist.h:248
wxCheckBox * AddCheckBox(const wxString &Prompt, const wxString &Selected)
Definition: ShuttleGui.cpp:298
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
ShuttleGui & Id(int id)
wxCheckBox * mVersionCheckBox
Definition: Nyquist.h:281
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxTextCtrl * AddTextWindow(const wxString &Value)
Multiline text box that grows.
Definition: ShuttleGui.cpp:608
wxStaticText * AddVariableText(const wxString &Str, bool bCenter=false, int PositionFlags=0)
Definition: ShuttleGui.cpp:414
wxSizerItem * AddSpace(int width, int height)
wxButton * AddButton(const wxString &Text, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:341
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:203
void StartVerticalLay(int iProp=1)
bool NyquistEffect::CheckWhetherSkipEffect ( )
overridevirtual

Reimplemented from Effect.

Definition at line 571 of file Nyquist.cpp.

References mControls, and mIsPrompt.

572 {
573  // If we're a prompt and we have controls, then we've already processed
574  // the audio, so skip further processing.
575  return (mIsPrompt && mControls.size() > 0);
576 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
bool mIsPrompt
Definition: Nyquist.h:225
void NyquistEffect::Continue ( )

Definition at line 1538 of file Nyquist.cpp.

References mCont.

1539 {
1540  mCont = true;
1541 }
bool mCont
Definition: Nyquist.h:213
bool NyquistEffect::DefineParams ( ShuttleParams S)
override

Definition at line 282 of file Nyquist.cpp.

References NyqControl::choices, ShuttleParams::Define(), ShuttleParams::DefineEnum(), GetAutomationParameters(), GetCtrlValue(), NyqControl::high, NyqControl::highStr, KEY_Command, KEY_Version, NyqControl::low, NyqControl::lowStr, mControls, mExternal, mInputCmd, mIsPrompt, mVersion, NYQ_CTRL_CHOICE, NYQ_CTRL_FILE, NYQ_CTRL_FLOAT, NYQ_CTRL_FLOAT_TEXT, NYQ_CTRL_INT, NYQ_CTRL_INT_TEXT, NYQ_CTRL_STRING, NYQ_CTRL_TIME, SetAutomationParameters(), NyqControl::type, UNINITIALIZED_CONTROL, NyqControl::val, NyqControl::valStr, and NyqControl::var.

283 {
284  // For now we assume Nyquist can do get and set better than DefineParams can,
285  // And so we ONLY use it for geting the signature.
286  auto pGa = dynamic_cast<ShuttleGetAutomation*>(&S);
287  if( pGa ){
288  GetAutomationParameters( *(pGa->mpEap) );
289  return true;
290  }
291  auto pSa = dynamic_cast<ShuttleSetAutomation*>(&S);
292  if( pSa ){
293  SetAutomationParameters( *(pSa->mpEap) );
294  return true;
295  }
296  auto pSd = dynamic_cast<ShuttleGetDefinition*>(&S);
297  if( pSd == nullptr )
298  return true;
299  //wxASSERT( pSd );
300 
301  if (mExternal)
302  return true;
303 
304  if (mIsPrompt)
305  {
306  S.Define( mInputCmd, KEY_Command, "" );
307  S.Define( mVersion, KEY_Version, 3 );
308  return true;
309  }
310 
311  for (size_t c = 0, cnt = mControls.size(); c < cnt; c++)
312  {
313  NyqControl & ctrl = mControls[c];
314  double d = ctrl.val;
315 
316  if (d == UNINITIALIZED_CONTROL && ctrl.type != NYQ_CTRL_STRING)
317  {
318  d = GetCtrlValue(ctrl.valStr);
319  }
320 
321  if (ctrl.type == NYQ_CTRL_FLOAT || ctrl.type == NYQ_CTRL_FLOAT_TEXT ||
322  ctrl.type == NYQ_CTRL_TIME)
323  {
324  S.Define( d, static_cast<const wxChar*>( ctrl.var.c_str() ), (double)0.0, ctrl.low, ctrl.high, 1.0);
325  }
326  else if (ctrl.type == NYQ_CTRL_INT || ctrl.type == NYQ_CTRL_INT_TEXT)
327  {
328  int x=d;
329  S.Define( x, static_cast<const wxChar*>( ctrl.var.c_str() ), 0, ctrl.low, ctrl.high, 1);
330  //parms.Write(ctrl.var, (int) d);
331  }
332  else if (ctrl.type == NYQ_CTRL_CHOICE)
333  {
334  // untranslated
335  int x=d;
336  //parms.WriteEnum(ctrl.var, (int) d, choices);
337  S.DefineEnum( x, static_cast<const wxChar*>( ctrl.var.c_str() ), 0,
338  ctrl.choices.data(), ctrl.choices.size() );
339  }
340  else if (ctrl.type == NYQ_CTRL_STRING || ctrl.type == NYQ_CTRL_FILE)
341  {
342  S.Define( ctrl.valStr, ctrl.var, "" , ctrl.lowStr, ctrl.highStr );
343  //parms.Write(ctrl.var, ctrl.valStr);
344  }
345  }
346  return true;
347 }
wxString highStr
Definition: Nyquist.h:70
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
#define UNINITIALIZED_CONTROL
Definition: Nyquist.cpp:95
int type
Definition: Nyquist.h:63
static const wxChar * KEY_Version
Definition: Nyquist.cpp:97
double GetCtrlValue(const wxString &s)
Definition: Nyquist.cpp:1586
Shuttle that gets parameter values into a string.
Definition: Shuttle.h:87
A control on a NyquistDialog.
Definition: Nyquist.h:54
bool mExternal
Definition: Nyquist.h:219
wxString valStr
Definition: Nyquist.h:68
wxString lowStr
Definition: Nyquist.h:69
Shuttle that retrieves a JSON format definition of a command's parameters.
Definition: Shuttle.h:129
wxString var
Definition: Nyquist.h:64
virtual void DefineEnum(int &var, const wxChar *key, const int vdefault, const IdentInterfaceSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:346
int mVersion
Definition: Nyquist.h:248
double low
Definition: Nyquist.h:72
bool SetAutomationParameters(CommandParameters &parms) override
Definition: Nyquist.cpp:403
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:339
std::vector< IdentInterfaceSymbol > choices
Definition: Nyquist.h:67
double val
Definition: Nyquist.h:71
bool GetAutomationParameters(CommandParameters &parms) override
Definition: Nyquist.cpp:349
wxString mInputCmd
Definition: Nyquist.h:228
bool mIsPrompt
Definition: Nyquist.h:225
Shuttle that sets parameters to a value (from a string)
Definition: Shuttle.h:105
double high
Definition: Nyquist.h:73
static const wxChar * KEY_Command
Definition: Nyquist.cpp:98
wxString NyquistEffect::EscapeString ( const wxString &  inStr)
private

Definition at line 1480 of file Nyquist.cpp.

Referenced by Process(), and ProcessOne().

1481 {
1482  wxString str = inStr;
1483 
1484  str.Replace(wxT("\\"), wxT("\\\\"));
1485  str.Replace(wxT("\""), wxT("\\\""));
1486 
1487  return str;
1488 }
bool NyquistEffect::GetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 349 of file Nyquist.cpp.

References NyqControl::choices, GetCtrlValue(), KEY_Command, KEY_Version, mControls, mExternal, mInputCmd, mIsPrompt, mVersion, NYQ_CTRL_CHOICE, NYQ_CTRL_FILE, NYQ_CTRL_FLOAT, NYQ_CTRL_FLOAT_TEXT, NYQ_CTRL_INT, NYQ_CTRL_INT_TEXT, NYQ_CTRL_STRING, NYQ_CTRL_TIME, resolveFilePath(), NyqControl::type, UNINITIALIZED_CONTROL, NyqControl::val, NyqControl::valStr, NyqControl::var, and CommandParameters::WriteEnum().

Referenced by DefineParams().

350 {
351  if (mExternal)
352  {
353  return true;
354  }
355 
356  if (mIsPrompt)
357  {
358  parms.Write(KEY_Command, mInputCmd);
359  parms.Write(KEY_Version, mVersion);
360 
361  return true;
362  }
363 
364  for (size_t c = 0, cnt = mControls.size(); c < cnt; c++)
365  {
366  NyqControl & ctrl = mControls[c];
367  double d = ctrl.val;
368 
369  if (d == UNINITIALIZED_CONTROL && ctrl.type != NYQ_CTRL_STRING)
370  {
371  d = GetCtrlValue(ctrl.valStr);
372  }
373 
374  if (ctrl.type == NYQ_CTRL_FLOAT || ctrl.type == NYQ_CTRL_FLOAT_TEXT ||
375  ctrl.type == NYQ_CTRL_TIME)
376  {
377  parms.Write(ctrl.var, d);
378  }
379  else if (ctrl.type == NYQ_CTRL_INT || ctrl.type == NYQ_CTRL_INT_TEXT)
380  {
381  parms.Write(ctrl.var, (int) d);
382  }
383  else if (ctrl.type == NYQ_CTRL_CHOICE)
384  {
385  // untranslated
386  parms.WriteEnum(ctrl.var, (int) d,
387  ctrl.choices.data(), ctrl.choices.size());
388  }
389  else if (ctrl.type == NYQ_CTRL_STRING)
390  {
391  parms.Write(ctrl.var, ctrl.valStr);
392  }
393  else if (ctrl.type == NYQ_CTRL_FILE)
394  {
395  resolveFilePath(ctrl.valStr);
396  parms.Write(ctrl.var, ctrl.valStr);
397  }
398  }
399 
400  return true;
401 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
#define UNINITIALIZED_CONTROL
Definition: Nyquist.cpp:95
int type
Definition: Nyquist.h:63
static const wxChar * KEY_Version
Definition: Nyquist.cpp:97
double GetCtrlValue(const wxString &s)
Definition: Nyquist.cpp:1586
A control on a NyquistDialog.
Definition: Nyquist.h:54
bool mExternal
Definition: Nyquist.h:219
wxString valStr
Definition: Nyquist.h:68
wxString var
Definition: Nyquist.h:64
int mVersion
Definition: Nyquist.h:248
std::vector< IdentInterfaceSymbol > choices
Definition: Nyquist.h:67
void resolveFilePath(wxString &path, wxString extension="")
Definition: Nyquist.cpp:2906
double val
Definition: Nyquist.h:71
wxString mInputCmd
Definition: Nyquist.h:228
bool mIsPrompt
Definition: Nyquist.h:225
bool WriteEnum(const wxString &key, int value, const IdentInterfaceSymbol choices[], size_t nChoices)
static const wxChar * KEY_Command
Definition: Nyquist.cpp:98
int NyquistEffect::GetCallback ( float *  buffer,
int  channel,
long  start,
long  len,
long  totlen 
)
private

Definition at line 2136 of file Nyquist.cpp.

References SampleBuffer::Allocate(), sampleCount::as_double(), CopySamples(), floatSample, SampleBuffer::Free(), WaveTrack::Get(), WaveTrack::GetBestBlockSize(), WaveTrack::GetIdealBlockSize(), limitSampleBufferSize(), mCurBuffer, mCurBufferLen, mCurBufferStart, mCurLen, mCurStart, mCurTrack, mpException, mProgressIn, mProgressOut, mProgressTot, mScale, SAMPLE_SIZE, and Effect::TotalProgress().

Referenced by StaticGetCallback().

2138 {
2139  if (mCurBuffer[ch].ptr()) {
2140  if ((mCurStart[ch] + start) < mCurBufferStart[ch] ||
2141  (mCurStart[ch] + start)+len >
2142  mCurBufferStart[ch]+mCurBufferLen[ch]) {
2143  mCurBuffer[ch].Free();
2144  }
2145  }
2146 
2147  if (!mCurBuffer[ch].ptr()) {
2148  mCurBufferStart[ch] = (mCurStart[ch] + start);
2150 
2151  if (mCurBufferLen[ch] < (size_t) len) {
2153  }
2154 
2155  mCurBufferLen[ch] =
2157  mCurStart[ch] + mCurLen - mCurBufferStart[ch] );
2158 
2160  try {
2161  mCurTrack[ch]->Get(
2162  mCurBuffer[ch].ptr(), floatSample,
2163  mCurBufferStart[ch], mCurBufferLen[ch]);
2164  }
2165  catch ( ... ) {
2166  // Save the exception object for re-throw when out of the library
2167  mpException = std::current_exception();
2168  return -1;
2169  }
2170  }
2171 
2172  // We have guaranteed above that this is nonnegative and bounded by
2173  // mCurBufferLen[ch]:
2174  auto offset = ( mCurStart[ch] + start - mCurBufferStart[ch] ).as_size_t();
2176  (samplePtr)buffer, floatSample,
2177  len);
2178 
2179  if (ch == 0) {
2180  double progress = mScale *
2181  ( (start+len)/ mCurLen.as_double() );
2182 
2183  if (progress > mProgressIn) {
2184  mProgressIn = progress;
2185  }
2186 
2188  return -1;
2189  }
2190  }
2191 
2192  return 0;
2193 }
sampleCount mCurLen
Definition: Nyquist.h:254
double mProgressIn
Definition: Nyquist.h:261
bool TotalProgress(double frac)
Definition: Effect.cpp:1977
void CopySamples(samplePtr src, sampleFormat srcFormat, samplePtr dst, sampleFormat dstFormat, unsigned int len, bool highQuality, unsigned int srcStride, unsigned int dstStride)
#define SAMPLE_SIZE(SampleFormat)
Definition: Types.h:198
double mProgressOut
Definition: Nyquist.h:262
SampleBuffer & Allocate(size_t count, sampleFormat format)
Definition: SampleFormat.h:67
double as_double() const
Definition: Types.h:88
size_t GetBestBlockSize(sampleCount t) const
Definition: WaveTrack.cpp:1607
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
sampleCount mCurStart[2]
Definition: Nyquist.h:253
WaveTrack * mCurTrack[2]
Definition: Nyquist.h:252
double mScale
Definition: Nyquist.h:264
size_t GetIdealBlockSize()
Definition: WaveTrack.cpp:1645
size_t mCurBufferLen[2]
Definition: Nyquist.h:268
char * samplePtr
Definition: Types.h:203
sampleCount mCurBufferStart[2]
Definition: Nyquist.h:267
SampleBuffer mCurBuffer[2]
Definition: Nyquist.h:266
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumCopied=nullptr) const
Definition: WaveTrack.cpp:1971
double mProgressTot
Definition: Nyquist.h:263
std::exception_ptr mpException
Definition: Nyquist.h:283
double NyquistEffect::GetCtrlValue ( const wxString &  s)
private

Definition at line 1586 of file Nyquist.cpp.

References Internat::CompatibleToDouble().

Referenced by DefineParams(), GetAutomationParameters(), Parse(), SetAutomationParameters(), and TransferDataFromEffectWindow().

1587 {
1588  /* For this to work correctly requires that the plug-in header is
1589  * parsed on each run so that the correct value for "half-srate" may
1590  * be determined.
1591  *
1592  AudacityProject *project = GetActiveProject();
1593  double rate = INT_MAX;
1594  if (project && s.IsSameAs(wxT("half-srate"), false)) {
1595  SelectedTrackListOfKindIterator sel(Track::Wave, project->GetTracks());
1596  for (WaveTrack *t = (WaveTrack *) sel.First(); t; t = (WaveTrack *) sel.Next()) {
1597  rate = std::min(t->GetRate(), rate);
1598  }
1599  return (rate / 2.0);
1600  }
1601  */
1602 
1603  return Internat::CompatibleToDouble(s);
1604 }
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:122
wxString NyquistEffect::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 227 of file Nyquist.cpp.

References mCopyright.

228 {
229  return mCopyright;
230 }
wxString mCopyright
Definition: Nyquist.h:234
IdentInterfaceSymbol NyquistEffect::GetFamilyId ( )
overridevirtual

Reimplemented from Effect.

Definition at line 261 of file Nyquist.cpp.

References NYQUISTEFFECTS_FAMILY.

262 {
263  return NYQUISTEFFECTS_FAMILY;
264 }
#define NYQUISTEFFECTS_FAMILY
Definition: Nyquist.h:35
wxArrayString NyquistEffect::GetNyquistSearchPath ( )
staticprivate

Definition at line 2277 of file Nyquist.cpp.

References AudacityApp::AddUniquePathToPathList(), AudacityApp::audacityPathList, FileNames::PlugInDir(), and wxGetApp().

Referenced by NyquistEffectsModule::AutoRegisterPlugins(), NyquistEffectsModule::FindPluginPaths(), HelpPage(), and Process().

2278 {
2279  wxArrayString audacityPathList = wxGetApp().audacityPathList;
2280  wxArrayString pathList;
2281 
2282  for (size_t i = 0; i < audacityPathList.GetCount(); i++)
2283  {
2284  wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH;
2285  wxGetApp().AddUniquePathToPathList(prefix + wxT("nyquist"), pathList);
2286  wxGetApp().AddUniquePathToPathList(prefix + wxT("plugins"), pathList);
2287  wxGetApp().AddUniquePathToPathList(prefix + wxT("plug-ins"), pathList);
2288  }
2289  pathList.Add(FileNames::PlugInDir());
2290 
2291  return pathList;
2292 }
static void AddUniquePathToPathList(const wxString &path, wxArrayString &pathList)
wxArrayString audacityPathList
A list of directories that should be searched for Audacity files (plug-ins, help files, etc.).
Definition: AudacityApp.h:138
AudacityApp & wxGetApp()
static wxString PlugInDir()
The user plug-in directory (not a system one)
Definition: FileNames.cpp:214
wxString NyquistEffect::GetPath ( )
overridevirtual

Reimplemented from Effect.

Definition at line 192 of file Nyquist.cpp.

References EffectTypeTool, mFileName, mIsPrompt, mType, NYQUIST_PROMPT_ID, and NYQUIST_TOOLS_PROMPT_ID.

193 {
194  if (mIsPrompt)
195  return (mType == EffectTypeTool) ?
198 
199  return mFileName.GetFullPath();
200 }
#define NYQUIST_TOOLS_PROMPT_ID
Definition: Nyquist.h:38
#define NYQUIST_PROMPT_ID
Definition: Nyquist.h:37
EffectType mType
Definition: Nyquist.h:238
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: Nyquist.h:208
bool mIsPrompt
Definition: Nyquist.h:225
IdentInterfaceSymbol NyquistEffect::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 202 of file Nyquist.cpp.

References EffectTypeTool, mIsPrompt, mName, mType, and XO.

203 {
204  if (mIsPrompt)
205  return (mType == EffectTypeTool) ?
206  XO("Nyquist Tools Prompt") :
207  XO("Nyquist Prompt");
208 
209  return mName;
210 }
wxString mName
Name of the Effect (untranslated)
Definition: Nyquist.h:230
#define XO(s)
Definition: Internat.h:33
EffectType mType
Definition: Nyquist.h:238
bool mIsPrompt
Definition: Nyquist.h:225
EffectType NyquistEffect::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 256 of file Nyquist.cpp.

References mType.

Referenced by Process(), and ProcessOne().

257 {
258  return mType;
259 }
EffectType mType
Definition: Nyquist.h:238
IdentInterfaceSymbol NyquistEffect::GetVendor ( )
overridevirtual

Reimplemented from Effect.

Definition at line 212 of file Nyquist.cpp.

References mAuthor, mIsPrompt, and XO.

213 {
214  if (mIsPrompt)
215  {
216  return XO("Audacity");
217  }
218 
219  return mAuthor;
220 }
#define XO(s)
Definition: Internat.h:33
bool mIsPrompt
Definition: Nyquist.h:225
wxString mAuthor
Definition: Nyquist.h:233
wxString NyquistEffect::GetVersion ( )
overridevirtual

Reimplemented from Effect.

Definition at line 222 of file Nyquist.cpp.

References XO.

223 {
224  return XO("n/a");
225 }
#define XO(s)
Definition: Internat.h:33
wxString NyquistEffect::HelpPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 239 of file Nyquist.cpp.

References GetNyquistSearchPath(), mHelpFile, and mHelpFileExists.

240 {
241  wxArrayString paths = NyquistEffect::GetNyquistSearchPath();
242  wxString fileName;
243 
244  for (size_t i = 0, cnt = paths.GetCount(); i < cnt; i++) {
245  fileName = wxFileName(paths[i] + wxT("/") + mHelpFile).GetFullPath();
246  if (wxFileExists(fileName)) {
247  mHelpFileExists = true;
248  return fileName;
249  }
250  }
251  return wxEmptyString;
252 }
wxString mHelpFile
Definition: Nyquist.h:236
static wxArrayString GetNyquistSearchPath()
Definition: Nyquist.cpp:2277
bool mHelpFileExists
Definition: Nyquist.h:237
bool NyquistEffect::Init ( )
overridevirtual

Reimplemented from Effect.

Definition at line 506 of file Nyquist.cpp.

References _(), EffectTypeProcess, GetActiveProject(), Effect::GetCurrentSettingsGroup(), AudacityProject::GetTracks(), Effect::LoadUserPreset(), mDebugButton, mEnablePreview, Effect::MessageBox(), mExternal, Effect::mF0, Effect::mF1, mFileModified, mFileName, mIsPrompt, mIsSpectral, mMaxLen, mName, mType, NYQ_MAX_LEN, ParseFile(), Effect::SaveUserPreset(), WaveTrack::Spectrum, Track::Wave, and XO.

507 {
508  // When Nyquist Prompt spawns an effect GUI, Init() is called for Nyquist Prompt,
509  // and then again for the spawned (mExternal) effect.
510 
511  // EffectType may not be defined in script, so
512  // reset each time we call the Nyquist Prompt.
513  if (mIsPrompt) {
514  mName = XO("Nyquist Prompt");
515  // Reset effect type each time we call the Nyquist Prompt.
517  mIsSpectral = false;
518  mDebugButton = true; // Debug button always enabled for Nyquist Prompt.
519  mEnablePreview = true; // Preview button always enabled for Nyquist Prompt.
520  }
521 
522  // As of Audacity 2.1.2 rc1, 'spectral' effects are allowed only if
523  // the selected track(s) are in a spectrogram view, and there is at
524  // least one frequency bound and Spectral Selection is enabled for the
525  // selected track(s) - (but don't apply to Nyquist Prompt).
526 
527  if (!mIsPrompt && mIsSpectral) {
528  AudacityProject *project = GetActiveProject();
529  bool bAllowSpectralEditing = true;
530 
532  for (WaveTrack *t = (WaveTrack *) sel.First(); t; t = (WaveTrack *) sel.Next()) {
533  if (t->GetDisplay() != WaveTrack::Spectrum ||
534  !(t->GetSpectrogramSettings().SpectralSelectionEnabled())) {
535  bAllowSpectralEditing = false;
536  break;
537  }
538  }
539 
540  if (!bAllowSpectralEditing || ((mF0 < 0.0) && (mF1 < 0.0))) {
541  Effect::MessageBox(_("To use 'Spectral effects', enable 'Spectral Selection'\n"
542  "in the track Spectrogram settings and select the\n"
543  "frequency range for the effect to act on."),
544  wxOK | wxICON_EXCLAMATION | wxCENTRE, _("Error"));
545 
546  return false;
547  }
548  }
549 
550  if (!mIsPrompt && !mExternal)
551  {
552  //TODO: If we want to auto-add parameters from spectral selection,
553  //we will need to modify this test.
554  //Note that removing it stops the caching of parameter values,
555  //(during this session).
556  if (mFileName.GetModificationTime().IsLaterThan(mFileModified))
557  {
559 
561  ParseFile();
562  mFileModified = mFileName.GetModificationTime();
563 
565  }
566  }
567 
568  return true;
569 }
bool SaveUserPreset(const wxString &name) override
Definition: Effect.cpp:600
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
wxString mName
Name of the Effect (untranslated)
Definition: Nyquist.h:230
wxString GetCurrentSettingsGroup() override
Definition: Effect.cpp:801
bool mExternal
Definition: Nyquist.h:219
#define XO(s)
Definition: Internat.h:33
EffectType mType
Definition: Nyquist.h:238
bool LoadUserPreset(const wxString &name) override
Definition: Effect.cpp:584
bool mDebugButton
Definition: Nyquist.h:241
double mF0
Definition: Effect.h:463
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
wxDateTime mFileModified
When the script was last modified on disk.
Definition: Nyquist.h:209
void ParseFile()
Definition: Nyquist.cpp:2114
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
#define NYQ_MAX_LEN
Definition: Nyquist.cpp:93
bool mIsSpectral
Definition: Nyquist.h:220
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: Nyquist.h:208
bool mIsPrompt
Definition: Nyquist.h:225
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
bool mEnablePreview
Definition: Nyquist.h:240
double mF1
Definition: Effect.h:464
TrackList * GetTracks()
Definition: Project.h:192
sampleCount mMaxLen
Definition: Nyquist.h:255
const wxString& NyquistEffect::InitializationError ( ) const
inlineprivate

Definition at line 146 of file Nyquist.h.

Referenced by NyquistEffectsModule::DiscoverPluginsAtPath().

146 { return mInitError; }
wxString mInitError
Definition: Nyquist.h:227
bool NyquistEffect::IsDefault ( )
overridevirtual

Reimplemented from Effect.

Definition at line 276 of file Nyquist.cpp.

References mIsPrompt.

277 {
278  return mIsPrompt;
279 }
bool mIsPrompt
Definition: Nyquist.h:225
bool NyquistEffect::IsInteractive ( )
overridevirtual

Reimplemented from Effect.

Definition at line 266 of file Nyquist.cpp.

References mControls, and mIsPrompt.

267 {
268  if (mIsPrompt)
269  {
270  return true;
271  }
272 
273  return mControls.size() != 0;
274 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
bool mIsPrompt
Definition: Nyquist.h:225
bool NyquistEffect::IsOk ( )
private

Definition at line 2667 of file Nyquist.cpp.

References mOK.

Referenced by NyquistEffectsModule::DiscoverPluginsAtPath().

2668 {
2669  return mOK;
2670 }
wxString NyquistEffect::ManualPage ( )
overridevirtual

Reimplemented from Effect.

Definition at line 232 of file Nyquist.cpp.

References mIsPrompt, and mManPage.

233 {
234  return mIsPrompt
235  ? wxT("Nyquist_Prompt")
236  : mManPage;
237 }
wxString mManPage
Definition: Nyquist.h:235
bool mIsPrompt
Definition: Nyquist.h:225
wxString NyquistEffect::NyquistToWxString ( const char *  nyqString)
staticprivate

Definition at line 1467 of file Nyquist.cpp.

References _(), and LAT1CTOWX.

Referenced by ProcessOne().

1468 {
1469  wxString str(nyqString, wxConvUTF8);
1470  if (nyqString != NULL && nyqString[0] && str.IsEmpty()) {
1471  // invalid UTF-8 string, convert as Latin-1
1472  str = _("[Warning: Nyquist returned invalid UTF-8 string, converted here as Latin-1]");
1473  // TODO: internationalization of strings from Nyquist effects, at least
1474  // from those shipped with Audacity
1475  str += LAT1CTOWX(nyqString);
1476  }
1477  return str;
1478 }
#define LAT1CTOWX(X)
Definition: Internat.h:180
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void NyquistEffect::OnChoice ( wxCommandEvent &  evt)
private

Definition at line 2757 of file Nyquist.cpp.

References ID_Choice, and mControls.

2758 {
2759  mControls[evt.GetId() - ID_Choice].val = (double) evt.GetInt();
2760 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
void NyquistEffect::OnDebug ( wxCommandEvent &  evt)
private
void NyquistEffect::OnFileButton ( wxCommandEvent &  evt)
private

Definition at line 2790 of file Nyquist.cpp.

References _(), NyqControl::highStr, ID_FILE, ID_Text, NyqControl::lowStr, mControls, Effect::MessageBox(), Effect::mUIParent, resolveFilePath(), and NyqControl::valStr.

2791 {
2792  int i = evt.GetId() - ID_FILE;
2793  NyqControl & ctrl = mControls[i];
2794  ctrl.lowStr.Trim(true).Trim(false); // Wildcard filter.
2795 
2796  // Basic sanity check of wildcard flags so that we
2797  // don't show scary wxFAIL_MSG from wxParseCommonDialogsFilter.
2798  if (ctrl.lowStr != wxEmptyString)
2799  {
2800  bool validWildcards = true;
2801  size_t wildcards = 0;
2802  wxStringTokenizer tokenizer(ctrl.lowStr, "|");
2803  while (tokenizer.HasMoreTokens())
2804  {
2805  wxString token = tokenizer.GetNextToken().Trim(true).Trim(false);
2806  if (token == wxEmptyString)
2807  {
2808  validWildcards = false;
2809  break;
2810  }
2811  wildcards += 1;
2812  }
2813  // Users should not normally see this, unless they are writing Nyquist plug-ins.
2814  if (wildcards % 2 != 0 || !validWildcards || ctrl.lowStr.EndsWith("|"))
2815  {
2816  Effect::MessageBox(_("Invalid wildcard string in 'path' control.'\n"
2817  "Using empty string instead."),
2818  wxOK | wxICON_EXCLAMATION | wxCENTRE, _("Error"));
2819  ctrl.lowStr = "";
2820  }
2821  }
2822 
2823  // Get style flags:
2824  // Ensure legal combinations so that wxWidgets does not throw an assert error.
2825  unsigned char flags = 0;
2826  if (ctrl.highStr != wxEmptyString)
2827  {
2828  wxStringTokenizer tokenizer(ctrl.highStr, ",");
2829  while ( tokenizer.HasMoreTokens() )
2830  {
2831  wxString token = tokenizer.GetNextToken().Trim(true).Trim(false);
2832  if (token.IsSameAs("open", false))
2833  {
2834  flags |= wxFD_OPEN;
2835  flags &= ~wxFD_SAVE;
2836  flags &= ~wxFD_OVERWRITE_PROMPT;
2837  }
2838  else if (token.IsSameAs("save", false))
2839  {
2840  flags |= wxFD_SAVE;
2841  flags &= ~wxFD_OPEN;
2842  flags &= ~wxFD_MULTIPLE;
2843  flags &= ~wxFD_FILE_MUST_EXIST;
2844  }
2845  else if (token.IsSameAs("overwrite", false) && !(flags & wxFD_OPEN))
2846  {
2847  flags |= wxFD_OVERWRITE_PROMPT;
2848  }
2849  else if (token.IsSameAs("exists", false) && !(flags & wxFD_SAVE))
2850  {
2851  flags |= wxFD_FILE_MUST_EXIST;
2852  }
2853  else if (token.IsSameAs("multiple", false) && !(flags & wxFD_SAVE))
2854  {
2855  flags |= wxFD_MULTIPLE;
2856  }
2857  }
2858  }
2859 
2860  resolveFilePath(ctrl.valStr);
2861 
2862  wxFileName fname = ctrl.valStr;
2863  wxString defaultDir = fname.GetPath();
2864  wxString defaultFile = fname.GetName();
2865  wxString message = _("Select a file");
2866 
2867  if (flags & wxFD_MULTIPLE)
2868  message = _("Select one or more files");
2869  else if (flags & wxFD_SAVE)
2870  message = _("Save file as");
2871 
2872  wxFileDialog openFileDialog(mUIParent->FindWindow(ID_FILE + i),
2873  message,
2874  defaultDir,
2875  defaultFile,
2876  ctrl.lowStr, // wildcard filter
2877  flags); // styles
2878 
2879  if (openFileDialog.ShowModal() == wxID_CANCEL)
2880  {
2881  return;
2882  }
2883 
2884  wxString path = "";
2885  // When multiple files selected, return file paths as a list of quoted strings.
2886  if (flags & wxFD_MULTIPLE)
2887  {
2888  wxArrayString selectedFiles;
2889  openFileDialog.GetPaths(selectedFiles);
2890 
2891  for (size_t sf = 0; sf < selectedFiles.GetCount(); sf++) {
2892  path += "\"";
2893  path += selectedFiles[sf];
2894  path += "\"";
2895  }
2896  ctrl.valStr = path;
2897  }
2898  else
2899  {
2900  ctrl.valStr = openFileDialog.GetPath();
2901  }
2902 
2903  mUIParent->FindWindow(ID_Text + i)->GetValidator()->TransferToWindow();
2904 }
wxString highStr
Definition: Nyquist.h:70
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
A control on a NyquistDialog.
Definition: Nyquist.h:54
wxString valStr
Definition: Nyquist.h:68
wxString lowStr
Definition: Nyquist.h:69
ID_Text
Definition: Nyquist.cpp:112
void resolveFilePath(wxString &path, wxString extension="")
Definition: Nyquist.cpp:2906
wxWindow * mUIParent
Definition: Effect.h:472
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void NyquistEffect::OnLoad ( wxCommandEvent &  evt)
private

Definition at line 2672 of file Nyquist.cpp.

References _(), mCommandText, Effect::MessageBox(), mFileName, and Effect::mUIParent.

2673 {
2674  if (mCommandText->IsModified())
2675  {
2676  if (Effect::MessageBox(_("Current program has been modified.\nDiscard changes?"),
2677  wxYES_NO) == wxNO)
2678  {
2679  return;
2680  }
2681  }
2682 
2684  _("Load Nyquist script"),
2685  mFileName.GetPath(),
2686  wxEmptyString,
2687  _("Nyquist scripts (*.ny)|*.ny|Lisp scripts (*.lsp)|*.lsp|Text files (*.txt)|*.txt|All files|*"),
2688  wxFD_OPEN | wxRESIZE_BORDER);
2689 
2690  if (dlog.ShowModal() != wxID_OK)
2691  {
2692  return;
2693  }
2694 
2695  mFileName = dlog.GetPath();
2696 
2697  if (!mCommandText->LoadFile(mFileName.GetFullPath()))
2698  {
2699  Effect::MessageBox(_("File could not be loaded"));
2700  }
2701 }
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
wxTextCtrl * mCommandText
Definition: Nyquist.h:280
wxWindow * mUIParent
Definition: Effect.h:472
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: Nyquist.h:208
void NyquistEffect::OnSave ( wxCommandEvent &  evt)
private

Definition at line 2703 of file Nyquist.cpp.

References _(), mCommandText, Effect::MessageBox(), mFileName, and Effect::mUIParent.

2704 {
2706  _("Save Nyquist script"),
2707  mFileName.GetPath(),
2708  mFileName.GetFullName(),
2709  _("Nyquist scripts (*.ny)|*.ny|Lisp scripts (*.lsp)|*.lsp|All files|*"),
2710  wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER);
2711 
2712  if (dlog.ShowModal() != wxID_OK)
2713  {
2714  return;
2715  }
2716 
2717  mFileName = dlog.GetPath();
2718 
2719  if (!mCommandText->SaveFile(mFileName.GetFullPath()))
2720  {
2721  Effect::MessageBox(_("File could not be saved"));
2722  }
2723 }
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
wxTextCtrl * mCommandText
Definition: Nyquist.h:280
wxWindow * mUIParent
Definition: Effect.h:472
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: Nyquist.h:208
void NyquistEffect::OnSlider ( wxCommandEvent &  evt)
private

Definition at line 2725 of file Nyquist.cpp.

References NyqControl::high, ID_Slider, ID_Text, NyqControl::low, mControls, Effect::mUIParent, NyqControl::ticks, and NyqControl::val.

2726 {
2727  int i = evt.GetId() - ID_Slider;
2728  NyqControl & ctrl = mControls[i];
2729 
2730  int val = evt.GetInt();
2731  double range = ctrl.high - ctrl.low;
2732  double newVal = (val / (double)ctrl.ticks) * range + ctrl.low;
2733 
2734  // Determine precision for displayed number
2735  int precision = range < 1.0 ? 3 :
2736  range < 10.0 ? 2 :
2737  range < 100.0 ? 1 :
2738  0;
2739 
2740  // If the value is at least one tick different from the current value
2741  // change it (this prevents changes from manually entered values unless
2742  // the slider actually moved)
2743  if (fabs(newVal - ctrl.val) >= (1 / (double)ctrl.ticks) * range &&
2744  fabs(newVal - ctrl.val) >= pow(0.1, precision) / 2)
2745  {
2746  // First round to the appropriate precision
2747  newVal *= pow(10.0, precision);
2748  newVal = floor(newVal + 0.5);
2749  newVal /= pow(10.0, precision);
2750 
2751  ctrl.val = newVal;
2752 
2753  mUIParent->FindWindow(ID_Text + i)->GetValidator()->TransferToWindow();
2754  }
2755 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
A control on a NyquistDialog.
Definition: Nyquist.h:54
ID_Text
Definition: Nyquist.cpp:112
double low
Definition: Nyquist.h:72
wxWindow * mUIParent
Definition: Effect.h:472
double val
Definition: Nyquist.h:71
double high
Definition: Nyquist.h:73
int ticks
Definition: Nyquist.h:74
void NyquistEffect::OnText ( wxCommandEvent &  evt)
private

Definition at line 2985 of file Nyquist.cpp.

References NyqControl::high, ID_Slider, ID_Text, NyqControl::low, mControls, Effect::mUIParent, NYQ_CTRL_FLOAT, NYQ_CTRL_INT, NyqControl::ticks, NyqControl::type, and NyqControl::val.

2986 {
2987  int i = evt.GetId() - ID_Text;
2988 
2989  NyqControl & ctrl = mControls[i];
2990 
2991  if (wxDynamicCast(evt.GetEventObject(), wxWindow)->GetValidator()->TransferFromWindow())
2992  {
2993  if (ctrl.type == NYQ_CTRL_FLOAT || ctrl.type == NYQ_CTRL_INT)
2994  {
2995  int pos = (int)floor((ctrl.val - ctrl.low) /
2996  (ctrl.high - ctrl.low) * ctrl.ticks + 0.5);
2997 
2998  wxSlider *slider = (wxSlider *)mUIParent->FindWindow(ID_Slider + i);
2999  slider->SetValue(pos);
3000  }
3001  }
3002 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
int type
Definition: Nyquist.h:63
A control on a NyquistDialog.
Definition: Nyquist.h:54
ID_Text
Definition: Nyquist.cpp:112
double low
Definition: Nyquist.h:72
wxWindow * mUIParent
Definition: Effect.h:472
double val
Definition: Nyquist.h:71
double high
Definition: Nyquist.h:73
int ticks
Definition: Nyquist.h:74
void NyquistEffect::OnTime ( wxCommandEvent &  evt)
private

Definition at line 2762 of file Nyquist.cpp.

References _(), NumericConverter::GetValue(), NyqControl::high, ID_Time, NyqControl::low, mControls, Effect::MessageBox(), Effect::mUIParent, NumericTextCtrl::SetValue(), and ToTimeFormat().

2763 {
2764  int i = evt.GetId() - ID_Time;
2765  static double value = 0.0;
2766  NyqControl & ctrl = mControls[i];
2767 
2768  NumericTextCtrl *n = (NumericTextCtrl *) mUIParent->FindWindow(ID_Time + i);
2769  double val = n->GetValue();
2770 
2771  // Observed that two events transmitted on each control change (Linux)
2772  // so skip if value has not changed.
2773  if (val != value) {
2774  if (val < ctrl.low || val > ctrl.high) {
2775  const auto message = wxString::Format(_("Value range:\n%s to %s"),
2776  ToTimeFormat(ctrl.low), ToTimeFormat(ctrl.high));
2777  Effect::MessageBox(message, wxOK | wxCENTRE, _("Value Error"));
2778  }
2779 
2780  if (val < ctrl.low)
2781  val = ctrl.low;
2782  else if (val > ctrl.high)
2783  val = ctrl.high;
2784 
2785  n->SetValue(val);
2786  value = val;
2787  }
2788 }
NyquistEffect::OnText ID_Time
Definition: Nyquist.cpp:116
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
A control on a NyquistDialog.
Definition: Nyquist.h:54
double low
Definition: Nyquist.h:72
void SetValue(double newValue)
wxWindow * mUIParent
Definition: Effect.h:472
wxString ToTimeFormat(double t)
Definition: Nyquist.cpp:2975
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
double high
Definition: Nyquist.h:73
void NyquistEffect::OSCallback ( )
private

Definition at line 2247 of file Nyquist.cpp.

References mBreak, mCont, and mStop.

2248 {
2249  if (mStop) {
2250  mStop = false;
2251  nyx_stop();
2252  }
2253  else if (mBreak) {
2254  mBreak = false;
2255  nyx_break();
2256  }
2257  else if (mCont) {
2258  mCont = false;
2259  nyx_continue();
2260  }
2261 
2262  // LLL: STF figured out that yielding while the effect is being applied
2263  // produces an EXTREME slowdown. It appears that yielding is not
2264  // really necessary on Linux and Windows.
2265  //
2266  // However, on the Mac, the spinning cursor appears during longer
2267  // Nyquist processing and that may cause the user to think Audacity
2268  // has crashed or hung. In addition, yielding or not on the Mac
2269  // doesn't seem to make much of a difference in execution time.
2270  //
2271  // So, yielding on the Mac only...
2272 #if defined(__WXMAC__)
2273  wxYieldIfNeeded();
2274 #endif
2275 }
bool mStop
Definition: Nyquist.h:211
bool mBreak
Definition: Nyquist.h:212
bool mCont
Definition: Nyquist.h:213
void NyquistEffect::OutputCallback ( int  c)
private

Definition at line 2231 of file Nyquist.cpp.

References mDebugOutput, and mRedirectOutput.

2232 {
2233  // Always collect Nyquist error messages for normal plug-ins
2234  if (!mRedirectOutput) {
2235  mDebugOutput += (char)c;
2236  return;
2237  }
2238 
2239  std::cout << (char)c;
2240 }
wxString mDebugOutput
Definition: Nyquist.h:246
bool mRedirectOutput
Definition: Nyquist.h:244
bool NyquistEffect::Parse ( Tokenizer tokenizer,
const wxString &  line,
bool  eof,
bool  first 
)
private

Definition at line 1705 of file Nyquist.cpp.

References _(), NyqControl::choices, EffectTypeAnalyze, EffectTypeGenerate, EffectTypeProcess, EffectTypeTool, GetCtrlValue(), NyqControl::high, NyqControl::highStr, NyqControl::label, NyqControl::low, NyqControl::lowStr, mAction, mAuthor, mCategories, mCompiler, mControls, mCopyright, mDebugButton, mEnablePreview, mFileName, mFoundType, mHelpFile, mInfo, mInitError, mIsSal, mIsSpectral, mManPage, mMaxLen, mMergeClips, mName, mOK, Effect::mPresetNames, mRestoreSplits, mTrace, mType, mVersion, NyqControl::name, NYQ_CTRL_CHOICE, NYQ_CTRL_FILE, NYQ_CTRL_FLOAT, NYQ_CTRL_FLOAT_TEXT, NYQ_CTRL_INT, NYQ_CTRL_INT_TEXT, NYQ_CTRL_STRING, NYQ_CTRL_TEXT, NYQ_CTRL_TIME, ParseChoice(), Effect::SetLinearEffectFlag(), Effect::SetPreviewFullSelectionFlag(), NyqControl::ticks, NyquistEffect::Tokenizer::Tokenize(), NyquistEffect::Tokenizer::tokens, NyqControl::type, UnQuote(), NyqControl::val, NyqControl::valStr, and NyqControl::var.

Referenced by ParseProgram().

1707 {
1708  if ( !tzer.Tokenize(line, eof, first ? 1 : 0, 0) )
1709  return false;
1710 
1711  const auto &tokens = tzer.tokens;
1712  int len = tokens.size();
1713  if (len < 1) {
1714  return true;
1715  }
1716 
1717  // Consistency decision is for "plug-in" as the correct spelling
1718  // "plugin" (deprecated) is allowed as an undocumented convenience.
1719  if (len == 2 && tokens[0] == wxT("nyquist") &&
1720  (tokens[1] == wxT("plug-in") || tokens[1] == wxT("plugin"))) {
1721  mOK = true;
1722  return true;
1723  }
1724 
1725  if (len >= 2 && tokens[0] == wxT("type")) {
1726  if (tokens[1] == wxT("process")) {
1728  }
1729  else if (tokens[1] == wxT("generate")) {
1731  }
1732  else if (tokens[1] == wxT("analyze")) {
1734  }
1735  else if (tokens[1] == wxT("tool")) {
1737  }
1738  if (len >= 3 && tokens[2] == wxT("spectral")) {;
1739  mIsSpectral = true;
1740  }
1741  return true;
1742  }
1743 
1744  if (len == 2 && tokens[0] == wxT("codetype")) {
1745  // This will stop ParseProgram() from doing a best guess as program type.
1746  if (tokens[1] == wxT("lisp")) {
1747  mIsSal = false;
1748  mFoundType = true;
1749  }
1750  else if (tokens[1] == wxT("sal")) {
1751  mIsSal = true;
1752  mFoundType = true;
1753  }
1754  return true;
1755  }
1756 
1757  if (len >= 2 && tokens[0] == wxT("debugflags")) {
1758  for (int i = 1; i < len; i++) {
1759  // "trace" sets *tracenable* (LISP) or *sal-traceback* (SAL)
1760  // and displays debug window IF there is anything to show.
1761  if (tokens[i] == wxT("trace")) {
1762  mTrace = true;
1763  }
1764  else if (tokens[i] == wxT("notrace")) {
1765  mTrace = false;
1766  }
1767  else if (tokens[i] == wxT("compiler")) {
1768  mCompiler = true;
1769  }
1770  else if (tokens[i] == wxT("nocompiler")) {
1771  mCompiler = false;
1772  }
1773  }
1774  return true;
1775  }
1776 
1777  // We support versions 1, 2 and 3
1778  // (Version 2 added support for string parameters.)
1779  // (Version 3 added support for choice parameters.)
1780  // (Version 4 added support for project/track/selection information.)
1781  if (len >= 2 && tokens[0] == wxT("version")) {
1782  long v;
1783  tokens[1].ToLong(&v);
1784  if (v < 1 || v > 4) {
1785  // This is an unsupported plug-in version
1786  mOK = false;
1787  mInitError.Format(
1788  _("This version of Audacity does not support Nyquist plug-in version %ld"),
1789  v
1790  );
1791  return true;
1792  }
1793  mVersion = (int) v;
1794  }
1795 
1796  if (len >= 2 && tokens[0] == wxT("name")) {
1797  mName = UnQuote(tokens[1]);
1798  // Strip ... from name if it's present, perhaps in third party plug-ins
1799  // Menu system puts ... back if there are any controls
1800  // This redundant naming convention must NOT be followed for
1801  // shipped Nyquist effects with internationalization. Else the msgid
1802  // later looked up will lack the ... and will not be found.
1803  if (mName.EndsWith(wxT("...")))
1804  mName = mName.RemoveLast(3);
1805  return true;
1806  }
1807 
1808  if (len >= 2 && tokens[0] == wxT("action")) {
1809  mAction = UnQuote(tokens[1]);
1810  return true;
1811  }
1812 
1813  if (len >= 2 && tokens[0] == wxT("info")) {
1814  mInfo = UnQuote(tokens[1]);
1815  return true;
1816  }
1817 
1818  if (len >= 2 && tokens[0] == wxT("preview")) {
1819  if (tokens[1] == wxT("enabled") || tokens[1] == wxT("true")) {
1820  mEnablePreview = true;
1821  SetLinearEffectFlag(false);
1822  }
1823  else if (tokens[1] == wxT("linear")) {
1824  mEnablePreview = true;
1825  SetLinearEffectFlag(true);
1826  }
1827  else if (tokens[1] == wxT("selection")) {
1828  mEnablePreview = true;
1830  }
1831  else if (tokens[1] == wxT("disabled") || tokens[1] == wxT("false")) {
1832  mEnablePreview = false;
1833  }
1834  return true;
1835  }
1836 
1837  // Maximum number of samples to be processed. This can help the
1838  // progress bar if effect does not process all of selection.
1839  if (len >= 2 && tokens[0] == wxT("maxlen")) {
1840  long long v; // Note that Nyquist may overflow at > 2^31 samples (bug 439)
1841  tokens[1].ToLongLong(&v);
1842  mMaxLen = (sampleCount) v;
1843  }
1844 
1845 #if defined(EXPERIMENTAL_NYQUIST_SPLIT_CONTROL)
1846  if (len >= 2 && tokens[0] == wxT("mergeclips")) {
1847  long v;
1848  // -1 = auto (default), 0 = don't merge clips, 1 = do merge clips
1849  tokens[1].ToLong(&v);
1850  mMergeClips = v;
1851  return true;
1852  }
1853 
1854  if (len >= 2 && tokens[0] == wxT("restoresplits")) {
1855  long v;
1856  // Splits are restored by default. Set to 0 to prevent.
1857  tokens[1].ToLong(&v);
1858  mRestoreSplits = !!v;
1859  return true;
1860  }
1861 #endif
1862 
1863  if (len >= 2 && tokens[0] == wxT("author")) {
1864  mAuthor = UnQuote(tokens[1]);
1865  return true;
1866  }
1867 
1868  if (len >= 2 && tokens[0] == wxT("copyright")) {
1869  mCopyright = UnQuote(tokens[1]);
1870  return true;
1871  }
1872 
1873  // Page name in Audacity development manual
1874  if (len >= 2 && tokens[0] == wxT("manpage")) {
1875  // do not translate
1876  mManPage = UnQuote(tokens[1], false);
1877  return true;
1878  }
1879 
1880  // Local Help file
1881  if (len >= 2 && tokens[0] == wxT("helpfile")) {
1882  // do not translate
1883  mHelpFile = UnQuote(tokens[1], false);
1884  return true;
1885  }
1886 
1887  // Debug button may be disabled for release plug-ins.
1888  if (len >= 2 && tokens[0] == wxT("debugbutton")) {
1889  if (tokens[1] == wxT("disabled") || tokens[1] == wxT("false")) {
1890  mDebugButton = false;
1891  }
1892  return true;
1893  }
1894 
1895 
1896  if (len >= 3 && tokens[0] == wxT("control")) {
1897  NyqControl ctrl;
1898 
1899  if (len == 3 && tokens[1] == wxT("text")) {
1900  ctrl.var = tokens[1];
1901  ctrl.label = UnQuote( tokens[2] );
1902  ctrl.type = NYQ_CTRL_TEXT;
1903  }
1904  else if (len >= 5)
1905  {
1906  ctrl.var = tokens[1];
1907  ctrl.name = UnQuote( tokens[2] );
1908  // 3 is type, below
1909  ctrl.label = tokens[4];
1910 
1911  // valStr may or may not be a quoted string
1912  ctrl.valStr = len > 5 ? tokens[5] : wxT("");
1913  ctrl.val = GetCtrlValue(ctrl.valStr);
1914  if (ctrl.valStr.Len() > 0 &&
1915  (ctrl.valStr[0] == wxT('(') ||
1916  ctrl.valStr[0] == wxT('"')))
1917  ctrl.valStr = UnQuote( ctrl.valStr );
1918 
1919  // 6 is minimum, below
1920  // 7 is maximum, below
1921 
1922  if (tokens[3] == wxT("string")) {
1923  ctrl.type = NYQ_CTRL_STRING;
1924  ctrl.label = UnQuote( ctrl.label );
1925  }
1926  else if (tokens[3] == wxT("choice")) {
1927  ctrl.type = NYQ_CTRL_CHOICE;
1928  ctrl.choices = ParseChoice(ctrl.label);
1929  ctrl.label = wxT("");
1930  }
1931  else {
1932  ctrl.label = UnQuote( ctrl.label );
1933 
1934  if (len < 8) {
1935  return true;
1936  }
1937 
1938  if ((tokens[3] == wxT("float")) ||
1939  (tokens[3] == wxT("real"))) // Deprecated
1940  ctrl.type = NYQ_CTRL_FLOAT;
1941  else if (tokens[3] == wxT("int"))
1942  ctrl.type = NYQ_CTRL_INT;
1943  else if (tokens[3] == wxT("float-text"))
1944  ctrl.type = NYQ_CTRL_FLOAT_TEXT;
1945  else if (tokens[3] == wxT("int-text"))
1946  ctrl.type = NYQ_CTRL_INT_TEXT;
1947  else if (tokens[3] == wxT("time"))
1948  ctrl.type = NYQ_CTRL_TIME;
1949  else if (tokens[3] == wxT("file"))
1950  ctrl.type = NYQ_CTRL_FILE;
1951  else
1952  {
1953  wxString str;
1954  str.Printf(_("Bad Nyquist 'control' type specification: '%s' in plug-in file '%s'.\nControl not created."),
1955  tokens[3], mFileName.GetFullPath());
1956 
1957  // Too disturbing to show alert before Audacity frame is up.
1958  // Effect::MessageBox(str, wxT("Nyquist Warning"), wxOK | wxICON_EXCLAMATION);
1959 
1960  // Note that the AudacityApp's mLogger has not yet been created,
1961  // so this brings up an alert box, but after the Audacity frame is up.
1962  wxLogWarning(str);
1963  return true;
1964  }
1965 
1966  ctrl.lowStr = UnQuote( tokens[6] );
1967  if (ctrl.type == NYQ_CTRL_INT_TEXT && ctrl.lowStr.IsSameAs(wxT("nil"), false)) {
1968  ctrl.low = INT_MIN;
1969  }
1970  else if (ctrl.type == NYQ_CTRL_FLOAT_TEXT && ctrl.lowStr.IsSameAs(wxT("nil"), false)) {
1971  ctrl.low = -(FLT_MAX);
1972  }
1973  else if (ctrl.type == NYQ_CTRL_TIME && ctrl.lowStr.IsSameAs(wxT("nil"), false)) {
1974  ctrl.low = 0.0;
1975  }
1976  else {
1977  ctrl.low = GetCtrlValue(ctrl.lowStr);
1978  }
1979 
1980  ctrl.highStr = UnQuote( tokens[7] );
1981  if (ctrl.type == NYQ_CTRL_INT_TEXT && ctrl.highStr.IsSameAs(wxT("nil"), false)) {
1982  ctrl.high = INT_MAX;
1983  }
1984  else if ((ctrl.type == NYQ_CTRL_FLOAT_TEXT || ctrl.type == NYQ_CTRL_TIME) &&
1985  ctrl.highStr.IsSameAs(wxT("nil"), false))
1986  {
1987  ctrl.high = FLT_MAX;
1988  }
1989  else {
1990  ctrl.high = GetCtrlValue(ctrl.highStr);
1991  }
1992 
1993  if (ctrl.high < ctrl.low) {
1994  ctrl.high = ctrl.low;
1995  }
1996 
1997  if (ctrl.val < ctrl.low) {
1998  ctrl.val = ctrl.low;
1999  }
2000 
2001  if (ctrl.val > ctrl.high) {
2002  ctrl.val = ctrl.high;
2003  }
2004 
2005  ctrl.ticks = 1000;
2006  if (ctrl.type == NYQ_CTRL_INT &&
2007  (ctrl.high - ctrl.low < ctrl.ticks)) {
2008  ctrl.ticks = (int)(ctrl.high - ctrl.low);
2009  }
2010  }
2011  }
2012 
2013  if( mPresetNames.Index( ctrl.var ) == wxNOT_FOUND )
2014  {
2015  mControls.push_back(ctrl);
2016  }
2017  }
2018 
2019  // Deprecated
2020  if (len >= 2 && tokens[0] == wxT("categories")) {
2021  for (size_t i = 1; i < tokens.GetCount(); ++i) {
2022  mCategories.Add(tokens[i]);
2023  }
2024  }
2025  return true;
2026 }
wxString highStr
Definition: Nyquist.h:70
bool mTrace
Definition: Nyquist.h:217
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
wxString mName
Name of the Effect (untranslated)
Definition: Nyquist.h:230
static wxString UnQuote(const wxString &s, bool allowParens=true, wxString *pExtraString=nullptr)
Definition: Nyquist.cpp:1548
bool mIsSal
Definition: Nyquist.h:218
wxString mHelpFile
Definition: Nyquist.h:236
void SetPreviewFullSelectionFlag(bool previewDurationFlag)
Definition: Effect.cpp:1966
int type
Definition: Nyquist.h:63
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: Effect.cpp:1961
wxString mManPage
Definition: Nyquist.h:235
double GetCtrlValue(const wxString &s)
Definition: Nyquist.cpp:1586
A control on a NyquistDialog.
Definition: Nyquist.h:54
wxString valStr
Definition: Nyquist.h:68
EffectType mType
Definition: Nyquist.h:238
wxString lowStr
Definition: Nyquist.h:69
wxString label
Definition: Nyquist.h:66
wxArrayString mPresetNames
Definition: Effect.h:466
wxString var
Definition: Nyquist.h:64
bool mDebugButton
Definition: Nyquist.h:241
int mVersion
Definition: Nyquist.h:248
bool mFoundType
Definition: Nyquist.h:215
double low
Definition: Nyquist.h:72
bool mCompiler
Definition: Nyquist.h:216
wxString name
Definition: Nyquist.h:65
std::vector< IdentInterfaceSymbol > choices
Definition: Nyquist.h:67
static std::vector< IdentInterfaceSymbol > ParseChoice(const wxString &text)
Definition: Nyquist.cpp:1490
bool mIsSpectral
Definition: Nyquist.h:220
wxString mAction
Definition: Nyquist.h:231
bool mRestoreSplits
Definition: Nyquist.h:277
wxString mCopyright
Definition: Nyquist.h:234
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
double val
Definition: Nyquist.h:71
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: Nyquist.h:208
bool mEnablePreview
Definition: Nyquist.h:240
wxString mInitError
Definition: Nyquist.h:227
double high
Definition: Nyquist.h:73
int mMergeClips
Definition: Nyquist.h:278
wxString mInfo
Definition: Nyquist.h:232
int ticks
Definition: Nyquist.h:74
sampleCount mMaxLen
Definition: Nyquist.h:255
wxArrayString mCategories
Definition: Nyquist.h:272
wxString mAuthor
Definition: Nyquist.h:233
std::vector< IdentInterfaceSymbol > NyquistEffect::ParseChoice ( const wxString &  text)
staticprivate

Definition at line 1490 of file Nyquist.cpp.

References label, NyquistEffect::Tokenizer::Tokenize(), NyquistEffect::Tokenizer::tokens, and UnQuote().

Referenced by Parse().

1491 {
1492  std::vector<IdentInterfaceSymbol> results;
1493  if (text[0] == wxT('(')) {
1494  // New style: expecting a Lisp-like list of strings
1495  Tokenizer tzer;
1496  tzer.Tokenize(text, true, 1, 1);
1497  auto &choices = tzer.tokens;
1498  wxString extra;
1499  for (auto &choice : choices) {
1500  auto label = UnQuote(choice, true, &extra);
1501  if (extra.empty())
1502  results.push_back( { label } );
1503  else
1504  results.push_back( { extra, label } );
1505  }
1506  }
1507  else {
1508  // Old style: expecting a comma-separated list of
1509  // un-internationalized names, ignoring leading and trailing spaces
1510  // on each; and the whole may be quoted
1511  auto choices = wxStringTokenize(
1512  text[0] == wxT('"') ? text.Mid(1, text.Length() - 2) : text,
1513  wxT(",")
1514  );
1515  for (auto &choice : choices)
1516  results.push_back( { choice.Trim(true).Trim(false) } );
1517  }
1518  return results;
1519 }
static wxString UnQuote(const wxString &s, bool allowParens=true, wxString *pExtraString=nullptr)
Definition: Nyquist.cpp:1548
wxString label
Definition: Tags.cpp:727
bool NyquistEffect::ParseCommand ( const wxString &  cmd)
private

Definition at line 2121 of file Nyquist.cpp.

References ParseProgram().

Referenced by SetCommand(), and TransferDataFromPromptWindow().

2122 {
2123  wxStringInputStream stream(cmd + wxT(" "));
2124 
2125  return ParseProgram(stream);
2126 }
bool ParseProgram(wxInputStream &stream)
Definition: Nyquist.cpp:2028
void NyquistEffect::ParseFile ( )
private

Definition at line 2114 of file Nyquist.cpp.

References mFileName, and ParseProgram().

Referenced by Init().

2115 {
2116  wxFileInputStream stream(mFileName.GetFullPath());
2117 
2118  ParseProgram(stream);
2119 }
bool ParseProgram(wxInputStream &stream)
Definition: Nyquist.cpp:2028
wxFileName mFileName
Name of the Nyquist script file this effect is loaded from.
Definition: Nyquist.h:208
bool NyquistEffect::ParseProgram ( wxInputStream &  stream)
private

Definition at line 2028 of file Nyquist.cpp.

References _(), Effect::DefaultMessageBoxStyle, mCategories, mCmd, mControls, mDebug, mDebugButton, mEnablePreview, Effect::MessageBox(), mFoundType, mHelpFile, mHelpFileExists, mInitError, mIsPrompt, mIsSal, mIsSpectral, mManPage, mTrace, and Parse().

Referenced by ParseCommand(), and ParseFile().

2029 {
2030  if (!stream.IsOk())
2031  {
2032  mInitError = _("Could not open file");
2033  return false;
2034  }
2035 
2036  wxTextInputStream pgm(stream, wxT(" \t"), wxConvUTF8);
2037 
2038  mCmd = wxT("");
2039  mIsSal = false;
2040  mControls.clear();
2041  mCategories.Clear();
2042  mIsSpectral = false;
2043  mManPage = wxEmptyString; // If not wxEmptyString, must be a page in the Audacity manual.
2044  mHelpFile = wxEmptyString; // If not wxEmptyString, must be a valid HTML help file.
2045  mHelpFileExists = false;
2046  mDebug = false;
2047  mTrace = false;
2048  mDebugButton = true; // Debug button enabled by default.
2049  mEnablePreview = true; // Preview button enabled by default.
2050 
2051  mFoundType = false;
2052  while (!stream.Eof() && stream.IsOk())
2053  {
2054  bool dollar = false;
2055  wxString line = pgm.ReadLine().Trim(false);
2056  if (line.Length() > 1 &&
2057  // New in 2.3.0: allow magic comment lines to start with $
2058  // The trick is that xgettext will not consider such lines comments
2059  // and will extract the strings they contain
2060  (line[0] == wxT(';') ||
2061  (dollar = (line[0] == wxT('$')))))
2062  {
2063  Tokenizer tzer;
2064  unsigned nLines = 1;
2065  bool done;
2066  do
2067  // Allow run-ons only for new $ format header lines
2068  done = Parse(tzer, line, !dollar || stream.Eof(), nLines == 1);
2069  while(!done &&
2070  (line = pgm.ReadLine().Trim(false), ++nLines, true));
2071 
2072  // Don't pass these lines to the interpreter, so it doesn't get confused
2073  // by $, but pass blanks,
2074  // so that SAL effects compile with proper line numbers
2075  while (nLines --)
2076  mCmd += wxT('\n');
2077  }
2078  else
2079  {
2080  if(!mFoundType && line.Length() > 0) {
2081  if (line[0] == wxT('(') ||
2082  (line[0] == wxT('#') && line.Length() > 1 && line[1] == wxT('|')))
2083  {
2084  mIsSal = false;
2085  mFoundType = true;
2086  }
2087  else if (line.Upper().Find(wxT("RETURN")) != wxNOT_FOUND)
2088  {
2089  mIsSal = true;
2090  mFoundType = true;
2091  }
2092  }
2093  mCmd += line + wxT("\n");
2094  }
2095  }
2096  if (!mFoundType && mIsPrompt)
2097  {
2098  /* i1n-hint: SAL and LISP are names for variant syntaxes for the
2099  Nyquist programming language. Leave them, and 'return', untranslated. */
2100  Effect::MessageBox(_("Your code looks like SAL syntax, but there is no \'return\' statement.\n\
2101 For SAL, use a return statement such as:\n\treturn *track* * 0.1\n\
2102 or for LISP, begin with an open parenthesis such as:\n\t(mult *track* 0.1)\n ."),
2104  _("Error in Nyquist code"));
2105  /* i18n-hint: refers to programming "languages" */
2106  mInitError = _("Could not determine language");
2107  return false;
2108  // Else just throw it at Nyquist to see what happens
2109  }
2110 
2111  return true;
2112 }
bool mTrace
Definition: Nyquist.h:217
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
bool mIsSal
Definition: Nyquist.h:218
wxString mHelpFile
Definition: Nyquist.h:236
wxString mManPage
Definition: Nyquist.h:235
bool mHelpFileExists
Definition: Nyquist.h:237
bool Parse(Tokenizer &tokenizer, const wxString &line, bool eof, bool first)
Definition: Nyquist.cpp:1705
bool mDebugButton
Definition: Nyquist.h:241
bool mFoundType
Definition: Nyquist.h:215
bool mIsSpectral
Definition: Nyquist.h:220
wxString mCmd
Definition: Nyquist.h:229
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
bool mIsPrompt
Definition: Nyquist.h:225
bool mEnablePreview
Definition: Nyquist.h:240
bool mDebug
Definition: Nyquist.h:243
wxString mInitError
Definition: Nyquist.h:227
wxArrayString mCategories
Definition: Nyquist.h:272
void NyquistEffect::PopulateOrExchange ( ShuttleGui S)
overridevirtual

Reimplemented from Effect.

Definition at line 923 of file Nyquist.cpp.

References BuildEffectWindow(), BuildPromptWindow(), Effect::EnableDebug(), mDebugButton, and mIsPrompt.

924 {
925  if (mIsPrompt)
926  {
928  }
929  else
930  {
932  }
933 
935 }
void BuildEffectWindow(ShuttleGui &S)
Definition: Nyquist.cpp:2506
virtual void EnableDebug(bool enable=true)
Definition: Effect.cpp:1956
void BuildPromptWindow(ShuttleGui &S)
Definition: Nyquist.cpp:2470
bool mDebugButton
Definition: Nyquist.h:241
bool mIsPrompt
Definition: Nyquist.h:225
bool NyquistEffect::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 580 of file Nyquist.cpp.

References _(), Track::All, AUDACITY_RELEASE, AUDACITY_REVISION, AUDACITY_VERSION, FileNames::BaseDir(), Effect::CopyInputTracks(), FileNames::DataDir(), EffectTypeProcess, EscapeString(), gAudacityProjects, EffectManager::Get(), GetActiveProject(), AudacityProject::GetName(), Effect::GetNumWaveGroups(), GetNyquistSearchPath(), AudacityProject::GetRate(), AudacityProject::GetTracks(), GetType(), gPrefs, FileNames::HtmlHelpDir(), AudacityApp::InitLang(), Effect::IsPreviewing(), Track::Label, mBreak, mCont, mCount, mCurLen, mCurNumChannels, mCurStart, mCurTrack, mDebug, mDebugOutput, Effect::MessageBox(), mExternal, Effect::mF0, Effect::mF1, mFirstInGroup, mHelpFile, mHelpFileExists, min(), mMaxLen, mName, mNumSelectedChannels, mOutputTime, Effect::mOutputTracks, mPerTrackProps, Effect::mProgress, mProgressIn, mProgressOut, mProgressTot, mProjectChanged, mProps, mRedirectOutput, mScale, mStop, Effect::mT0, Effect::mT1, mTrace, mTrackIndex, Effect::mUIParent, mVersion, NYQ_MAX_LEN, ProcessOne(), RegisterFunctions(), Effect::ReplaceProcessedTracks(), EffectManager::SetSkipStateFlag(), StaticOSCallback(), StaticOutputCallback(), FileNames::TempDir(), Track::Time, Internat::ToString(), Track::Wave, and wxGetApp().

581 {
583 
584  bool success = true;
585 
586  mProjectChanged = false;
588  em.SetSkipStateFlag(false);
589 
590  if (mExternal) {
591  mProgress->Hide();
592  }
593 
594  // We must copy all the tracks, because Paste needs label tracks to ensure
595  // correct sync-lock group behavior when the timeline is affected; then we just want
596  // to operate on the selected wave tracks
599  mCurTrack[0] = (WaveTrack *) iter.First();
600  mOutputTime = 0;
601  mCount = 0;
602  mProgressIn = 0;
603  mProgressOut = 0;
604  mProgressTot = 0;
605  mScale = (GetType() == EffectTypeProcess ? 0.5 : 1.0) / GetNumWaveGroups();
606 
607  mStop = false;
608  mBreak = false;
609  mCont = false;
610 
611  mTrackIndex = 0;
612 
615  for (WaveTrack *t = (WaveTrack *) sel.First(); t; t = (WaveTrack *) sel.Next()) {
617  if (mT1 >= mT0) {
618  if (t->GetLinked()) {
620  sel.Next();
621  }
622  }
623  }
624 
625  mDebugOutput.Clear();
626  if (!mHelpFile.IsEmpty() && !mHelpFileExists) {
627  mDebugOutput = wxString::Format(_("error: File \"%s\" specified in header but not found in plug-in path.\n"), mHelpFile);
628  }
629 
630  if (mVersion >= 4)
631  {
632  AudacityProject *project = GetActiveProject();
633 
634  mProps = wxEmptyString;
635 
636  mProps += wxString::Format(wxT("(putprop '*AUDACITY* (list %d %d %d) 'VERSION)\n"), AUDACITY_VERSION, AUDACITY_RELEASE, AUDACITY_REVISION);
637  // TODO: Document.
638  wxString lang = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
639  lang = (lang == wxEmptyString)? wxGetApp().InitLang(lang) : lang;
640  mProps += wxString::Format(wxT("(putprop '*AUDACITY* \"%s\" 'LANGUAGE)\n"), lang);
641 
642  mProps += wxString::Format(wxT("(setf *DECIMAL-SEPARATOR* #\\%c)\n"), wxNumberFormatter::GetDecimalSeparator());
643 
644  mProps += wxString::Format(wxT("(putprop '*SYSTEM-DIR* \"%s\" 'BASE)\n"), EscapeString(FileNames::BaseDir()));
645  mProps += wxString::Format(wxT("(putprop '*SYSTEM-DIR* \"%s\" 'DATA)\n"), EscapeString(FileNames::DataDir()));
646  mProps += wxString::Format(wxT("(putprop '*SYSTEM-DIR* \"%s\" 'HELP)\n"), EscapeString(FileNames::HtmlHelpDir().RemoveLast()));
647  mProps += wxString::Format(wxT("(putprop '*SYSTEM-DIR* \"%s\" 'TEMP)\n"), EscapeString(FileNames::TempDir()));
648 
649  wxArrayString paths = NyquistEffect::GetNyquistSearchPath();
650  wxString list;
651  for (size_t i = 0, cnt = paths.GetCount(); i < cnt; i++)
652  {
653  list += wxT("\"") + EscapeString(paths[i]) + wxT("\" ");
654  }
655  list = list.RemoveLast();
656 
657  mProps += wxString::Format(wxT("(putprop '*SYSTEM-DIR* (list %s) 'PLUGIN)\n"), list);
658  mProps += wxString::Format(wxT("(putprop '*SYSTEM-DIR* (list %s) 'PLUG-IN)\n"), list);
659 
660 
661  // Date and time:
662  wxDateTime now = wxDateTime::Now();
663  int year = now.GetYear();
664  int doy = now.GetDayOfYear();
665  int dom = now.GetDay();
666  // enumerated constants
667  wxDateTime::Month month = now.GetMonth();
668  wxDateTime::WeekDay day = now.GetWeekDay();
669 
670  // Date/time as a list: year, day of year, hour, minute, seconds
671  mProps += wxString::Format(wxT("(setf *SYSTEM-TIME* (list %d %d %d %d %d))\n"),
672  year, doy, now.GetHour(), now.GetMinute(), now.GetSecond());
673 
674  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* \"%s\" 'DATE)\n"), now.FormatDate());
675  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* \"%s\" 'TIME)\n"), now.FormatTime());
676  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* \"%s\" 'ISO-DATE)\n"), now.FormatISODate());
677  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* \"%s\" 'ISO-TIME)\n"), now.FormatISOTime());
678  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* %d 'YEAR)\n"), year);
679  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* %d 'DAY)\n"), dom); // day of month
680  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* %d 'MONTH)\n"), month);
681  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* \"%s\" 'MONTH-NAME)\n"), now.GetMonthName(month));
682  mProps += wxString::Format(wxT("(putprop '*SYSTEM-TIME* \"%s\" 'DAY-NAME)\n"), now.GetWeekDayName(day));
683 
684  mProps += wxString::Format(wxT("(putprop '*PROJECT* %d 'PROJECTS)\n"), (int) gAudacityProjects.size());
685  mProps += wxString::Format(wxT("(putprop '*PROJECT* \"%s\" 'NAME)\n"), project->GetName());
686 
687  TrackListIterator all(project->GetTracks());
688  Track *t;
689  int numTracks = 0;
690  int numWave = 0;
691  int numLabel = 0;
692  int numMidi = 0;
693  int numTime = 0;
694  wxString waveTrackList = wxT(""); // track positions of selected audio tracks.
695 
696  for (t = all.First(); t; t = all.Next())
697  {
698  switch (t->GetKind())
699  {
700  case Track::Wave:
701  numWave++;
702  if (t->GetSelected()) {
703  waveTrackList += wxString::Format(wxT("%d "), 1 + numTracks);
704  }
705  break;
706  case Track::Label: numLabel++; break;
707 #if defined(USE_MIDI)
708  case Track::Note: numMidi++; break;
709 #endif
710  case Track::Time: numTime++; break;
711  default: break;
712  }
713 
714  numTracks++;
715  if (t->GetLinked())
716  {
717  all.Next();
718  }
719  }
720 
721  // We use Internat::ToString() rather than "%g" here because we
722  // always have to use the dot as decimal separator when giving
723  // numbers to Nyquist, whereas using "%g" will use the user's
724  // decimal separator which may be a comma in some countries.
725  mProps += wxString::Format(wxT("(putprop '*PROJECT* (float %s) 'RATE)\n"),
726  Internat::ToString(project->GetRate()));
727  mProps += wxString::Format(wxT("(putprop '*PROJECT* %d 'TRACKS)\n"), numTracks);
728  mProps += wxString::Format(wxT("(putprop '*PROJECT* %d 'WAVETRACKS)\n"), numWave);
729  mProps += wxString::Format(wxT("(putprop '*PROJECT* %d 'LABELTRACKS)\n"), numLabel);
730  mProps += wxString::Format(wxT("(putprop '*PROJECT* %d 'MIDITRACKS)\n"), numMidi);
731  mProps += wxString::Format(wxT("(putprop '*PROJECT* %d 'TIMETRACKS)\n"), numTime);
732 
733  double previewLen = 6.0;
734  gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLen);
735  mProps += wxString::Format(wxT("(putprop '*PROJECT* (float %s) 'PREVIEW-DURATION)\n"),
736  Internat::ToString(previewLen));
737 
738  // *PREVIEWP* is true when previewing (better than relying on track view).
739  wxString isPreviewing = (this->IsPreviewing())? wxT("T") : wxT("NIL");
740  mProps += wxString::Format(wxT("(setf *PREVIEWP* %s)\n"), isPreviewing);
741 
742  mProps += wxString::Format(wxT("(putprop '*SELECTION* (float %s) 'START)\n"),
744  mProps += wxString::Format(wxT("(putprop '*SELECTION* (float %s) 'END)\n"),
746  mProps += wxString::Format(wxT("(putprop '*SELECTION* (list %s) 'TRACKS)\n"), waveTrackList);
747  mProps += wxString::Format(wxT("(putprop '*SELECTION* %d 'CHANNELS)\n"), mNumSelectedChannels);
748  }
749 
750  // Keep track of whether the current track is first selected in its sync-lock group
751  // (we have no idea what the length of the returned audio will be, so we have
752  // to handle sync-lock group behavior the "old" way).
753  mFirstInGroup = true;
754  Track *gtLast = NULL;
755 
756  while (mCurTrack[0]) {
757  mCurNumChannels = 1;
758  if (mT1 >= mT0) {
759  if (mCurTrack[0]->GetLinked()) {
760  mCurNumChannels = 2;
761 
762  mCurTrack[1] = (WaveTrack *)iter.Next();
763  if (mCurTrack[1]->GetRate() != mCurTrack[0]->GetRate()) {
764  Effect::MessageBox(_("Sorry, cannot apply effect on stereo tracks where the tracks don't match."),
765  wxOK | wxCENTRE);
766  success = false;
767  goto finish;
768  }
769  mCurStart[1] = mCurTrack[1]->TimeToLongSamples(mT0);
770  }
771 
772  // Check whether we're in the same group as the last selected track
774  Track *gt = gIter.StartWith(mCurTrack[0]);
775  mFirstInGroup = !gtLast || (gtLast != gt);
776  gtLast = gt;
777 
778  mCurStart[0] = mCurTrack[0]->TimeToLongSamples(mT0);
779  auto end = mCurTrack[0]->TimeToLongSamples(mT1);
780  mCurLen = end - mCurStart[0];
781 
782  if (mCurLen > NYQ_MAX_LEN) {
783  float hours = (float)NYQ_MAX_LEN / (44100 * 60 * 60);
784  const auto message = wxString::Format(
785 _("Selection too long for Nyquist code.\nMaximum allowed selection is %ld samples\n(about %.1f hours at 44100 Hz sample rate)."),
786  (long)NYQ_MAX_LEN, hours
787  );
788  Effect::MessageBox(message, wxOK | wxCENTRE, _("Nyquist Error"));
789  if (!mProjectChanged)
790  em.SetSkipStateFlag(true);
791  return false;
792  }
793 
795 
796  mProgressIn = 0.0;
797  mProgressOut = 0.0;
798 
799  // libnyquist breaks except in LC_NUMERIC=="C".
800  //
801  // Note that we must set the locale to "C" even before calling
802  // nyx_init() because otherwise some effects will not work!
803  //
804  // MB: setlocale is not thread-safe. Should use uselocale()
805  // if available, or fix libnyquist to be locale-independent.
806  // See also http://bugzilla.audacityteam.org/show_bug.cgi?id=642#c9
807  // for further info about this thread safety question.
808  wxString prevlocale = wxSetlocale(LC_NUMERIC, NULL);
809  wxSetlocale(LC_NUMERIC, wxString(wxT("C")));
810 
811  nyx_init();
812  nyx_set_os_callback(StaticOSCallback, (void *)this);
813  nyx_capture_output(StaticOutputCallback, (void *)this);
814 
815  auto cleanup = finally( [&] {
816  nyx_capture_output(NULL, (void *)NULL);
817  nyx_set_os_callback(NULL, (void *)NULL);
818  nyx_cleanup();
819  } );
820 
821 
822  if (mVersion >= 4)
823  {
824  mPerTrackProps = wxEmptyString;
825  wxString lowHz = wxT("nil");
826  wxString highHz = wxT("nil");
827  wxString centerHz = wxT("nil");
828  wxString bandwidth = wxT("nil");
829 
830 #if defined(EXPERIMENTAL_SPECTRAL_EDITING)
831  if (mF0 >= 0.0) {
832  lowHz.Printf(wxT("(float %s)"), Internat::ToString(mF0));
833  }
834 
835  if (mF1 >= 0.0) {
836  highHz.Printf(wxT("(float %s)"), Internat::ToString(mF1));
837  }
838 
839  if ((mF0 >= 0.0) && (mF1 >= 0.0)) {
840  centerHz.Printf(wxT("(float %s)"), Internat::ToString(sqrt(mF0 * mF1)));
841  }
842 
843  if ((mF0 > 0.0) && (mF1 >= mF0)) {
844  // with very small values, bandwidth calculation may be inf.
845  // (Observed on Linux)
846  double bw = log(mF1 / mF0) / log(2.0);
847  if (!std::isinf(bw)) {
848  bandwidth.Printf(wxT("(float %s)"), Internat::ToString(bw));
849  }
850  }
851 
852 #endif
853  mPerTrackProps += wxString::Format(wxT("(putprop '*SELECTION* %s 'LOW-HZ)\n"), lowHz);
854  mPerTrackProps += wxString::Format(wxT("(putprop '*SELECTION* %s 'CENTER-HZ)\n"), centerHz);
855  mPerTrackProps += wxString::Format(wxT("(putprop '*SELECTION* %s 'HIGH-HZ)\n"), highHz);
856  mPerTrackProps += wxString::Format(wxT("(putprop '*SELECTION* %s 'BANDWIDTH)\n"), bandwidth);
857  }
858 
859  success = ProcessOne();
860 
861  // Reset previous locale
862  wxSetlocale(LC_NUMERIC, prevlocale);
863 
864  if (!success) {
865  goto finish;
866  }
868  }
869 
870  mCurTrack[0] = (WaveTrack *) iter.Next();
872  }
873 
874  if (mOutputTime > 0.0) {
875  mT1 = mT0 + mOutputTime;
876  }
877 
878 finish:
879 
880  // Show debug window if trace set in plug-in header and something to show.
881  mDebug = (mTrace && !mDebugOutput.IsEmpty())? true : mDebug;
882 
883  if (mDebug && !mRedirectOutput) {
885  mName,
886  _("Debug Output: "),
887  mDebugOutput);
888  dlog.CentreOnParent();
889  dlog.ShowModal();
890  }
891 
892  ReplaceProcessedTracks(success);
893 
894  if (!mProjectChanged)
895  em.SetSkipStateFlag(true);
896 
897  return success;
898 }
#define AUDACITY_REVISION
Definition: Audacity.h:65
wxString mDebugOutput
Definition: Nyquist.h:246
bool mTrace
Definition: Nyquist.h:217
sampleCount mCurLen
Definition: Nyquist.h:254
double mProgressIn
Definition: Nyquist.h:261
bool mStop
Definition: Nyquist.h:211
double mT1
Definition: Effect.h:461
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
wxString mName
Name of the Effect (untranslated)
Definition: Nyquist.h:230
ProgressDialog * mProgress
Definition: Effect.h:452
bool mProjectChanged
Definition: Nyquist.h:245
wxString mHelpFile
Definition: Nyquist.h:236
unsigned mNumSelectedChannels
Definition: Nyquist.h:260
bool IsPreviewing()
Definition: Effect.h:361
void CopyInputTracks()
Definition: Effect.cpp:2036
AProjectArray gAudacityProjects
Definition: Project.cpp:303
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
double mProgressOut
Definition: Nyquist.h:262
static wxArrayString GetNyquistSearchPath()
Definition: Nyquist.cpp:2277
bool mExternal
Definition: Nyquist.h:219
bool mHelpFileExists
Definition: Nyquist.h:237
static void StaticOSCallback(void *userdata)
Definition: Nyquist.cpp:2242
#define AUDACITY_VERSION
Definition: Audacity.h:63
double mF0
Definition: Effect.h:463
static wxString BaseDir()
Definition: FileNames.cpp:229
static void RegisterFunctions()
Definition: Nyquist.cpp:3089
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
bool mBreak
Definition: Nyquist.h:212
double mOutputTime
Definition: Nyquist.h:258
static wxString HtmlHelpDir()
Definition: FileNames.cpp:173
wxString InitLang(const wxString &lang)
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:138
int mVersion
Definition: Nyquist.h:248
sampleCount mCurStart[2]
Definition: Nyquist.h:253
unsigned mCount
Definition: Nyquist.h:259
WaveTrack * mCurTrack[2]
Definition: Nyquist.h:252
double mScale
Definition: Nyquist.h:264
bool mFirstInGroup
Definition: Nyquist.h:257
bool ProcessOne()
Definition: Nyquist.cpp:976
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
#define NYQ_MAX_LEN
Definition: Nyquist.cpp:93
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:45
int min(int a, int b)
#define AUDACITY_RELEASE
Definition: Audacity.h:64
wxString EscapeString(const wxString &inStr)
Definition: Nyquist.cpp:1480
Dialog used with NyquistEffect.
Definition: Nyquist.h:290
static EffectManager & Get()
EffectType GetType() override
Definition: Nyquist.cpp:256
bool mCont
Definition: Nyquist.h:213
static wxString TempDir()
Definition: FileNames.cpp:86
wxWindow * mUIParent
Definition: Effect.h:472
An iterator for a TrackList.
Definition: Track.h:402
bool mRedirectOutput
Definition: Nyquist.h:244
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxString mProps
Definition: Nyquist.h:274
unsigned mCurNumChannels
Definition: Nyquist.h:251
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
void SetSkipStateFlag(bool flag)
int GetNumWaveGroups()
Definition: Effect.h:345
wxString GetName()
Definition: Project.cpp:1465
static wxString DataDir()
Audacity user data directory.
Definition: FileNames.cpp:130
int mTrackIndex
Definition: Nyquist.h:256
wxString mPerTrackProps
Definition: Nyquist.h:275
bool mDebug
Definition: Nyquist.h:243
double GetRate() const
Definition: Project.h:199
AudacityApp & wxGetApp()
double mF1
Definition: Effect.h:464
TrackList * GetTracks()
Definition: Project.h:192
double mProgressTot
Definition: Nyquist.h:263
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
static void StaticOutputCallback(int c, void *userdata)
Definition: Nyquist.cpp:2226
sampleCount mMaxLen
Definition: Nyquist.h:255
double mT0
Definition: Effect.h:460
bool NyquistEffect::ProcessOne ( )
private

Definition at line 976 of file Nyquist.cpp.

References _(), LabelTrack::AddLabel(), Effect::AddToOutputTracks(), sampleCount::as_long_long(), WaveTrack::ClearAndPaste(), EffectTypeGenerate, EffectTypeProcess, EscapeString(), floatSample, WaveTrack::Flush(), format, SampleBuffer::Free(), WaveTrack::GetEndTime(), Track::GetEndTime(), Track::GetLink(), WaveTrack::GetMinMax(), WaveTrack::GetRate(), WaveTrack::GetRMS(), WaveTrack::GetSampleFormat(), WaveTrack::GetSpectrogramSettings(), WaveTrack::GetStartTime(), Track::GetStartTime(), GetType(), WaveTrack::GetWaveformSettings(), int16Sample, int24Sample, Track::Label, mCmd, mCompiler, mControls, mCount, mCurBuffer, mCurLen, mCurNumChannels, mCurTrack, mDebug, mDebugOutput, Effect::MessageBox(), mExternal, Effect::mFactory, mFirstInGroup, min(), mIsPrompt, mIsSal, mMergeClips, mName, mNumSelectedChannels, mOutputTime, mOutputTrack, Effect::mOutputTracks, mPerTrackProps, mpException, mProjectChanged, mProps, mRestoreSplits, Effect::mT0, Effect::mT1, mTrace, mTrackIndex, mVersion, TrackFactory::NewLabelTrack(), TrackFactory::NewWaveTrack(), NYQ_CTRL_CHOICE, NYQ_CTRL_FILE, NYQ_CTRL_FLOAT, NYQ_CTRL_FLOAT_TEXT, NYQ_CTRL_INT, NYQ_CTRL_INT_TEXT, NYQ_CTRL_STRING, NYQ_CTRL_TIME, NyquistToWxString(), WaveformSettings::scaleType, WaveTrack::SetWaveColorIndex(), WaveTrack::SortedClipArray(), SpectrogramSettings::SpectralSelectionEnabled(), WaveTrack::Spectrum, StaticGetCallback(), StaticPutCallback(), Track::SyncLockAdjust(), Track::Time, WaveTrack::TimeToLongSamples(), Internat::ToString(), Effect::TrackGroupProgress(), Effect::TrackProgress(), UTF8CTOWX, valueRestorer(), Track::Wave, and WaveTrack::Waveform.

Referenced by Process().

977 {
978  mpException = {};
979 
980  nyx_rval rval;
981 
982  wxString cmd;
983  cmd += wxT("(snd-set-latency 0.1)");
984 
985  if (mVersion >= 4) {
986  nyx_set_audio_name("*TRACK*");
987  cmd += wxT("(setf S 0.25)\n");
988  }
989  else {
990  nyx_set_audio_name("S");
991  cmd += wxT("(setf *TRACK* '*unbound*)\n");
992  }
993 
994  if (mVersion >= 4) {
995  cmd += mProps;
996  cmd += mPerTrackProps;
997 
998  // Set the track TYPE and VIEW properties
999  wxString type;
1000  wxString view;
1001  wxString bitFormat;
1002  wxString spectralEditp;
1003 
1004  switch (mCurTrack[0]->GetKind())
1005  {
1006  case Track::Wave:
1007  type = wxT("wave");
1008  spectralEditp = mCurTrack[0]->GetSpectrogramSettings().SpectralSelectionEnabled()? wxT("T") : wxT("NIL");
1009  switch (((WaveTrack *) mCurTrack[0])->GetDisplay())
1010  {
1011  case WaveTrack::Waveform:
1012  view = (mCurTrack[0]->GetWaveformSettings().scaleType == 0) ? wxT("\"Waveform\"") : wxT("\"Waveform (dB)\"");
1013  break;
1014  case WaveTrack::Spectrum:
1015  view = wxT("\"Spectrogram\"");
1016  break;
1017  default: view = wxT("NIL"); break;
1018  }
1019  break;
1020 #if defined(USE_MIDI)
1021  case Track::Note:
1022  type = wxT("midi");
1023  view = wxT("\"Midi\"");
1024  break;
1025 #endif
1026  case Track::Label:
1027  type = wxT("label");
1028  view = wxT("\"Label\"");
1029  break;
1030  case Track::Time:
1031  type = wxT("time");
1032  view = wxT("\"Time\"");
1033  break;
1034  }
1035 
1036  cmd += wxString::Format(wxT("(putprop '*TRACK* %d 'INDEX)\n"), ++mTrackIndex);
1037  cmd += wxString::Format(wxT("(putprop '*TRACK* \"%s\" 'NAME)\n"), mCurTrack[0]->GetName());
1038  cmd += wxString::Format(wxT("(putprop '*TRACK* \"%s\" 'TYPE)\n"), type);
1039  // Note: "View" property may change when Audacity's choice of track views has stabilized.
1040  cmd += wxString::Format(wxT("(putprop '*TRACK* %s 'VIEW)\n"), view);
1041  cmd += wxString::Format(wxT("(putprop '*TRACK* %d 'CHANNELS)\n"), mCurNumChannels);
1042 
1043  //NOTE: Audacity 2.1.3 True if spectral selection is enabled regardless of track view.
1044  cmd += wxString::Format(wxT("(putprop '*TRACK* %s 'SPECTRAL-EDIT-ENABLED)\n"), spectralEditp);
1045 
1046  double startTime = 0.0;
1047  double endTime = 0.0;
1048 
1049  if (mCurTrack[0]->GetLinked()) {
1050  startTime = std::min<double>(mCurTrack[0]->GetStartTime(), mCurTrack[0]->GetLink()->GetStartTime());
1051  }
1052  else {
1053  startTime = mCurTrack[0]->GetStartTime();
1054  }
1055 
1056  if (mCurTrack[0]->GetLinked()) {
1057  endTime = std::max<double>(mCurTrack[0]->GetEndTime(), mCurTrack[0]->GetLink()->GetEndTime());
1058  }
1059  else {
1060  endTime = mCurTrack[0]->GetEndTime();
1061  }
1062 
1063  cmd += wxString::Format(wxT("(putprop '*TRACK* (float %s) 'START-TIME)\n"),
1064  Internat::ToString(startTime));
1065  cmd += wxString::Format(wxT("(putprop '*TRACK* (float %s) 'END-TIME)\n"),
1066  Internat::ToString(endTime));
1067  cmd += wxString::Format(wxT("(putprop '*TRACK* (float %s) 'GAIN)\n"),
1068  Internat::ToString(mCurTrack[0]->GetGain()));
1069  cmd += wxString::Format(wxT("(putprop '*TRACK* (float %s) 'PAN)\n"),
1070  Internat::ToString(mCurTrack[0]->GetPan()));
1071  cmd += wxString::Format(wxT("(putprop '*TRACK* (float %s) 'RATE)\n"),
1072  Internat::ToString(mCurTrack[0]->GetRate()));
1073 
1074  switch (mCurTrack[0]->GetSampleFormat())
1075  {
1076  case int16Sample:
1077  bitFormat = wxT("16");
1078  break;
1079  case int24Sample:
1080  bitFormat = wxT("24");
1081  break;
1082  case floatSample:
1083  bitFormat = wxT("32.0");
1084  break;
1085  }
1086  cmd += wxString::Format(wxT("(putprop '*TRACK* %s 'FORMAT)\n"), bitFormat);
1087 
1088  float maxPeakLevel = 0.0; // Deprecated as of 2.1.3
1089  wxString clips, peakString, rmsString;
1090  for (size_t i = 0; i < mCurNumChannels; i++) {
1091  auto ca = mCurTrack[i]->SortedClipArray();
1092  float maxPeak = 0.0;
1093 
1094  // A list of clips for mono, or an array of lists for multi-channel.
1095  if (mCurNumChannels > 1) {
1096  clips += wxT("(list ");
1097  }
1098  // Each clip is a list (start-time, end-time)
1099  for (const auto clip: ca) {
1100  clips += wxString::Format(wxT("(list (float %s) (float %s))"),
1101  Internat::ToString(clip->GetStartTime()),
1102  Internat::ToString(clip->GetEndTime()));
1103  }
1104  if (mCurNumChannels > 1) clips += wxT(" )");
1105 
1106  float min, max;
1107  auto pair = mCurTrack[i]->GetMinMax(mT0, mT1); // may throw
1108  min = pair.first, max = pair.second;
1109  maxPeak = wxMax(wxMax(fabs(min), fabs(max)), maxPeak);
1110  maxPeakLevel = wxMax(maxPeakLevel, maxPeak);
1111 
1112  // On Debian, NaN samples give maxPeak = 3.40282e+38 (FLT_MAX)
1113  if (!std::isinf(maxPeak) && !std::isnan(maxPeak) && (maxPeak < FLT_MAX)) {
1114  peakString += wxString::Format(wxT("(float %s) "), Internat::ToString(maxPeak));
1115  } else {
1116  peakString += wxT("nil ");
1117  }
1118 
1119  float rms = mCurTrack[i]->GetRMS(mT0, mT1); // may throw
1120  if (!std::isinf(rms) && !std::isnan(rms)) {
1121  rmsString += wxString::Format(wxT("(float %s) "), Internat::ToString(rms));
1122  } else {
1123  rmsString += wxT("nil ");
1124  }
1125  }
1126  // A list of clips for mono, or an array of lists for multi-channel.
1127  cmd += wxString::Format(wxT("(putprop '*TRACK* %s%s ) 'CLIPS)\n"),
1128  (mCurNumChannels == 1) ? wxT("(list ") : wxT("(vector "),
1129  clips);
1130 
1131  (mCurNumChannels > 1)?
1132  cmd += wxString::Format(wxT("(putprop '*SELECTION* (vector %s) 'PEAK)\n"), peakString) :
1133  cmd += wxString::Format(wxT("(putprop '*SELECTION* %s 'PEAK)\n"), peakString);
1134 
1135  if (!std::isinf(maxPeakLevel) && !std::isnan(maxPeakLevel) && (maxPeakLevel < FLT_MAX)) {
1136  cmd += wxString::Format(wxT("(putprop '*SELECTION* (float %s) 'PEAK-LEVEL)\n"),
1137  Internat::ToString(maxPeakLevel));
1138  }
1139 
1140  (mCurNumChannels > 1)?
1141  cmd += wxString::Format(wxT("(putprop '*SELECTION* (vector %s) 'RMS)\n"), rmsString) :
1142  cmd += wxString::Format(wxT("(putprop '*SELECTION* %s 'RMS)\n"), rmsString);
1143  }
1144 
1145  if (GetType() == EffectTypeGenerate) {
1146  nyx_set_audio_params(mCurTrack[0]->GetRate(), 0);
1147  }
1148  else {
1149  // UNSAFE_SAMPLE_COUNT_TRUNCATION
1150  // Danger! Truncation of long long to long!
1151  // Don't say we didn't warn you!
1152 
1153  // Note mCurLen was elsewhere limited to mMaxLen, which is normally
1154  // the greatest long value, and yet even mMaxLen may be experimentally
1155  // increased with a nyquist comment directive.
1156  // See the parsing of "maxlen"
1157 
1158  auto curLen = long(mCurLen.as_long_long());
1159  nyx_set_audio_params(mCurTrack[0]->GetRate(), curLen);
1160 
1161  nyx_set_input_audio(StaticGetCallback, (void *)this,
1162  (int)mCurNumChannels,
1163  curLen, mCurTrack[0]->GetRate());
1164  }
1165 
1166  // Restore the Nyquist sixteenth note symbol for Generate plug-ins.
1167  // See http://bugzilla.audacityteam.org/show_bug.cgi?id=490.
1168  if (GetType() == EffectTypeGenerate) {
1169  cmd += wxT("(setf s 0.25)\n");
1170  }
1171 
1172  if (mDebug || mTrace) {
1173  cmd += wxT("(setf *tracenable* T)\n");
1174  if (mExternal) {
1175  cmd += wxT("(setf *breakenable* T)\n");
1176  }
1177  }
1178  else {
1179  // Explicitly disable backtrace and prevent values
1180  // from being carried through to the output.
1181  // This should be the final command before evaluating the Nyquist script.
1182  cmd += wxT("(setf *tracenable* NIL)\n");
1183  }
1184 
1185  for (unsigned int j = 0; j < mControls.size(); j++) {
1186  if (mControls[j].type == NYQ_CTRL_FLOAT || mControls[j].type == NYQ_CTRL_FLOAT_TEXT ||
1187  mControls[j].type == NYQ_CTRL_TIME) {
1188  // We use Internat::ToString() rather than "%f" here because we
1189  // always have to use the dot as decimal separator when giving
1190  // numbers to Nyquist, whereas using "%f" will use the user's
1191  // decimal separator which may be a comma in some countries.
1192  cmd += wxString::Format(wxT("(setf %s %s)\n"),
1193  mControls[j].var,
1194  Internat::ToString(mControls[j].val, 14));
1195  }
1196  else if (mControls[j].type == NYQ_CTRL_INT ||
1197  mControls[j].type == NYQ_CTRL_INT_TEXT ||
1198  mControls[j].type == NYQ_CTRL_CHOICE) {
1199  cmd += wxString::Format(wxT("(setf %s %d)\n"),
1200  mControls[j].var,
1201  (int)(mControls[j].val));
1202  }
1203  else if (mControls[j].type == NYQ_CTRL_STRING || mControls[j].type == NYQ_CTRL_FILE) {
1204  cmd += wxT("(setf ");
1205  // restrict variable names to 7-bit ASCII:
1206  cmd += mControls[j].var;
1207  cmd += wxT(" \"");
1208  cmd += EscapeString(mControls[j].valStr); // unrestricted value will become quoted UTF-8
1209  cmd += wxT("\")\n");
1210  }
1211  }
1212 
1213  if (mIsSal) {
1214  wxString str = EscapeString(mCmd);
1215  // this is tricky: we need SAL to call main so that we can get a
1216  // SAL traceback in the event of an error (sal-compile catches the
1217  // error and calls sal-error-output), but SAL does not return values.
1218  // We will catch the value in a special global aud:result and if no
1219  // error occurs, we will grab the value with a LISP expression
1220  str += wxT("\nset aud:result = main()\n");
1221 
1222  if (mDebug || mTrace) {
1223  // since we're about to evaluate SAL, remove LISP trace enable and
1224  // break enable (which stops SAL processing) and turn on SAL stack
1225  // trace
1226  cmd += wxT("(setf *tracenable* nil)\n");
1227  cmd += wxT("(setf *breakenable* nil)\n");
1228  cmd += wxT("(setf *sal-traceback* t)\n");
1229  }
1230 
1231  if (mCompiler) {
1232  cmd += wxT("(setf *sal-compiler-debug* t)\n");
1233  }
1234 
1235  cmd += wxT("(setf *sal-call-stack* nil)\n");
1236  // if we do not set this here and an error occurs in main, another
1237  // error will be raised when we try to return the value of aud:result
1238  // which is unbound
1239  cmd += wxT("(setf aud:result nil)\n");
1240  cmd += wxT("(sal-compile-audacity \"") + str + wxT("\" t t nil)\n");
1241  // Capture the value returned by main (saved in aud:result), but
1242  // set aud:result to nil so sound results can be evaluated without
1243  // retaining audio in memory
1244  cmd += wxT("(prog1 aud:result (setf aud:result nil))\n");
1245  }
1246  else {
1247  cmd += mCmd;
1248  }
1249 
1250  // Put the fetch buffers in a clean initial state
1251  for (size_t i = 0; i < mCurNumChannels; i++)
1252  mCurBuffer[i].Free();
1253 
1254  // Guarantee release of memory when done
1255  auto cleanup = finally( [&] {
1256  for (size_t i = 0; i < mCurNumChannels; i++)
1257  mCurBuffer[i].Free();
1258  } );
1259 
1260  // Evaluate the expression, which may invoke the get callback, but often does
1261  // not, leaving that to delayed evaluation of the output sound
1262  rval = nyx_eval_expression(cmd.mb_str(wxConvUTF8));
1263 
1264  // If we're not showing debug window, log errors and warnings:
1265  if (!mDebugOutput.IsEmpty() && !mDebug && !mTrace) {
1266  /* i18n-hint: An effect "returned" a message.*/
1267  wxLogMessage(_("\'%s\' returned:\n%s"), mName, mDebugOutput);
1268  }
1269 
1270  // Audacity has no idea how long Nyquist processing will take, but
1271  // can monitor audio being returned.
1272  // Anything other than audio should be returned almost instantly
1273  // so notify the user that process has completed (bug 558)
1274  if ((rval != nyx_audio) && ((mCount + mCurNumChannels) == mNumSelectedChannels)) {
1275  if (mCurNumChannels == 1) {
1276  TrackProgress(mCount, 1.0, _("Processing complete."));
1277  }
1278  else {
1279  TrackGroupProgress(mCount, 1.0, _("Processing complete."));
1280  }
1281  }
1282 
1283  if (rval == nyx_error) {
1284  // Return value is not valid type.
1285  // Show error in debug window if trace enabled, otherwise log.
1286  if (mTrace) {
1287  /* i18n-hint: "%s" is replaced by name of plug-in.*/
1288  mDebugOutput = wxString::Format(_("nyx_error returned from %s.\n"),
1289  mName.IsEmpty()? _("plug-in") : mName) + mDebugOutput;
1290  mDebug = true;
1291  return false;
1292  }
1293  else {
1294  wxLogMessage(wxT("Nyquist returned nyx_error."));
1295  }
1296  return true;
1297  }
1298 
1299  if (rval == nyx_string) {
1300  wxString msg = NyquistToWxString(nyx_get_string());
1301  if (!msg.IsEmpty()) // Not currently a documented feature, but could be useful as a No-Op.
1302  Effect::MessageBox(msg);
1303 
1304  // True if not process type.
1305  // If not returning audio from process effect,
1306  // return first reult then stop (disables preview)
1307  // but allow all output from Nyquist Prompt.
1308  return (GetType() != EffectTypeProcess || mIsPrompt);
1309  }
1310 
1311  if (rval == nyx_double) {
1312  wxString str;
1313  str.Printf(_("Nyquist returned the value:") + wxString(wxT(" %f")),
1314  nyx_get_double());
1315  Effect::MessageBox(str);
1316  return (GetType() != EffectTypeProcess || mIsPrompt);
1317  }
1318 
1319  if (rval == nyx_int) {
1320  wxString str;
1321  str.Printf(_("Nyquist returned the value:") + wxString(wxT(" %d")),
1322  nyx_get_int());
1323  Effect::MessageBox(str);
1324  return (GetType() != EffectTypeProcess || mIsPrompt);
1325  }
1326 
1327  if (rval == nyx_labels) {
1328  mProjectChanged = true;
1329  unsigned int numLabels = nyx_get_num_labels();
1330  unsigned int l;
1331  LabelTrack *ltrack = NULL;
1332 
1333  TrackListIterator iter(mOutputTracks.get());
1334  for (Track *t = iter.First(); t; t = iter.Next()) {
1335  if (t->GetKind() == Track::Label) {
1336  ltrack = (LabelTrack *)t;
1337  break;
1338  }
1339  }
1340 
1341  if (!ltrack) {
1342  ltrack = static_cast<LabelTrack*>(AddToOutputTracks(mFactory->NewLabelTrack()));
1343  }
1344 
1345  for (l = 0; l < numLabels; l++) {
1346  double t0, t1;
1347  const char *str;
1348 
1349  // PRL: to do:
1350  // let Nyquist analyzers define more complicated selections
1351  nyx_get_label(l, &t0, &t1, &str);
1352 
1353  ltrack->AddLabel(SelectedRegion(t0 + mT0, t1 + mT0), UTF8CTOWX(str), -2);
1354  }
1355  return (GetType() != EffectTypeProcess || mIsPrompt);
1356  }
1357 
1358  wxASSERT(rval == nyx_audio);
1359 
1360  int outChannels = nyx_get_audio_num_channels();
1361  if (outChannels > (int)mCurNumChannels) {
1362  Effect::MessageBox(_("Nyquist returned too many audio channels.\n"));
1363  return false;
1364  }
1365 
1366  if (outChannels == -1) {
1367  Effect::MessageBox(_("Nyquist returned one audio channel as an array.\n"));
1368  return false;
1369  }
1370 
1371  if (outChannels == 0) {
1372  Effect::MessageBox(_("Nyquist returned an empty array.\n"));
1373  return false;
1374  }
1375 
1376  std::unique_ptr<WaveTrack> outputTrack[2];
1377 
1378  double rate = mCurTrack[0]->GetRate();
1379  for (int i = 0; i < outChannels; i++) {
1381 
1382  if (outChannels == (int)mCurNumChannels) {
1383  rate = mCurTrack[i]->GetRate();
1384  }
1385 
1386  outputTrack[i] = mFactory->NewWaveTrack(format, rate);
1387  outputTrack[i]->SetWaveColorIndex( mCurTrack[i]->GetWaveColorIndex() );
1388 
1389  // Clean the initial buffer states again for the get callbacks
1390  // -- is this really needed?
1391  mCurBuffer[i].Free();
1392  }
1393 
1394  // Now fully evaluate the sound
1395  int success;
1396  {
1397  auto vr0 = valueRestorer( mOutputTrack[0], outputTrack[0].get() );
1398  auto vr1 = valueRestorer( mOutputTrack[1], outputTrack[1].get() );
1399  success = nyx_get_audio(StaticPutCallback, (void *)this);
1400  }
1401 
1402  // See if GetCallback found read errors
1403  {
1404  auto pException = mpException;
1405  mpException = {};
1406  if (pException)
1407  std::rethrow_exception( pException );
1408  }
1409 
1410  if (!success)
1411  return false;
1412 
1413  for (int i = 0; i < outChannels; i++) {
1414  outputTrack[i]->Flush();
1415  mOutputTime = outputTrack[i]->GetEndTime();
1416 
1417  if (mOutputTime <= 0) {
1418  Effect::MessageBox(_("Nyquist returned nil audio.\n"));
1419  return true;
1420  }
1421  }
1422 
1423  for (size_t i = 0; i < mCurNumChannels; i++) {
1424  WaveTrack *out;
1425 
1426  if (outChannels == (int)mCurNumChannels) {
1427  out = outputTrack[i].get();
1428  }
1429  else {
1430  out = outputTrack[0].get();
1431  }
1432 
1433  if (mMergeClips < 0) {
1434  // Use sample counts to determine default behaviour - times will rarely be equal.
1435  bool bMergeClips = (out->TimeToLongSamples(mT0) + out->TimeToLongSamples(mOutputTime) ==
1436  out->TimeToLongSamples(mT1));
1437  mCurTrack[i]->ClearAndPaste(mT0, mT1, out, mRestoreSplits, bMergeClips);
1438  }
1439  else {
1441  }
1442 
1443  // If we were first in the group adjust non-selected group tracks
1444  if (mFirstInGroup) {
1446  Track *t;
1447  for (t = git.StartWith(mCurTrack[i]); t; t = git.Next())
1448  {
1449  if (!t->GetSelected() && t->IsSyncLockSelected()) {
1450  t->SyncLockAdjust(mT1, mT0 + out->GetEndTime());
1451  }
1452  }
1453  }
1454 
1455  // Only the first channel can be first in its group
1456  mFirstInGroup = false;
1457  }
1458 
1459  mProjectChanged = true;
1460  return true;
1461 }
wxString mDebugOutput
Definition: Nyquist.h:246
bool mTrace
Definition: Nyquist.h:217
sampleCount mCurLen
Definition: Nyquist.h:254
double mT1
Definition: Effect.h:461
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
wxString mName
Name of the Effect (untranslated)
Definition: Nyquist.h:230
Track * AddToOutputTracks(std::unique_ptr< Track > &&t)
Definition: Effect.cpp:2067
bool TrackProgress(int whichTrack, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1985
bool mIsSal
Definition: Nyquist.h:218
bool mProjectChanged
Definition: Nyquist.h:245
unsigned mNumSelectedChannels
Definition: Nyquist.h:260
const WaveformSettings & GetWaveformSettings() const
Definition: WaveTrack.cpp:738
virtual double GetEndTime() const =0
static int StaticGetCallback(float *buffer, int channel, long start, long len, long totlen, void *userdata)
Definition: Nyquist.cpp:2128
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2576
#define UTF8CTOWX(X)
Definition: Internat.h:179
bool SpectralSelectionEnabled() const
bool mExternal
Definition: Nyquist.h:219
void ClearAndPaste(double t0, double t1, const Track *src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=NULL)
Definition: WaveTrack.cpp:782
double GetEndTime() const override
Get the time at which the last clip in the track ends, plus recorded stuff.
Definition: WaveTrack.cpp:1873
virtual double GetStartTime() const =0
const SpectrogramSettings & GetSpectrogramSettings() const
Definition: WaveTrack.cpp:690
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
float GetRMS(double t0, double t1, bool mayThrow=true) const
Definition: WaveTrack.cpp:1937
double mOutputTime
Definition: Nyquist.h:258
double GetStartTime() const override
Get the time at which the first clip in the track starts.
Definition: WaveTrack.cpp:1853
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:138
int mVersion
Definition: Nyquist.h:248
int format
Definition: ExportPCM.cpp:56
unsigned mCount
Definition: Nyquist.h:259
WaveTrack * mCurTrack[2]
Definition: Nyquist.h:252
Defines a selected portion of a project.
void SetWaveColorIndex(int colorIndex)
Definition: WaveTrack.cpp:477
bool mFirstInGroup
Definition: Nyquist.h:257
sampleFormat
Definition: Types.h:188
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
bool mCompiler
Definition: Nyquist.h:216
WaveTrack * mOutputTrack[2]
Definition: Nyquist.h:270
static int StaticPutCallback(float *buffer, int channel, long start, long len, long totlen, void *userdata)
Definition: Nyquist.cpp:2195
int min(int a, int b)
wxString mCmd
Definition: Nyquist.h:229
wxString EscapeString(const wxString &inStr)
Definition: Nyquist.cpp:1480
EffectType GetType() override
Definition: Nyquist.cpp:256
bool mRestoreSplits
Definition: Nyquist.h:277
std::unique_ptr< WaveTrack > NewWaveTrack(sampleFormat format=(sampleFormat) 0, double rate=0)
Definition: WaveTrack.cpp:78
An iterator for a TrackList.
Definition: Track.h:402
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
TrackFactory * mFactory
Definition: Effect.h:457
ValueRestorer< T > valueRestorer(T &var)
Definition: MemoryX.h:494
wxString mProps
Definition: Nyquist.h:274
unsigned mCurNumChannels
Definition: Nyquist.h:251
SampleBuffer mCurBuffer[2]
Definition: Nyquist.h:266
Track * GetLink() const
Definition: Track.cpp:269
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
bool mIsPrompt
Definition: Nyquist.h:225
sampleFormat GetSampleFormat() const
Definition: WaveTrack.h:146
long long as_long_long() const
Definition: Types.h:90
int mTrackIndex
Definition: Nyquist.h:256
std::pair< float, float > GetMinMax(double t0, double t1, bool mayThrow=true) const
Definition: WaveTrack.cpp:1898
bool TrackGroupProgress(int whichGroup, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1993
wxString mPerTrackProps
Definition: Nyquist.h:275
bool mDebug
Definition: Nyquist.h:243
double GetRate() const
Definition: WaveTrack.cpp:398
virtual void SyncLockAdjust(double oldT1, double newT1)
Definition: Track.cpp:320
int mMergeClips
Definition: Nyquist.h:278
std::unique_ptr< LabelTrack > NewLabelTrack()
Definition: LabelTrack.cpp:99
static wxString NyquistToWxString(const char *nyqString)
Definition: Nyquist.cpp:1467
int AddLabel(const SelectedRegion &region, const wxString &title=wxT(""), int restoreFocus=-1)
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
std::exception_ptr mpException
Definition: Nyquist.h:283
double mT0
Definition: Effect.h:460
void Flush()
Flush must be called after last Append.
Definition: WaveTrack.cpp:1650
int NyquistEffect::PutCallback ( float *  buffer,
int  channel,
long  start,
long  len,
long  totlen 
)
private

Definition at line 2203 of file Nyquist.cpp.

References WaveTrack::Append(), floatSample, MakeSimpleGuard(), mOutputTrack, mProgressIn, mProgressOut, mProgressTot, mScale, and Effect::TotalProgress().

Referenced by StaticPutCallback().

2205 {
2206  // Don't let C++ exceptions propagate through the Nyquist library
2207  return GuardedCall<int>( [&] {
2208  if (channel == 0) {
2209  double progress = mScale*((float)(start+len)/totlen);
2210 
2211  if (progress > mProgressOut) {
2212  mProgressOut = progress;
2213  }
2214 
2216  return -1;
2217  }
2218  }
2219 
2220  mOutputTrack[channel]->Append((samplePtr)buffer, floatSample, len);
2221 
2222  return 0; // success
2223  }, MakeSimpleGuard( -1 ) ); // translate all exceptions into failure
2224 }
double mProgressIn
Definition: Nyquist.h:261
bool TotalProgress(double frac)
Definition: Effect.cpp:1977
double mProgressOut
Definition: Nyquist.h:262
SimpleGuard< R > MakeSimpleGuard(R value)
double mScale
Definition: Nyquist.h:264
char * samplePtr
Definition: Types.h:203
WaveTrack * mOutputTrack[2]
Definition: Nyquist.h:270
void Append(samplePtr buffer, sampleFormat format, size_t len, unsigned int stride=1, XMLWriter *blockFileLog=NULL)
Append the sample data to the WaveTrack. You must call Flush() after the last Append.
Definition: WaveTrack.cpp:1557
double mProgressTot
Definition: Nyquist.h:263
void NyquistEffect::RedirectOutput ( )

Definition at line 1521 of file Nyquist.cpp.

References mRedirectOutput.

1522 {
1523  mRedirectOutput = true;
1524 }
bool mRedirectOutput
Definition: Nyquist.h:244
void NyquistEffect::resolveFilePath ( wxString &  path,
wxString  extension = "" 
)
private

Definition at line 2906 of file Nyquist.cpp.

References _(), FileNames::DataDir(), and FileNames::DefaultToDocumentsFolder().

Referenced by BuildEffectWindow(), GetAutomationParameters(), OnFileButton(), and TransferDataFromEffectWindow().

2907 {
2908 #if defined(__WXMSW__)
2909  path.Replace("/", wxFileName::GetPathSeparator());
2910 #endif
2911 
2912  path.Trim(true).Trim(false);
2913 
2914  typedef std::unordered_map<wxString, wxString> map;
2915  map pathKeys = {
2916  {"*home*", wxGetHomeDir()},
2917  {"~", wxGetHomeDir()},
2918  {"*default*", FileNames::DefaultToDocumentsFolder("").GetPath()},
2919  {"*export*", FileNames::DefaultToDocumentsFolder(wxT("/Export/Path")).GetPath()},
2920  {"*save*", FileNames::DefaultToDocumentsFolder(wxT("/SaveAs/Path")).GetPath()},
2921  {"*config*", FileNames::DataDir()}
2922  };
2923 
2924  int characters = path.Find(wxFileName::GetPathSeparator());
2925  if(characters == wxNOT_FOUND) // Just a path or just a file name
2926  {
2927  if (path.IsEmpty())
2928  path = "*default*";
2929 
2930  if (pathKeys.find(path) != pathKeys.end())
2931  {
2932  // Keyword found, so assume this is the intended directory.
2933  path = pathKeys[path] + wxFileName::GetPathSeparator();
2934  }
2935  else // Just a file name
2936  {
2937  path = pathKeys["*default*"] + wxFileName::GetPathSeparator() + path;
2938  }
2939  }
2940  else // path + file name
2941  {
2942  wxString firstDir = path.Left(characters);
2943  wxString rest = path.Mid(characters);
2944 
2945  if (pathKeys.find(firstDir) != pathKeys.end())
2946  {
2947  path = pathKeys[firstDir] + rest;
2948  }
2949  }
2950 
2951  wxFileName fname = path;
2952 
2953  // If the directory is invalid, better to leave it as is (invalid) so that
2954  // the user sees the error rather than an unexpected file path.
2955  if (fname.wxFileName::IsOk() && fname.GetFullName() == wxEmptyString)
2956  {
2957  path = fname.GetPathWithSep() + _("untitled");
2958  if (!extension.IsEmpty())
2959  path = path + extension;
2960  }
2961 }
static wxFileNameWrapper DefaultToDocumentsFolder(const wxString &preference)
Definition: FileNames.cpp:354
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static wxString DataDir()
Audacity user data directory.
Definition: FileNames.cpp:130
bool NyquistEffect::SetAutomationParameters ( CommandParameters parms)
overridevirtual

Reimplemented from Effect.

Definition at line 403 of file Nyquist.cpp.

References NyqControl::choices, GetCtrlValue(), NyqControl::high, KEY_Command, KEY_Version, NyqControl::low, mControls, mExternal, mInputCmd, mIsPrompt, mVersion, NYQ_CTRL_CHOICE, NYQ_CTRL_FILE, NYQ_CTRL_FLOAT, NYQ_CTRL_FLOAT_TEXT, NYQ_CTRL_INT, NYQ_CTRL_INT_TEXT, NYQ_CTRL_STRING, NYQ_CTRL_TEXT, NYQ_CTRL_TIME, CommandParameters::ReadEnum(), NyqControl::type, UNINITIALIZED_CONTROL, NyqControl::val, NyqControl::valStr, and NyqControl::var.

Referenced by DefineParams().

404 {
405  if (mExternal)
406  {
407  return true;
408  }
409 
410  if (mIsPrompt)
411  {
412  parms.Read(KEY_Command, &mInputCmd, wxEmptyString);
413  parms.Read(KEY_Version, &mVersion, mVersion);
414 
415  return true;
416  }
417 
418  // First pass verifies values
419  for (size_t c = 0, cnt = mControls.size(); c < cnt; c++)
420  {
421  NyqControl & ctrl = mControls[c];
422  bool good = false;
423 
424  if (ctrl.type == NYQ_CTRL_FLOAT || ctrl.type == NYQ_CTRL_FLOAT_TEXT ||
425  ctrl.type == NYQ_CTRL_TIME)
426  {
427  double val;
428  good = parms.Read(ctrl.var, &val) &&
429  val >= ctrl.low &&
430  val <= ctrl.high;
431  }
432  else if (ctrl.type == NYQ_CTRL_INT || ctrl.type == NYQ_CTRL_INT_TEXT)
433  {
434  int val;
435  good = parms.Read(ctrl.var, &val) &&
436  val >= ctrl.low &&
437  val <= ctrl.high;
438  }
439  else if (ctrl.type == NYQ_CTRL_CHOICE)
440  {
441  int val;
442  // untranslated
443  good = parms.ReadEnum(ctrl.var, &val,
444  ctrl.choices.data(), ctrl.choices.size()) &&
445  val != wxNOT_FOUND;
446  }
447  else if (ctrl.type == NYQ_CTRL_STRING || ctrl.type == NYQ_CTRL_FILE)
448  {
449  wxString val;
450  good = parms.Read(ctrl.var, &val);
451  }
452  else if (ctrl.type == NYQ_CTRL_TEXT)
453  {
454  // This "control" is just fixed text (nothing to save or restore),
455  // so control is always "good".
456  good = true;
457  }
458 
459  if (!good)
460  {
461  return false;
462  }
463  }
464 
465  // Second pass sets the variables
466  for (size_t c = 0, cnt = mControls.size(); c < cnt; c++)
467  {
468  NyqControl & ctrl = mControls[c];
469 
470  double d = ctrl.val;
471  if (d == UNINITIALIZED_CONTROL && ctrl.type != NYQ_CTRL_STRING)
472  {
473  d = GetCtrlValue(ctrl.valStr);
474  }
475 
476  if (ctrl.type == NYQ_CTRL_FLOAT || ctrl.type == NYQ_CTRL_FLOAT_TEXT ||
477  ctrl.type == NYQ_CTRL_TIME)
478  {
479  parms.Read(ctrl.var, &ctrl.val);
480  }
481  else if (ctrl.type == NYQ_CTRL_INT || ctrl.type == NYQ_CTRL_INT_TEXT)
482  {
483  int val;
484  parms.Read(ctrl.var, &val);
485  ctrl.val = (double) val;
486  }
487  else if (ctrl.type == NYQ_CTRL_CHOICE)
488  {
489  int val {0};
490  // untranslated
491  parms.ReadEnum(ctrl.var, &val,
492  ctrl.choices.data(), ctrl.choices.size());
493  ctrl.val = (double) val;
494  }
495  else if (ctrl.type == NYQ_CTRL_STRING || ctrl.type == NYQ_CTRL_FILE)
496  {
497  parms.Read(ctrl.var, &ctrl.valStr);
498  }
499  }
500 
501  return true;
502 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
#define UNINITIALIZED_CONTROL
Definition: Nyquist.cpp:95
int type
Definition: Nyquist.h:63
static const wxChar * KEY_Version
Definition: Nyquist.cpp:97
double GetCtrlValue(const wxString &s)
Definition: Nyquist.cpp:1586
A control on a NyquistDialog.
Definition: Nyquist.h:54
bool mExternal
Definition: Nyquist.h:219
wxString valStr
Definition: Nyquist.h:68
wxString var
Definition: Nyquist.h:64
int mVersion
Definition: Nyquist.h:248
double low
Definition: Nyquist.h:72
bool ReadEnum(const wxString &key, int *pi, const IdentInterfaceSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
std::vector< IdentInterfaceSymbol > choices
Definition: Nyquist.h:67
double val
Definition: Nyquist.h:71
wxString mInputCmd
Definition: Nyquist.h:228
bool mIsPrompt
Definition: Nyquist.h:225
double high
Definition: Nyquist.h:73
static const wxChar * KEY_Command
Definition: Nyquist.cpp:98
void NyquistEffect::SetCommand ( const wxString &  cmd)

Definition at line 1526 of file Nyquist.cpp.

References mExternal, and ParseCommand().

Referenced by ShowInterface().

1527 {
1528  mExternal = true;
1529 
1530  ParseCommand(cmd);
1531 }
bool mExternal
Definition: Nyquist.h:219
bool ParseCommand(const wxString &cmd)
Definition: Nyquist.cpp:2121
bool NyquistEffect::ShowInterface ( wxWindow *  parent,
bool  forceModal = false 
)
overridevirtual

Reimplemented from Effect.

Definition at line 900 of file Nyquist.cpp.

References Effect::Delegate(), eDebugID, mControls, mDebug, mInputCmd, mIsPrompt, Effect::mUIResultID, NYQUIST_WORKER_ID, SetCommand(), and Effect::ShowInterface().

901 {
902  // Show the normal (prompt or effect) interface
903  bool res = Effect::ShowInterface(parent, forceModal);
904 
905  // Remember if the user clicked debug
906  mDebug = (mUIResultID == eDebugID);
907 
908  // We're done if the user clicked "Close", we are not the Nyquist Prompt,
909  // or the program currently loaded into the prompt doesn't have a UI.
910  if (!res || !mIsPrompt || mControls.size() == 0)
911  {
912  return res;
913  }
914 
916 
917  effect.SetCommand(mInputCmd);
918  effect.mDebug = (mUIResultID == eDebugID);
919 
920  return Delegate(effect, parent, true);
921 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class...
Definition: Nyquist.h:78
#define NYQUIST_WORKER_ID
Definition: Nyquist.h:39
wxString mInputCmd
Definition: Nyquist.h:228
bool mIsPrompt
Definition: Nyquist.h:225
bool ShowInterface(wxWindow *parent, bool forceModal=false) override
Definition: Effect.cpp:514
bool mDebug
Definition: Nyquist.h:243
bool Delegate(Effect &delegate, wxWindow *parent, bool shouldPrompt)
Definition: Effect.cpp:1257
int mUIResultID
Definition: Effect.h:473
int NyquistEffect::StaticGetCallback ( float *  buffer,
int  channel,
long  start,
long  len,
long  totlen,
void *  userdata 
)
staticprivate

Definition at line 2128 of file Nyquist.cpp.

References GetCallback().

Referenced by ProcessOne().

2131 {
2132  NyquistEffect *This = (NyquistEffect *)userdata;
2133  return This->GetCallback(buffer, channel, start, len, totlen);
2134 }
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class...
Definition: Nyquist.h:78
int GetCallback(float *buffer, int channel, long start, long len, long totlen)
Definition: Nyquist.cpp:2136
void NyquistEffect::StaticOSCallback ( void *  userdata)
staticprivate

Definition at line 2242 of file Nyquist.cpp.

Referenced by Process().

2243 {
2244  ((NyquistEffect *)This)->OSCallback();
2245 }
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class...
Definition: Nyquist.h:78
void NyquistEffect::StaticOutputCallback ( int  c,
void *  userdata 
)
staticprivate

Definition at line 2226 of file Nyquist.cpp.

Referenced by Process().

2227 {
2228  ((NyquistEffect *)This)->OutputCallback(c);
2229 }
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class...
Definition: Nyquist.h:78
int NyquistEffect::StaticPutCallback ( float *  buffer,
int  channel,
long  start,
long  len,
long  totlen,
void *  userdata 
)
staticprivate

Definition at line 2195 of file Nyquist.cpp.

References PutCallback().

Referenced by ProcessOne().

2198 {
2199  NyquistEffect *This = (NyquistEffect *)userdata;
2200  return This->PutCallback(buffer, channel, start, len, totlen);
2201 }
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class...
Definition: Nyquist.h:78
int PutCallback(float *buffer, int channel, long start, long len, long totlen)
Definition: Nyquist.cpp:2203
void NyquistEffect::Stop ( )

Definition at line 1543 of file Nyquist.cpp.

References mStop.

1544 {
1545  mStop = true;
1546 }
bool mStop
Definition: Nyquist.h:211
wxString NyquistEffect::ToTimeFormat ( double  t)
private

Definition at line 2975 of file Nyquist.cpp.

Referenced by OnTime().

2976 {
2977  int seconds = static_cast<int>(t);
2978  int hh = seconds / 3600;
2979  int mm = seconds % 3600;
2980  mm = mm / 60;
2981  return wxString::Format("%d:%d:%.3f", hh, mm, t - (hh * 3600 + mm * 60));
2982 }
bool NyquistEffect::TransferDataFromEffectWindow ( )
private

Definition at line 2342 of file Nyquist.cpp.

References _(), GetCtrlValue(), NumericConverter::GetValue(), NyqControl::high, NyqControl::highStr, ID_Time, NyqControl::low, NyqControl::lowStr, mControls, Effect::MessageBox(), Effect::mUIParent, NYQ_CTRL_CHOICE, NYQ_CTRL_FILE, NYQ_CTRL_FLOAT_TEXT, NYQ_CTRL_INT, NYQ_CTRL_INT_TEXT, NYQ_CTRL_STRING, NYQ_CTRL_TIME, resolveFilePath(), NyqControl::ticks, NyqControl::type, UNINITIALIZED_CONTROL, NyqControl::val, validatePath(), and NyqControl::valStr.

Referenced by TransferDataFromWindow().

2343 {
2344  if (mControls.size() == 0)
2345  {
2346  return true;
2347  }
2348 
2349  for (unsigned int i = 0; i < mControls.size(); i++)
2350  {
2351  NyqControl *ctrl = &mControls[i];
2352 
2353  if (ctrl->type == NYQ_CTRL_STRING)
2354  {
2355  continue;
2356  }
2357 
2358  if (ctrl->val == UNINITIALIZED_CONTROL)
2359  {
2360  ctrl->val = GetCtrlValue(ctrl->valStr);
2361  }
2362 
2363  if (ctrl->type == NYQ_CTRL_CHOICE)
2364  {
2365  continue;
2366  }
2367 
2368  if (ctrl->type == NYQ_CTRL_FILE)
2369  {
2370  resolveFilePath(ctrl->valStr);
2371 
2372  wxString path;
2373  if (ctrl->valStr.StartsWith("\"", &path))
2374  {
2375  // Validate if a list of quoted paths.
2376  if (path.EndsWith("\"", &path))
2377  {
2378  path.Replace("\"\"", "\"");
2379  wxStringTokenizer tokenizer(path, "\"");
2380  while (tokenizer.HasMoreTokens())
2381  {
2382  wxString token = tokenizer.GetNextToken();
2383  if(!validatePath(token))
2384  {
2385  const auto message = wxString::Format(_("\"%s\" is not a valid file path."), token);
2386  Effect::MessageBox(message, wxOK | wxICON_EXCLAMATION | wxCENTRE, _("Error"));
2387  return false;
2388  }
2389  }
2390  continue;
2391  }
2392  else
2393  {
2394  /* i18n-hint: Warning that there is one quotation mark rather than a pair.*/
2395  const auto message = wxString::Format(_("Mismatched quotes in\n%s"), ctrl->valStr);
2396  Effect::MessageBox(message, wxOK | wxICON_EXCLAMATION | wxCENTRE, _("Error"));
2397  return false;
2398  }
2399  }
2400  // Validate a single path.
2401  else if (validatePath(ctrl->valStr))
2402  {
2403  continue;
2404  }
2405 
2406  // Validation failed
2407  const auto message = wxString::Format(_("\"%s\" is not a valid file path."), ctrl->valStr);
2408  Effect::MessageBox(message, wxOK | wxICON_EXCLAMATION | wxCENTRE, _("Error"));
2409  return false;
2410  }
2411 
2412  if (ctrl->type == NYQ_CTRL_TIME)
2413  {
2414  NumericTextCtrl *n = (NumericTextCtrl *) mUIParent->FindWindow(ID_Time + i);
2415  ctrl->val = n->GetValue();
2416  }
2417 
2418  if (ctrl->type == NYQ_CTRL_INT_TEXT && ctrl->lowStr.IsSameAs(wxT("nil"), false)) {
2419  ctrl->low = INT_MIN;
2420  }
2421  else if ((ctrl->type == NYQ_CTRL_FLOAT_TEXT || ctrl->type == NYQ_CTRL_TIME) &&
2422  ctrl->lowStr.IsSameAs(wxT("nil"), false))
2423  {
2424  ctrl->low = -(FLT_MAX);
2425  }
2426  else
2427  {
2428  ctrl->low = GetCtrlValue(ctrl->lowStr);
2429  }
2430 
2431  if (ctrl->type == NYQ_CTRL_INT_TEXT && ctrl->highStr.IsSameAs(wxT("nil"), false)) {
2432  ctrl->high = INT_MAX;
2433  }
2434  else if ((ctrl->type == NYQ_CTRL_FLOAT_TEXT || ctrl->type == NYQ_CTRL_TIME) &&
2435  ctrl->highStr.IsSameAs(wxT("nil"), false))
2436  {
2437  ctrl->high = FLT_MAX;
2438  }
2439  else
2440  {
2441  ctrl->high = GetCtrlValue(ctrl->highStr);
2442  }
2443 
2444  if (ctrl->high < ctrl->low)
2445  {
2446  ctrl->high = ctrl->low + 1;
2447  }
2448 
2449  if (ctrl->val < ctrl->low)
2450  {
2451  ctrl->val = ctrl->low;
2452  }
2453 
2454  if (ctrl->val > ctrl->high)
2455  {
2456  ctrl->val = ctrl->high;
2457  }
2458 
2459  ctrl->ticks = 1000;
2460  if (ctrl->type == NYQ_CTRL_INT &&
2461  (ctrl->high - ctrl->low < ctrl->ticks))
2462  {
2463  ctrl->ticks = (int)(ctrl->high - ctrl->low);
2464  }
2465  }
2466 
2467  return true;
2468 }
NyquistEffect::OnText ID_Time
Definition: Nyquist.cpp:116
wxString highStr
Definition: Nyquist.h:70
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
#define UNINITIALIZED_CONTROL
Definition: Nyquist.cpp:95
int type
Definition: Nyquist.h:63
double GetCtrlValue(const wxString &s)
Definition: Nyquist.cpp:1586
A control on a NyquistDialog.
Definition: Nyquist.h:54
wxString valStr
Definition: Nyquist.h:68
wxString lowStr
Definition: Nyquist.h:69
double low
Definition: Nyquist.h:72
void resolveFilePath(wxString &path, wxString extension="")
Definition: Nyquist.cpp:2906
wxWindow * mUIParent
Definition: Effect.h:472
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
double val
Definition: Nyquist.h:71
double high
Definition: Nyquist.h:73
bool validatePath(wxString path)
Definition: Nyquist.cpp:2964
int ticks
Definition: Nyquist.h:74
bool NyquistEffect::TransferDataFromPromptWindow ( )
private

Definition at line 2334 of file Nyquist.cpp.

References mCommandText, mInputCmd, mVersion, mVersionCheckBox, and ParseCommand().

Referenced by TransferDataFromWindow().

2335 {
2336  mInputCmd = mCommandText->GetValue();
2337  mVersion = mVersionCheckBox->GetValue() ? 3 : 4;
2338 
2339  return ParseCommand(mInputCmd);
2340 }
wxTextCtrl * mCommandText
Definition: Nyquist.h:280
bool ParseCommand(const wxString &cmd)
Definition: Nyquist.cpp:2121
int mVersion
Definition: Nyquist.h:248
wxCheckBox * mVersionCheckBox
Definition: Nyquist.h:281
wxString mInputCmd
Definition: Nyquist.h:228
bool NyquistEffect::TransferDataFromWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 959 of file Nyquist.cpp.

References mIsPrompt, Effect::mUIParent, TransferDataFromEffectWindow(), and TransferDataFromPromptWindow().

960 {
961  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
962  {
963  return false;
964  }
965 
966  if (mIsPrompt)
967  {
969  }
970 
972 }
bool TransferDataFromEffectWindow()
Definition: Nyquist.cpp:2342
wxWindow * mUIParent
Definition: Effect.h:472
bool TransferDataFromPromptWindow()
Definition: Nyquist.cpp:2334
bool mIsPrompt
Definition: Nyquist.h:225
bool NyquistEffect::TransferDataToEffectWindow ( )
private

Definition at line 2302 of file Nyquist.cpp.

References NyqControl::choices, NyqControl::high, ID_Choice, ID_Slider, if(), NyqControl::low, mControls, Effect::mUIParent, NYQ_CTRL_CHOICE, NYQ_CTRL_FLOAT, NYQ_CTRL_INT, NyqControl::ticks, NyqControl::type, and NyqControl::val.

Referenced by TransferDataToWindow().

2303 {
2304  for (size_t i = 0, cnt = mControls.size(); i < cnt; i++)
2305  {
2306  NyqControl & ctrl = mControls[i];
2307 
2308  if (ctrl.type == NYQ_CTRL_CHOICE)
2309  {
2310  const auto count = ctrl.choices.size();
2311 
2312  int val = (int)ctrl.val;
2313  if (val < 0 || val >= (int)count)
2314  {
2315  val = 0;
2316  }
2317 
2318  wxChoice *c = (wxChoice *) mUIParent->FindWindow(ID_Choice + i);
2319  c->SetSelection(val);
2320  }
2321  else if (ctrl.type == NYQ_CTRL_INT || ctrl.type == NYQ_CTRL_FLOAT)
2322  {
2323  // wxTextCtrls are handled by the validators
2324  double range = ctrl.high - ctrl.low;
2325  int val = (int)(0.5 + ctrl.ticks * (ctrl.val - ctrl.low) / range);
2326  wxSlider *s = (wxSlider *) mUIParent->FindWindow(ID_Slider + i);
2327  s->SetValue(val);
2328  }
2329  }
2330 
2331  return true;
2332 }
std::vector< NyqControl > mControls
Definition: Nyquist.h:249
int type
Definition: Nyquist.h:63
A control on a NyquistDialog.
Definition: Nyquist.h:54
double low
Definition: Nyquist.h:72
std::vector< IdentInterfaceSymbol > choices
Definition: Nyquist.h:67
if(pTrack &&pTrack->GetDisplay()!=WaveTrack::Spectrum)
wxWindow * mUIParent
Definition: Effect.h:472
double val
Definition: Nyquist.h:71
double high
Definition: Nyquist.h:73
int ticks
Definition: Nyquist.h:74
bool NyquistEffect::TransferDataToPromptWindow ( )
private

Definition at line 2294 of file Nyquist.cpp.

References mCommandText, mInputCmd, mVersion, and mVersionCheckBox.

Referenced by TransferDataToWindow().

2295 {
2296  mCommandText->ChangeValue(mInputCmd);
2297  mVersionCheckBox->SetValue(mVersion <= 3);
2298 
2299  return true;
2300 }
wxTextCtrl * mCommandText
Definition: Nyquist.h:280
int mVersion
Definition: Nyquist.h:248
wxCheckBox * mVersionCheckBox
Definition: Nyquist.h:281
wxString mInputCmd
Definition: Nyquist.h:228
bool NyquistEffect::TransferDataToWindow ( )
overridevirtual

Reimplemented from Effect.

Definition at line 937 of file Nyquist.cpp.

References Effect::EnablePreview(), mEnablePreview, mIsPrompt, Effect::mUIParent, TransferDataToEffectWindow(), and TransferDataToPromptWindow().

938 {
939  mUIParent->TransferDataToWindow();
940 
941  bool success;
942  if (mIsPrompt)
943  {
944  success = TransferDataToPromptWindow();
945  }
946  else
947  {
948  success = TransferDataToEffectWindow();
949  }
950 
951  if (success)
952  {
954  }
955 
956  return success;
957 }
wxWindow * mUIParent
Definition: Effect.h:472
bool TransferDataToEffectWindow()
Definition: Nyquist.cpp:2302
bool mIsPrompt
Definition: Nyquist.h:225
bool mEnablePreview
Definition: Nyquist.h:240
bool TransferDataToPromptWindow()
Definition: Nyquist.cpp:2294
virtual bool EnablePreview(bool enable=true)
Definition: Effect.cpp:1917
wxString NyquistEffect::UnQuote ( const wxString &  s,
bool  allowParens = true,
wxString *  pExtraString = nullptr 
)
staticprivate

Definition at line 1548 of file Nyquist.cpp.

References NyquistEffect::Tokenizer::Tokenize(), and NyquistEffect::Tokenizer::tokens.

Referenced by Parse(), and ParseChoice().

1550 {
1551  if (pExtraString)
1552  *pExtraString = wxString{};
1553 
1554  int len = s.Length();
1555  if (len >= 2 && s[0] == wxT('\"') && s[len - 1] == wxT('\"')) {
1556  auto unquoted = s.Mid(1, len - 2);
1557  return unquoted;
1558  }
1559  else if (allowParens &&
1560  len >= 2 && s[0] == wxT('(') && s[len - 1] == wxT(')')) {
1561  Tokenizer tzer;
1562  tzer.Tokenize(s, true, 1, 1);
1563  auto &tokens = tzer.tokens;
1564  if (tokens.size() > 1) {
1565  if (pExtraString && tokens[1][0] == '(') {
1566  // A choice with a distinct internal string form like
1567  // ("InternalString" (_ "Visible string"))
1568  // Recur to find the two strings
1569  *pExtraString = UnQuote(tokens[0], false);
1570  return UnQuote(tokens[1]);
1571  }
1572  else {
1573  // Assume the first token was _ -- we don't check that
1574  // And the second is the string, which is internationalized
1575  return UnQuote( tokens[1], false );
1576  }
1577  }
1578  else
1579  return {};
1580  }
1581  else
1582  // If string was not quoted, assume no translation exists
1583  return s;
1584 }
static wxString UnQuote(const wxString &s, bool allowParens=true, wxString *pExtraString=nullptr)
Definition: Nyquist.cpp:1548
bool NyquistEffect::validatePath ( wxString  path)
private

Definition at line 2964 of file Nyquist.cpp.

Referenced by TransferDataFromEffectWindow().

2965 {
2966  wxFileName fname = path;
2967  wxString dir = fname.GetPath();
2968 
2969  return (fname.wxFileName::IsOk() &&
2970  wxFileName::DirExists(dir) &&
2971  fname.GetFullName() != wxEmptyString);
2972 }

Friends And Related Function Documentation

friend class NyquistEffectsModule
friend

Definition at line 287 of file Nyquist.h.

Member Data Documentation

wxString NyquistEffect::mAction
private

Definition at line 231 of file Nyquist.h.

Referenced by Parse().

wxString NyquistEffect::mAuthor
private

Definition at line 233 of file Nyquist.h.

Referenced by GetVendor(), and Parse().

bool NyquistEffect::mBreak
private

Definition at line 212 of file Nyquist.h.

Referenced by Break(), OSCallback(), and Process().

wxArrayString NyquistEffect::mCategories
private

Definition at line 272 of file Nyquist.h.

Referenced by Parse(), and ParseProgram().

wxString NyquistEffect::mCmd
private

Definition at line 229 of file Nyquist.h.

Referenced by ParseProgram(), and ProcessOne().

wxTextCtrl* NyquistEffect::mCommandText
private
bool NyquistEffect::mCompiler
private

Definition at line 216 of file Nyquist.h.

Referenced by Parse(), and ProcessOne().

bool NyquistEffect::mCont
private

Definition at line 213 of file Nyquist.h.

Referenced by Continue(), OSCallback(), and Process().

std::vector<NyqControl> NyquistEffect::mControls
private
wxString NyquistEffect::mCopyright
private

Definition at line 234 of file Nyquist.h.

Referenced by GetDescription(), and Parse().

unsigned NyquistEffect::mCount
private

Definition at line 259 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

SampleBuffer NyquistEffect::mCurBuffer[2]
private

Definition at line 266 of file Nyquist.h.

Referenced by GetCallback(), and ProcessOne().

size_t NyquistEffect::mCurBufferLen[2]
private

Definition at line 268 of file Nyquist.h.

Referenced by GetCallback().

sampleCount NyquistEffect::mCurBufferStart[2]
private

Definition at line 267 of file Nyquist.h.

Referenced by GetCallback().

sampleCount NyquistEffect::mCurLen
private

Definition at line 254 of file Nyquist.h.

Referenced by GetCallback(), Process(), and ProcessOne().

unsigned NyquistEffect::mCurNumChannels
private

Definition at line 251 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

sampleCount NyquistEffect::mCurStart[2]
private

Definition at line 253 of file Nyquist.h.

Referenced by GetCallback(), and Process().

WaveTrack* NyquistEffect::mCurTrack[2]
private

Definition at line 252 of file Nyquist.h.

Referenced by GetCallback(), Process(), and ProcessOne().

bool NyquistEffect::mDebug
private

Definition at line 243 of file Nyquist.h.

Referenced by ParseProgram(), Process(), ProcessOne(), and ShowInterface().

bool NyquistEffect::mDebugButton
private

Definition at line 241 of file Nyquist.h.

Referenced by Init(), Parse(), ParseProgram(), and PopulateOrExchange().

wxString NyquistEffect::mDebugOutput
private

Definition at line 246 of file Nyquist.h.

Referenced by OutputCallback(), Process(), and ProcessOne().

bool NyquistEffect::mEnablePreview
private

Definition at line 240 of file Nyquist.h.

Referenced by Init(), Parse(), ParseProgram(), and TransferDataToWindow().

bool NyquistEffect::mExternal
private
wxDateTime NyquistEffect::mFileModified
private

When the script was last modified on disk.

Definition at line 209 of file Nyquist.h.

Referenced by Init().

wxFileName NyquistEffect::mFileName
private

Name of the Nyquist script file this effect is loaded from.

Definition at line 208 of file Nyquist.h.

Referenced by GetPath(), Init(), OnLoad(), OnSave(), Parse(), and ParseFile().

bool NyquistEffect::mFirstInGroup
private

Definition at line 257 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

bool NyquistEffect::mFoundType
private

Definition at line 215 of file Nyquist.h.

Referenced by Parse(), and ParseProgram().

wxString NyquistEffect::mHelpFile
private

Definition at line 236 of file Nyquist.h.

Referenced by HelpPage(), Parse(), ParseProgram(), and Process().

bool NyquistEffect::mHelpFileExists
private

Definition at line 237 of file Nyquist.h.

Referenced by HelpPage(), ParseProgram(), and Process().

wxString NyquistEffect::mInfo
private

Definition at line 232 of file Nyquist.h.

Referenced by Parse().

wxString NyquistEffect::mInitError
private

Definition at line 227 of file Nyquist.h.

Referenced by Parse(), and ParseProgram().

wxString NyquistEffect::mInputCmd
private
bool NyquistEffect::mIsPrompt
private

True if the code to execute is obtained interactively from the user via the "Nyquist Prompt", or "Nyquist Tools Prompt", false for all other effects (lisp code read from files)

Definition at line 225 of file Nyquist.h.

Referenced by CheckWhetherSkipEffect(), DefineParams(), GetAutomationParameters(), GetPath(), GetSymbol(), GetVendor(), Init(), IsDefault(), IsInteractive(), ManualPage(), ParseProgram(), PopulateOrExchange(), ProcessOne(), SetAutomationParameters(), ShowInterface(), TransferDataFromWindow(), and TransferDataToWindow().

bool NyquistEffect::mIsSal
private

Definition at line 218 of file Nyquist.h.

Referenced by Parse(), ParseProgram(), and ProcessOne().

bool NyquistEffect::mIsSpectral
private

Definition at line 220 of file Nyquist.h.

Referenced by Init(), Parse(), and ParseProgram().

wxString NyquistEffect::mManPage
private

Definition at line 235 of file Nyquist.h.

Referenced by ManualPage(), Parse(), and ParseProgram().

sampleCount NyquistEffect::mMaxLen
private

Definition at line 255 of file Nyquist.h.

Referenced by Init(), Parse(), and Process().

int NyquistEffect::mMergeClips
private

Definition at line 278 of file Nyquist.h.

Referenced by Parse(), and ProcessOne().

wxString NyquistEffect::mName
private

Name of the Effect (untranslated)

Definition at line 230 of file Nyquist.h.

Referenced by GetSymbol(), Init(), Parse(), Process(), and ProcessOne().

unsigned NyquistEffect::mNumSelectedChannels
private

Definition at line 260 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

bool NyquistEffect::mOK
private

Definition at line 226 of file Nyquist.h.

Referenced by IsOk(), and Parse().

double NyquistEffect::mOutputTime
private

Definition at line 258 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

WaveTrack* NyquistEffect::mOutputTrack[2]
private

Definition at line 270 of file Nyquist.h.

Referenced by ProcessOne(), and PutCallback().

wxString NyquistEffect::mPerTrackProps
private

Definition at line 275 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

std::exception_ptr NyquistEffect::mpException {}
private

Definition at line 283 of file Nyquist.h.

Referenced by GetCallback(), and ProcessOne().

double NyquistEffect::mProgressIn
private

Definition at line 261 of file Nyquist.h.

Referenced by GetCallback(), Process(), and PutCallback().

double NyquistEffect::mProgressOut
private

Definition at line 262 of file Nyquist.h.

Referenced by GetCallback(), Process(), and PutCallback().

double NyquistEffect::mProgressTot
private

Definition at line 263 of file Nyquist.h.

Referenced by GetCallback(), Process(), and PutCallback().

bool NyquistEffect::mProjectChanged
private

Definition at line 245 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

wxString NyquistEffect::mProps
private

Definition at line 274 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

bool NyquistEffect::mRedirectOutput
private

Definition at line 244 of file Nyquist.h.

Referenced by OutputCallback(), Process(), and RedirectOutput().

bool NyquistEffect::mRestoreSplits
private

Definition at line 277 of file Nyquist.h.

Referenced by Parse(), and ProcessOne().

double NyquistEffect::mScale
private

Definition at line 264 of file Nyquist.h.

Referenced by GetCallback(), Process(), and PutCallback().

bool NyquistEffect::mStop
private

Definition at line 211 of file Nyquist.h.

Referenced by OSCallback(), Process(), and Stop().

bool NyquistEffect::mTrace
private

Definition at line 217 of file Nyquist.h.

Referenced by Parse(), ParseProgram(), Process(), and ProcessOne().

int NyquistEffect::mTrackIndex
private

Definition at line 256 of file Nyquist.h.

Referenced by Process(), and ProcessOne().

EffectType NyquistEffect::mType
private

Definition at line 238 of file Nyquist.h.

Referenced by GetPath(), GetSymbol(), GetType(), Init(), and Parse().

int NyquistEffect::mVersion
private
wxCheckBox* NyquistEffect::mVersionCheckBox
private
wxString NyquistEffect::mXlispPath
private

Definition at line 206 of file Nyquist.h.


The documentation for this class was generated from the following files: