libfluidsynth  2.3.5
Creating a real-time MIDI driver

FluidSynth can process real-time MIDI events received from hardware MIDI ports or other applications. To do so, the client must create a MIDI input driver. It is a very similar process to the creation of the audio driver: you initialize some properties in a settings instance and call the new_fluid_midi_driver() function providing a callback function that will be invoked when a MIDI event is received. The following MIDI drivers are currently supported:

  • jack: JACK Audio Connection Kit MIDI driver (Linux, Mac OS X)
  • oss: Open Sound System raw MIDI (Linux, Unix)
  • alsa_raw: ALSA raw MIDI interface (Linux)
  • alsa_seq: ALSA sequencer MIDI interface (Linux)
  • winmidi: Microsoft Windows MM System (Windows)
  • midishare: MIDI Share (Linux, Mac OS X)
  • coremidi: Apple CoreMIDI (Mac OS X)
#include <fluidsynth.h>
int handle_midi_event(void* data, fluid_midi_event_t* event)
{
printf("event type: %d\n", fluid_midi_event_get_type(event));
}
int main(int argc, char** argv)
{
fluid_settings_t* settings;
settings = new_fluid_settings();
mdriver = new_fluid_midi_driver(settings, handle_midi_event, NULL);
/* ... */
return 0;
}
struct _fluid_midi_event_t fluid_midi_event_t
MIDI event.
Definition: types.h:49
struct _fluid_hashtable_t fluid_settings_t
Configuration settings instance.
Definition: types.h:38
struct _fluid_midi_driver_t fluid_midi_driver_t
MIDI driver instance.
Definition: types.h:50
fluid_midi_driver_t * new_fluid_midi_driver(fluid_settings_t *settings, handle_midi_event_func_t handler, void *event_handler_data)
Create a new MIDI driver instance.
Definition: fluid_mdriver.c:147
void delete_fluid_midi_driver(fluid_midi_driver_t *driver)
Delete a MIDI driver instance.
Definition: fluid_mdriver.c:192
int fluid_midi_event_get_type(const fluid_midi_event_t *evt)
Get the event type field of a MIDI event structure.
Definition: fluid_midi.c:1114
fluid_settings_t * new_fluid_settings(void)
Create a new settings object.
Definition: fluid_settings.c:262

There are a number of general MIDI driver settings. The midi.driver setting defines the MIDI subsystem that will be used. There are additional settings for the MIDI subsystems used. For a full list of available midi driver settings, please refer to the MIDI driver settings documentation.