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: ");
fgetc(stdin);
fgetc(stdin);
printf("done\n");
cleanup:
if (adriver) {
delete_fluid_audio_driver(adriver);
}
if (synth) {
delete_fluid_synth(synth);
}
if (settings) {
delete_fluid_settings(settings);
}
if (midiDriver){
delete_fluid_midi_driver(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);
break;
case NOTE_OFF:
fprintf(stdout, "event_post_noteoff %i %i %i\n",
event->channel, event->param1, event->param2);
break;
default:
break;
}
return fluid_synth_handle_midi_event((fluid_synth_t*) data, event);
}