diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index f1c5e5c..d9cb337 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -7,13 +7,15 @@ using namespace std; -FluidSynthModel::FluidSynthModel() { - initialised = false; - channel = 0; - sfont_id = 0; - settings = nullptr; - synth = nullptr; -} +FluidSynthModel::FluidSynthModel() + : processor(nullptr), + synth(nullptr), + settings(nullptr), + initialised(false), + sfont_id(0), + channel(0) + +{} FluidSynthModel::~FluidSynthModel() { if (initialised) { @@ -25,7 +27,8 @@ FluidSynthModel::~FluidSynthModel() { } } -void FluidSynthModel::initialise() { +void FluidSynthModel::initialise(JuicySFAudioProcessor& p) { + processor = &p; // if (initialised) { // delete_fluid_synth(synth); // delete_fluid_settings(settings); @@ -36,8 +39,9 @@ void FluidSynthModel::initialise() { synth = new_fluid_synth(settings); -// loadFont("/Users/birch/Documents/soundfont/EarthBound.sf2"); - + if (processor->soundFontPath.isNotEmpty()) { + loadFont(processor->soundFontPath.toStdString()); + } fluid_synth_set_gain(synth, 2.0); @@ -127,7 +131,7 @@ fluid_synth_t* FluidSynthModel::getSynth() { void FluidSynthModel::onFileNameChanged(const string &absPath) { unloadAndLoadFont(absPath); - eventListeners.call(&FluidSynthModel::Listener::fontChanged, this); + eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath); } void FluidSynthModel::unloadAndLoadFont(const string &absPath) { @@ -147,7 +151,10 @@ void FluidSynthModel::loadFont(const string &absPath) { FluidSynthModel::Listener::~Listener() { } -void FluidSynthModel::Listener::fontChanged(FluidSynthModel *) { +void FluidSynthModel::Listener::fontChanged(FluidSynthModel * model, const string &absPath) { + if (model->initialised) { + model->processor->soundFontPath = String(absPath); + } } //============================================================================== diff --git a/Source/FluidSynthModel.h b/Source/FluidSynthModel.h index 0d96c8d..7ce41a8 100644 --- a/Source/FluidSynthModel.h +++ b/Source/FluidSynthModel.h @@ -5,6 +5,7 @@ #pragma once #include "../JuceLibraryCode/JuceHeader.h" +#include "PluginProcessor.h" #include #include #include "PresetsToBanks.h" @@ -19,7 +20,7 @@ public: ~FluidSynthModel(); fluid_synth_t* getSynth(); - void initialise(); + void initialise(JuicySFAudioProcessor& p); BanksToPresets getBanks(); @@ -41,7 +42,7 @@ public: virtual ~Listener(); /** Called when the button is clicked. */ - virtual void fontChanged (FluidSynthModel*); + virtual void fontChanged (FluidSynthModel*, const string &absPath); }; /** Registers a listener to receive events when this button's state changes. @@ -56,6 +57,8 @@ public: void removeListener (Listener* listener); private: + JuicySFAudioProcessor* processor; + fluid_synth_t* synth; fluid_settings_t* settings; // fluid_audio_driver_t* driver; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 45f3668..346fa1e 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -21,8 +21,8 @@ JuicySFAudioProcessor::JuicySFAudioProcessor() : AudioProcessor (getBusesProperties()), lastUIWidth(400), lastUIHeight(300), - fluidSynthModel(), - soundFontPath(String()) + soundFontPath(String()), + fluidSynthModel() { initialiseSynth(); } @@ -33,7 +33,7 @@ JuicySFAudioProcessor::~JuicySFAudioProcessor() } void JuicySFAudioProcessor::initialiseSynth() { - fluidSynthModel.initialise(); + fluidSynthModel.initialise(*this); fluidSynth = fluidSynthModel.getSynth(); @@ -191,6 +191,7 @@ void JuicySFAudioProcessor::getStateInformation (MemoryBlock& destData) // add some attributes to it.. xml.setAttribute ("uiWidth", lastUIWidth); xml.setAttribute ("uiHeight", lastUIHeight); + xml.setAttribute ("soundFontPath", soundFontPath); // list::iterator p; // for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); p++) { @@ -226,6 +227,7 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt // ok, now pull out our last window size.. lastUIWidth = jmax (xmlState->getIntAttribute ("uiWidth", lastUIWidth), 400); lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 300); + soundFontPath = xmlState->getStringAttribute ("soundFontPath", soundFontPath); // Now reload our parameters.. for (auto* param : getParameters()) diff --git a/Source/TablesComponent.cpp b/Source/TablesComponent.cpp index c441008..9fde5f7 100644 --- a/Source/TablesComponent.cpp +++ b/Source/TablesComponent.cpp @@ -164,7 +164,7 @@ bool TablesComponent::keyPressed(const KeyPress &key) { return presetTable->keyPressed(key); } -void TablesComponent::fontChanged(FluidSynthModel *) { +void TablesComponent::fontChanged(FluidSynthModel *, const string &) { banksToPresets = fluidSynthModel->getBanks(); fluid_preset_t* currentPreset = getCurrentPreset(); diff --git a/Source/TablesComponent.h b/Source/TablesComponent.h index 16e5930..bf334f2 100644 --- a/Source/TablesComponent.h +++ b/Source/TablesComponent.h @@ -27,7 +27,7 @@ public: void resized() override; bool keyPressed(const KeyPress &key) override; - void fontChanged(FluidSynthModel *) override; + void fontChanged(FluidSynthModel *, const string &) override; private: FluidSynthModel* fluidSynthModel;