Index: music/fluidsynth_midi.cc =================================================================== --- music/fluidsynth_midi.cc (revision 0) +++ music/fluidsynth_midi.cc (working copy) @@ -0,0 +1,169 @@ +/* + * fluidsynth_midi.cc + * + * Copyright (c) 1997 - 2011 Hansjörg Malthaner and + * the simutrans development team + * + * This file is part of the Simutrans project under the artistic license. + * (see license.txt) + */ + +#include + +#include "../dataobj/umgebung.h" +#include "../utils/plainstring.h" +#include "music.h" + +static int midi_number = -1; +static plainstring midi_filenames[MAX_MIDI]; + +static fluid_settings_t* settings; +static fluid_synth_t* synth; +static fluid_player_t* player; +static fluid_audio_driver_t* adriver; + + +/** + * MIDI initialisation routines + */ +bool dr_init_midi(void) +{ + int sfont_id; + + if( !(settings = new_fluid_settings()) ) { + printf("FluidSynth: MIDI settings failed.\n"); + return false; + } + + if( !umgebung_t::fluidsynth_driver.empty() ) { + printf("FluidSynth: set driver: %s",umgebung_t::fluidsynth_driver.c_str()); + if( fluid_settings_setstr(settings, "audio.driver", umgebung_t::fluidsynth_driver.c_str()) != 1) { + printf(" - Failed.\n"); + return false; + } + printf(".\n"); + } + + if( !(synth = new_fluid_synth(settings)) ) { + printf("FluidSynth: synth setup failed.\n"); + return false; + } + + if( !(adriver = new_fluid_audio_driver(settings,synth)) ) { + printf("FluidSynth: audio driver setup failed.\n"); + return false; + } + + if( !fluid_is_soundfont(umgebung_t::soundfont_filename.c_str()) ) { + printf("FluidSynth: %s is not a soundfont.\n", umgebung_t::soundfont_filename.c_str()); + return false; + } + sfont_id = fluid_synth_sfload(synth, umgebung_t::soundfont_filename.c_str(), 1); + if( sfont_id == FLUID_FAILED ) { + printf("FluidSynth: %s soundfont load failed.\n", umgebung_t::soundfont_filename.c_str()); + return false; + } + printf("FluidSynth: loaded soundfont: %s.\n", umgebung_t::soundfont_filename.c_str()); + + //if all is fine, return true + return true; +} + + +/** + * Sets MIDI playback volume + */ +void dr_set_midi_volume(int vol) +{ + if( fluid_settings_setnum(settings, "synth.gain", 0.8 * vol / 256.0) != 1 ) { + printf("FluidSynth: set volume failed.\n"); + } +} + + +/** + * Checks MIDI file, adds to playlist + */ +int dr_load_midi(const char * filename) +{ + if( midi_number=0 && i do not touch further bool umgebung_t::quit_simutrans = false; Index: dataobj/umgebung.h =================================================================== --- dataobj/umgebung.h (revision 5067) +++ dataobj/umgebung.h (working copy) @@ -287,6 +287,12 @@ static sint16 global_volume, midi_volume; static bool mute_sound, mute_midi, shuffle_midi; + // FluidSynth MIDI parameters +#ifdef USE_FLUIDSYNTH_MIDI + static std::string fluidsynth_driver; + static std::string soundfont_filename; +#endif + static bool left_to_right_graphs; // how to highlight topped (untopped windows) Index: dataobj/einstellungen.cc =================================================================== --- dataobj/einstellungen.cc (revision 5067) +++ dataobj/einstellungen.cc (working copy) @@ -1187,6 +1187,16 @@ // Default pak file path objfilename = ltrim(contents.get_string("pak_file_path", "" ) ); + // FluidSynth MIDI parameters +#ifdef USE_FLUIDSYNTH_MIDI + if( *contents.get("fluidsynth_driver") ) { + umgebung_t::fluidsynth_driver = ltrim(contents.get("fluidsynth_driver")); + } + if( *contents.get("soundfont_filename") ) { + umgebung_t::soundfont_filename = ltrim(contents.get("soundfont_filename")); + } +#endif + printf("Reading simuconf.tab successful!\n" ); simuconf.close( );