Support bool parameters in parameter component. Add freeze parameter to plugin.

This commit is contained in:
xenakios 2017-11-16 19:45:40 +02:00
parent aee132519a
commit 0dcd410780
4 changed files with 49 additions and 25 deletions

View File

@ -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);

View File

@ -29,14 +29,14 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa
for (int i=0;i<pars.size();++i)
{
m_parcomps.push_back(std::make_shared<ParameterComponent>(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<double> range, int which)
{
*processor.getFloatParameter(5) = range.getStart();

View File

@ -44,7 +44,7 @@ inline void attachCallback(Button& button, std::function<void()> 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<AudioParameterBool*>(par);
if (boolpar)
{
m_togglebut = std::make_unique<ToggleButton>();
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<AudioParameterFloat*>(m_par);
*floatpar = slid->getValue();
}
void buttonClicked(Button* but) override
{
AudioParameterBool* boolpar = dynamic_cast<AudioParameterBool*>(m_par);
if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar)
{
*boolpar = m_togglebut->getToggleState();
}
}
void updateComponent()
{
AudioParameterFloat* floatpar = dynamic_cast<AudioParameterFloat*>(m_par);
@ -89,6 +102,11 @@ public:
{
m_slider->setValue(*floatpar, dontSendNotification);
}
AudioParameterBool* boolpar = dynamic_cast<AudioParameterBool*>(m_par);
if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar)
{
m_togglebut->setToggleState(*boolpar, dontSendNotification);
}
}
private:
Label m_label;

View File

@ -10,9 +10,13 @@
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <set>
#undef min
#undef max
std::set<PaulstretchpluginAudioProcessor*> g_activeprocessors;
template<typename F>
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<AudioFormatManager>();
@ -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;i<buffer.getNumSamples();++i)
{
buffer.setSample(0, i, 0.1*sin(2*3.141592/44100*m_phase*440));
buffer.setSample(1, i, 0.1*sin(2*3.141592/44100*m_phase*440));
m_phase+=1.0;
}
return;
*/
m_control->getStretchAudioSource()->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;i<getNumParameters();++i)
{
auto par = getFloatParameter(i);
paramtree.setProperty(par->paramID, (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; i<getNumParameters(); ++i)
{
auto par = getFloatParameter(i);
double parval = tree.getProperty(par->paramID, (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)