void MusicPlayer::PlayMidi(const void* data, size_t len) { this->player = new_fluid_player(this->synth); this->adriver = new_fluid_audio_driver(this->settings, this->synth); if (FLUID_OK == fluid_player_add_mem(this->player, data, len)) { fluid_player_set_playback_callback(this->player, &midi_event_callback, this->synth); vgmtrans_fluid_player_play(this->player); } }
int main(int argc, char** argv) { int i; fluid_settings_t* settings; fluid_synth_t* synth; fluid_player_t* player; fluid_audio_driver_t* adriver; settings = new_fluid_settings(); fluid_settings_setstr(settings, "audio.driver", "alsa"); fluid_settings_setint(settings, "synth.polyphony", 64); synth = new_fluid_synth(settings); player = new_fluid_player(synth); /* Set the MIDI event callback to our own functions rather than the system default */ fluid_player_set_playback_callback(player, event_callback, synth); /* Add an onload callback so we can get information from new data before it plays */ fluid_player_set_onload_callback(player, onload_callback, NULL); adriver = new_fluid_audio_driver(settings, synth); /* process command line arguments */ for (i = 1; i < argc; i++) { if (fluid_is_soundfont(argv[i])) { fluid_synth_sfload(synth, argv[1], 1); } else { fluid_player_add(player, argv[i]); } } /* play the midi files, if any */ fluid_player_play(player); /* wait for playback termination */ fluid_player_join(player); /* cleanup */ delete_fluid_audio_driver(adriver); delete_fluid_player(player); delete_fluid_synth(synth); delete_fluid_settings(settings); return 0; }
/** * Create a new MIDI player. * @param synth Fluid synthesizer instance to create player for * @return New MIDI player instance or NULL on error (out of memory) */ fluid_player_t * new_fluid_player(fluid_synth_t *synth) { int i; fluid_player_t *player; player = FLUID_NEW(fluid_player_t); if (player == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); return NULL; } player->status = FLUID_PLAYER_READY; player->loop = 1; player->ntracks = 0; for (i = 0; i < MAX_NUMBER_OF_TRACKS; i++) { player->track[i] = NULL; } player->synth = synth; player->system_timer = NULL; player->sample_timer = NULL; player->playlist = NULL; player->currentfile = NULL; player->division = 0; player->send_program_change = 1; player->miditempo = 480000; player->deltatime = 4.0; player->cur_msec = 0; player->cur_ticks = 0; fluid_player_set_playback_callback(player, fluid_synth_handle_midi_event, synth); player->use_system_timer = fluid_settings_str_equal(synth->settings, "player.timing-source", "system"); fluid_settings_getint(synth->settings, "player.reset-synth", &i); player->reset_synth_between_songs = i; return player; }