Permalink
Browse files

Merge pull request #646 from heftig/master

MIDI/FluidSynth cleanup and fixes
  • Loading branch information...
joncampbell123 committed Apr 5, 2018
2 parents ed0fe35 + 792ae67 commit 6f1b749adc0f42c31686e65061d69f36ab4176ac
Showing with 134 additions and 226 deletions.
  1. +5 −1 src/dosbox.cpp
  2. +39 −34 src/gui/midi.cpp
  3. +90 −191 src/gui/midi_synth.h
@@ -1639,10 +1639,14 @@ void DOSBOX_SetupConfigSections(void) {
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"
" 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"
" In that case, add 'delaysysex', for example: midiconfig=2 delaysysex\n"
" 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->SetMinMax(-1,15);
@@ -614,11 +614,18 @@ bool MIDI_Available(void) {
class MIDI:public Module_base{
public:
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");
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 */
MidiHandler * handler;
bool opened = false;
// MAPPER_AddHandler(MIDI_SaveRawEvent,MK_f8,MMOD1|MMOD2,"caprawmidi","Cap MIDI");
midi.sysex.delay = 0;
midi.sysex.start = 0;
@@ -632,43 +639,41 @@ class MIDI:public Module_base{
midi.status=0x00;
midi.cmd_pos=0;
midi.cmd_len=0;
if (!strcasecmp(dev,"default")) goto getdefault;
handler=handler_list;
while (handler) {
if (!strcasecmp(dev,handler->GetName())) {
#if C_FLUIDSYNTH
if(!strcasecmp(dev,"synth")) // synth device, get sample rate from config
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;
if (strcasecmp(dev,"default")) {
for (handler = handler_list; handler; handler = handler->next) {
if (!strcasecmp(dev,handler->GetName())) {
opened = handler->Open(conf);
break;
}
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:
handler=handler_list;
while (handler) {
if (handler->Open(conf)) {
midi.available=true;
midi.handler=handler;
LOG(LOG_MISC,LOG_DEBUG)("MIDI:Opened device:%s",handler->GetName());
return;
if (!opened) {
for (handler = handler_list; handler; handler = handler->next) {
opened = handler->Open(conf);
if (opened) break;
}
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(){
if( midi.status < 0xf0 ) {
Oops, something went wrong.

0 comments on commit 6f1b749

Please sign in to comment.