Is there a function that can return the list of all the instruments (preset names) in a soundfont file in FluidSynth or at least the number of presets in each soundbank?
Asked
Active
Viewed 3,138 times
4
-
Did you figure this out? I know [this program](https://github.com/gleitz/MIDI.js/blob/master/soundfont-generator/ruby/soundfont_builder.rb) will output the .wav files but I would like to know if something can analyze the .sf2 file and return instrument names/numbers. – gleitz Oct 01 '13 at 20:36
3 Answers
9
I was able to get instrument names and banks using fluidsynth. The command you want to send is "inst 1" (obtain all instruments for the soundfont loaded in position 1).
$ echo "inst 1" | fluidsynth /path/to/FluidR3_GM.sf2
FluidSynth version 1.1.6
Copyright (C) 2000-2012 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.
Type 'help' for help topics.
000-000 Yamaha Grand Piano
000-001 Bright Yamaha Grand
000-002 Electric Piano
000-003 Honky Tonk
000-004 Rhodes EP
000-005 Legend EP 2
000-006 Harpsichord
000-007 Clavinet
...
...
...
128-035 Jazz 3
128-036 Jazz 4
128-040 Brush
128-041 Brush 1
128-042 Brush 2
128-048 Orchestra Kit

gleitz
- 595
- 4
- 12
-
Yes but how exactly how do you do that within, for instance, a C++ program? – Petru Dimitriu Oct 17 '13 at 17:29
0
This is not exactly "non-iterative", but it's the only way I could find to get a list of all the presets in a soundfont file.
fluid_preset_t* preset = new fluid_preset_t();
// Reset the iteration
sf->iteration_start(sf);
// Go through all the presets within the soundfont
int more = 1;
while (more) {
more = sf->iteration_next(sf, preset); // Will return 0 if no more soundfonts left
if (more) {
// Get preset name
char* presetname = preset->get_name(preset);
int banknum = preset->get_banknum(preset);
int num = preset->get_num(preset);
// Do something with the presetname, bank number and program number
// Such as add it to some list so that you can refer to it later
}
}
... where sf is a soundfont object.
Found this while going through the API documentation at http://fluidsynth.sourceforge.net/api/index.html. Note the menu at the top with links to the data structures, files, etc.

gideon
- 16
-
Question. From where do you obtain the `sf2` soundfont object? I only know how to obtain the soundfont id. – Hector Ricardo Oct 05 '20 at 05:00
0
I tried this:
static void inspectsoundfont()
{
fluid_sfont_t* sfont = fluid_synth_get_sfont_by_id(synth, font_id);
for (int bank = 0; bank < 16384; bank++)
{
for (int num = 0; num < 128; num++)
{
fluid_preset_t* preset = fluid_sfont_get_preset(sfont, bank, num);
if (preset == nullptr)
continue;
const char* name = fluid_preset_get_name(preset);
std::cout << "bank: " << bank << " index: " << num << " " << name << std::endl;
}
}
}
synth is the synthesiser object, and font_id is from fluid_synth_sfload. Gave me a list of banks and preset names.

imekon
- 1,501
- 4
- 22
- 39