Getting all instrument names from a loaded soundfont file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting all instrument names from a loaded soundfont file

Reinhold Hoffmann

Hi,

 

I want to display to the user the instrument names of the samples of a loaded soundfont file (sf2, sf3 format).

 

Is there a public interface available in the libfluidsynth library where the instrument names of the soundfont samples can be obtained after a soundfont file is loaded with fluid_synth_sfload to a fluidsynth synthesizer? It looks as if those sample names are handled internally but I am not sure if those instrument sample names can be read using the public interface.

 

Any idea, help, advice or code example is highly appreciated.

 

Thx

 

Reinhold

 

 


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Kjetil Matheussen-2
On Thu, Jul 11, 2019 at 10:26 AM Reinhold Hoffmann
<[hidden email]> wrote:

>
> Hi,
>
>
>
> I want to display to the user the instrument names of the samples of a loaded soundfont file (sf2, sf3 format).
>
>
>
> Is there a public interface available in the libfluidsynth library where the instrument names of the soundfont samples can be obtained after a soundfont file is loaded with fluid_synth_sfload to a fluidsynth synthesizer? It looks as if those sample names are handled internally but I am not sure if those instrument sample names can be read using the public interface.
>
>
>
> Any idea, help, advice or code example is highly appreciated.
>

libgig has a pretty clear interface to parse sf2 files

This is from sf2dump.cpp in libgig:

void PrintPeresets(sf2::File* sf) {
    cout << "Presets (" << sf->GetPresetCount() << "): " << endl;
    for (int i = 0; i < sf->GetPresetCount(); i++) { /* exclude the
terminal header - EOP */
        sf2::Preset* p = sf->GetPreset(i);
        cout << "\t" << p->Name << " (Preset: " << p->PresetNum << ",
Bank: " << p->Bank;
        if (p->pGlobalRegion) PrintRegion(-1, p->pGlobalRegion);

        for (int j = 0; j < p->GetRegionCount(); j++) {
            PrintRegion(j, p->GetRegion(j));
        }
        cout << endl;
       cout << endl;
    }
}


void PrintInstruments(sf2::File* sf) {
    cout << "Instruments (" << sf->GetInstrumentCount() << "): " << endl;
    for (int i = 0; i < sf->GetInstrumentCount(); i++) {
        sf2::Instrument* instr = sf->GetInstrument(i);
        cout << "Instrument bag: " << instr->InstBagNdx << ")" << endl;
        cout << "\t    Regions (" << instr->GetRegionCount() << ")" << endl;

        if (instr->pGlobalRegion) PrintRegion(-1, instr->pGlobalRegion);

        for (int j = 0; j < instr->GetRegionCount(); j++) {
            PrintRegion(j, instr->GetRegion(j));
        }
       cout << "\t" << instr->Name << " (";
        cout << endl;
    }
}

To find out which samples are used in instruments and presets, you
look at the regions:

void PrintRegion(int idx, sf2::Region* reg) {
    if (idx == -1) cout << "\t\tGlobal Region " << endl;
    else cout << "\t\tRegion " << idx << endl;
    sf2::Sample* s = reg->GetSample();
    if (s != NULL) {
        cout << "\t\t    Sample: " << s->Name << ", Fine Tune: " <<
reg->fineTune;
        ...
        cout << endl;
    }
    ...
}

void PrintSamples(sf2::File* sf) {
    cout << "Samples (" << sf->GetSampleCount() << "): " << endl;
    for (int i = 0; i < sf->GetSampleCount(); i++) {
        sf2::Sample* s = sf->GetSample(i);
        cout << "\t" << s->Name << " (Depth: " << ((s->GetFrameSize()
/ s->GetChannelCount()) * 8);
        ...
    }
}

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Reinhold Hoffmann
Hi Kjetil,

