libfluidsynth  2.3.5
MIDI Input

MIDI Input Subsystem. More...

Modules

 MIDI Driver
 Functions for managing MIDI drivers.
 
 MIDI Events
 Functions to create, modify, query and delete MIDI events.
 
 MIDI File Player
 Parse standard MIDI files and emit MIDI events.
 
 MIDI Router
 Rule based transformation and filtering of MIDI events.
 

Typedefs

typedef int(* handle_midi_event_func_t) (void *data, fluid_midi_event_t *event)
 Generic callback function for MIDI event handler. More...
 
typedef int(* handle_midi_tick_func_t) (void *data, int tick)
 Generic callback function fired once by MIDI tick change. More...
 

Functions

int fluid_synth_handle_midi_event (void *data, fluid_midi_event_t *event)
 Handle MIDI event from MIDI router, used as a callback function. More...
 

Detailed Description

MIDI Input Subsystem.

There are multiple ways to send MIDI events to the synthesizer. They can come from MIDI files, from external MIDI sequencers or raw MIDI event sources, can be modified via MIDI routers and also generated manually.

The interface connecting all sources and sinks of MIDI events in libfluidsynth is handle_midi_event_func_t.

Typedef Documentation

◆ handle_midi_event_func_t

typedef int(* handle_midi_event_func_t) (void *data, fluid_midi_event_t *event)

Generic callback function for MIDI event handler.

Parameters
dataUser defined data pointer
eventThe MIDI event
Returns
Should return FLUID_OK on success, FLUID_FAILED otherwise

This callback is used to pass MIDI events

Additionally, there is a translation layer to pass MIDI events to a MIDI Sequencer via fluid_sequencer_add_midi_event_to_buffer().

◆ handle_midi_tick_func_t

typedef int(* handle_midi_tick_func_t) (void *data, int tick)

Generic callback function fired once by MIDI tick change.

Parameters
dataUser defined data pointer
tickThe current (zero-based) tick, which triggered the callback
Returns
Should return FLUID_OK on success, FLUID_FAILED otherwise

This callback is fired at a constant rate depending on the current BPM and PPQ. e.g. for PPQ = 192 and BPM = 140 the callback is fired 192 * 140 times per minute (448/sec).

It can be used to sync external elements with the beat, or stop / loop the song on a given tick. Ticks being BPM-dependent, you can manipulate values such as bars or beats, without having to care about BPM.

For example, this callback loops the song whenever it reaches the 5th bar :

int handle_tick(void *data, int tick)
{
fluid_player_t *player = (fluid_player_t *)data;
int ppq = 192; // From MIDI header
int beatsPerBar = 4; // From the song's time signature
int loopBar = 5;
int loopTick = (loopBar - 1) * ppq * beatsPerBar;
if (tick == loopTick)
{
return fluid_player_seek(player, 0);
}
return FLUID_OK;
}
struct _fluid_player_t fluid_player_t
MIDI player instance.
Definition: types.h:48
int fluid_player_seek(fluid_player_t *player, int ticks)
Seek in the currently playing file.
Definition: fluid_midi.c:2356
#define FLUID_OK
Value that indicates success, used by most libfluidsynth functions.
Definition: misc.h:56

Function Documentation

◆ fluid_synth_handle_midi_event()

int fluid_synth_handle_midi_event ( void *  data,
fluid_midi_event_t event 
)

Handle MIDI event from MIDI router, used as a callback function.

Parameters
dataFluidSynth instance
eventMIDI event to handle
Returns
FLUID_OK on success, FLUID_FAILED otherwise