begins life with no soundfont and survives
This commit is contained in:
parent
86a0c005ef
commit
c78756aeef
@ -36,8 +36,7 @@ void FluidSynthModel::initialise() {
|
|||||||
|
|
||||||
synth = new_fluid_synth(settings);
|
synth = new_fluid_synth(settings);
|
||||||
|
|
||||||
sfont_id = 0;
|
// loadFont("/Users/birch/Documents/soundfont/EarthBound.sf2");
|
||||||
loadFont("/Users/birch/Documents/soundfont/EarthBound.sf2");
|
|
||||||
|
|
||||||
|
|
||||||
fluid_synth_set_gain(synth, 2.0);
|
fluid_synth_set_gain(synth, 2.0);
|
||||||
@ -85,11 +84,23 @@ void FluidSynthModel::selectFirstPreset() {
|
|||||||
BanksToPresets FluidSynthModel::getBanks() {
|
BanksToPresets FluidSynthModel::getBanks() {
|
||||||
BanksToPresets banksToPresets;
|
BanksToPresets banksToPresets;
|
||||||
|
|
||||||
|
int soundfontCount = fluid_synth_sfcount(synth);
|
||||||
|
|
||||||
|
if (soundfontCount == 0) {
|
||||||
|
// no soundfont selected
|
||||||
|
return banksToPresets;
|
||||||
|
}
|
||||||
|
|
||||||
fluid_sfont_t* sfont = fluid_synth_get_sfont_by_id(synth, sfont_id);
|
fluid_sfont_t* sfont = fluid_synth_get_sfont_by_id(synth, sfont_id);
|
||||||
|
if(sfont == nullptr) {
|
||||||
|
// no soundfont found by that ID
|
||||||
|
// the above guard (soundfontCount) protects us for the
|
||||||
|
// main case we're expecting. this guard is just defensive programming.
|
||||||
|
return banksToPresets;
|
||||||
|
}
|
||||||
|
|
||||||
int offset = fluid_synth_get_bank_offset(synth, sfont_id);
|
int offset = fluid_synth_get_bank_offset(synth, sfont_id);
|
||||||
|
|
||||||
jassert(sfont != nullptr);
|
|
||||||
sfont->iteration_start(sfont);
|
sfont->iteration_start(sfont);
|
||||||
|
|
||||||
fluid_preset_t preset;
|
fluid_preset_t preset;
|
||||||
|
@ -14,9 +14,13 @@ TablesComponent::TablesComponent(
|
|||||||
initialised(false)
|
initialised(false)
|
||||||
{
|
{
|
||||||
fluid_preset_t* currentPreset = getCurrentPreset();
|
fluid_preset_t* currentPreset = getCurrentPreset();
|
||||||
|
selectedBank = -1;
|
||||||
|
int selectedPreset = -1;
|
||||||
|
|
||||||
selectedBank = currentPreset->get_banknum(currentPreset);
|
if (currentPreset != nullptr) {
|
||||||
int selectedPreset = currentPreset->get_num(currentPreset);
|
selectedBank = currentPreset->get_banknum(currentPreset);
|
||||||
|
selectedPreset = currentPreset->get_num(currentPreset);
|
||||||
|
}
|
||||||
|
|
||||||
auto rowToPresetMapper = [this](const vector<string> &row) {
|
auto rowToPresetMapper = [this](const vector<string> &row) {
|
||||||
return stoi(row[0]);
|
return stoi(row[0]);
|
||||||
@ -29,7 +33,7 @@ TablesComponent::TablesComponent(
|
|||||||
{"Preset", "Name"},
|
{"Preset", "Name"},
|
||||||
mapPresets(
|
mapPresets(
|
||||||
banksToPresets,
|
banksToPresets,
|
||||||
currentPreset->get_banknum(currentPreset)
|
selectedBank
|
||||||
),
|
),
|
||||||
[this](int preset){
|
[this](int preset){
|
||||||
this->onPresetSelected(preset);
|
this->onPresetSelected(preset);
|
||||||
@ -71,7 +75,7 @@ Preset TablesComponent::getFirstPresetInBank(int bank) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TablesComponent::onBankSelected(int bank) {
|
void TablesComponent::onBankSelected(int bank) {
|
||||||
if (!initialised) {
|
if (!initialised || bank == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cout << "Bank " << bank << endl;
|
cout << "Bank " << bank << endl;
|
||||||
@ -99,7 +103,7 @@ int TablesComponent::presetToIndexMapper(int preset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TablesComponent::onPresetSelected(int preset) {
|
void TablesComponent::onPresetSelected(int preset) {
|
||||||
if (!initialised) {
|
if (!initialised || preset == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cout << "Preset " << preset << endl;
|
cout << "Preset " << preset << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user