Thanks for the immediate response. libgig and the code sample really looks
good, simple and easy. However, libgig is under the GPL license. Our
software is a commercial software where we use the libfluidsynth library
strictly under the LGPL license. libgig does not offer the LGPL license but
only the GPL license which we therefore cannot use.

Reinhold

-----Ursprüngliche Nachricht-----
Von: fluid-dev [mailto:fluid-dev-bounces+reinhold=[hidden email]]
Im Auftrag von Kjetil Matheussen
Gesendet: Donnerstag, 11. Juli 2019 10:54
An: FluidSynth mailing list
Betreff: Re: [fluid-dev] Getting all instrument names from a loaded
soundfont file

On Thu, Jul 11, 2019 at 10:26 AM Reinhold Hoffmann
<[hidden email]> wrote:
>
> Hi,
>
>
>
> I want to display to the user the instrument names of the samples of a
loaded soundfont file (sf2, sf3 format).
>
>
>
> Is there a public interface available in the libfluidsynth library where
the instrument names of the soundfont samples can be obtained after a
soundfont file is loaded with fluid_synth_sfload to a fluidsynth
synthesizer? It looks as if those sample names are handled internally but I
am not sure if those instrument sample names can be read using the public
interface.
>
>
>
> Any idea, help, advice or code example is highly appreciated.
>

libgig has a pretty clear interface to parse sf2 files

This is from sf2dump.cpp in libgig:

void PrintPeresets(sf2::File* sf) {
    cout << "Presets (" << sf->GetPresetCount() << "): " << endl;
    for (int i = 0; i < sf->GetPresetCount(); i++) { /* exclude the
terminal header - EOP */
        sf2::Preset* p = sf->GetPreset(i);
        cout << "\t" << p->Name << " (Preset: " << p->PresetNum << ",
Bank: " << p->Bank;
        if (p->pGlobalRegion) PrintRegion(-1, p->pGlobalRegion);

        for (int j = 0; j < p->GetRegionCount(); j++) {
            PrintRegion(j, p->GetRegion(j));
        }
        cout << endl;
       cout << endl;
    }
}


void PrintInstruments(sf2::File* sf) {
    cout << "Instruments (" << sf->GetInstrumentCount() << "): " << endl;
    for (int i = 0; i < sf->GetInstrumentCount(); i++) {
        sf2::Instrument* instr = sf->GetInstrument(i);
        cout << "Instrument bag: " << instr->InstBagNdx << ")" << endl;
        cout << "\t    Regions (" << instr->GetRegionCount() << ")" << endl;

        if (instr->pGlobalRegion) PrintRegion(-1, instr->pGlobalRegion);

        for (int j = 0; j < instr->GetRegionCount(); j++) {
            PrintRegion(j, instr->GetRegion(j));
        }
       cout << "\t" << instr->Name << " (";
        cout << endl;
    }
}

To find out which samples are used in instruments and presets, you
look at the regions:

void PrintRegion(int idx, sf2::Region* reg) {
    if (idx == -1) cout << "\t\tGlobal Region " << endl;
    else cout << "\t\tRegion " << idx << endl;
    sf2::Sample* s = reg->GetSample();
    if (s != NULL) {
        cout << "\t\t    Sample: " << s->Name << ", Fine Tune: " <<
reg->fineTune;
        ...
        cout << endl;
    }
    ...
}

void PrintSamples(sf2::File* sf) {
    cout << "Samples (" << sf->GetSampleCount() << "): " << endl;
    for (int i = 0; i < sf->GetSampleCount(); i++) {
        sf2::Sample* s = sf->GetSample(i);
        cout << "\t" << s->Name << " (Depth: " << ((s->GetFrameSize()
/ s->GetChannelCount()) * 8);
        ...
    }
}

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Kjetil Matheussen-2
On Thu, Jul 11, 2019 at 11:30 AM Reinhold Hoffmann
<[hidden email]> wrote:
>
> Hi Kjetil,
>
> Thanks for the immediate response. libgig and the code sample really looks
> good, simple and easy. However, libgig is under the GPL license. Our
> software is a commercial software where we use the libfluidsynth library
> strictly under the LGPL license. libgig does not offer the LGPL license but
> only the GPL license which we therefore cannot use.
>

