From d05a5d41a807d6a0b33abe61f65c8c7b840f4b25 Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 14 Dec 2017 00:19:46 +0200 Subject: [PATCH] Preliminary work to enable multichannel output again with a parameter to determine the output channels to render --- Source/PluginEditor.h | 38 +++++++++++++++++++++++++++++++++----- Source/PluginProcessor.cpp | 13 ++++++++++--- Source/PluginProcessor.h | 2 ++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index a5114a4..e889dda 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -61,16 +61,21 @@ inline void attachCallback(Button& button, std::function callback) class MySlider : public Slider { public: + MySlider() {} MySlider(NormalisableRange* range) : m_range(range) { } double proportionOfLengthToValue(double x) override { - return m_range->convertFrom0to1(x); + if (m_range) + return m_range->convertFrom0to1(x); + return Slider::proportionOfLengthToValue(x); } double valueToProportionOfLength(double x) override { - return m_range->convertTo0to1(x); + if (m_range) + return m_range->convertTo0to1(x); + return Slider::valueToProportionOfLength(x); } private: NormalisableRange* m_range = nullptr; @@ -94,6 +99,16 @@ public: m_slider->addListener(this); addAndMakeVisible(m_slider.get()); } + AudioParameterInt* intpar = dynamic_cast(par); + if (intpar) + { + m_slider = std::make_unique(); + m_notify_only_on_release = notifyOnlyOnRelease; + m_slider->setRange(intpar->getRange().getStart(), intpar->getRange().getEnd(), 1.0); + m_slider->setValue(*intpar, dontSendNotification); + m_slider->addListener(this); + addAndMakeVisible(m_slider.get()); + } AudioParameterChoice* choicepar = dynamic_cast(par); if (choicepar) { @@ -121,7 +136,11 @@ public: if (m_notify_only_on_release == true) return; AudioParameterFloat* floatpar = dynamic_cast(m_par); - *floatpar = slid->getValue(); + if (floatpar!=nullptr) + *floatpar = slid->getValue(); + AudioParameterInt* intpar = dynamic_cast(m_par); + if (intpar != nullptr) + *intpar = slid->getValue(); } void sliderDragStarted(Slider* slid) override { @@ -133,7 +152,11 @@ public: if (m_notify_only_on_release == false) return; AudioParameterFloat* floatpar = dynamic_cast(m_par); - *floatpar = slid->getValue(); + if (floatpar!=nullptr) + *floatpar = slid->getValue(); + AudioParameterInt* intpar = dynamic_cast(m_par); + if (intpar != nullptr) + *intpar = slid->getValue(); } void buttonClicked(Button* but) override { @@ -146,10 +169,15 @@ public: void updateComponent() { AudioParameterFloat* floatpar = dynamic_cast(m_par); - if (m_slider != nullptr && m_dragging == false && (float)m_slider->getValue() != *floatpar) + if (floatpar!=nullptr && m_slider != nullptr && m_dragging == false && (float)m_slider->getValue() != *floatpar) { m_slider->setValue(*floatpar, dontSendNotification); } + AudioParameterInt* intpar = dynamic_cast(m_par); + if (intpar != nullptr && m_slider != nullptr && m_dragging == false && (int)m_slider->getValue() != *intpar) + { + m_slider->setValue(*intpar, dontSendNotification); + } AudioParameterBool* boolpar = dynamic_cast(m_par); if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar) { diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 28afb64..fc26043 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -115,6 +115,8 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() addParameter(new AudioParameterFloat("filter_high_0", "Filter high", 20.0f, 20000.0f, 20000.0f)); // 24 addParameter(new AudioParameterFloat("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f)); // 25 addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26 + m_outchansparam = new AudioParameterInt("numoutchans0", "Num output channels", 1, 8, 2); + addParameter(m_outchansparam); // 27 startTimer(1, 50); } @@ -234,7 +236,8 @@ void PaulstretchpluginAudioProcessor::startplay(Range playrange, int num void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) { ScopedLock locker(m_cs); - if (getNumOutputChannels() != m_cur_num_out_chans) + int numoutchans = *m_outchansparam; + if (numoutchans != m_cur_num_out_chans) m_ready_to_play = false; if (m_using_memory_buffer == true) { @@ -251,8 +254,8 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl String err; startplay({ *getFloatParameter(5),*getFloatParameter(6) }, - 2, err); - m_cur_num_out_chans = getNumOutputChannels(); + numoutchans, err); + m_cur_num_out_chans = numoutchans; m_ready_to_play = true; } } @@ -393,6 +396,7 @@ void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData paramtree.setProperty(par->paramID, (double)*par, nullptr); } } + paramtree.setProperty(m_outchansparam->paramID, (int)*m_outchansparam, nullptr); if (m_current_file != File()) { paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr); @@ -417,6 +421,9 @@ void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int *par = parval; } } + if (tree.hasProperty(m_outchansparam->paramID)) + *m_outchansparam = tree.getProperty(m_outchansparam->paramID, 2); + } String fn = tree.getProperty("importedfile"); if (fn.isEmpty() == false) diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 09a00e4..af2a47d 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -42,6 +42,7 @@ const int cpi_filter_low = 23; const int cpi_filter_high = 24; const int cpi_onsetdetection = 25; const int cpi_capture_enabled = 26; +const int cpi_num_outchans = 27; class PaulstretchpluginAudioProcessor : public AudioProcessor, public MultiTimer { @@ -126,6 +127,7 @@ private: void setFFTSize(double size); void startplay(Range playrange, int numoutchans, String& err); SharedResourcePointer m_thumbcache; + AudioParameterInt* m_outchansparam = nullptr; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) };