libfluidsynth  2.4.5
Real-time MIDI router

The MIDI router is one more processing layer directly behind the MIDI input. It processes incoming MIDI events and generates control events for the synth. It can be used to filter or modify events prior to sending them to the synthesizer. When created, the MIDI router is transparent and simply passes all MIDI events. Router "rules" must be added to actually make use of its capabilities.

Some examples of MIDI router usage:

  • Filter messages (Example: Pass sustain pedal CCs only to selected channels)
  • Split the keyboard (Example: noteon with notenr < x: to ch 1, >x to ch 2)
  • Layer sounds (Example: for each noteon received on ch 1, create a noteon on ch1, ch2, ch3,...)
  • Velocity scaling (Example: for each noteon event, scale the velocity by 1.27)
  • Velocity switching (Example: v <= 100: "Angel Choir"; v > 100: "Hell's Bells")
  • Get rid of aftertouch

The MIDI driver API has a clean separation between the midi thread and the synthesizer. That opens the door to add a midi router module.

MIDI events coming from the MIDI player do not pass through the MIDI router.

#include <fluidsynth.h>
int main(int argc, char** argv)
{
fluid_settings_t* settings;
fluid_synth_t* synth;
settings = new_fluid_settings();
synth = new_fluid_synth(settings);
/* Create the MIDI router and pass events to the synthesizer */
/* Clear default rules */
/* Add rule to map all notes < MIDI note #60 on any channel to channel 4 */
fluid_midi_router_rule_set_chan (rule, 0, 15, 0.0, 4); /* Map all to channel 4 */
fluid_midi_router_rule_set_param1 (rule, 0, 59, 1.0, 0); /* Match notes < 60 */
/* Add rule to map all notes >= MIDI note #60 on any channel to channel 5 */
fluid_midi_router_rule_set_chan (rule, 0, 15, 0.0, 5); /* Map all to channel 5 */
fluid_midi_router_rule_set_param1 (rule, 60, 127, 1.0, 0); /* Match notes >= 60 */
/* Add rule to reverse direction of pitch bender on channel 7 */
fluid_midi_router_rule_set_chan (rule, 7, 7, 1.0, 0); /* Match channel 7 only */
fluid_midi_router_rule_set_param1 (rule, 0, 16383, -1.0, 16383); /* Reverse pitch bender */
/* ... Create audio driver, process events, etc ... */
/* cleanup */
return 0;
}
struct _fluid_midi_router_rule_t fluid_midi_router_rule_t
MIDI router rule.
Definition: types.h:52
struct _fluid_hashtable_t fluid_settings_t
Configuration settings instance.
Definition: types.h:38
struct _fluid_midi_router_t fluid_midi_router_t
MIDI router instance.
Definition: types.h:51
struct _fluid_synth_t fluid_synth_t
Synthesizer instance.
Definition: types.h:39
int fluid_synth_handle_midi_event(void *data, fluid_midi_event_t *event)
Handle MIDI event from MIDI router, used as a callback function.
Definition: fluid_synth.c:7859
fluid_midi_router_rule_t * new_fluid_midi_router_rule(void)
Create a new MIDI router rule.
Definition: fluid_midi_router.c:378
fluid_midi_router_t * new_fluid_midi_router(fluid_settings_t *settings, handle_midi_event_func_t handler, void *event_handler_data)
Create a new midi router.
Definition: fluid_midi_router.c:86
int fluid_midi_router_clear_rules(fluid_midi_router_t *router)
Clear all rules in a MIDI router.
Definition: fluid_midi_router.c:263
void delete_fluid_midi_router(fluid_midi_router_t *handler)
Delete a MIDI router instance.
Definition: fluid_midi_router.c:135
void fluid_midi_router_rule_set_chan(fluid_midi_router_rule_t *rule, int min, int max, float mul, int add)
Set the channel portion of a rule.
Definition: fluid_midi_router.c:446
void fluid_midi_router_rule_set_param1(fluid_midi_router_rule_t *rule, int min, int max, float mul, int add)
Set the first parameter portion of a rule.
Definition: fluid_midi_router.c:486
int fluid_midi_router_add_rule(fluid_midi_router_t *router, fluid_midi_router_rule_t *rule, int type)
Add a rule to a MIDI router.
Definition: fluid_midi_router.c:334
@ FLUID_MIDI_ROUTER_RULE_PITCH_BEND
MIDI pitch bend rule.
Definition: midi.h:163
@ FLUID_MIDI_ROUTER_RULE_NOTE
MIDI note rule.
Definition: midi.h:160
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
fluid_synth_t * new_fluid_synth(fluid_settings_t *settings)
Create new FluidSynth instance.
Definition: fluid_synth.c:645
void delete_fluid_synth(fluid_synth_t *synth)
Delete a FluidSynth instance.
Definition: fluid_synth.c:1044