It's probably not much work parsing the soundfont files manually...

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Tom M.
In reply to this post by Reinhold Hoffmann
ATM, you can only get the names of the soundfont presets, see preset iteration here:

https://github.com/FluidSynth/fluidsynth/blob/b8cc5197953f74700feda84b6ade3dc56419978f/src/bindings/fluid_cmd.c#L843-L860

Everything below that level, i.e. which samples belong to which instruments and which instruments to which presets, is currently internal to fluidsynth.

What could be implemented pretty straight forward is iterating over all the samples that a soundfont has. This might also include lonesome samples, that are not linked to any instrument. Also, you would not know which samples belong to which preset and the soundfont instrument layer would be invisible as well.

Implementing an iteration over all instruments of a preset as well as all samples of an instrument would need some discussion, but it would make sure that you only see instruments and samples that are actually used. In this case it would be good to know what's the benefit you're intending by displaying sample names to the user and what else you're planning to do when you have the sample. Thinking of e.g. changing the sample's wave form and manually spawning voices from it.

Tom




_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Philippe Simons
I understand that FluidSynth primary usage is not a SoundFont editor, but being able to live edit the SoundFonts would be awesome.

On Thu, Jul 11, 2019 at 3:03 PM Tom M. <[hidden email]> wrote:
ATM, you can only get the names of the soundfont presets, see preset iteration here:

https://github.com/FluidSynth/fluidsynth/blob/b8cc5197953f74700feda84b6ade3dc56419978f/src/bindings/fluid_cmd.c#L843-L860

Everything below that level, i.e. which samples belong to which instruments and which instruments to which presets, is currently internal to fluidsynth.

What could be implemented pretty straight forward is iterating over all the samples that a soundfont has. This might also include lonesome samples, that are not linked to any instrument. Also, you would not know which samples belong to which preset and the soundfont instrument layer would be invisible as well.

Implementing an iteration over all instruments of a preset as well as all samples of an instrument would need some discussion, but it would make sure that you only see instruments and samples that are actually used. In this case it would be good to know what's the benefit you're intending by displaying sample names to the user and what else you're planning to do when you have the sample. Thinking of e.g. changing the sample's wave form and manually spawning voices from it.

Tom




_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Reinhold Hoffmann

Tom,

 

Thanks. The link which you provided is exactly what I was looking for. Nothing else is required from a lower level.

 

In our software mainly General MIDI soundfont are used. The objective is not to tweak nor edit anything from the soundfont samples. As General MIDI soundfont become better and better and include more banks than just bank 0, the objective of knowing the instrument names is to display these instruments to the users that the user can select any instrument soundfont sample from any bank and is able to allocate that instrument sound to any MIDI track of a MIDI file.

 

E.g. a soundfont file may contain a Standard „Guitar“ soundfont sample in bank=0, Num=27  but also a „Fender guitar“ or a „Gibson guitar“ sample in higher banks.  The objective is to display these instrument names to the user. Thx.

 

Reinhold

 


Von: fluid-dev [mailto:fluid-dev-bounces+reinhold=[hidden email]] Im Auftrag von Philippe Simons
Gesendet: Donnerstag, 11. Juli 2019 16:00
An: FluidSynth mailing list
Betreff: Re: [fluid-dev] Getting all instrument names from a loaded soundfont file

 

I understand that FluidSynth primary usage is not a SoundFont editor, but being able to live edit the SoundFonts would be awesome.

 

On Thu, Jul 11, 2019 at 3:03 PM Tom M. <[hidden email]> wrote:

ATM, you can only get the names of the soundfont presets, see preset iteration here:

