libfluidsynth  2.3.5
SoundFont Loader

Create custom SoundFont loaders. More...

Typedefs

typedef void(* fluid_preset_free_t) (fluid_preset_t *preset)
 Method to free a virtual SoundFont preset. More...
 
typedef int(* fluid_preset_get_banknum_t) (fluid_preset_t *preset)
 Method to get a virtual SoundFont preset MIDI bank number. More...
 
typedef const char *(* fluid_preset_get_name_t) (fluid_preset_t *preset)
 Method to get a virtual SoundFont preset name. More...
 
typedef int(* fluid_preset_get_num_t) (fluid_preset_t *preset)
 Method to get a virtual SoundFont preset MIDI program number. More...
 
typedef int(* fluid_preset_noteon_t) (fluid_preset_t *preset, fluid_synth_t *synth, int chan, int key, int vel)
 Method to handle a noteon event (synthesize the instrument). More...
 
typedef int(* fluid_sfloader_callback_close_t) (void *handle)
 Closes the handle returned by fluid_sfloader_callback_open_t and frees used resources. More...
 
typedef void *(* fluid_sfloader_callback_open_t) (const char *filename)
 Opens the file or memory indicated by filename in binary read mode. More...
 
typedef int(* fluid_sfloader_callback_read_t) (void *buf, fluid_long_long_t count, void *handle)
 Reads count bytes to the specified buffer buf. More...
 
typedef int(* fluid_sfloader_callback_seek_t) (void *handle, fluid_long_long_t offset, int origin)
 Same purpose and behaviour as fseek. More...
 
typedef fluid_long_long_t(* fluid_sfloader_callback_tell_t) (void *handle)
 
typedef void(* fluid_sfloader_free_t) (fluid_sfloader_t *loader)
 The free method should free the memory allocated for a fluid_sfloader_t instance in addition to any private data. More...
 
typedef fluid_sfont_t *(* fluid_sfloader_load_t) (fluid_sfloader_t *loader, const char *filename)
 Method to load an instrument file (does not actually need to be a real file name, could be another type of string identifier that the loader understands). More...
 
typedef int(* fluid_sfont_free_t) (fluid_sfont_t *sfont)
 Method to free a virtual SoundFont bank. More...
 
typedef const char *(* fluid_sfont_get_name_t) (fluid_sfont_t *sfont)
 Method to return the name of a virtual SoundFont. More...
 
typedef fluid_preset_t *(* fluid_sfont_get_preset_t) (fluid_sfont_t *sfont, int bank, int prenum)
 Get a virtual SoundFont preset by bank and program numbers. More...
 
typedef fluid_preset_t *(* fluid_sfont_iteration_next_t) (fluid_sfont_t *sfont)
 Virtual SoundFont preset iteration function. More...
 
typedef void(* fluid_sfont_iteration_start_t) (fluid_sfont_t *sfont)
 Start virtual SoundFont preset iteration method. More...
 

Enumerations

enum  {
  FLUID_PRESET_SELECTED ,
  FLUID_PRESET_UNSELECTED ,
  FLUID_SAMPLE_DONE ,
  FLUID_PRESET_PIN ,
  FLUID_PRESET_UNPIN
}
 Some notification enums for presets and samples. More...
 
enum  fluid_sample_type {
  FLUID_SAMPLETYPE_MONO = 0x1 ,
  FLUID_SAMPLETYPE_RIGHT = 0x2 ,
  FLUID_SAMPLETYPE_LEFT = 0x4 ,
  FLUID_SAMPLETYPE_LINKED = 0x8 ,
  FLUID_SAMPLETYPE_OGG_VORBIS = 0x10 ,
  FLUID_SAMPLETYPE_ROM = 0x8000
}
 Indicates the type of a sample used by the _fluid_sample_t::sampletype field. More...
 

