try to hook up soundfont path. perhaps encountering circular dependency on FSModel's inclusion of my plugin processor

This commit is contained in:
Alex Birch 2018-04-10 00:51:21 +01:00
parent 9bbb27d780
commit 27b9dfb9df
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
5 changed files with 31 additions and 19 deletions

View File

@ -7,13 +7,15 @@
using namespace std; using namespace std;
FluidSynthModel::FluidSynthModel() { FluidSynthModel::FluidSynthModel()
initialised = false; : processor(nullptr),
channel = 0; synth(nullptr),
sfont_id = 0; settings(nullptr),
settings = nullptr; initialised(false),
synth = nullptr; sfont_id(0),
} channel(0)
{}
FluidSynthModel::~FluidSynthModel() { FluidSynthModel::~FluidSynthModel() {
if (initialised) { if (initialised) {
@ -25,7 +27,8 @@ FluidSynthModel::~FluidSynthModel() {
} }
} }
void FluidSynthModel::initialise() { void FluidSynthModel::initialise(JuicySFAudioProcessor& p) {
processor = &p;
// if (initialised) { // if (initialised) {
// delete_fluid_synth(synth); // delete_fluid_synth(synth);
// delete_fluid_settings(settings); // delete_fluid_settings(settings);
@ -36,8 +39,9 @@ void FluidSynthModel::initialise() {
synth = new_fluid_synth(settings); 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); fluid_synth_set_gain(synth, 2.0);
@ -127,7 +131,7 @@ fluid_synth_t* FluidSynthModel::getSynth() {
void FluidSynthModel::onFileNameChanged(const string &absPath) { void FluidSynthModel::onFileNameChanged(const string &absPath) {
unloadAndLoadFont(absPath); unloadAndLoadFont(absPath);
eventListeners.call(&FluidSynthModel::Listener::fontChanged, this); eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath);
} }
void FluidSynthModel::unloadAndLoadFont(const string &absPath) { void FluidSynthModel::unloadAndLoadFont(const string &absPath) {
@ -147,7 +151,10 @@ void FluidSynthModel::loadFont(const string &absPath) {
FluidSynthModel::Listener::~Listener() { 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);
}
} }
//============================================================================== //==============================================================================

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include "../JuceLibraryCode/JuceHeader.h" #include "../JuceLibraryCode/JuceHeader.h"
#include "PluginProcessor.h"
#include <fluidsynth.h> #include <fluidsynth.h>
#include <memory> #include <memory>
#include "PresetsToBanks.h" #include "PresetsToBanks.h"
@ -19,7 +20,7 @@ public:
~FluidSynthModel(); ~FluidSynthModel();
fluid_synth_t* getSynth(); fluid_synth_t* getSynth();
void initialise(); void initialise(JuicySFAudioProcessor& p);
BanksToPresets getBanks(); BanksToPresets getBanks();
@ -41,7 +42,7 @@ public:
virtual ~Listener(); virtual ~Listener();
/** Called when the button is clicked. */ /** 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. /** Registers a listener to receive events when this button's state changes.
@ -56,6 +57,8 @@ public:
void removeListener (Listener* listener); void removeListener (Listener* listener);
private: private:
JuicySFAudioProcessor* processor;
fluid_synth_t* synth; fluid_synth_t* synth;
fluid_settings_t* settings; fluid_settings_t* settings;
// fluid_audio_driver_t* driver; // fluid_audio_driver_t* driver;

View File

@ -21,8 +21,8 @@ JuicySFAudioProcessor::JuicySFAudioProcessor()
: AudioProcessor (getBusesProperties()), : AudioProcessor (getBusesProperties()),
lastUIWidth(400), lastUIWidth(400),
lastUIHeight(300), lastUIHeight(300),
fluidSynthModel(), soundFontPath(String()),
soundFontPath(String()) fluidSynthModel()
{ {
initialiseSynth(); initialiseSynth();
} }
@ -33,7 +33,7 @@ JuicySFAudioProcessor::~JuicySFAudioProcessor()
} }
void JuicySFAudioProcessor::initialiseSynth() { void JuicySFAudioProcessor::initialiseSynth() {
fluidSynthModel.initialise(); fluidSynthModel.initialise(*this);
fluidSynth = fluidSynthModel.getSynth(); fluidSynth = fluidSynthModel.getSynth();
@ -191,6 +191,7 @@ void JuicySFAudioProcessor::getStateInformation (MemoryBlock& destData)
// add some attributes to it.. // add some attributes to it..
xml.setAttribute ("uiWidth", lastUIWidth); xml.setAttribute ("uiWidth", lastUIWidth);
xml.setAttribute ("uiHeight", lastUIHeight); xml.setAttribute ("uiHeight", lastUIHeight);
xml.setAttribute ("soundFontPath", soundFontPath);
// list<StateChangeSubscriber*>::iterator p; // list<StateChangeSubscriber*>::iterator p;
// for(p = stateChangeSubscribers.begin(); p != stateChangeSubscribers.end(); 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.. // ok, now pull out our last window size..
lastUIWidth = jmax (xmlState->getIntAttribute ("uiWidth", lastUIWidth), 400); lastUIWidth = jmax (xmlState->getIntAttribute ("uiWidth", lastUIWidth), 400);
lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 300); lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 300);
soundFontPath = xmlState->getStringAttribute ("soundFontPath", soundFontPath);
// Now reload our parameters.. // Now reload our parameters..
for (auto* param : getParameters()) for (auto* param : getParameters())

View File

@ -164,7 +164,7 @@ bool TablesComponent::keyPressed(const KeyPress &key) {
return presetTable->keyPressed(key); return presetTable->keyPressed(key);
} }
void TablesComponent::fontChanged(FluidSynthModel *) { void TablesComponent::fontChanged(FluidSynthModel *, const string &) {
banksToPresets = fluidSynthModel->getBanks(); banksToPresets = fluidSynthModel->getBanks();
fluid_preset_t* currentPreset = getCurrentPreset(); fluid_preset_t* currentPreset = getCurrentPreset();

View File

@ -27,7 +27,7 @@ public:
void resized() override; void resized() override;
bool keyPressed(const KeyPress &key) override; bool keyPressed(const KeyPress &key) override;
void fontChanged(FluidSynthModel *) override; void fontChanged(FluidSynthModel *, const string &) override;
private: private:
FluidSynthModel* fluidSynthModel; FluidSynthModel* fluidSynthModel;