From 7ee8032f3c1f4b5873ea319bacc48bcef41e5d27 Mon Sep 17 00:00:00 2001 From: Steve Daulton Date: Thu, 13 Aug 2015 09:04:01 +0100 Subject: [PATCH] Limit selection length for Nyquist plug-ins This can improve progress count for Nyquist effects that do not process all of selection (bug 558) and provides some protection against 2^31 overflow issues (bug 439). --- plug-ins/sample-data-export.ny | 3 ++- src/effects/nyquist/Nyquist.cpp | 22 ++++++++++++++++++++++ src/effects/nyquist/Nyquist.h | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/plug-ins/sample-data-export.ny b/plug-ins/sample-data-export.ny index 19d7e3e24..84abf3070 100644 --- a/plug-ins/sample-data-export.ny +++ b/plug-ins/sample-data-export.ny @@ -3,6 +3,7 @@ ;type analyze ;name "Sample Data Export..." ;action "Analyzing..." +;maxlen 1000001 ;categories "http://lv2plug.in/ns/lv2core#AnalyserPlugin" ;author "Steve Daulton" ;copyright "Released under terms of the GNU General Public License version 2" @@ -90,7 +91,7 @@ (if (< number 1) (add-error "No samples selected.")) (if (> number 1000000) - (add-error "Too many samples selected.\nSet limit to less than 1 million")) + (add-error "Cannot export more than 1 million samples.")) (setq number (truncate number))) diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index 64ebf6979..d75376d25 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -79,6 +79,9 @@ enum ID_Choice = 13000 }; +// Protect Nyquist from selections greater than 2^31 samples (bug 439) +#define NYQ_MAX_LEN ((sampleCount) 2147483647) + #define UNINITIALIZED_CONTROL ((double)99999999.99) static const wxChar *KEY_Version = XO("Version"); @@ -130,6 +133,8 @@ NyquistEffect::NyquistEffect(wxString fName) mBreak = false; mCont = false; + mMaxLen = NYQ_MAX_LEN; + // Interactive Nyquist if (fName == NYQUIST_PROMPT_ID) { @@ -379,6 +384,7 @@ bool NyquistEffect::Init() { SaveUserPreset(GetCurrentSettingsGroup()); + mMaxLen = NYQ_MAX_LEN; ParseFile(); mFileModified = mFileName.GetModificationTime(); @@ -577,6 +583,14 @@ bool NyquistEffect::Process() sampleCount end = mCurTrack[0]->TimeToLongSamples(mT1); mCurLen = (sampleCount)(end - mCurStart[0]); + if (mCurLen > NYQ_MAX_LEN) { + wxMessageBox(_("Selection too long for Nyquist code.\nMaximum allowed selection is 2147483647 samples\n(about 13.5 hours at 44100 Hz sample rate)."), + _("Nyquist Error"), wxOK | wxCENTRE); + return false; + } + + if (mCurLen > mMaxLen) mCurLen = mMaxLen; + mProgressIn = 0.0; mProgressOut = 0.0; @@ -1401,6 +1415,14 @@ void NyquistEffect::Parse(wxString line) return; } + // Maximum number of samples to be processed. This can help the + // progress bar if effect does not process all of selection. + if (len >= 2 && tokens[0] == wxT("maxlen")) { + long long v; // Note that Nyquist may overflow at > 2^31 samples (bug 439) + tokens[1].ToLongLong(&v); + mMaxLen = (sampleCount) v; + } + #if defined(EXPERIMENTAL_NYQUIST_SPLIT_CONTROL) if (len >= 2 && tokens[0] == wxT("mergeclips")) { long v; diff --git a/src/effects/nyquist/Nyquist.h b/src/effects/nyquist/Nyquist.h index 68b7be760..ebb28b64d 100644 --- a/src/effects/nyquist/Nyquist.h +++ b/src/effects/nyquist/Nyquist.h @@ -205,6 +205,7 @@ private: WaveTrack *mCurTrack[2]; sampleCount mCurStart[2]; sampleCount mCurLen; + sampleCount mMaxLen; int mTrackIndex; bool mFirstInGroup; double mOutputTime;