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 <kode54@gmail.com>
CQTexperiment
Christopher Snowhill 2022-01-26 21:15:07 -08:00
parent fce851bfff
commit 3c35cf1037
2 changed files with 24 additions and 7 deletions

View File

@ -24,6 +24,7 @@ class SFPlayer;
MIDIPlayer* player;
midi_container midi_file;
NSString * globalSoundFontPath;
BOOL soundFontsAssigned;
BOOL isLooped;

View File

@ -175,7 +175,24 @@ static OSType getOSType(const char * in_)
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 (globalSoundFontPath != nil) {
if (sfplayer)
sfplayer->setSoundFont( [soundFontPath UTF8String] );
sfplayer->setSoundFont( [globalSoundFontPath UTF8String] );
else if (auplayer)
auplayer->setSoundFont( [soundFontPath UTF8String] );
auplayer->setSoundFont( [globalSoundFontPath UTF8String] );
}
soundFontsAssigned = YES;
}