From 0dcd41078055d947e20cdddb3338b445af935279 Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 16 Nov 2017 19:45:40 +0200 Subject: [PATCH] Support bool parameters in parameter component. Add freeze parameter to plugin. --- Source/PS_Source/StretchSource.cpp | 4 +-- Source/PluginEditor.cpp | 4 +-- Source/PluginEditor.h | 22 +++++++++++++-- Source/PluginProcessor.cpp | 44 +++++++++++++++++------------- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index f6c2a0f..94e32a3 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -134,7 +134,7 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer if (m_stretchoutringbuf.available() > 0) m_output_has_begun = true; bool freezing = m_freezing; - /* + if (m_stretchers[0]->isFreezing() != freezing) { if (freezing == true && m_inputfile!=nullptr) @@ -142,7 +142,7 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer for (auto& e : m_stretchers) e->set_freezing(m_freezing); } - */ + double maingain = Decibels::decibelsToGain((double)val_MainVolume.getValue()); if (m_vol_smoother.getTargetValue() != maingain) m_vol_smoother.setValue(maingain); diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 44b5af5..44a0f7a 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -29,14 +29,14 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa for (int i=0;i(pars[i])); - m_parcomps.back()->setBounds(1, i * 25, 598, 24); + m_parcomps.back()->setBounds(1, 30+i * 25, 598, 24); addAndMakeVisible(m_parcomps.back().get()); } addAndMakeVisible(&m_rec_enable); m_rec_enable.setButtonText("Capture"); attachCallback(m_rec_enable, [this]() { processor.setRecordingEnabled(m_rec_enable.getToggleState()); }); - setSize (700, pars.size()*25+200); + setSize (700, 30+pars.size()*25+200); m_wavecomponent.TimeSelectionChangedCallback = [this](Range range, int which) { *processor.getFloatParameter(5) = range.getStart(); diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index eb26c2e..7292cf5 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -44,7 +44,7 @@ inline void attachCallback(Button& button, std::function callback) } class ParameterComponent : public Component, - public Slider::Listener + public Slider::Listener, public Button::Listener { public: ParameterComponent(AudioProcessorParameter* par) : m_par(par) @@ -68,7 +68,10 @@ public: AudioParameterBool* boolpar = dynamic_cast(par); if (boolpar) { - + m_togglebut = std::make_unique(); + m_togglebut->setToggleState(*boolpar, dontSendNotification); + m_togglebut->addListener(this); + addAndMakeVisible(m_togglebut.get()); } } void resized() override @@ -76,12 +79,22 @@ public: m_label.setBounds(0, 0, 200, 24); if (m_slider) m_slider->setBounds(m_label.getRight() + 1, 0, getWidth() - 2 - m_label.getWidth(), 24); + if (m_togglebut) + m_togglebut->setBounds(m_label.getRight() + 1, 0, getWidth() - 2 - m_label.getWidth(), 24); } void sliderValueChanged(Slider* slid) override { AudioParameterFloat* floatpar = dynamic_cast(m_par); *floatpar = slid->getValue(); } + void buttonClicked(Button* but) override + { + AudioParameterBool* boolpar = dynamic_cast(m_par); + if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar) + { + *boolpar = m_togglebut->getToggleState(); + } + } void updateComponent() { AudioParameterFloat* floatpar = dynamic_cast(m_par); @@ -89,6 +102,11 @@ public: { m_slider->setValue(*floatpar, dontSendNotification); } + AudioParameterBool* boolpar = dynamic_cast(m_par); + if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar) + { + m_togglebut->setToggleState(*boolpar, dontSendNotification); + } } private: Label m_label; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 3a4845e..aa6238b 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -10,9 +10,13 @@ #include "PluginProcessor.h" #include "PluginEditor.h" +#include + #undef min #undef max +std::set g_activeprocessors; + template void callGUI(AudioProcessor* ap, F&& f, bool async) { @@ -39,6 +43,7 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() ) #endif { + g_activeprocessors.insert(this); m_recbuffer.setSize(2, 44100); m_recbuffer.clear(); m_afm = std::make_unique(); @@ -49,17 +54,19 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() m_control->ppar.freq_shift.enabled = true; m_control->setOnsetDetection(0.0); m_control->getStretchAudioSource()->setLoopingEnabled(true); - addParameter(new AudioParameterFloat("mainvolume0", "Main volume", -24.0f, 12.0f, -3.0f)); - addParameter(new AudioParameterFloat("stretchamount0", "Stretch amount", 0.1f, 128.0f, 1.0f)); - addParameter(new AudioParameterFloat("fftsize0", "FFT size", 0.0f, 1.0f, 0.7f)); - 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)); + addParameter(new AudioParameterFloat("mainvolume0", "Main volume", -24.0f, 12.0f, -3.0f)); // 0 + addParameter(new AudioParameterFloat("stretchamount0", "Stretch amount", 0.1f, 128.0f, 1.0f)); // 1 + addParameter(new AudioParameterFloat("fftsize0", "FFT size", 0.0f, 1.0f, 0.7f)); // 2 + addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f)); // 3 + addParameter(new AudioParameterFloat("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f)); // 4 + addParameter(new AudioParameterFloat("playrange_start0", "Sound start", 0.0f, 1.0f, 0.0f)); // 5 + addParameter(new AudioParameterFloat("playrange_end0", "Sound end", 0.0f, 1.0f, 1.0f)); // 6 + addParameter(new AudioParameterBool("freeze0", "Freeze", false)); // 7 } PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor() { + g_activeprocessors.erase(this); m_control->stopplay(); } @@ -224,15 +231,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M m_rec_pos = (m_rec_pos + buffer.getNumSamples()) % recbuflenframes; return; } - /* - for (int i=0;igetStretchAudioSource()->val_MainVolume = (float)*getFloatParameter(0); m_control->getStretchAudioSource()->setRate(*getFloatParameter(1)); m_control->getStretchAudioSource()->val_XFadeLen = 0.1; @@ -246,6 +245,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M if (t1 - t0 < 0.001) t1 = t0 + 0.001; m_control->getStretchAudioSource()->setPlayRange({ t0,t1 }, true); + m_control->getStretchAudioSource()->setFreezing(getParameter(7)); m_control->update_process_parameters(); m_control->processAudio(buffer); } @@ -268,7 +268,10 @@ void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData for (int i=0;iparamID, (double)*par, nullptr); + if (par != nullptr) + { + paramtree.setProperty(par->paramID, (double)*par, nullptr); + } } if (m_current_file != File()) { @@ -286,8 +289,11 @@ void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int for (int i = 0; iparamID, (double)*par); - *par = parval; + if (par != nullptr) + { + double parval = tree.getProperty(par->paramID, (double)*par); + *par = parval; + } } String fn = tree.getProperty("importedfile"); if (fn.isEmpty() == false)