Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion dataobj/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ bool env_t::player_finance_display_account = true;

// the following initialisation is not important; set values in init()!
std::string env_t::objfilename;
std::string env_t::midi_command = "";
bool env_t::night_shift;
bool env_t::hide_with_transparency;
bool env_t::hide_trees;
Expand Down Expand Up @@ -254,6 +255,7 @@ void env_t::init()
mute_sound = false;
mute_midi = false;
shuffle_midi = true;
midi_command = "";

left_to_right_graphs = false;

Expand Down Expand Up @@ -388,7 +390,20 @@ void env_t::rdwr(loadsave_t *file)
file->rdwr_bool( mute_sound );
file->rdwr_bool( mute_midi );
file->rdwr_bool( shuffle_midi );

/*
* ToDo: Include midi command to settings.xml
* Nov 20, 2019 K.Ohta
*/
/*

if( file->is_version_atleast(120, 4) ) {
plainstring str = midi_command.c_str();
file->rdwr_str( str );
if( file->is_loading() ) {
midi_command = str ? str.c_str() : "";
}
}
*/
if( file->is_version_atleast(102, 2) ) {
file->rdwr_byte( show_vehicle_states );
file->rdwr_bool( left_to_right_graphs );
Expand Down
1 change: 1 addition & 0 deletions dataobj/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ class env_t

static sint16 global_volume, midi_volume;
static bool mute_sound, mute_midi, shuffle_midi;
static std::string midi_command;

/// @}

Expand Down
2 changes: 2 additions & 0 deletions dataobj/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

settings_t::settings_t() :
filename(""),
midi_command(""),
heightfield("")
{
size_x = 256;
Expand Down Expand Up @@ -869,6 +870,7 @@ void settings_t::parse_simuconf(tabfile_t& simuconf, sint16& disp_width, sint16&
env_t::fontname = fname;
}

env_t::midi_command = contents.get_string( "midi_command", env_t::midi_command.c_str());
env_t::water_animation = contents.get_int("water_animation_ms", env_t::water_animation );
env_t::ground_object_probability = contents.get_int("random_grounds_probability", env_t::ground_object_probability );
env_t::moving_object_probability = contents.get_int("random_wildlife_probability", env_t::moving_object_probability );
Expand Down
4 changes: 4 additions & 0 deletions dataobj/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class settings_t
sint16 bits_per_month;

std::string filename;
std::string midi_command;

bool beginner_mode;
sint32 beginner_price_factor;
Expand Down Expand Up @@ -428,6 +429,9 @@ class settings_t
void set_filename(const char *n) {filename=n;} // prissi, Jun-06
const char* get_filename() const { return filename.c_str(); }

void set_midi_command(const char *n) {midi_command = n;} // K.Ohta Nov-19
const char *get_midi_command() const { return midi_command.c_str(); }

bool get_beginner_mode() const {return beginner_mode;}

void set_just_in_time(uint8 b) { just_in_time = b; }
Expand Down
33 changes: 32 additions & 1 deletion music/sdl_midi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

#include "../simdebug.h"
#include "../utils/plainstring.h"
#include "../dataobj/environment.h"
#include "../dataobj/settings.h"
#include "music.h"

static int midi_number = -1;
static plainstring midi_filenames[MAX_MIDI];
static char *ext_cmd_name = NULL;

//Mix_Music *music[MAX_MIDI];
Mix_Music *music = NULL;
Expand Down Expand Up @@ -65,7 +68,16 @@ void dr_play_midi(int key)
dr_stop_midi();
}
music = Mix_LoadMUS(midi_filenames[key]);
Mix_PlayMusic(music, 1);
/*
* If error on loading MIDI with external CMD, use internal MIDI decoder.
*/
if( Mix_PlayMusic(music, 1) != 0 && ext_cmd_name != NULL) {
Mix_SetMusicCMD(NULL);
dbg->warning( "dr_play_midi()", "Failed to execute external MIDI PLAYER because %s, using fallback internal player.", ext_cmd_name, Mix_GetError() );
ext_cmd_name = NULL;
music = Mix_LoadMUS(midi_filenames[key]);
Mix_PlayMusic(music, 1);
}
}


Expand Down Expand Up @@ -130,5 +142,24 @@ bool dr_init_midi(void)
}
}
//if all is fine, return true
const char *arg_midi_cmd = env_t::default_settings.get_midi_command();
if(arg_midi_cmd != NULL) {
if(strlen(arg_midi_cmd) > 0) {
if(Mix_SetMusicCMD(arg_midi_cmd) != -1) {
ext_cmd_name = (char *)arg_midi_cmd;
}
}
}
if(ext_cmd_name == NULL) {
ext_cmd_name = SDL_getenv((const char *)"SIMUTRANS_MIDI_CMD");
}
if(ext_cmd_name != NULL && strlen(ext_cmd_name) > 0) {
if(Mix_SetMusicCMD(ext_cmd_name) == 0) {
DBG_MESSAGE("simmain", "Using \"%s\" instead of internal player.\n", ext_cmd_name);
return true;
}
} else {
Mix_SetMusicCMD(NULL);
}
return true;
}
6 changes: 5 additions & 1 deletion simmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ int simu_main(int argc, char** argv)
" -mute mute all sounds\n"
" -noaddons does not load any addon (default)\n"
" -nomidi turns off background music\n"
" -midicmd COMMAND set external midi command.(default environment variable SIMUTRANS_MIDI_CMD)\n"
" -nosound turns off ambient sounds\n"
" -objects DIR_NAME/ load the pakset in specified directory\n"
" -pause starts game with paused after loading\n"
Expand Down Expand Up @@ -978,7 +979,10 @@ int simu_main(int argc, char** argv)
env_t::default_settings.set_with_private_paks( false );
}
}

// Set external midi command.
if(const char * midi_cmd = gimme_arg(argc, argv, "-midicmd", 1) ) {
env_t::default_settings.set_midi_command( midi_cmd );
}
// parse ~/simutrans/pakxyz/config.tab"
if( env_t::default_settings.get_with_private_paks() ) {
obj_conf = string(env_t::user_dir) + "addons/" + env_t::objfilename + "config/simuconf.tab";
Expand Down