libfluidsynth  2.3.5
Loading and playing a MIDI file

FluidSynth can be used to play MIDI files, using the MIDI File Player interface. It follows a high level implementation, though its implementation is currently incomplete. After initializing the synthesizer, create the player passing the synth instance to new_fluid_player(). Then, you can add some SMF file names to the player using fluid_player_add(), and finally call fluid_player_play() to start the playback. You can check if the player has finished by calling fluid_player_get_status(), or wait for the player to terminate using fluid_player_join().

#include <fluidsynth.h>
int main(int argc, char** argv)
{
int i;
fluid_settings_t* settings;
fluid_synth_t* synth;
fluid_player_t* player;
settings = new_fluid_settings();
synth = new_fluid_synth(settings);
player = new_fluid_player(synth);
/* process command line arguments */
for (i = 1; i < argc; i++) {
if (fluid_is_soundfont(argv[i])) {
fluid_synth_sfload(synth, argv[1], 1);
}
if (fluid_is_midifile(argv[i])) {
fluid_player_add(player, argv[i]);
}
}
/* start the synthesizer thread */
adriver = new_fluid_audio_driver(settings, synth);
/* play the midi files, if any */
/* wait for playback termination */
/* cleanup */
return 0;
}
struct _fluid_hashtable_t fluid_settings_t
Configuration settings instance.
Definition: types.h:38
struct _fluid_audio_driver_t fluid_audio_driver_t
Audio driver instance.
Definition: types.h:46
struct _fluid_synth_t fluid_synth_t
Synthesizer instance.
Definition: types.h:39
struct _fluid_player_t fluid_player_t
MIDI player instance.
Definition: types.h:48
fluid_audio_driver_t * new_fluid_audio_driver(fluid_settings_t *settings, fluid_synth_t *synth)
Create a new audio driver.
Definition: fluid_adriver.c:330
void delete_fluid_audio_driver(fluid_audio_driver_t *driver)
Deletes an audio driver instance.
Definition: fluid_adriver.c:423
int fluid_player_join(fluid_player_t *player)
Wait for a MIDI player until the playback has been stopped.
Definition: fluid_midi.c:2578
int fluid_player_play(fluid_player_t *player)
Activates play mode for a MIDI player if not already playing.
Definition: fluid_midi.c:2283
void delete_fluid_player(fluid_player_t *player)
Delete a MIDI player instance.
Definition: fluid_midi.c:1757
fluid_player_t * new_fluid_player(fluid_synth_t *synth)
Create a new MIDI player.
Definition: fluid_midi.c:1667
int fluid_player_add(fluid_player_t *player, const char *midifile)
Add a MIDI file to a player queue.
Definition: fluid_midi.c:1903
int fluid_is_midifile(const char *filename)
Check if a file is a MIDI file.
Definition: fluid_midi.c:89
int fluid_is_soundfont(const char *filename)
Check if a file is a SoundFont file.
Definition: fluid_sffile.c:263
fluid_settings_t * new_fluid_settings(void)
Create a new settings object.
Definition: fluid_settings.c:262
void delete_fluid_settings(fluid_settings_t *settings)
Delete the provided settings object.
Definition: fluid_settings.c:286
int fluid_synth_sfload(fluid_synth_t *synth, const char *filename, int reset_presets)
Load a SoundFont file (filename is interpreted by SoundFont loaders).
Definition: fluid_synth.c:5344
fluid_synth_t * new_fluid_synth(fluid_settings_t *settings)
Create new FluidSynth instance.
Definition: fluid_synth.c:628
void delete_fluid_synth(fluid_synth_t *synth)
Delete a FluidSynth instance.
Definition: fluid_synth.c:1023

A list of available MIDI player settings can be found in the MIDI player settings documentation.