15 or so years ago I came across a vb script to extract a presets list from a soundfont2 file, which I adapted to use in various VB.net Fluidsynth projects.
Now that Pure Data has the file handle object to read binary files I decided to give it a go in Pd on Windows 10.
I have also tried it using linux and it seems to work with the latest portable version.
Edit: Thursday 22nd August 2024, I've just updated choose-sf2-example.pd in the zip because it was incorrectly wired an triggered
sf2-presets-reader.zip
contains:
sf2-presets-reader.pd to create soundfont.txt
choose-sf2-example.pd to launch choose-sf2.pd and show index, bank and name extraction from [r $0-chosen]
choose-sf2.pd
soundfont,txt contains the presets from a soundfont I use SGM-V2.01.sf2 (236MB), this will be overwritten with your choice.
My preferred soundfont player to use with Pure Data is RGC-Audio SFZ.dll or SFZ+.dll loaded in @spacechild1 very excellent vstplugin~
Other options are Qsynth via midiout
Fluidsynth,exe via midiout launched with motex/system
Warning Purr-Data will not open sf2-presets-reader.pd because it does not have the file object.
Method;
open the soundfont2 file;
then look for phdr by searching backwards;
one byte at a time from the end of the file and look for p;
then see if the remainder from route is hdr;
then forwards 38 bytes for each instrument preset;
to retrieve bank, index and name until EOP tag;
send to text: (bank as integer, index / 1000 added to bank) and name as symbol;
;
then sort in order:- text define [sort(;
;
next write the text to soundfont, txt;
Cheers
Balwyn