From 3c35cf103711a22598dc26bac8c4cbe2df1394a0 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Wed, 26 Jan 2022 21:15:07 -0800 Subject: [PATCH] MIDI Input: Fall back to system DLS Synth If there's no configured SoundFont bank, or if the selected bank has gone missing, and the user has configured the player to use the FluidSynth driver, fall back to the system DLS Synthesizer, which has its own Roland bank to fall back on if unconfigured. Also, whether falling back, or already on an AU synthesizer, don't fail if there's no bank configured or found. DLS doesn't explicitly require a bank, and most other synthesizers of interest would not require a bank either. Signed-off-by: Christopher Snowhill --- Plugins/MIDI/MIDI/MIDIDecoder.h | 1 + Plugins/MIDI/MIDI/MIDIDecoder.mm | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Plugins/MIDI/MIDI/MIDIDecoder.h b/Plugins/MIDI/MIDI/MIDIDecoder.h index d45bf2585..a709e09c7 100755 --- a/Plugins/MIDI/MIDI/MIDIDecoder.h +++ b/Plugins/MIDI/MIDI/MIDIDecoder.h @@ -24,6 +24,7 @@ class SFPlayer; MIDIPlayer* player; midi_container midi_file; + NSString * globalSoundFontPath; BOOL soundFontsAssigned; BOOL isLooped; diff --git a/Plugins/MIDI/MIDI/MIDIDecoder.mm b/Plugins/MIDI/MIDI/MIDIDecoder.mm index fd26a10dc..af7541669 100755 --- a/Plugins/MIDI/MIDI/MIDIDecoder.mm +++ b/Plugins/MIDI/MIDI/MIDIDecoder.mm @@ -174,8 +174,25 @@ static OSType getOSType(const char * in_) mode = MIDIPlayer::filter_sc8850; else if ([flavor isEqualToString:@"xg"]) mode = MIDIPlayer::filter_xg; + + globalSoundFontPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"soundFontPath"]; + + // First detect if soundfont has gone AWOL + if (![[NSFileManager defaultManager] fileExistsAtPath:globalSoundFontPath]) { + globalSoundFontPath = nil; + [[NSUserDefaults standardUserDefaults] setValue:globalSoundFontPath forKey:@"soundFontPath"]; + } NSString * plugin = [[NSUserDefaults standardUserDefaults] stringForKey:@"midi.plugin"]; + + // Then detect if we should force the DLSMusicSynth, which has its own bank + if (!plugin || [plugin isEqualToString:@"FluidSynth"]) { + if (!globalSoundFontPath || [globalSoundFontPath isEqualToString:@""]) { + plugin = @"dls appl"; // Apple DLSMusicSynth if soundfont doesn't exist + [[NSUserDefaults standardUserDefaults] setValue:plugin forKey:@"midi.plugin"]; + } + } + if (!plugin || [plugin isEqualToString:@"FluidSynth"]) { sfplayer = new SFPlayer; @@ -277,14 +294,13 @@ static OSType getOSType(const char * in_) return 0; if ( (sfplayer||auplayer) && !soundFontsAssigned ) { - NSString * soundFontPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"soundFontPath"]; - if (soundFontPath == nil) - return 0; - if (sfplayer) - sfplayer->setSoundFont( [soundFontPath UTF8String] ); - else if (auplayer) - auplayer->setSoundFont( [soundFontPath UTF8String] ); + if (globalSoundFontPath != nil) { + if (sfplayer) + sfplayer->setSoundFont( [globalSoundFontPath UTF8String] ); + else if (auplayer) + auplayer->setSoundFont( [globalSoundFontPath UTF8String] ); + } soundFontsAssigned = YES; }