From 23c0a2dd3793deee8dc0c01ecf4b44548d8ce131 Mon Sep 17 00:00:00 2001 From: Alex Birch Date: Sun, 30 Jun 2019 21:40:24 +0100 Subject: [PATCH] make sliders send MIDI CC to FluidSynth. Make name column in table wider. Make synth wider. --- Source/FluidSynthModel.cpp | 22 +++++++++++++--------- Source/FluidSynthModel.h | 1 + Source/MidiConstants.h | 12 ++++++------ Source/PluginEditor.cpp | 7 ++++--- Source/SlidersComponent.cpp | 26 +++++++++++++++----------- Source/SlidersComponent.h | 7 +++++-- Source/TableComponent.cpp | 2 +- 7 files changed, 45 insertions(+), 32 deletions(-) diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index 305d5cc..7d3b309 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -58,14 +58,7 @@ void FluidSynthModel::initialise() { for(int i{SOUND_CTRL1}; i <= SOUND_CTRL10; i++) { - fluid_midi_event_t *midi_event(new_fluid_midi_event()); - fluid_midi_event_set_type(midi_event, static_cast(CONTROL_CHANGE)); - fluid_midi_event_set_channel(midi_event, channel); - fluid_midi_event_set_control(midi_event, i); - fluid_midi_event_set_value(midi_event, 0); - fluid_synth_handle_midi_event(synth, midi_event); - delete_fluid_midi_event(midi_event); -// fluid_channel_set_cc(channel, i, 0); + setControllerValue(i, 0); } // fluid_synth_bank_select(synth, 0, 3); @@ -159,7 +152,7 @@ void FluidSynthModel::initialise() { static_cast(SOUND_CTRL10), // MIDI CC 79 undefined FLUID_MOD_CC | FLUID_MOD_UNIPOLAR - | FLUID_MOD_LINEAR + | FLUID_MOD_CONCAVE | FLUID_MOD_POSITIVE); fluid_mod_set_source2(mod, 0, 0); fluid_mod_set_dest(mod, GEN_VOLENVSUSTAIN); @@ -172,6 +165,17 @@ void FluidSynthModel::initialise() { initialised = true; } +void FluidSynthModel::setControllerValue(int controller, int value) { + fluid_midi_event_t *midi_event(new_fluid_midi_event()); + fluid_midi_event_set_type(midi_event, static_cast(CONTROL_CHANGE)); + fluid_midi_event_set_channel(midi_event, channel); + fluid_midi_event_set_control(midi_event, controller); + fluid_midi_event_set_value(midi_event, value); + fluid_synth_handle_midi_event(synth, midi_event); + delete_fluid_midi_event(midi_event); + // fluid_channel_set_cc(channel, i, 0); +} + int FluidSynthModel::getChannel() { return channel; } diff --git a/Source/FluidSynthModel.h b/Source/FluidSynthModel.h index 11e7a49..a630cdf 100644 --- a/Source/FluidSynthModel.h +++ b/Source/FluidSynthModel.h @@ -31,6 +31,7 @@ public: int getChannel(); void onFileNameChanged(const String &absPath, int bank, int preset); + void setControllerValue(int controller, int value); //============================================================================== /** diff --git a/Source/MidiConstants.h b/Source/MidiConstants.h index a5fef83..f31a69a 100644 --- a/Source/MidiConstants.h +++ b/Source/MidiConstants.h @@ -97,15 +97,15 @@ enum fluid_midi_control_change LEGATO_SWITCH = 0x44, HOLD2_SWITCH = 0x45, SOUND_CTRL1 = 0x46, - SOUND_CTRL2 = 0x47, - SOUND_CTRL3 = 0x48, - SOUND_CTRL4 = 0x49, - SOUND_CTRL5 = 0x4A, - SOUND_CTRL6 = 0x4B, + SOUND_CTRL2 = 0x47, // MIDI CC 71 Timbre/Harmonic Intensity (filter resonance) + SOUND_CTRL3 = 0x48, // MIDI CC 72 Release time + SOUND_CTRL4 = 0x49, // MIDI CC 73 Attack time + SOUND_CTRL5 = 0x4A, // MIDI CC 74 Brightness (cutoff frequency, FILTERFC) + SOUND_CTRL6 = 0x4B, // MIDI CC 75 Decay Time SOUND_CTRL7 = 0x4C, SOUND_CTRL8 = 0x4D, SOUND_CTRL9 = 0x4E, - SOUND_CTRL10 = 0x4F, + SOUND_CTRL10 = 0x4F, // MIDI CC 79 undefined GPC5 = 0x50, GPC6 = 0x51, GPC7 = 0x52, diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index e5cf407..8edc3c4 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -17,10 +17,11 @@ JuicySFAudioProcessorEditor::JuicySFAudioProcessorEditor (JuicySFAudioProcessor& processor (p), midiKeyboard (p.keyboardState, SurjectiveMidiKeyboardComponent::horizontalKeyboard), tablesComponent(p.getFluidSynthModel()), - filePicker(p.getFluidSynthModel()) + filePicker(p.getFluidSynthModel()), + slidersComponent{p.getFluidSynthModel()} { // set resize limits for this plug-in - setResizeLimits (400, 300, 1900, 1000); + setResizeLimits (500, 300, 1900, 1000); setSize (p.lastUIWidth, p.lastUIHeight); @@ -82,7 +83,7 @@ void JuicySFAudioProcessorEditor::resized() const int padding{8}; const int pianoHeight{70}; const int filePickerHeight{25}; - const int slidersHeight{150}; + // const int slidersHeight{150}; Rectangle r{getLocalBounds()}; filePicker.setBounds(r.removeFromTop(filePickerHeight + padding).reduced(padding, 0).withTrimmedTop(padding)); diff --git a/Source/SlidersComponent.cpp b/Source/SlidersComponent.cpp index 0bffe74..4d008d5 100644 --- a/Source/SlidersComponent.cpp +++ b/Source/SlidersComponent.cpp @@ -7,10 +7,13 @@ // #include "SlidersComponent.h" +#include "FluidSynthModel.h" +#include "MidiConstants.h" -std::function SlidersComponent::makeSliderListener(Slider& slider) { - return [&slider]{ - slider.setValue(slider.getValue(), NotificationType::dontSendNotification); +std::function SlidersComponent::makeSliderListener(Slider& slider, int controller) { + return [this, controller, &slider]{ +// slider.setValue(slider.getValue(), NotificationType::dontSendNotification); + fluidSynthModel->setControllerValue(controller, slider.getValue()); }; } @@ -55,7 +58,8 @@ void SlidersComponent::resized() { filterResonanceSlider.setBounds(rFilter.removeFromLeft(sliderWidth + sliderXMargin).withTrimmedTop(labelHeight).withTrimmedLeft(sliderXMargin)); } -SlidersComponent::SlidersComponent() : +SlidersComponent::SlidersComponent(FluidSynthModel* fluidSynthModel) : +fluidSynthModel{fluidSynthModel}, envelopeGroup{"envelopeGroup", "Envelope"}, filterGroup{"filterGroup", "Filter"} { @@ -66,32 +70,32 @@ filterGroup{"filterGroup", "Filter"} attackSlider.setSliderStyle(style); attackSlider.setRange(rangeMin, rangeMax, rangeStep); - // attackSlider.onValueChange = makeSliderListener(attackSlider); + attackSlider.onValueChange = makeSliderListener(attackSlider, static_cast(SOUND_CTRL4)); attackSlider.setTextBoxStyle(Slider::TextBoxBelow, true, attackSlider.getTextBoxWidth(), attackSlider.getTextBoxHeight()); decaySlider.setSliderStyle(style); decaySlider.setRange(rangeMin, rangeMax, rangeStep); - // decaySlider.onValueChange = makeSliderListener(decaySlider); + decaySlider.onValueChange = makeSliderListener(decaySlider, static_cast(SOUND_CTRL6)); decaySlider.setTextBoxStyle(Slider::TextBoxBelow, true, decaySlider.getTextBoxWidth(), decaySlider.getTextBoxHeight()); sustainSlider.setSliderStyle(style); sustainSlider.setRange(rangeMin, rangeMax, rangeStep); - // sustainSlider.onValueChange = makeSliderListener(sustainSlider); + sustainSlider.onValueChange = makeSliderListener(sustainSlider, static_cast(SOUND_CTRL10)); sustainSlider.setTextBoxStyle(Slider::TextBoxBelow, true, sustainSlider.getTextBoxWidth(), sustainSlider.getTextBoxHeight()); releaseSlider.setSliderStyle(style); releaseSlider.setRange(rangeMin, rangeMax, rangeStep); - // releaseSlider.onValueChange = makeSliderListener(releaseSlider); + releaseSlider.onValueChange = makeSliderListener(releaseSlider, static_cast(SOUND_CTRL3)); releaseSlider.setTextBoxStyle(Slider::TextBoxBelow, true, releaseSlider.getTextBoxWidth(), releaseSlider.getTextBoxHeight()); filterCutOffSlider.setSliderStyle(style); filterCutOffSlider.setRange(rangeMin, rangeMax, rangeStep); - // filterCutOffSlider.onValueChange = makeSliderListener(filterCutOffSlider); + filterCutOffSlider.onValueChange = makeSliderListener(filterCutOffSlider, static_cast(SOUND_CTRL5)); filterCutOffSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterCutOffSlider.getTextBoxWidth(), filterCutOffSlider.getTextBoxHeight()); filterResonanceSlider.setSliderStyle(style); filterResonanceSlider.setRange(rangeMin, rangeMax, rangeStep); - // filterResonanceSlider.onValueChange = makeSliderListener(filterResonanceSlider); + filterResonanceSlider.onValueChange = makeSliderListener(filterResonanceSlider, static_cast(SOUND_CTRL2)); filterResonanceSlider.setTextBoxStyle(Slider::TextBoxBelow, true, filterResonanceSlider.getTextBoxWidth(), filterResonanceSlider.getTextBoxHeight()); addAndMakeVisible(attackSlider); @@ -134,4 +138,4 @@ filterGroup{"filterGroup", "Filter"} addAndMakeVisible(envelopeGroup); addAndMakeVisible(filterGroup); -} \ No newline at end of file +} diff --git a/Source/SlidersComponent.h b/Source/SlidersComponent.h index 48ceee2..ede78d3 100644 --- a/Source/SlidersComponent.h +++ b/Source/SlidersComponent.h @@ -1,13 +1,14 @@ # pragma once #include "../JuceLibraryCode/JuceHeader.h" +#include "FluidSynthModel.h" using namespace std; class SlidersComponent : public Component { public: - SlidersComponent(); + SlidersComponent(FluidSynthModel* fluidSynthModel); ~SlidersComponent(); void resized() override; @@ -15,7 +16,9 @@ public: const int getDesiredWidth(); private: - std::function makeSliderListener(Slider& slider); + std::function makeSliderListener(Slider& slider, int controller); + + FluidSynthModel* fluidSynthModel; GroupComponent envelopeGroup; diff --git a/Source/TableComponent.cpp b/Source/TableComponent.cpp index e57a201..75487e5 100644 --- a/Source/TableComponent.cpp +++ b/Source/TableComponent.cpp @@ -40,7 +40,7 @@ TableComponent::TableComponent( // Add some columns to the table header, based on the column list in our database.. for (auto &column : columns) // access by reference to avoid copying { - const int colWidth{ columnIx == 1 ? 30 : 100 }; + const int colWidth{ columnIx == 1 ? 30 : 200 }; table.getHeader().addColumn ( String(column), columnIx++,