#include "midi2fluid.h"
#include <assert.h>
#include <fluidsynth.h>

void midi2fluid_event(fluid_synth_t *synth,midi_event_t *ev) // {{{
{
  assert( (synth)&&(ev) );

//midi_event_dump(ev);
  switch (ev->type) {
  case EV_NOTE_OFF:
    fluid_synth_noteoff(synth,ev->channel,ev->note.tune);
    break;
  case EV_NOTE_ON:
    fluid_synth_noteon(synth,ev->channel,ev->note.tune,ev->note.value);
    break;
  case EV_CONTROLLER:
    fluid_synth_cc(synth,ev->channel,ev->controller.number,ev->controller.value);
    break;
  case EV_PROGRAM_CHANGE:
    fluid_synth_program_change(synth,ev->channel,ev->program.number);
    break;
  case EV_PITCH_BEND:
    fluid_synth_pitch_bend(synth,ev->channel,ev->pitch_bend.value+8192);
    break;
/*
  case EV_META: // e.g. lyrics
    break;
*/
  case EV_SYSEX_VERBATIM:
    if ( (ev->sysex.len==1)&&(*ev->sysex.data==SYSREAL_RESET) ) {
      fluid_synth_system_reset(synth);
      // TODO:  reset pgms (to correct sf2)
    }
    break;
  case EV_NOTE_AFTERTOUCH:
  case EV_CHANNEL_AFTERTOUCH:
  default: // >=EV_SYSEX
    break;
  }
}
// }}}

