start setting up a global shared state and listeners

This commit is contained in:
Alex Birch 2019-07-02 23:27:56 +01:00
parent 218beb00e7
commit 1fe64e31f7
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
6 changed files with 62 additions and 15 deletions

View File

@ -13,14 +13,15 @@
#include "GuiConstants.h" #include "GuiConstants.h"
//============================================================================== //==============================================================================
JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(JuicySFAudioProcessor& p) JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor(JuicySFAudioProcessor& p, AudioProcessorValueTreeState& state)
: AudioProcessorEditor{&p}, : AudioProcessorEditor{&p},
processor{p}, processor{p},
state{state},
sharedParams{p.sharedParams}, sharedParams{p.sharedParams},
midiKeyboard{p.keyboardState, SurjectiveMidiKeyboardComponent::horizontalKeyboard}, midiKeyboard{p.keyboardState, SurjectiveMidiKeyboardComponent::horizontalKeyboard},
tablesComponent{p.getFluidSynthModel()}, tablesComponent{p.getFluidSynthModel()},
filePicker{p.getFluidSynthModel()}, filePicker{p.getFluidSynthModel()},
slidersComponent{p.sharedParams, p.getFluidSynthModel()} slidersComponent{p.sharedParams, state, p.getFluidSynthModel()}
{ {
// set resize limits for this plug-in // set resize limits for this plug-in
setResizeLimits( setResizeLimits(

View File

@ -28,7 +28,7 @@ class JuicySFAudioProcessorEditor : public AudioProcessorEditor,
public StateChangeSubscriber*/ public StateChangeSubscriber*/
{ {
public: public:
JuicySFAudioProcessorEditor (JuicySFAudioProcessor&); JuicySFAudioProcessorEditor (JuicySFAudioProcessor&, AudioProcessorValueTreeState& state);
~JuicySFAudioProcessorEditor(); ~JuicySFAudioProcessorEditor();
//============================================================================== //==============================================================================
@ -49,6 +49,7 @@ private:
// access the processor object that created it. // access the processor object that created it.
JuicySFAudioProcessor& processor; JuicySFAudioProcessor& processor;
AudioProcessorValueTreeState& state;
shared_ptr<SharesParams> sharedParams; shared_ptr<SharesParams> sharedParams;
SurjectiveMidiKeyboardComponent midiKeyboard; SurjectiveMidiKeyboardComponent midiKeyboard;

View File

@ -19,21 +19,44 @@
#include "Params.h" #include "Params.h"
using namespace std; using namespace std;
using Parameter = AudioProcessorValueTreeState::Parameter;
AudioProcessor* JUCE_CALLTYPE createPluginFilter(); AudioProcessor* JUCE_CALLTYPE createPluginFilter();
//============================================================================== //==============================================================================
JuicySFAudioProcessor::JuicySFAudioProcessor() JuicySFAudioProcessor::JuicySFAudioProcessor()
: AudioProcessor{getBusesProperties()}, : AudioProcessor{getBusesProperties()}
sharedParams{static_pointer_cast<SharesParams>(make_shared<Params>())}, , sharedParams{static_pointer_cast<SharesParams>(make_shared<Params>())}
fluidSynthModel{sharedParams}/*, , state{*this, nullptr,
fluidSynthModel{*this}, { "PARAMETERS" /* MYPLUGINSETTINGS */ },
pluginEditor(nullptr)*/ createParameterLayout()
}
, fluidSynthModel{sharedParams}
//, fluidSynthModel{*this}
//, pluginEditor(nullptr)
{ {
initialiseSynth(); initialiseSynth();
} }
AudioProcessorValueTreeState::ParameterLayout JuicySFAudioProcessor::createParameterLayout() {
// std::vector<std::unique_ptr<AudioParameterInt>> params;
// for (int i = 1; i < 9; ++i)
// params.push_back (std::make_unique<AudioParameterInt> (String (i), String (i), 0, i, 0));
vector<unique_ptr<AudioParameterInt>> params{
make_unique<AudioParameterInt>("attack", "volume envelope attack time", 0, 127, 0, "A" ),
make_unique<AudioParameterInt>("decay", "volume envelope sustain attentuation", 0, 127, 0, "D" ),
make_unique<AudioParameterInt>("sustain", "volume envelope decay time", 0, 127, 0, "S" ),
make_unique<AudioParameterInt>("release", "volume envelope release time", 0, 127, 0, "R" ),
make_unique<AudioParameterInt>("filterCutOff", "low-pass filter cut-off frequency", 0, 127, 0, "Cut" ),
make_unique<AudioParameterInt>("filterResonance", "low-pass filter resonance attentuation", 0, 127, 0, "Res" ),
};
return { params.begin(), params.end() };
}
JuicySFAudioProcessor::~JuicySFAudioProcessor() JuicySFAudioProcessor::~JuicySFAudioProcessor()
{ {
// delete fluidSynthModel; // delete fluidSynthModel;
@ -268,7 +291,7 @@ bool JuicySFAudioProcessor::hasEditor() const
AudioProcessorEditor* JuicySFAudioProcessor::createEditor() AudioProcessorEditor* JuicySFAudioProcessor::createEditor()
{ {
// grab a raw pointer to it for our own use // grab a raw pointer to it for our own use
return /*pluginEditor = */new JuicySFAudioProcessorEditor (*this); return /*pluginEditor = */new JuicySFAudioProcessorEditor (*this, state);
} }
//============================================================================== //==============================================================================

View File

@ -74,6 +74,8 @@ public:
private: private:
void initialiseSynth(); void initialiseSynth();
AudioProcessorValueTreeState state;
FluidSynthModel fluidSynthModel; FluidSynthModel fluidSynthModel;
fluid_synth_t* fluidSynth; fluid_synth_t* fluidSynth;
Synthesiser synth; Synthesiser synth;
@ -83,6 +85,8 @@ private:
// list<StateChangeSubscriber*> stateChangeSubscribers; // list<StateChangeSubscriber*> stateChangeSubscribers;
AudioProcessorValueTreeState::ParameterLayout createParameterLayout();
static BusesProperties getBusesProperties(); static BusesProperties getBusesProperties();
// Model* model; // Model* model;

View File

@ -9,6 +9,7 @@
#include "SlidersComponent.h" #include "SlidersComponent.h"
#include "FluidSynthModel.h" #include "FluidSynthModel.h"
#include "MidiConstants.h" #include "MidiConstants.h"
using SliderAttachment = AudioProcessorValueTreeState::SliderAttachment;
std::function<void()> SlidersComponent::makeSliderListener(Slider& slider, int controller/*, std::function<void()> callback*/) { std::function<void()> SlidersComponent::makeSliderListener(Slider& slider, int controller/*, std::function<void()> callback*/) {
return [this, controller, &slider]{ return [this, controller, &slider]{
@ -105,11 +106,13 @@ void SlidersComponent::acceptMidiControlEvent(int controller, int value) {
SlidersComponent::SlidersComponent( SlidersComponent::SlidersComponent(
shared_ptr<SharesParams> sharedParams, shared_ptr<SharesParams> sharedParams,
FluidSynthModel* fluidSynthModel) : AudioProcessorValueTreeState& state,
sharedParams{sharedParams}, FluidSynthModel* fluidSynthModel)
fluidSynthModel{fluidSynthModel}, : sharedParams{sharedParams}
envelopeGroup{"envelopeGroup", "Envelope"}, , state{state}
filterGroup{"filterGroup", "Filter"} , fluidSynthModel{fluidSynthModel}
, envelopeGroup{"envelopeGroup", "Envelope"}
, filterGroup{"filterGroup", "Filter"}
{ {
const Slider::SliderStyle style{Slider::SliderStyle::LinearVertical}; const Slider::SliderStyle style{Slider::SliderStyle::LinearVertical};
const double rangeMin(0); const double rangeMin(0);
@ -120,31 +123,37 @@ filterGroup{"filterGroup", "Filter"}
attackSlider.setRange(rangeMin, rangeMax, rangeStep); attackSlider.setRange(rangeMin, rangeMax, rangeStep);
attackSlider.onValueChange = makeSliderListener(attackSlider, static_cast<int>(SOUND_CTRL4)); attackSlider.onValueChange = makeSliderListener(attackSlider, static_cast<int>(SOUND_CTRL4));
attackSlider.setTextBoxStyle(Slider::TextBoxBelow, true, attackSlider.getTextBoxWidth(), attackSlider.getTextBoxHeight()); attackSlider.setTextBoxStyle(Slider::TextBoxBelow, true, attackSlider.getTextBoxWidth(), attackSlider.getTextBoxHeight());
attackSliderAttachment = make_unique<SliderAttachment>(state, "attack", attackSlider);
decaySlider.setSliderStyle(style); decaySlider.setSliderStyle(style);
decaySlider.setRange(rangeMin, rangeMax, rangeStep); decaySlider.setRange(rangeMin, rangeMax, rangeStep);
decaySlider.onValueChange = makeSliderListener(decaySlider, static_cast<int>(SOUND_CTRL6)); decaySlider.onValueChange = makeSliderListener(decaySlider, static_cast<int>(SOUND_CTRL6));
decaySlider.setTextBoxStyle(Slider::TextBoxBelow, true, decaySlider.getTextBoxWidth(), decaySlider.getTextBoxHeight()); decaySlider.setTextBoxStyle(Slider::TextBoxBelow, true, decaySlider.getTextBoxWidth(), decaySlider.getTextBoxHeight());
decaySliderAttachment = make_unique<SliderAttachment>(state, "decay", decaySlider);
sustainSlider.setSliderStyle(style); sustainSlider.setSliderStyle(style);
sustainSlider.setRange(rangeMin, rangeMax, rangeStep); sustainSlider.setRange(rangeMin, rangeMax, rangeStep);
sustainSlider.onValueChange = makeSliderListener(sustainSlider, static_cast<int>(SOUND_CTRL10)); sustainSlider.onValueChange = makeSliderListener(sustainSlider, static_cast<int>(SOUND_CTRL10));
sustainSlider.setTextBoxStyle(Slider::TextBoxBelow, true, sustainSlider.getTextBoxWidth(), sustainSlider.getTextBoxHeight()); sustainSlider.setTextBoxStyle(Slider::TextBoxBelow, true, sustainSlider.getTextBoxWidth(), sustainSlider.getTextBoxHeight());
sustainSliderAttachment = make_unique<SliderAttachment>(state, "sustain", sustainSlider);
releaseSlider.setSliderStyle(style); releaseSlider.setSliderStyle(style);
releaseSlider.setRange(rangeMin, rangeMax, rangeStep); releaseSlider.setRange(rangeMin, rangeMax, rangeStep);
releaseSlider.onValueChange = makeSliderListener(releaseSlider, static_cast<int>(SOUND_CTRL3)); releaseSlider.onValueChange = makeSliderListener(releaseSlider, static_cast<int>(SOUND_CTRL3));
releaseSlider.setTextBoxStyle(Slider::TextBoxBelow, true, releaseSlider.getTextBoxWidth(), releaseSlider.getTextBoxHeight()); releaseSlider.setTextBoxStyle(Slider::TextBoxBelow, true, releaseSlider.getTextBoxWidth(), releaseSlider.getTextBoxHeight());
releaseSliderAttachment = make_unique<SliderAttachment>(state, "release", releaseSlider);
filterCutOffSlider.setSliderStyle(style); filterCutOffSlider.setSliderStyle(style);
filterCutOffSlider.setRange(rangeMin, rangeMax, rangeStep); filterCutOffSlider.setRange(rangeMin, rangeMax, rangeStep);
filterCutOffSlider.onValueChange = makeSliderListener(filterCutOffSlider, static_cast<int>(SOUND_CTRL5)); filterCutOffSlider.onValueChange = makeSliderListener(filterCutOffSlider, static_cast<int>(SOUND_CTRL5));
filterCutOffSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterCutOffSlider.getTextBoxWidth(), filterCutOffSlider.getTextBoxHeight()); filterCutOffSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterCutOffSlider.getTextBoxWidth(), filterCutOffSlider.getTextBoxHeight());
filterCutOffSliderAttachment = make_unique<SliderAttachment>(state, "filterCutOff", filterCutOffSlider);
filterResonanceSlider.setSliderStyle(style); filterResonanceSlider.setSliderStyle(style);
filterResonanceSlider.setRange(rangeMin, rangeMax, rangeStep); filterResonanceSlider.setRange(rangeMin, rangeMax, rangeStep);
filterResonanceSlider.onValueChange = makeSliderListener(filterResonanceSlider, static_cast<int>(SOUND_CTRL2)); filterResonanceSlider.onValueChange = makeSliderListener(filterResonanceSlider, static_cast<int>(SOUND_CTRL2));
filterResonanceSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterResonanceSlider.getTextBoxWidth(), filterResonanceSlider.getTextBoxHeight()); filterResonanceSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterResonanceSlider.getTextBoxWidth(), filterResonanceSlider.getTextBoxHeight());
filterResonanceSliderAttachment = make_unique<SliderAttachment>(state, "filterResonance", filterResonanceSlider);
addAndMakeVisible(attackSlider); addAndMakeVisible(attackSlider);
addAndMakeVisible(decaySlider); addAndMakeVisible(decaySlider);

View File

@ -6,6 +6,7 @@
#include "SlidersFragment.h" #include "SlidersFragment.h"
using namespace std; using namespace std;
using SliderAttachment = AudioProcessorValueTreeState::SliderAttachment;
class SlidersComponent : public Component, class SlidersComponent : public Component,
public SlidersFragment public SlidersFragment
@ -13,6 +14,7 @@ class SlidersComponent : public Component,
public: public:
SlidersComponent( SlidersComponent(
shared_ptr<SharesParams> sharedParams, shared_ptr<SharesParams> sharedParams,
AudioProcessorValueTreeState& state,
FluidSynthModel* fluidSynthModel); FluidSynthModel* fluidSynthModel);
~SlidersComponent(); ~SlidersComponent();
@ -34,29 +36,36 @@ private:
std::function<void()> makeSliderListener(Slider& slider, int controller); std::function<void()> makeSliderListener(Slider& slider, int controller);
shared_ptr<SharesParams> sharedParams; shared_ptr<SharesParams> sharedParams;
AudioProcessorValueTreeState& state;
FluidSynthModel* fluidSynthModel; FluidSynthModel* fluidSynthModel;
GroupComponent envelopeGroup; GroupComponent envelopeGroup;
Slider attackSlider; Slider attackSlider;
Label attackLabel; Label attackLabel;
unique_ptr<SliderAttachment> attackSliderAttachment;
Slider decaySlider; Slider decaySlider;
Label decayLabel; Label decayLabel;
unique_ptr<SliderAttachment> decaySliderAttachment;
Slider sustainSlider; Slider sustainSlider;
Label sustainLabel; Label sustainLabel;
unique_ptr<SliderAttachment> sustainSliderAttachment;
Slider releaseSlider; Slider releaseSlider;
Label releaseLabel; Label releaseLabel;
unique_ptr<SliderAttachment> releaseSliderAttachment;
GroupComponent filterGroup; GroupComponent filterGroup;
Slider filterCutOffSlider; Slider filterCutOffSlider;
Label filterCutOffLabel; Label filterCutOffLabel;
unique_ptr<SliderAttachment> filterCutOffSliderAttachment;
Slider filterResonanceSlider; Slider filterResonanceSlider;
Label filterResonanceLabel; Label filterResonanceLabel;
unique_ptr<SliderAttachment> filterResonanceSliderAttachment;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SlidersComponent) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SlidersComponent)
}; };