From db7a15d16185573bc47e2323ea6b2af4a1215628 Mon Sep 17 00:00:00 2001 From: xenakios Date: Fri, 18 May 2018 16:20:51 +0300 Subject: [PATCH] Made rewind a parameter. Attempts to fix the time range not being recalled properly in hosts because the time range parameters may be quickly changed when the plugin is initializing and doing the sound source smoothing fades. etc --- Source/PS_Source/Input/AInputS.h | 3 ++- Source/PS_Source/StretchSource.cpp | 7 ++++--- Source/PS_Source/StretchSource.h | 2 +- Source/PluginEditor.cpp | 3 ++- Source/PluginProcessor.cpp | 30 ++++++++++++++++++++++-------- Source/PluginProcessor.h | 2 ++ readme.txt | 3 ++- 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Source/PS_Source/Input/AInputS.h b/Source/PS_Source/Input/AInputS.h index ec60a0b..56ee93c 100644 --- a/Source/PS_Source/Input/AInputS.h +++ b/Source/PS_Source/Input/AInputS.h @@ -330,6 +330,7 @@ public: void setActiveRange(Range rng) override { std::lock_guard locker(m_mutex); + /* if (rng.contains(getCurrentPositionPercent())) { @@ -338,7 +339,7 @@ public: } */ m_seekfade.requestedrange = rng; - if (m_seekfade.state == 0) + //if (m_seekfade.state == 0) { m_seekfade.counter = 0; m_seekfade.state = 1; diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index e34c1dc..d4a2aa9 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -156,7 +156,7 @@ void StretchAudioSource::setAudioBufferAsInputSource(AudioBuffer* buf, in m_curfile = File(); if (m_playrange.isEmpty()) - setPlayRange({ 0.0,1.0 }, true); + setPlayRange({ 0.0,1.0 }); ++m_param_change_count; } @@ -684,6 +684,7 @@ void StretchAudioSource::seekPercent(double pos) { ScopedLock locker(m_cs); m_seekpos = pos; + //m_firstbuffer = true; //m_resampler->Reset(); m_inputfile->seek(pos); ++m_param_change_count; @@ -715,7 +716,7 @@ void StretchAudioSource::setOnsetDetection(double x) } } -void StretchAudioSource::setPlayRange(Range playrange, bool isloop) +void StretchAudioSource::setPlayRange(Range playrange) { if (m_playrange.isEmpty() == false && playrange == m_playrange) return; @@ -727,7 +728,7 @@ void StretchAudioSource::setPlayRange(Range playrange, bool isloop) m_playrange = playrange; m_stream_end_reached = false; m_inputfile->setActiveRange(m_playrange); - m_inputfile->setLoopEnabled(isloop); + //if (m_playrange.contains(m_seekpos) == false) // m_inputfile->seek(m_playrange.getStart()); m_seekpos = m_playrange.getStart(); diff --git a/Source/PS_Source/StretchSource.h b/Source/PS_Source/StretchSource.h index b9830ab..9c90af9 100644 --- a/Source/PS_Source/StretchSource.h +++ b/Source/PS_Source/StretchSource.h @@ -77,7 +77,7 @@ public: double getOutputDurationSecondsForRange(Range range, int fftsize); void setOnsetDetection(double x); - void setPlayRange(Range playrange, bool isloop); + void setPlayRange(Range playrange); Range getPlayRange() { return m_playrange; } bool isLoopEnabled(); bool hasReachedEnd(); diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 1a6f766..0275f6f 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -67,7 +67,8 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(Pau m_rewind_button.setButtonText("<<"); m_rewind_button.onClick = [this]() { - processor.getStretchSource()->seekPercent(processor.getStretchSource()->getPlayRange().getStart()); + *processor.getBoolParameter(cpi_rewind) = true; + //processor.getStretchSource()->seekPercent(processor.getStretchSource()->getPlayRange().getStart()); }; addAndMakeVisible(&m_info_label); diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 61334d8..10154a5 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -175,6 +175,7 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() } addParameter(new AudioParameterBool("loop_enabled0", "Loop", true)); // 60 + addParameter(new AudioParameterBool("rewind0", "Rewind", false)); // 61 auto& pars = getParameters(); for (const auto& p : pars) @@ -392,7 +393,7 @@ void PaulstretchpluginAudioProcessor::setFFTSize(double size) void PaulstretchpluginAudioProcessor::startplay(Range playrange, int numoutchans, int maxBlockSize, String& err) { - m_stretch_source->setPlayRange(playrange, true); + m_stretch_source->setPlayRange(playrange); m_stretch_source->setFreeFilterEnvelope(m_free_filter_envelope); int bufamt = m_bufamounts[m_prebuffer_amount]; @@ -479,7 +480,7 @@ String PaulstretchpluginAudioProcessor::offlineRender(File outputfile) double t1 = *getFloatParameter(cpi_soundend); sanitizeTimeRange(t0, t1); ss->setRate(*getFloatParameter(cpi_stretchamount)); - ss->setPlayRange({ t0,t1 }, true); + ss->setPlayRange({ t0,t1 }); ss->setLoopingEnabled(true); ss->setNumOutChannels(numoutchans); ss->setFFTWindowingType(1); @@ -542,6 +543,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl m_cur_sr = sampleRate; m_curmaxblocksize = samplesPerBlock; m_input_buffer.setSize(getMainBusNumInputChannels(), samplesPerBlock); + *getBoolParameter(cpi_rewind) = false; int numoutchans = *m_outchansparam; if (numoutchans != m_cur_num_out_chans) m_prebuffering_inited = false; @@ -663,6 +665,10 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M } jassert(m_buffering_source != nullptr); jassert(m_bufferingthread.isThreadRunning()); + double t0 = *getFloatParameter(cpi_soundstart); + double t1 = *getFloatParameter(cpi_soundend); + sanitizeTimeRange(t0, t1); + m_stretch_source->setPlayRange({ t0,t1 }); if (m_last_host_playing == false && m_playposinfo.isPlaying) { m_stretch_source->seekPercent(*getFloatParameter(cpi_soundstart)); @@ -686,6 +692,16 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M if (m_stretch_source->isLoopEnabled() != *getBoolParameter(cpi_looping_enabled)) m_stretch_source->setLoopingEnabled(*getBoolParameter(cpi_looping_enabled)); + bool rew = *getBoolParameter(cpi_rewind); + if (rew !=m_lastrewind) + { + if (rew == true) + { + *getBoolParameter(cpi_rewind) = false; + m_stretch_source->seekPercent(m_stretch_source->getPlayRange().getStart()); + } + m_lastrewind = rew; + } m_stretch_source->setMainVolume(*getFloatParameter(cpi_main_volume)); m_stretch_source->setRate(*getFloatParameter(cpi_stretchamount)); @@ -696,11 +712,9 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M m_stretch_source->setOnsetDetection(*getFloatParameter(cpi_onsetdetection)); m_stretch_source->setLoopXFadeLength(*getFloatParameter(cpi_loopxfadelen)); - double t0 = *getFloatParameter(cpi_soundstart); - double t1 = *getFloatParameter(cpi_soundend); - sanitizeTimeRange(t0, t1); - - m_stretch_source->setPlayRange({ t0,t1 }, true); + + + m_stretch_source->setFreezing(getParameter(cpi_freeze)); m_stretch_source->setPaused(getParameter(cpi_pause_enabled)); m_stretch_source->setProcessParameters(&m_ppar); @@ -902,7 +916,7 @@ void PaulstretchpluginAudioProcessor::finishRecording(int lenrecording) { m_is_recording = false; m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer, getSampleRateChecked(), lenrecording); - m_stretch_source->setPlayRange({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, true); + m_stretch_source->setPlayRange({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }); } AudioProcessor* JUCE_CALLTYPE createPluginFilter() diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index e08e6d9..2e2a703 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -88,6 +88,7 @@ const int cpi_octaves_ratio5 = 57; const int cpi_octaves_ratio6 = 58; const int cpi_octaves_ratio7 = 59; const int cpi_looping_enabled = 60; +const int cpi_rewind = 61; class MyPropertiesFile { @@ -258,6 +259,7 @@ private: float m_cur_playrangeoffset = 0.0; void updateStretchParametersFromPluginParameters(ProcessParameters& pars); std::array m_sm_enab_pars; + bool m_lastrewind = false; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) }; diff --git a/readme.txt b/readme.txt index 25ba877..0ce24a6 100644 --- a/readme.txt +++ b/readme.txt @@ -9,8 +9,9 @@ Released under GNU General Public License v.2 license. History : 05-18-2018 1.2.1 -Added looping enabled parameter - -Added button to rewind to beginning of selected time range + -Added button and parameter to rewind to beginning of selected time range -Flush old stretched audio faster when source audio is changed + -Fix time range not being recalled properly when loading host project 05-07-2018 1.2.0 -Changed "Octaves" module to "Ratios". The Ratios module has more shifters than the previous Octaves module and allows changing the pitch ratios (and the shifters mix)