Preliminary work to enable multichannel output again with a parameter to determine the output channels to render

This commit is contained in:
xenakios 2017-12-14 00:19:46 +02:00
parent 71a9419e51
commit d05a5d41a8
3 changed files with 45 additions and 8 deletions

View File

@ -61,16 +61,21 @@ inline void attachCallback(Button& button, std::function<void()> callback)
class MySlider : public Slider class MySlider : public Slider
{ {
public: public:
MySlider() {}
MySlider(NormalisableRange<float>* range) : m_range(range) MySlider(NormalisableRange<float>* range) : m_range(range)
{ {
} }
double proportionOfLengthToValue(double x) override 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 double valueToProportionOfLength(double x) override
{ {
return m_range->convertTo0to1(x); if (m_range)
return m_range->convertTo0to1(x);
return Slider::valueToProportionOfLength(x);
} }
private: private:
NormalisableRange<float>* m_range = nullptr; NormalisableRange<float>* m_range = nullptr;
@ -94,6 +99,16 @@ public:
m_slider->addListener(this); m_slider->addListener(this);
addAndMakeVisible(m_slider.get()); addAndMakeVisible(m_slider.get());
} }
AudioParameterInt* intpar = dynamic_cast<AudioParameterInt*>(par);
if (intpar)
{
m_slider = std::make_unique<MySlider>();
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<AudioParameterChoice*>(par); AudioParameterChoice* choicepar = dynamic_cast<AudioParameterChoice*>(par);
if (choicepar) if (choicepar)
{ {
@ -121,7 +136,11 @@ public:
if (m_notify_only_on_release == true) if (m_notify_only_on_release == true)
return; return;
AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par); AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
*floatpar = slid->getValue(); if (floatpar!=nullptr)
*floatpar = slid->getValue();
AudioParameterInt* intpar = dynamic_cast<AudioParameterInt*>(m_par);
if (intpar != nullptr)
*intpar = slid->getValue();
} }
void sliderDragStarted(Slider* slid) override void sliderDragStarted(Slider* slid) override
{ {
@ -133,7 +152,11 @@ public:
if (m_notify_only_on_release == false) if (m_notify_only_on_release == false)
return; return;
AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par); AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
*floatpar = slid->getValue(); if (floatpar!=nullptr)
*floatpar = slid->getValue();
AudioParameterInt* intpar = dynamic_cast<AudioParameterInt*>(m_par);
if (intpar != nullptr)
*intpar = slid->getValue();
} }
void buttonClicked(Button* but) override void buttonClicked(Button* but) override
{ {
@ -146,10 +169,15 @@ public:
void updateComponent() void updateComponent()
{ {
AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par); AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(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); m_slider->setValue(*floatpar, dontSendNotification);
} }
AudioParameterInt* intpar = dynamic_cast<AudioParameterInt*>(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<AudioParameterBool*>(m_par); AudioParameterBool* boolpar = dynamic_cast<AudioParameterBool*>(m_par);
if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar) if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar)
{ {

View File

@ -115,6 +115,8 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
addParameter(new AudioParameterFloat("filter_high_0", "Filter high", 20.0f, 20000.0f, 20000.0f)); // 24 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 AudioParameterFloat("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f)); // 25
addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26 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); startTimer(1, 50);
} }
@ -234,7 +236,8 @@ void PaulstretchpluginAudioProcessor::startplay(Range<double> playrange, int num
void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
{ {
ScopedLock locker(m_cs); 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; m_ready_to_play = false;
if (m_using_memory_buffer == true) if (m_using_memory_buffer == true)
{ {
@ -251,8 +254,8 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl
String err; String err;
startplay({ *getFloatParameter(5),*getFloatParameter(6) }, startplay({ *getFloatParameter(5),*getFloatParameter(6) },
2, err); numoutchans, err);
m_cur_num_out_chans = getNumOutputChannels(); m_cur_num_out_chans = numoutchans;
m_ready_to_play = true; m_ready_to_play = true;
} }
} }
@ -393,6 +396,7 @@ void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData
paramtree.setProperty(par->paramID, (double)*par, nullptr); paramtree.setProperty(par->paramID, (double)*par, nullptr);
} }
} }
paramtree.setProperty(m_outchansparam->paramID, (int)*m_outchansparam, nullptr);
if (m_current_file != File()) if (m_current_file != File())
{ {
paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr); paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr);
@ -417,6 +421,9 @@ void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int
*par = parval; *par = parval;
} }
} }
if (tree.hasProperty(m_outchansparam->paramID))
*m_outchansparam = tree.getProperty(m_outchansparam->paramID, 2);
} }
String fn = tree.getProperty("importedfile"); String fn = tree.getProperty("importedfile");
if (fn.isEmpty() == false) if (fn.isEmpty() == false)

View File

@ -42,6 +42,7 @@ const int cpi_filter_low = 23;
const int cpi_filter_high = 24; const int cpi_filter_high = 24;
const int cpi_onsetdetection = 25; const int cpi_onsetdetection = 25;
const int cpi_capture_enabled = 26; const int cpi_capture_enabled = 26;
const int cpi_num_outchans = 27;
class PaulstretchpluginAudioProcessor : public AudioProcessor, public MultiTimer class PaulstretchpluginAudioProcessor : public AudioProcessor, public MultiTimer
{ {
@ -126,6 +127,7 @@ private:
void setFFTSize(double size); void setFFTSize(double size);
void startplay(Range<double> playrange, int numoutchans, String& err); void startplay(Range<double> playrange, int numoutchans, String& err);
SharedResourcePointer<MyThumbCache> m_thumbcache; SharedResourcePointer<MyThumbCache> m_thumbcache;
AudioParameterInt* m_outchansparam = nullptr;
//============================================================================== //==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
}; };