Skip to content

Commit

Permalink
Handle MIDI End of track events (Credit: Matt Giuca). Fixes ticket #101.
Browse files Browse the repository at this point in the history
  • Loading branch information
diwic committed Sep 18, 2011
1 parent 8791c11 commit 15e6508
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions fluidsynth/doc/fluidsynth-v11-devdoc.txt
Expand Up @@ -1455,11 +1455,11 @@ FluidSynth can be also play MIDI files directly from a buffer in memory. If you
const char MIDIFILE[] = {
0x4d, 0x54, 0x68, 0x64, 0x00, 0x00, 0x00, 0x06,
0x00, 0x01, 0x00, 0x01, 0x01, 0xe0, 0x4d, 0x54,
0x72, 0x6b, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x90,
0x72, 0x6b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x90,
0x3c, 0x64, 0x87, 0x40, 0x80, 0x3c, 0x7f, 0x00,
0x90, 0x43, 0x64, 0x87, 0x40, 0x80, 0x43, 0x7f,
0x00, 0x90, 0x48, 0x64, 0x87, 0x40, 0x80, 0x48,
0x7f, 0x00, 0xff, 0x2f, 0x00,
0x7f, 0x83, 0x60, 0xff, 0x2f, 0x00
};

int main(int argc, char** argv)
Expand Down
21 changes: 17 additions & 4 deletions fluidsynth/src/midi/fluid_midi.c
Expand Up @@ -585,6 +585,16 @@ fluid_midi_file_read_event(fluid_midi_file *mf, fluid_track_t *track)
break;
}
mf->eot = 1;
evt = new_fluid_midi_event();
if (evt == NULL) {
FLUID_LOG(FLUID_ERR, "Out of memory");
result = FLUID_FAILED;
break;
}
evt->dtime = mf->dtime;
evt->type = MIDI_EOT;
fluid_track_add_event(track, evt);
mf->dtime = 0;
break;

case MIDI_SET_TEMPO:
Expand Down Expand Up @@ -1204,12 +1214,15 @@ fluid_track_send_events(fluid_track_t *track,

track->ticks += event->dtime;

if (event->type != MIDI_SET_TEMPO) {
if (!player || event->type == MIDI_EOT) {
}
else if (event->type == MIDI_SET_TEMPO) {
fluid_player_set_midi_tempo(player, event->param1);
}
else {
if (player->playback_callback)
player->playback_callback(player->playback_userdata, event);
}
else if (player)
fluid_player_set_midi_tempo(player, event->param1);
}

fluid_track_next_event(track);

Expand Down

0 comments on commit 15e6508

Please sign in to comment.