presets and banks saved correctly in audio plugin host. display seems to work also.
This commit is contained in:
19
Source/BankAndPreset.cpp
Normal file
19
Source/BankAndPreset.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by Alex Birch on 13/04/2018.
|
||||
// Copyright (c) 2018 Birchlabs. All rights reserved.
|
||||
//
|
||||
|
||||
#include "BankAndPreset.h"
|
||||
|
||||
BankAndPreset::BankAndPreset(int bank, int preset)
|
||||
: bank(bank),
|
||||
preset(preset)
|
||||
{}
|
||||
|
||||
int BankAndPreset::getBank() {
|
||||
return bank;
|
||||
}
|
||||
|
||||
int BankAndPreset::getPreset() {
|
||||
return preset;
|
||||
}
|
23
Source/BankAndPreset.h
Normal file
23
Source/BankAndPreset.h
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by Alex Birch on 13/04/2018.
|
||||
// Copyright (c) 2018 Birchlabs. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../JuceLibraryCode/JuceHeader.h"
|
||||
|
||||
class BankAndPreset {
|
||||
public:
|
||||
BankAndPreset(int bank, int preset);
|
||||
|
||||
int getBank();
|
||||
int getPreset();
|
||||
|
||||
private:
|
||||
int bank;
|
||||
int preset;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BankAndPreset)
|
||||
};
|
||||
|
@ -47,7 +47,7 @@ void FilePicker::paint(Graphics& g)
|
||||
|
||||
void FilePicker::filenameComponentChanged (FilenameComponent*) {
|
||||
currentPath = fileChooser.getCurrentFile().getFullPathName();
|
||||
fluidSynthModel->onFileNameChanged(fileChooser.getCurrentFile().getFullPathName());
|
||||
fluidSynthModel->onFileNameChanged(fileChooser.getCurrentFile().getFullPathName(), -1, -1);
|
||||
}
|
||||
|
||||
void FilePicker::setDisplayedFilePath(const String& path) {
|
||||
|
@ -41,11 +41,7 @@ void FluidSynthModel::initialise() {
|
||||
|
||||
if (sharesParams.getSoundFontPath().isNotEmpty()) {
|
||||
loadFont(sharesParams.getSoundFontPath());
|
||||
if (sharesParams.getPreset() == -1 || sharesParams.getBank() == -1) {
|
||||
changePreset(sharesParams.getBank(), sharesParams.getPreset());
|
||||
} else {
|
||||
selectFirstPreset();
|
||||
}
|
||||
changePreset(sharesParams.getBank(), sharesParams.getPreset());
|
||||
}
|
||||
|
||||
fluid_synth_set_gain(synth, 2.0);
|
||||
@ -67,7 +63,9 @@ int FluidSynthModel::getChannel() {
|
||||
|
||||
void FluidSynthModel::changePreset(int bank, int preset) {
|
||||
if (bank == -1 || preset == -1) {
|
||||
return;
|
||||
unique_ptr<BankAndPreset> bankAndPreset = getFirstBankAndPreset();
|
||||
bank = bankAndPreset->getBank();
|
||||
preset = bankAndPreset->getPreset();
|
||||
}
|
||||
changePresetImpl(bank, preset);
|
||||
sharesParams.setPreset(preset);
|
||||
@ -91,6 +89,14 @@ const fluid_preset_t FluidSynthModel::getFirstPreset() {
|
||||
return preset;
|
||||
}
|
||||
|
||||
unique_ptr<BankAndPreset> FluidSynthModel::getFirstBankAndPreset() {
|
||||
fluid_preset_t preset = getFirstPreset();
|
||||
|
||||
int offset = fluid_synth_get_bank_offset(synth, sfont_id);
|
||||
|
||||
return make_unique<BankAndPreset>(preset.get_banknum(&preset) + offset, preset.get_num(&preset));
|
||||
};
|
||||
|
||||
void FluidSynthModel::selectFirstPreset() {
|
||||
fluid_preset_t preset = getFirstPreset();
|
||||
|
||||
@ -143,11 +149,12 @@ fluid_synth_t* FluidSynthModel::getSynth() {
|
||||
return synth;
|
||||
}
|
||||
|
||||
void FluidSynthModel::onFileNameChanged(const String &absPath) {
|
||||
void FluidSynthModel::onFileNameChanged(const String &absPath, int bank, int preset) {
|
||||
if (!shouldLoadFont(absPath)) {
|
||||
return;
|
||||
}
|
||||
unloadAndLoadFont(absPath);
|
||||
changePreset(bank, preset);
|
||||
sharesParams.setSoundFontPath(absPath);
|
||||
eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath);
|
||||
}
|
||||
@ -158,7 +165,6 @@ void FluidSynthModel::unloadAndLoadFont(const String &absPath) {
|
||||
fluid_synth_sfunload(synth, sfont_id, 1);
|
||||
}
|
||||
loadFont(absPath);
|
||||
selectFirstPreset();
|
||||
}
|
||||
|
||||
void FluidSynthModel::loadFont(const String &absPath) {
|
||||
|
@ -8,11 +8,14 @@
|
||||
#include "SharesParams.h"
|
||||
#include <fluidsynth.h>
|
||||
#include <memory>
|
||||
#include "BankAndPreset.h"
|
||||
#include "PresetsToBanks.h"
|
||||
|
||||
|
||||
// https://stackoverflow.com/a/13446565/5257399
|
||||
using std::shared_ptr;
|
||||
//using std::shared_ptr;
|
||||
|
||||
using namespace std;
|
||||
|
||||
class FluidSynthModel {
|
||||
public:
|
||||
@ -27,7 +30,7 @@ public:
|
||||
void changePreset(int bank, int preset);
|
||||
int getChannel();
|
||||
|
||||
void onFileNameChanged(const String &absPath);
|
||||
void onFileNameChanged(const String &absPath, int bank, int preset);
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
@ -69,6 +72,7 @@ private:
|
||||
|
||||
const fluid_preset_t getFirstPreset();
|
||||
void selectFirstPreset();
|
||||
unique_ptr<BankAndPreset> getFirstBankAndPreset();
|
||||
|
||||
void unloadAndLoadFont(const String &absPath);
|
||||
void loadFont(const String &absPath);
|
||||
|
@ -243,8 +243,7 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
|
||||
if (auto* p = dynamic_cast<AudioProcessorParameterWithID*> (param))
|
||||
p->setValue ((float) xmlState->getDoubleAttribute (p->paramID, p->getValue()));
|
||||
|
||||
fluidSynthModel.onFileNameChanged(soundFontPath);
|
||||
fluidSynthModel.changePreset(lastBank, lastPreset);
|
||||
fluidSynthModel.onFileNameChanged(soundFontPath, lastBank, lastPreset);
|
||||
|
||||
AudioProcessorEditor* editor = getActiveEditor();
|
||||
if (editor != nullptr) {
|
||||
|
Reference in New Issue
Block a user