void MidiPlayer::play() { int status = fluid_player_get_status(player); if (status == FLUID_PLAYER_READY) fluid_player_play(player); if (true && status == FLUID_PLAYER_DONE) { fluid_player_stop(player); delete_fluid_player(player); player = new_fluid_player(synth); if (player == NULL) { //setError("Failed to play MIDI."); return; } fluid_player_add_mem(player, midi.c_str(), midi.size()); fluid_player_play(player); } _is_playing = true; //if (fluid_player_get_status(player) != FLUID_PLAYER_DONE) // SoundStream::play(); /* play the midi files, if any */ //fluid_player_play(player); /* wait for playback termination */ //fluid_player_join(player); }
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); } }
bool MidiPlayer::loadMidiFromFile(const std::string &filename) { stop(); if (player != NULL) delete_fluid_player(player); player = new_fluid_player(synth); if (player == NULL) return false; // it crashed because not all dll files were included correctly std::ifstream file(filename.c_str(), std::ios::binary); if (!file.is_open()) { //setError("Failed to load MIDI."); return false; } file.seekg(0, std::ios::end); unsigned int size = static_cast<unsigned int>(file.tellg()); file.seekg(0, std::ios::beg); char* data = new char[size]; if (data == NULL) { //setError("Failed to load MIDI."); return false; } file.read(data, size); midi = std::string(data, size); delete[] data; file.close(); if (fluid_player_add_mem(player, midi.c_str(), midi.size()) != FLUID_OK) return false; return true; }