Lifecycle Functions for SoundFont Loader_linebr@{

fluid_sfloader_tnew_fluid_sfloader (fluid_sfloader_load_t load, fluid_sfloader_free_t free)
 Creates a new SoundFont loader. More...
 
void delete_fluid_sfloader (fluid_sfloader_t *loader)
 Frees a SoundFont loader created with new_fluid_sfloader(). More...
 
fluid_sfloader_tnew_fluid_defsfloader (fluid_settings_t *settings)
 Creates a default soundfont2 loader that can be used with fluid_synth_add_sfloader(). More...
 

Lifecycle Functions for SoundFont_linebr@{

fluid_sfont_tnew_fluid_sfont (fluid_sfont_get_name_t get_name, fluid_sfont_get_preset_t get_preset, fluid_sfont_iteration_start_t iter_start, fluid_sfont_iteration_next_t iter_next, fluid_sfont_free_t free)
 Creates a new virtual SoundFont instance structure. More...
 
int delete_fluid_sfont (fluid_sfont_t *sfont)
 Destroys a SoundFont instance created with new_fluid_sfont(). More...
 

Lifecycle Functions for Preset_linebr@{

fluid_preset_tnew_fluid_preset (fluid_sfont_t *parent_sfont, fluid_preset_get_name_t get_name, fluid_preset_get_banknum_t get_bank, fluid_preset_get_num_t get_num, fluid_preset_noteon_t noteon, fluid_preset_free_t free)
 Create a virtual SoundFont preset instance. More...
 
void delete_fluid_preset (fluid_preset_t *preset)
 Destroys a SoundFont preset instance created with new_fluid_preset(). More...
 

Lifecycle Functions for Sample_linebr@{

fluid_sample_tnew_fluid_sample (void)
 Create a new sample instance. More...
 
void delete_fluid_sample (fluid_sample_t *sample)
 Destroy a sample instance previously created with new_fluid_sample(). More...
 

Functions

int fluid_preset_get_banknum (fluid_preset_t *preset)
 Retrieves the presets bank number by executing the get_bank function provided on its creation. More...
 
void * fluid_preset_get_data (fluid_preset_t *preset)
 Retrieve the private data of a SoundFont preset instance. More...
 
const char * fluid_preset_get_name (fluid_preset_t *preset)
 Retrieves the presets name by executing the get_name function provided on its creation. More...
 
int fluid_preset_get_num (fluid_preset_t *preset)
 Retrieves the presets (instrument) number by executing the get_num function provided on its creation. More...
 
fluid_sfont_tfluid_preset_get_sfont (fluid_preset_t *preset)
 Retrieves the presets parent SoundFont instance. More...
 
int fluid_preset_set_data (fluid_preset_t *preset, void *data)
 Set private data to use with a SoundFont preset instance. More...
 
int fluid_sample_set_loop (fluid_sample_t *sample, unsigned int loop_start, unsigned int loop_end)
 Set the loop of a sample. More...
 
int fluid_sample_set_name (fluid_sample_t *sample, const char *name)
 Set the name of a SoundFont sample. More...
 
int fluid_sample_set_pitch (fluid_sample_t *sample, int root_key, int fine_tune)
 Set the pitch of a sample. More...
 
int fluid_sample_set_sound_data (fluid_sample_t *sample, short *data, char *data24, unsigned int nbframes, unsigned int sample_rate, short copy_data)
 Assign sample data to a SoundFont sample. More...
 
size_t fluid_sample_sizeof (void)
 Returns the size of the fluid_sample_t structure. More...
 
void * fluid_sfloader_get_data (fluid_sfloader_t *loader)
 Obtain private data previously set with fluid_sfloader_set_data(). More...
 
int fluid_sfloader_set_callbacks (fluid_sfloader_t *loader, fluid_sfloader_callback_open_t open, fluid_sfloader_callback_read_t read, fluid_sfloader_callback_seek_t seek, fluid_sfloader_callback_tell_t tell, fluid_sfloader_callback_close_t close)
 Set custom callbacks to be used upon soundfont loading. More...
 
int fluid_sfloader_set_data (fluid_sfloader_t *loader, void *data)
 Specify private data to be used by fluid_sfloader_load_t. More...
 
void * fluid_sfont_get_data (fluid_sfont_t *sfont)
 Retrieve the private data of a SoundFont instance. More...
 
int fluid_sfont_get_id (fluid_sfont_t *sfont)
 Retrieve the unique ID of a SoundFont instance. More...
 
const char * fluid_sfont_get_name (fluid_sfont_t *sfont)
 Retrieve the name of a SoundFont instance. More...
 
fluid_preset_tfluid_sfont_get_preset (fluid_sfont_t *sfont, int bank, int prenum)
 Retrieve the preset assigned the a SoundFont instance for the given bank and preset number. More...
 
fluid_preset_tfluid_sfont_iteration_next (fluid_sfont_t *sfont)
 Virtual SoundFont preset iteration function. More...
 
void fluid_sfont_iteration_start (fluid_sfont_t *sfont)
 Starts / re-starts virtual preset iteration in a SoundFont. More...
 
int fluid_sfont_set_data (fluid_sfont_t *sfont, void *data)
 Set private data to use with a SoundFont instance. More...
 
void fluid_synth_add_sfloader (fluid_synth_t *synth, fluid_sfloader_t *loader)
 Add a SoundFont loader to the synth. More...
 
fluid_preset_tfluid_synth_get_channel_preset (fluid_synth_t *synth, int chan)
 Get active preset on a MIDI channel. More...
 

Detailed Description

Create custom SoundFont loaders.

It is possible to add new SoundFont loaders to the synthesizer. This API allows for virtual SoundFont files to be loaded and synthesized, which may not actually be SoundFont files, as long as they can be represented by the SoundFont synthesis model.

To add a new SoundFont loader to the synthesizer, call fluid_synth_add_sfloader() and pass a pointer to an fluid_sfloader_t instance created by new_fluid_sfloader(). On creation, you must specify a callback function load that will be called for every file attempting to load it and if successful returns a fluid_sfont_t instance, or NULL if it fails.

The fluid_sfont_t structure contains a callback to obtain the name of the SoundFont. It contains two functions to iterate though the contained presets, and one function to obtain a preset corresponding to a bank and preset number. This function should return a fluid_preset_t instance.

The fluid_preset_t instance contains some functions to obtain information from the preset (name, bank, number). The most important callback is the noteon function. The noteon function is called by fluidsynth internally and should call fluid_synth_alloc_voice() for every sample that has to be played. fluid_synth_alloc_voice() expects a pointer to a fluid_sample_t instance and returns a pointer to the opaque fluid_voice_t structure. To set or increment the values of a generator, use fluid_voice_gen_set() or fluid_voice_gen_incr(). When you are finished initializing the voice call fluid_voice_start() to start playing the synthesis voice.

Typedef Documentation

◆ fluid_preset_free_t

typedef void(* fluid_preset_free_t) (fluid_preset_t *preset)

Method to free a virtual SoundFont preset.

Parameters
presetVirtual SoundFont preset
Returns
Should return 0

Any custom user provided cleanup function must ultimately call delete_fluid_preset() to ensure proper cleanup of the fluid_preset_t struct. If no private data needs to be freed, setting this to delete_fluid_preset() is sufficient.

◆ fluid_preset_get_banknum_t

typedef int(* fluid_preset_get_banknum_t) (fluid_preset_t *preset)

Method to get a virtual SoundFont preset MIDI bank number.

Parameters
presetVirtual SoundFont preset
returnThe bank number of the preset

◆ fluid_preset_get_name_t

typedef const char*(* fluid_preset_get_name_t) (fluid_preset_t *preset)

Method to get a virtual SoundFont preset name.

Parameters
presetVirtual SoundFont preset
Returns
Should return the name of the preset. The returned string must be valid for the duration of the virtual preset (or the duration of the SoundFont, in the case of preset iteration).

◆ fluid_preset_get_num_t

typedef int(* fluid_preset_get_num_t) (fluid_preset_t *preset)

Method to get a virtual SoundFont preset MIDI program number.

Parameters
presetVirtual SoundFont preset
returnThe program number of the preset

◆ fluid_preset_noteon_t

typedef int(* fluid_preset_noteon_t) (fluid_preset_t *preset, fluid_synth_t *synth, int chan, int key, int vel)

Method to handle a noteon event (synthesize the instrument).

Parameters
presetVirtual SoundFont preset
synthSynthesizer instance
chanMIDI channel number of the note on event
keyMIDI note number (0-127)
velMIDI velocity (0-127)
Returns
FLUID_OK on success (0) or FLUID_FAILED (-1) otherwise

This method may be called from within synthesis context and therefore should be as efficient as possible and not perform any operations considered bad for realtime audio output (memory allocations and other OS calls).

Call fluid_synth_alloc_voice() for every sample that has to be played. fluid_synth_alloc_voice() expects a pointer to a fluid_sample_t structure and returns a pointer to the opaque fluid_voice_t structure. To set or increment the values of a generator, use fluid_voice_gen_set() or fluid_voice_gen_incr(). When you are finished initializing the voice call fluid_voice_start() to start playing the synthesis voice. Starting with FluidSynth 1.1.0 all voices created will be started at the same time.

◆ fluid_sfloader_callback_close_t

typedef int(* fluid_sfloader_callback_close_t) (void *handle)

Closes the handle returned by fluid_sfloader_callback_open_t and frees used resources.

Returns
returns FLUID_OK on success, FLUID_FAILED on error

◆ fluid_sfloader_callback_open_t

typedef void*(* fluid_sfloader_callback_open_t) (const char *filename)

Opens the file or memory indicated by filename in binary read mode.

Returns
returns a file handle on success, NULL otherwise

filename matches the string provided during the fluid_synth_sfload() call.

◆ fluid_sfloader_callback_read_t

typedef int(* fluid_sfloader_callback_read_t) (void *buf, fluid_long_long_t count, void *handle)

Reads count bytes to the specified buffer buf.

Returns
returns FLUID_OK if exactly count bytes were successfully read, else returns FLUID_FAILED and leaves buf unmodified.

◆ fluid_sfloader_callback_seek_t

typedef int(* fluid_sfloader_callback_seek_t) (void *handle, fluid_long_long_t offset, int origin)

Same purpose and behaviour as fseek.

Parameters
origineither SEEK_SET, SEEK_CUR or SEEK_END
Returns
returns FLUID_OK if the seek was successfully performed while not seeking beyond a buffer or file, FLUID_FAILED otherwise

◆ fluid_sfloader_callback_tell_t

typedef fluid_long_long_t(* fluid_sfloader_callback_tell_t) (void *handle)
Returns
returns current file offset or FLUID_FAILED on error

◆ fluid_sfloader_free_t

typedef void(* fluid_sfloader_free_t) (fluid_sfloader_t *loader)

The free method should free the memory allocated for a fluid_sfloader_t instance in addition to any private data.

Parameters
loaderSoundFont loader

Any custom user provided cleanup function must ultimately call delete_fluid_sfloader() to ensure proper cleanup of the fluid_sfloader_t struct. If no private data needs to be freed, setting this to delete_fluid_sfloader() is sufficient.

◆ fluid_sfloader_load_t

typedef fluid_sfont_t*(* fluid_sfloader_load_t) (fluid_sfloader_t *loader, const char *filename)

Method to load an instrument file (does not actually need to be a real file name, could be another type of string identifier that the loader understands).

Parameters
loaderSoundFont loader
filenameFile name or other string identifier
Returns
The loaded instrument file (SoundFont) or NULL if an error occurred.

◆ fluid_sfont_free_t

typedef int(* fluid_sfont_free_t) (fluid_sfont_t *sfont)

Method to free a virtual SoundFont bank.

Parameters
sfontVirtual SoundFont to free.
Returns
Should return 0 when it was able to free all resources or non-zero if some of the samples could not be freed because they are still in use, in which case the free will be tried again later, until success.

Any custom user provided cleanup function must ultimately call delete_fluid_sfont() to ensure proper cleanup of the fluid_sfont_t struct. If no private data needs to be freed, setting this to delete_fluid_sfont() is sufficient.

◆ fluid_sfont_get_name_t

typedef const char*(* fluid_sfont_get_name_t) (fluid_sfont_t *sfont)

Method to return the name of a virtual SoundFont.

Parameters
sfontVirtual SoundFont
Returns
The name of the virtual SoundFont.

◆ fluid_sfont_get_preset_t

typedef fluid_preset_t*(* fluid_sfont_get_preset_t) (fluid_sfont_t *sfont, int bank, int prenum)

Get a virtual SoundFont preset by bank and program numbers.

Parameters
sfontVirtual SoundFont
bankMIDI bank number (0-16383)
prenumMIDI preset number (0-127)
Returns
Should return an allocated virtual preset or NULL if it could not be found.

◆ fluid_sfont_iteration_next_t

typedef fluid_preset_t*(* fluid_sfont_iteration_next_t) (fluid_sfont_t *sfont)

Virtual SoundFont preset iteration function.

Parameters
sfontVirtual SoundFont
Returns
NULL when no more presets are available, otherwise the a pointer to the current preset

Returns preset information to the caller. The returned buffer is only valid until a subsequent call to this function.

◆ fluid_sfont_iteration_start_t

typedef void(* fluid_sfont_iteration_start_t) (fluid_sfont_t *sfont)

Start virtual SoundFont preset iteration method.

Parameters
sfontVirtual SoundFont

Starts/re-starts virtual preset iteration in a SoundFont.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Some notification enums for presets and samples.

Enumerator
FLUID_PRESET_SELECTED 

Preset selected notify.

FLUID_PRESET_UNSELECTED 

Preset unselected notify.

FLUID_SAMPLE_DONE 

Sample no longer needed notify.

FLUID_PRESET_PIN 

Request to pin preset samples to cache.

FLUID_PRESET_UNPIN 

Request to unpin preset samples from cache.

◆ fluid_sample_type

Indicates the type of a sample used by the _fluid_sample_t::sampletype field.

This enum corresponds to the SFSampleLink enum in the SoundFont spec. One flag may be bit-wise OR-ed with one value.

Enumerator
FLUID_SAMPLETYPE_MONO 

Value used for mono samples.

FLUID_SAMPLETYPE_RIGHT 

Value used for right samples of a stereo pair.

FLUID_SAMPLETYPE_LEFT 

Value used for left samples of a stereo pair.

FLUID_SAMPLETYPE_LINKED 

Value used for linked sample, which is currently not supported.

FLUID_SAMPLETYPE_OGG_VORBIS 

Flag used for Ogg Vorbis compressed samples (non-standard compliant extension) as found in the program "sftools" developed by Werner Schweer from MuseScore.

Since
1.1.7
FLUID_SAMPLETYPE_ROM 

Flag that indicates ROM samples, causing the sample to be ignored.

Function Documentation

◆ delete_fluid_preset()

void delete_fluid_preset ( fluid_preset_t preset)

Destroys a SoundFont preset instance created with new_fluid_preset().

Parameters
presetThe SoundFont preset instance to destroy.

Implements fluid_preset_free_t.

◆ delete_fluid_sample()

void delete_fluid_sample ( fluid_sample_t sample)

Destroy a sample instance previously created with new_fluid_sample().

Parameters
sampleThe sample to destroy.

◆ delete_fluid_sfloader()

void delete_fluid_sfloader ( fluid_sfloader_t loader)

Frees a SoundFont loader created with new_fluid_sfloader().

Parameters
loaderThe SoundFont loader instance to free.

◆ delete_fluid_sfont()

int delete_fluid_sfont ( fluid_sfont_t sfont)

Destroys a SoundFont instance created with new_fluid_sfont().

Parameters
sfontThe SoundFont instance to destroy.
Returns
Always returns 0.

Implements fluid_sfont_free_t.

◆ fluid_preset_get_banknum()

int fluid_preset_get_banknum ( fluid_preset_t preset)

Retrieves the presets bank number by executing the get_bank function provided on its creation.

Parameters
presetThe SoundFont preset instance.
Returns
The bank number of preset.

◆ fluid_preset_get_data()

void* fluid_preset_get_data ( fluid_preset_t preset)

Retrieve the private data of a SoundFont preset instance.

Parameters
presetThe SoundFont preset instance.
Returns
The private data or NULL if none explicitly set before.

◆ fluid_preset_get_name()

const char* fluid_preset_get_name ( fluid_preset_t preset)

Retrieves the presets name by executing the get_name function provided on its creation.

Parameters
presetThe SoundFont preset instance.
Returns
Pointer to a NULL-terminated string containing the presets name.

◆ fluid_preset_get_num()

int fluid_preset_get_num ( fluid_preset_t preset)

Retrieves the presets (instrument) number by executing the get_num function provided on its creation.

Parameters
presetThe SoundFont preset instance.
Returns
The number of preset.

◆ fluid_preset_get_sfont()

fluid_sfont_t* fluid_preset_get_sfont ( fluid_preset_t preset)

Retrieves the presets parent SoundFont instance.

Parameters
presetThe SoundFont preset instance.
Returns
The parent SoundFont of preset.

◆ fluid_preset_set_data()

int fluid_preset_set_data ( fluid_preset_t preset,
void *  data 
)

Set private data to use with a SoundFont preset instance.

Parameters
presetThe SoundFont preset instance.
dataThe private data to store.
Returns
FLUID_OK on success, FLUID_FAILED otherwise.

◆ fluid_sample_set_loop()

int fluid_sample_set_loop ( fluid_sample_t sample,
unsigned int  loop_start,
unsigned int  loop_end 
)

Set the loop of a sample.

Parameters
sampleSoundFont sample
loop_startStart sample index of the loop.
loop_endEnd index of the loop (must be a valid sample as it marks the last sample to be played).
Returns
FLUID_OK on success, FLUID_FAILED otherwise.

◆ fluid_sample_set_name()

int fluid_sample_set_name ( fluid_sample_t sample,
const char *  name 
)

Set the name of a SoundFont sample.

Parameters
sampleSoundFont sample
nameName to assign to sample (20 chars in length + zero terminator)
Returns
FLUID_OK on success, FLUID_FAILED otherwise

◆ fluid_sample_set_pitch()

int fluid_sample_set_pitch ( fluid_sample_t sample,
int  root_key,
int  fine_tune 
)

Set the pitch of a sample.

Parameters
sampleSoundFont sample
root_keyRoot MIDI note of sample (0-127)
fine_tuneFine tune in cents
Returns
FLUID_OK on success, FLUID_FAILED otherwise.

◆ fluid_sample_set_sound_data()

int fluid_sample_set_sound_data ( fluid_sample_t sample,
short *  data,
char *  data24,
unsigned int  nbframes,
unsigned int  sample_rate,
short  copy_data 
)

Assign sample data to a SoundFont sample.

Parameters
sampleSoundFont sample
dataBuffer containing 16 bit (mono-)audio sample data
data24If not NULL, pointer to the least significant byte counterparts of each sample data point in order to create 24 bit audio samples
nbframesNumber of samples in data
sample_rateSampling rate of the sample data
copy_dataTRUE to copy the sample data (and automatically free it upon delete_fluid_sample()), FALSE to use it directly (and not free it)
Returns
FLUID_OK on success, FLUID_FAILED otherwise
Note
If copy_data is FALSE, data should have 8 unused frames at start and 8 unused frames at the end and nbframes should be >=48

◆ fluid_sample_sizeof()

size_t fluid_sample_sizeof ( void  )

Returns the size of the fluid_sample_t structure.

Returns
Size of fluid_sample_t in bytes

Useful in low latency scenarios e.g. to allocate a pool of samples.

Note
It is recommend to zero initialize the memory before using the object.
Warning
Do NOT allocate samples on the stack and assign them to a voice!

◆ fluid_sfloader_get_data()

void* fluid_sfloader_get_data ( fluid_sfloader_t loader)

Obtain private data previously set with fluid_sfloader_set_data().

Parameters
loaderThe SoundFont loader instance.
Returns
The private data or NULL if none explicitly set before.

◆ fluid_sfloader_set_callbacks()

Set custom callbacks to be used upon soundfont loading.

Parameters
loaderThe SoundFont loader instance.
openA function implementing fluid_sfloader_callback_open_t.
readA function implementing fluid_sfloader_callback_read_t.
seekA function implementing fluid_sfloader_callback_seek_t.
tellA function implementing fluid_sfloader_callback_tell_t.
closeA function implementing fluid_sfloader_callback_close_t.
Returns
FLUID_OK if the callbacks have been successfully set, FLUID_FAILED otherwise.

Useful for loading a soundfont from memory, see doc/fluidsynth_sfload_mem.c as an example.

Examples
fluidsynth_sfload_mem.c.

◆ fluid_sfloader_set_data()

int fluid_sfloader_set_data ( fluid_sfloader_t loader,
void *  data 
)

Specify private data to be used by fluid_sfloader_load_t.

Parameters
loaderThe SoundFont loader instance.
dataThe private data to store.
Returns
FLUID_OK on success, FLUID_FAILED otherwise.

◆ fluid_sfont_get_data()

void* fluid_sfont_get_data ( fluid_sfont_t sfont)

Retrieve the private data of a SoundFont instance.

Parameters
sfontThe SoundFont instance.
Returns
The private data or NULL if none explicitly set before.

◆ fluid_sfont_get_id()

int fluid_sfont_get_id ( fluid_sfont_t sfont)

Retrieve the unique ID of a SoundFont instance.

Parameters
sfontThe SoundFont instance.
Returns
The SoundFont ID.

◆ fluid_sfont_get_name()

const char* fluid_sfont_get_name ( fluid_sfont_t sfont)

Retrieve the name of a SoundFont instance.

Parameters
sfontThe SoundFont instance.
Returns
The name of the SoundFont.

◆ fluid_sfont_get_preset()

fluid_preset_t* fluid_sfont_get_preset ( fluid_sfont_t sfont,
int  bank,
int  prenum 
)

Retrieve the preset assigned the a SoundFont instance for the given bank and preset number.

Parameters
sfontThe SoundFont instance.
bankbank number of the preset
prenumprogram number of the preset
Returns
The preset instance or NULL if none found.

◆ fluid_sfont_iteration_next()

fluid_preset_t* fluid_sfont_iteration_next ( fluid_sfont_t sfont)

Virtual SoundFont preset iteration function.

Returns preset information to the caller and advances the internal iteration state to the next preset for subsequent calls.

Parameters
sfontThe SoundFont instance.
Returns
NULL when no more presets are available, otherwise the a pointer to the current preset

◆ fluid_sfont_iteration_start()

void fluid_sfont_iteration_start ( fluid_sfont_t sfont)

Starts / re-starts virtual preset iteration in a SoundFont.

Parameters
sfontVirtual SoundFont instance

◆ fluid_sfont_set_data()

int fluid_sfont_set_data ( fluid_sfont_t sfont,
void *  data 
)

Set private data to use with a SoundFont instance.

Parameters
sfontThe SoundFont instance.
dataThe private data to store.
Returns
FLUID_OK on success, FLUID_FAILED otherwise.

◆ fluid_synth_add_sfloader()

void fluid_synth_add_sfloader ( fluid_synth_t synth,
fluid_sfloader_t loader 
)

Add a SoundFont loader to the synth.

This function takes ownership of loader and frees it automatically upon synth destruction.

Parameters
synthFluidSynth instance
loaderLoader API structure

SoundFont loaders are used to add custom instrument loading to FluidSynth. The caller supplied functions for loading files, allocating presets, retrieving information on them and synthesizing note-on events. Using this method even non SoundFont instruments can be synthesized, although limited to the SoundFont synthesis model.

Note
Should only be called before any SoundFont files are loaded.
Examples
fluidsynth_sfload_mem.c.

◆ fluid_synth_get_channel_preset()

fluid_preset_t* fluid_synth_get_channel_preset ( fluid_synth_t synth,
int  chan 
)

Get active preset on a MIDI channel.

Parameters
synthFluidSynth instance
chanMIDI channel number (0 to MIDI channel count - 1)
Returns
Preset or NULL if no preset active on chan
Note
Should only be called from within synthesis thread, which includes SoundFont loader preset noteon methods. Not thread safe otherwise.

◆ new_fluid_defsfloader()

fluid_sfloader_t* new_fluid_defsfloader ( fluid_settings_t settings)

Creates a default soundfont2 loader that can be used with fluid_synth_add_sfloader().

By default every synth instance has an initial default soundfont loader instance. Calling this function is usually only necessary to load a soundfont from memory, by providing custom callback functions via fluid_sfloader_set_callbacks().

Parameters
settingsA settings instance obtained by new_fluid_settings()
Returns
A default soundfont2 loader struct
Examples
fluidsynth_sfload_mem.c.

◆ new_fluid_preset()

fluid_preset_t* new_fluid_preset ( fluid_sfont_t parent_sfont,
fluid_preset_get_name_t  get_name,
fluid_preset_get_banknum_t  get_bank,
fluid_preset_get_num_t  get_num,
fluid_preset_noteon_t  noteon,
fluid_preset_free_t  free 
)

Create a virtual SoundFont preset instance.

Parameters
parent_sfontThe SoundFont instance this preset shall belong to
get_nameA function implementing fluid_preset_get_name_t
get_bankA function implementing fluid_preset_get_banknum_t
get_numA function implementing fluid_preset_get_num_t
noteonA function implementing fluid_preset_noteon_t
freeA function implementing fluid_preset_free_t
Returns
The preset instance on success, NULL otherwise.

◆ new_fluid_sample()

fluid_sample_t* new_fluid_sample ( void  )

Create a new sample instance.

Returns
The sample on success, NULL otherwise.

◆ new_fluid_sfloader()

fluid_sfloader_t* new_fluid_sfloader ( fluid_sfloader_load_t  load,
fluid_sfloader_free_t  free 
)

Creates a new SoundFont loader.

Parameters
loadPointer to a function that provides a fluid_sfont_t (see fluid_sfloader_load_t).
freePointer to a function that destroys this instance (see fluid_sfloader_free_t). Unless any private data needs to be freed it is sufficient to set this to delete_fluid_sfloader().
Returns
the SoundFont loader instance on success, NULL otherwise.

◆ new_fluid_sfont()

fluid_sfont_t* new_fluid_sfont ( fluid_sfont_get_name_t  get_name,
fluid_sfont_get_preset_t  get_preset,
fluid_sfont_iteration_start_t  iter_start,
fluid_sfont_iteration_next_t  iter_next,
fluid_sfont_free_t  free 
)

Creates a new virtual SoundFont instance structure.

Parameters
get_nameA function implementing fluid_sfont_get_name_t.
get_presetA function implementing fluid_sfont_get_preset_t.
iter_startA function implementing fluid_sfont_iteration_start_t, or NULL if preset iteration not needed.
iter_nextA function implementing fluid_sfont_iteration_next_t, or NULL if preset iteration not needed.
freeA function implementing fluid_sfont_free_t.
Returns
The soundfont instance on success or NULL otherwise.