diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index 76c7814..4b1906c 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -451,6 +451,8 @@ void StretchAudioSource::setOnsetDetection(double x) void StretchAudioSource::setPlayRange(Range playrange, bool isloop) { std::lock_guard locker(m_mutex); + if (m_playrange.isEmpty()==false && playrange == m_playrange) + return; if (playrange.isEmpty()) m_playrange = { 0.0,1.0 }; else diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index a7d73e8..6f5c650 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -23,7 +23,10 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa m_parcomps.back()->setBounds(1, i * 25, 598, 24); addAndMakeVisible(m_parcomps.back().get()); } - setSize (600, pars.size()*25); + addAndMakeVisible(&m_rec_enable); + m_rec_enable.setButtonText("Capture"); + m_rec_enable.addListener(this); + setSize (600, pars.size()*25+30); startTimer(1, 100); } @@ -31,6 +34,14 @@ PaulstretchpluginAudioProcessorEditor::~PaulstretchpluginAudioProcessorEditor() { } +void PaulstretchpluginAudioProcessorEditor::buttonClicked(Button * but) +{ + if (but == &m_rec_enable) + { + processor.setRecordingEnabled(but->getToggleState()); + } +} + //============================================================================== void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g) { @@ -39,8 +50,8 @@ void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g) void PaulstretchpluginAudioProcessorEditor::resized() { - // This is generally where you'll want to lay out the positions of any - // subcomponents in your editor.. + m_rec_enable.setBounds(1, getHeight() - 25, 10, 24); + m_rec_enable.changeWidthToFitText(); } void PaulstretchpluginAudioProcessorEditor::timerCallback(int id) diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 6821cb9..bd43ec1 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -71,12 +71,12 @@ private: }; class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor, - public MultiTimer + public MultiTimer, public Button::Listener { public: PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&); ~PaulstretchpluginAudioProcessorEditor(); - + void buttonClicked(Button* but) override; //============================================================================== void paint (Graphics&) override; void resized() override; @@ -84,5 +84,6 @@ public: private: PaulstretchpluginAudioProcessor& processor; std::vector> m_parcomps; + ToggleButton m_rec_enable; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor) }; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index d2fe053..a2c2501 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -36,6 +36,8 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() addParameter(new AudioParameterFloat("fftsize0", "FFT size", 0.0f, 1.0f, 0.6f)); addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f)); addParameter(new AudioParameterFloat("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f)); + addParameter(new AudioParameterFloat("playrange_start0", "Sound start", 0.0f, 1.0f, 0.0f)); + addParameter(new AudioParameterFloat("playrange_end0", "Sound end", 0.0f, 1.0f, 1.0f)); } PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor() @@ -163,10 +165,27 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M buffer.clear (i, 0, buffer.getNumSamples()); if (m_ready_to_play == false) return; + if (m_is_recording == true) + { + m_rec_pos += buffer.getNumSamples(); + if (m_rec_pos >= m_max_reclen * getSampleRate()) + { + m_is_recording = false; + // Set record buffer as strech source... + } + return; + } m_control->getStretchAudioSource()->setRate(*getFloatParameter(1)); //m_control->setFFTSize(*getFloatParameter(2)); m_control->ppar.pitch_shift.cents = *getFloatParameter(3) * 100.0; m_control->ppar.freq_shift.Hz = *getFloatParameter(4); + double t0 = *getFloatParameter(5); + double t1 = *getFloatParameter(6); + if (t0 > t1) + std::swap(t0, t1); + if (t1 - t0 < 0.001) + t1 = t0 + 0.001; + m_control->getStretchAudioSource()->setPlayRange({ t0,t1 }, true); m_control->update_process_parameters(); m_control->processAudio(buffer); } @@ -196,6 +215,20 @@ void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int // whose contents will have been created by the getStateInformation() call. } +void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b) +{ + if (b == true) + { + m_is_recording = true; + m_recbuffer.setSize(2, m_max_reclen*getSampleRate()); + m_rec_pos = 0; + } + else + { + m_is_recording = false; + } +} + //============================================================================== // This creates new instances of the plugin.. AudioProcessor* JUCE_CALLTYPE createPluginFilter() diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index c5d41f8..152abfd 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -59,10 +59,15 @@ public: { return dynamic_cast(getParameters()[index]); } + void setRecordingEnabled(bool b); private: std::unique_ptr m_control; std::unique_ptr m_afm; bool m_ready_to_play = false; + AudioBuffer m_recbuffer; + double m_max_reclen = 10.0; + bool m_is_recording = true; + int m_rec_pos = 0; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) };