[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [fluid-dev] Intercepting midi events

From: Christopher Leger
Subject: Re: [fluid-dev] Intercepting midi events
Date: Sun, 3 Jun 2018 23:50:03 -0400

Ok, I made the changes but it not working for me. Here is a program which is supposed to synthesize the midi input and print note on and note off events:

#include <string.h>
#include <stdio.h>
#include <fluidsynth.h>
#include "fluid_midi.h"
#include "fluid_sfont.h"

int intercept(void* data, fluid_midi_event_t* event);

int main(int argc, char** argv)
  fluid_settings_t* settings;
  fluid_synth_t* synth = NULL;
  fluid_audio_driver_t* adriver = NULL;

  int err = 0;

  if (argc != 2) {
    fprintf(stderr, "Usage: fluidsynth_keyboard [soundfont]\n");
    return 1;

  /* Create the settings object. This example uses the default                                                       
   * values for the settings. */
  settings = new_fluid_settings();
  if (settings == NULL) {
    fprintf(stderr, "Failed to create the settings\n");
    err = 2;
    goto cleanup;

  /* set driver settings */
  fluid_settings_setstr(settings, "audio.driver", "alsa");
  fluid_settings_setstr(settings, "midi.driver", "alsa_raw");
  fluid_settings_setstr(settings, "midi.alsa.device", "hw:1,0");

  /* Create the synthesizer */
  synth = new_fluid_synth(settings);
  if (synth == NULL) {
    fprintf(stderr, "Failed to create the synthesizer\n");
    err = 3;
    goto cleanup;

    /* load the soundfont */
  if (fluid_synth_sfload(synth, argv[1], 1) == FLUID_FAILED) {
    fprintf(stderr, "Failed to load the SoundFont\n");
    err = 5;
    goto cleanup;

  /* Create the audio driver. As soon as the audio driver is                                                         
   * created, the synthesizer can be played. */
  adriver = new_fluid_audio_driver(settings, synth);
  if (adriver == NULL) {
    fprintf(stderr, "Failed to create the audio driver\n");
    err = 6;
    goto cleanup;

/* create midi driver */

  fluid_midi_driver_t* midiDriver;
  midiDriver = new_fluid_midi_driver(settings, intercept, NULL);

  printf("Press \"Enter\" to stop: ");


  if (adriver) {
  if (synth) {
  if (settings) {
  if (midiDriver){

  return err;

/* My processing function for midi events */
int intercept(void* data, fluid_midi_event_t* event)
  switch (event->type) {

  case NOTE_ON:

    fprintf(stdout, "event_post_noteon %i %i %i\n",
            event->channel, event->param1, event->param2);


  case NOTE_OFF:

    fprintf(stdout, "event_post_noteoff %i %i %i\n",
            event->channel, event->param1, event->param2);


  return fluid_synth_handle_midi_event((fluid_synth_t*) data, event);

On Sun, Jun 3, 2018 at 10:53 PM, Tom M. <address@hidden> wrote:
Without any code it's hard to tell. However the order looks wrong to me, as the synth is not setup when creating the midi driver. You should instead:

 1. create settings
 2. set midi driver settings
 3. set audio driver settings
 4. create synth
 5. load soundfont
 6. create audio driver
 7. create midi driver


reply via email to

[Prev in Thread] Current Thread [Next in Thread]