public IMidiRenderer GetNewRenderer() { if (!FluidsynthInitialized) { InitializeFluidsynth(); } var soundfontLoader = SoundFontLoader.NewDefaultSoundFontLoader(_settings); soundfontLoader.SetCallbacks(_soundfontLoaderCallbacks); var renderer = new MidiRenderer(_settings, soundfontLoader); // Since the last loaded soundfont takes priority, we load the fallback soundfont first. renderer.LoadSoundfont(FallbackSoundfont); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { foreach (var filepath in LinuxSoundfonts) { if (!File.Exists(filepath) || !SoundFont.IsSoundFont(filepath)) { continue; } try { renderer.LoadSoundfont(filepath, true); } catch (Exception) { continue; } break; } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { if (File.Exists(OSXSoundfont) && SoundFont.IsSoundFont(OSXSoundfont)) { renderer.LoadSoundfont(OSXSoundfont, true); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (File.Exists(WindowsSoundfont) && SoundFont.IsSoundFont(WindowsSoundfont)) { renderer.LoadSoundfont(WindowsSoundfont, true); } } lock (_renderers) _renderers.Add(renderer); return(renderer); }
public IMidiRenderer GetNewRenderer() { if (!FluidsynthInitialized) { InitializeFluidsynth(); if (!FluidsynthInitialized) // init failed { return(null); } } var soundfontLoader = SoundFontLoader.NewDefaultSoundFontLoader(_settings); // Just making double sure these don't get GC'd. // They shouldn't, MidiRenderer keeps a ref, but making sure... var handle = GCHandle.Alloc(soundfontLoader); try { soundfontLoader.SetCallbacks(_soundfontLoaderCallbacks); var renderer = new MidiRenderer(_settings, soundfontLoader); // Since the last loaded soundfont takes priority, we load the fallback soundfont first. renderer.LoadSoundfont(FallbackSoundfont); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { foreach (var filepath in LinuxSoundfonts) { if (!File.Exists(filepath) || !SoundFont.IsSoundFont(filepath)) { continue; } try { renderer.LoadSoundfont(filepath, true); } catch (Exception) { continue; } break; } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { if (File.Exists(OsxSoundfont) && SoundFont.IsSoundFont(OsxSoundfont)) { renderer.LoadSoundfont(OsxSoundfont, true); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (File.Exists(WindowsSoundfont) && SoundFont.IsSoundFont(WindowsSoundfont)) { renderer.LoadSoundfont(WindowsSoundfont, true); } } lock (_renderers) _renderers.Add(renderer); return(renderer); } finally { handle.Free(); } }