switch to JUCE Strings so we can copy and compare more easily. make state load attempt to load soundfont and restore window size.

This commit is contained in:
Alex Birch 2018-04-10 23:29:32 +01:00
parent 649a1fcf36
commit 191641ddd1
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
7 changed files with 49 additions and 18 deletions

View File

@ -43,5 +43,5 @@ void FilePicker::paint(Graphics& g)
}
void FilePicker::filenameComponentChanged (FilenameComponent*) {
fluidSynthModel->onFileNameChanged(fileChooser.getCurrentFile().getFullPathName().toStdString());
fluidSynthModel->onFileNameChanged(fileChooser.getCurrentFile().getFullPathName());
}

View File

@ -11,6 +11,7 @@ FluidSynthModel::FluidSynthModel(SharesParams& p)
: sharesParams(p),
synth(nullptr),
settings(nullptr),
currentSoundFontAbsPath(),
initialised(false),
sfont_id(0),
channel(0)
@ -38,9 +39,7 @@ void FluidSynthModel::initialise() {
synth = new_fluid_synth(settings);
if (sharesParams.getSoundFontPath().isNotEmpty()) {
loadFont(sharesParams.getSoundFontPath().toStdString());
}
loadFont(sharesParams.getSoundFontPath());
fluid_synth_set_gain(synth, 2.0);
@ -128,13 +127,16 @@ fluid_synth_t* FluidSynthModel::getSynth() {
return synth;
}
void FluidSynthModel::onFileNameChanged(const string &absPath) {
void FluidSynthModel::onFileNameChanged(const String &absPath) {
if (!shouldLoadFont(absPath)) {
return;
}
unloadAndLoadFont(absPath);
sharesParams.setSoundFontPath(String(absPath));
sharesParams.setSoundFontPath(absPath);
eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath);
}
void FluidSynthModel::unloadAndLoadFont(const string &absPath) {
void FluidSynthModel::unloadAndLoadFont(const String &absPath) {
// in the base case, there is no font loaded
if (fluid_synth_sfcount(synth) > 0) {
fluid_synth_sfunload(synth, sfont_id, 1);
@ -142,16 +144,30 @@ void FluidSynthModel::unloadAndLoadFont(const string &absPath) {
loadFont(absPath);
}
void FluidSynthModel::loadFont(const string &absPath) {
void FluidSynthModel::loadFont(const String &absPath) {
if (!shouldLoadFont(absPath)) {
return;
}
currentSoundFontAbsPath = absPath;
sfont_id++;
fluid_synth_sfload(synth, absPath.c_str(), 1);
fluid_synth_sfload(synth, absPath.toStdString().c_str(), 1);
selectFirstPreset();
}
FluidSynthModel::Listener::~Listener() {
}
void FluidSynthModel::Listener::fontChanged(FluidSynthModel * model, const string &absPath) {
bool FluidSynthModel::shouldLoadFont(const String &absPath) {
if (absPath.isEmpty()) {
return false;
}
if (absPath == currentSoundFontAbsPath) {
return false;
}
return true;
}
void FluidSynthModel::Listener::fontChanged(FluidSynthModel * model, const String &absPath) {
}
//==============================================================================

View File

@ -27,7 +27,7 @@ public:
void changePreset(int bank, int preset);
int getChannel();
void onFileNameChanged(const string &absPath);
void onFileNameChanged(const String &absPath);
//==============================================================================
/**
@ -42,7 +42,7 @@ public:
virtual ~Listener();
/** Called when the button is clicked. */
virtual void fontChanged (FluidSynthModel*, const string &absPath);
virtual void fontChanged (FluidSynthModel*, const String &absPath);
};
/** Registers a listener to receive events when this button's state changes.
@ -63,11 +63,14 @@ private:
fluid_settings_t* settings;
// fluid_audio_driver_t* driver;
String currentSoundFontAbsPath;
const fluid_preset_t getFirstPreset();
void selectFirstPreset();
void unloadAndLoadFont(const string &absPath);
void loadFont(const string &absPath);
void unloadAndLoadFont(const String &absPath);
void loadFont(const String &absPath);
bool shouldLoadFont(const String &absPath);
bool initialised;
unsigned int sfont_id;

View File

@ -22,7 +22,8 @@ JuicySFAudioProcessor::JuicySFAudioProcessor()
lastUIWidth(400),
lastUIHeight(300),
soundFontPath(String()),
fluidSynthModel(*this)
fluidSynthModel(*this)/*,
pluginEditor(nullptr)*/
{
initialiseSynth();
}
@ -175,7 +176,8 @@ bool JuicySFAudioProcessor::hasEditor() const
AudioProcessorEditor* JuicySFAudioProcessor::createEditor()
{
return new JuicySFAudioProcessorEditor (*this);
// grab a raw pointer to it for our own use
return /*pluginEditor = */new JuicySFAudioProcessorEditor (*this);
}
//==============================================================================
@ -233,6 +235,13 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
for (auto* param : getParameters())
if (auto* p = dynamic_cast<AudioProcessorParameterWithID*> (param))
p->setValue ((float) xmlState->getDoubleAttribute (p->paramID, p->getValue()));
fluidSynthModel.onFileNameChanged(soundFontPath);
AudioProcessorEditor* editor = getActiveEditor();
if (editor != nullptr) {
editor->setSize(lastUIWidth, lastUIHeight);
}
}
}
}

View File

@ -84,6 +84,9 @@ private:
fluid_synth_t* fluidSynth;
Synthesiser synth;
// // just a raw pointer; we do not own
// AudioProcessorEditor* pluginEditor;
// list<StateChangeSubscriber*> stateChangeSubscribers;
static BusesProperties getBusesProperties();

View File

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

View File

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