https://github.com/FluidSynth/fluidsynth/blob/b8cc5197953f74700feda84b6ade3dc56419978f/src/bindings/fluid_cmd.c#L843-L860

Everything below that level, i.e. which samples belong to which instruments and which instruments to which presets, is currently internal to fluidsynth.

What could be implemented pretty straight forward is iterating over all the samples that a soundfont has. This might also include lonesome samples, that are not linked to any instrument. Also, you would not know which samples belong to which preset and the soundfont instrument layer would be invisible as well.

Implementing an iteration over all instruments of a preset as well as all samples of an instrument would need some discussion, but it would make sure that you only see instruments and samples that are actually used. In this case it would be good to know what's the benefit you're intending by displaying sample names to the user and what else you're planning to do when you have the sample. Thinking of e.g. changing the sample's wave form and manually spawning voices from it.

Tom




_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Kjetil Matheussen-2
In reply to this post by Kjetil Matheussen-2
On Thu, Jul 11, 2019 at 11:34 AM Kjetil Matheussen
<[hidden email]> wrote:

>
> On Thu, Jul 11, 2019 at 11:30 AM Reinhold Hoffmann
> <[hidden email]> wrote:
> >
> > Hi Kjetil,
> >
> > Thanks for the immediate response. libgig and the code sample really looks
> > good, simple and easy. However, libgig is under the GPL license. Our
> > software is a commercial software where we use the libfluidsynth library
> > strictly under the LGPL license. libgig does not offer the LGPL license but
> > only the GPL license which we therefore cannot use.
> >
>
> It's probably not much work parsing the soundfont files manually...

Here's the spec: http://www.synthfont.com/sfspec24.pdf
It's a common RIFF structure. In my experience, writing code to read
and write riff files directly are often faster than trying to
understand a 3rd party API.

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Aere Greenway-2
Kjetl:

If you use Linux, install vmpk.

Then run vmpk, and in its file menu, select "Import Soundfont".  It will
write a text file having all the instrument names.

- Aere

On 7/11/19 9:13 AM, Kjetil Matheussen wrote:

> On Thu, Jul 11, 2019 at 11:34 AM Kjetil Matheussen
> <[hidden email]> wrote:
>> On Thu, Jul 11, 2019 at 11:30 AM Reinhold Hoffmann
>> <[hidden email]> wrote:
>>> Hi Kjetil,
>>>
>>> Thanks for the immediate response. libgig and the code sample really looks
>>> good, simple and easy. However, libgig is under the GPL license. Our
>>> software is a commercial software where we use the libfluidsynth library
>>> strictly under the LGPL license. libgig does not offer the LGPL license but
>>> only the GPL license which we therefore cannot use.
>>>
>> It's probably not much work parsing the soundfont files manually...
> Here's the spec: http://www.synthfont.com/sfspec24.pdf
> It's a common RIFF structure. In my experience, writing code to read
> and write riff files directly are often faster than trying to
> understand a 3rd party API.
>
> _______________________________________________
> fluid-dev mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/fluid-dev


--
Sincerely,
Aere



_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Brad Stewart
In reply to this post by Kjetil Matheussen-2

There are modules available in Python that allow you to quickly parse sound fonts.
For example at pypi.org you can find sf2utils and pyFluidSynth (which provides bindings to FludiSynth).

Google "python soundfont" for more info.

--Brad



On 7/11/2019 8:13 AM, Kjetil Matheussen wrote:
On Thu, Jul 11, 2019 at 11:34 AM Kjetil Matheussen
[hidden email] wrote:
On Thu, Jul 11, 2019 at 11:30 AM Reinhold Hoffmann
[hidden email] wrote:
Hi Kjetil,

Thanks for the immediate response. libgig and the code sample really looks
good, simple and easy. However, libgig is under the GPL license. Our
software is a commercial software where we use the libfluidsynth library
strictly under the LGPL license. libgig does not offer the LGPL license but
only the GPL license which we therefore cannot use.

