Skip to content

Commit

Permalink
Merge pull request #646 from heftig/master
Browse files Browse the repository at this point in the history
MIDI/FluidSynth cleanup and fixes
  • Loading branch information
joncampbell123 committed Apr 5, 2018
2 parents ed0fe35 + 792ae67 commit 6f1b749
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 226 deletions.
6 changes: 5 additions & 1 deletion src/dosbox.cpp
Expand Up @@ -1639,10 +1639,14 @@ void DOSBOX_SetupConfigSections(void) {


Pstring = secprop->Add_string("midiconfig",Property::Changeable::WhenIdle,""); Pstring = secprop->Add_string("midiconfig",Property::Changeable::WhenIdle,"");
Pstring->Set_help("Special configuration options for the device driver. This is usually the id of the device you want to use.\n" Pstring->Set_help("Special configuration options for the device driver. This is usually the id of the device you want to use.\n"
" or in the case of coreaudio, you can specify a soundfont here.\n" " or in the case of coreaudio or synth, you can specify a soundfont here.\n"
" When using a Roland MT-32 rev. 0 as midi output device, some games may require a delay in order to prevent 'buffer overflow' issues.\n" " When using a Roland MT-32 rev. 0 as midi output device, some games may require a delay in order to prevent 'buffer overflow' issues.\n"
" In that case, add 'delaysysex', for example: midiconfig=2 delaysysex\n" " In that case, add 'delaysysex', for example: midiconfig=2 delaysysex\n"
" See the README/Manual for more details."); " See the README/Manual for more details.");

Pint = secprop->Add_int("samplerate",Property::Changeable::WhenIdle,44100);
Pint->Set_values(rates);
Pint->Set_help("Sample rate for MIDI synthesizer, if applicable.");


Pint = secprop->Add_int("mpuirq",Property::Changeable::WhenIdle,-1); Pint = secprop->Add_int("mpuirq",Property::Changeable::WhenIdle,-1);
Pint->SetMinMax(-1,15); Pint->SetMinMax(-1,15);
Expand Down
73 changes: 39 additions & 34 deletions src/gui/midi.cpp
Expand Up @@ -614,11 +614,18 @@ bool MIDI_Available(void) {
class MIDI:public Module_base{ class MIDI:public Module_base{
public: public:
MIDI(Section* configuration):Module_base(configuration){ MIDI(Section* configuration):Module_base(configuration){
Section_prop * section=static_cast<Section_prop *>(configuration); Section_prop * section = static_cast<Section_prop *>(configuration);
const char * dev=section->Get_string("mididevice"); const char * dev=section->Get_string("mididevice");
std::string fullconf=section->Get_string("midiconfig"); std::string fullconf = section->Get_string("midiconfig");
#if C_FLUIDSYNTH
synthsamplerate = section->Get_int("samplerate");
if (synthsamplerate == 0) synthsamplerate = 44100;
#endif

/* If device = "default" go for first handler that works */ /* If device = "default" go for first handler that works */
MidiHandler * handler; MidiHandler * handler;
bool opened = false;

// MAPPER_AddHandler(MIDI_SaveRawEvent,MK_f8,MMOD1|MMOD2,"caprawmidi","Cap MIDI"); // MAPPER_AddHandler(MIDI_SaveRawEvent,MK_f8,MMOD1|MMOD2,"caprawmidi","Cap MIDI");
midi.sysex.delay = 0; midi.sysex.delay = 0;
midi.sysex.start = 0; midi.sysex.start = 0;
Expand All @@ -632,43 +639,41 @@ class MIDI:public Module_base{
midi.status=0x00; midi.status=0x00;
midi.cmd_pos=0; midi.cmd_pos=0;
midi.cmd_len=0; midi.cmd_len=0;
if (!strcasecmp(dev,"default")) goto getdefault;
handler=handler_list; if (strcasecmp(dev,"default")) {
while (handler) { for (handler = handler_list; handler; handler = handler->next) {
if (!strcasecmp(dev,handler->GetName())) { if (!strcasecmp(dev,handler->GetName())) {
#if C_FLUIDSYNTH opened = handler->Open(conf);
if(!strcasecmp(dev,"synth")) // synth device, get sample rate from config break;
synthsamplerate=section->Get_int("samplerate");
#endif
if (!handler->Open(conf)) {
LOG(LOG_MISC,LOG_WARN)("MIDI:Can't open device:%s with config:%s.",dev,conf);
goto getdefault;
} }
midi.handler=handler;
midi.available=true;
LOG(LOG_MISC,LOG_DEBUG)("MIDI:Opened device:%s",handler->GetName());

// force reset to prevent crashes (when not properly shutdown)
// ex. Roland VSC = unexpected hard system crash
midi_state[0].init = false;
MIDI_State_LoadMessage();
return;
} }
handler=handler->next; if (handler == NULL)
LOG(LOG_MISC,LOG_DEBUG)("MIDI:Can't find device:%s, finding default handler.",dev);
else if (!opened)
LOG(LOG_MISC,LOG_WARN)("MIDI:Can't open device:%s with config:%s.",dev,conf);
} }
LOG(LOG_MISC,LOG_DEBUG)("MIDI:Can't find device:%s, finding default handler.",dev);
getdefault: if (!opened) {
handler=handler_list; for (handler = handler_list; handler; handler = handler->next) {
while (handler) { opened = handler->Open(conf);
if (handler->Open(conf)) { if (opened) break;
midi.available=true;
midi.handler=handler;
LOG(LOG_MISC,LOG_DEBUG)("MIDI:Opened device:%s",handler->GetName());
return;
} }
handler=handler->next;
} }
/* This shouldn't be possible */
if (!opened) {
// This shouldn't be possible
LOG(LOG_MISC,LOG_WARN)("MIDI:Couldn't open a handler");
return;
}

midi.available=true;
midi.handler=handler;
LOG(LOG_MISC,LOG_DEBUG)("MIDI:Opened device:%s",handler->GetName());

// force reset to prevent crashes (when not properly shutdown)
// ex. Roland VSC = unexpected hard system crash
midi_state[0].init = false;
MIDI_State_LoadMessage();
} }
~MIDI(){ ~MIDI(){
if( midi.status < 0xf0 ) { if( midi.status < 0xf0 ) {
Expand Down

0 comments on commit 6f1b749

Please sign in to comment.