fluid-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [fluid-dev] Getting all instrument names from a loaded soundfont fil


From: Kjetil Matheussen
Subject: Re: [fluid-dev] Getting all instrument names from a loaded soundfont file
Date: Thu, 11 Jul 2019 10:54:09 +0200

On Thu, Jul 11, 2019 at 10:26 AM Reinhold Hoffmann
<address@hidden> 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);
        ...
    }
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]