It's probably not much work parsing the soundfont files manually...
Here's the spec: http://www.synthfont.com/sfspec24.pdf
It's a common RIFF structure. In my experience, writing code to read
and write riff files directly are often faster than trying to
understand a 3rd party API.

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Kjetil Matheussen-2
In reply to this post by Aere Greenway-2
On Thu, Jul 11, 2019 at 5:38 PM Aere Greenway <[hidden email]> wrote:
>
> Kjetl:
>
> If you use Linux, install vmpk.
>
> Then run vmpk, and in its file menu, select "Import Soundfont".  It will
> write a text file having all the instrument names.
>

Thank you, but I didn't ask the question, and I also think the
question was how to get a list of samples used in an instrument in a
soundfount, not how to get a list of instruments in a soundfont.

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Tom M.
In reply to this post by Kjetil Matheussen-2
> On Thu, Jul 11, 2019 at 5:14 PM Kjetil Matheussen
> <[hidden email]> wrote:
> >
> > It's probably not much work parsing the soundfont files manually...
>
> Here's the spec: http://www.synthfont.com/sfspec24.pdf
> It's a common RIFF structure. In my experience, writing code to read
> and write riff files directly are often faster than trying to
> understand a 3rd party API.

Kjetil, "do-it-yourself" is poor advice. There are rules how to cope
with the file when parts of it are invalid. Not even libgig 4.1.0 does
an accurate job here as it rejects the whole file if it recognizes
e.g. invalid sample loops, which is against the spec though.

The question was how to do it with fluidsynth for both SF2 and SF3
files. And once fluidsynth supports DLS files, you can write a custom
parser for this as well. Ofc, you cannot know about those problems, as
you seem to prefer hard-coded fluidsynth 1.1.6 .

I encourage anybody to ask for help, rather than locking yourself up
in a dark room and start solving problems that have already been
solved. And I appreciate the input so far.

Tom

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Getting all instrument names from a loaded soundfont file

Reinhold Hoffmann
Here I would like to thank all for this helpful discussion and the advices
given. With the help of the fluidsynth code library it was possible to
implement this feature within a few hours including everything (from
analysis, asking the community, doing the coding up to intensive testing).
Ultimately the coding is just 10 lines of new code using publicly available
library calls. No new lib has to be built and distributed with all the
consequences nor any deeper expertise has been required. To me it was very
professional and very time efficient.    

Thanks

Reinhold

-----Ursprüngliche Nachricht-----
Von: fluid-dev [mailto:fluid-dev-bounces+reinhold=[hidden email]]
Im Auftrag von Tom M.
Gesendet: Freitag, 12. Juli 2019 09:51
An: [hidden email]; FluidSynth mailing list
Betreff: Re: [fluid-dev] Getting all instrument names from a loaded
soundfont file

> On Thu, Jul 11, 2019 at 5:14 PM Kjetil Matheussen
> <[hidden email]> wrote:
> >
> > It's probably not much work parsing the soundfont files manually...
>
> Here's the spec: http://www.synthfont.com/sfspec24.pdf
> It's a common RIFF structure. In my experience, writing code to read
> and write riff files directly are often faster than trying to
> understand a 3rd party API.

Kjetil, "do-it-yourself" is poor advice. There are rules how to cope
with the file when parts of it are invalid. Not even libgig 4.1.0 does
an accurate job here as it rejects the whole file if it recognizes
e.g. invalid sample loops, which is against the spec though.

The question was how to do it with fluidsynth for both SF2 and SF3
files. And once fluidsynth supports DLS files, you can write a custom
parser for this as well. Ofc, you cannot know about those problems, as
you seem to prefer hard-coded fluidsynth 1.1.6 .

I encourage anybody to ask for help, rather than locking yourself up
in a dark room and start solving problems that have already been
solved. And I appreciate the input so far.

Tom

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev