/// <summary> /// Load Simplified SoundFont from OS (edit mode) /// </summary> /// <param name="soundPath"></param> /// <param name="soundFontName"></param> public static void LoadImSF(string soundPath = null, string soundFontName = null) { try { if (soundPath == null || soundFontName == null) //Load active SF { if (MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo != null) { soundPath = Path.Combine(Application.dataPath + "/", MidiPlayerGlobal.PathToSoundfonts); soundPath = Path.Combine(soundPath + "/", MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name); soundFontName = MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.Name; } } if (soundPath != null && soundFontName != null) { Debug.Log("SoundFont loading " + soundFontName); MidiPlayerGlobal.ImSFCurrent = ImSoundFont.Load(soundPath, soundFontName); MidiPlayerGlobal.ImSFCurrent.CreateBankDescription(); MidiPlayerGlobal.BuildPresetList(); MidiPlayerGlobal.BuildDrumList(); } else { Debug.Log("LoadImSF : no sf defined"); } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
//! @cond NODOC /// <summary> /// Core function to load a SF when playing or from editor from the Unity asset /// </summary> public static void LoadCurrentSF() { MPTK_SoundFontLoaded = false; // Load simplfied soundfont try { DateTime start = DateTime.Now; if (CurrentMidiSet == null) { Debug.Log(MidiPlayerGlobal.ErrorNoSoundFont); } else { SoundFontInfo sfi = CurrentMidiSet.ActiveSounFontInfo; if (sfi == null) { Debug.Log(MidiPlayerGlobal.ErrorNoSoundFont); } else { //Debug.Log("Start loading " + sfi.Name); // Path to the soundfonts directory for this SF, start from resource folder string pathToImSF = Path.Combine(SoundfontsDB + "/", sfi.Name); WavePath = Path.Combine(pathToImSF + "/", PathToWave); // Load all presets defined in the sf ImSFCurrent = ImSoundFont.Load(pathToImSF, sfi.Name); // Add if (ImSFCurrent == null) { Debug.LogWarning("Error loading " + sfi.Name ?? "name not defined"); } else { BuildBankList(); BuildPresetList(true); BuildPresetList(false); //BuildDrumList(); timeToLoadSoundFont = DateTime.Now - start; //Debug.Log("End loading SoundFont " + timeToLoadSoundFont.TotalSeconds + " seconds"); } } } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } if (ImSFCurrent == null) { Debug.LogWarning("SoundFont not loaded."); return; } // Load samples only in run mode if (Application.isPlaying) { try { MPTK_CountWaveLoaded = 0; System.Diagnostics.Stopwatch watchLoadWave = new System.Diagnostics.Stopwatch(); // High resolution time watchLoadWave.Start(); if (MPTK_LoadWaveAtStartup) { LoadAudioClip(); } LoadWave(); timeToLoadWave = watchLoadWave.Elapsed; //Debug.Log("End loading Waves " + timeToLoadWave.TotalSeconds + " seconds" + " count:" + MPTK_CountWaveLoaded); } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } } if (ImSFCurrent != null) { MPTK_SoundFontLoaded = true; } if (OnEventPresetLoaded != null) { OnEventPresetLoaded.Invoke(); } }
public static void LoadCurrentSF() { // Load simplfied soundfont try { DateTime start = DateTime.Now; if (CurrentMidiSet == null) { Debug.LogWarning("No SoundFont defined, go to Unity menu Tools to add a Soundfont"); } else { SoundFontInfo sfi = CurrentMidiSet.ActiveSounFontInfo; if (sfi == null) { Debug.LogWarning("No SoundFont defined, go to Unity menu Tools to add a Soundfont"); } else { // Path to the soundfonts directory for this SF, start from resource folder string pathToImSF = Path.Combine(SoundfontsDB + "/", sfi.Name); // Path to the soundfonts file for this SF TextAsset sf = Resources.Load <TextAsset>(Path.Combine(pathToImSF + "/", sfi.Name)); if (sf == null) { Debug.LogWarning("No SoundFont found " + pathToImSF); } else { WavePath = Path.Combine(pathToImSF + "/", PathToWave); // Load all presets defined in the XML sf ImSFCurrent = ImSoundFont.Load(sf.text); timeToLoadSoundFont = DateTime.Now - start; BuildPresetList(); BuildDrumList(); } } } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } if (ImSFCurrent == null) { Debug.LogWarning("SoundFont not loaded."); return; } // Load samples only in run mode if (Application.isPlaying) { try { MPTK_CountWaveLoaded = 0; MPTK_CountPresetLoaded = 0; DateTime start = DateTime.Now; for (int ibank = 0; ibank < ImSFCurrent.Banks.Length; ibank++) { if (ImSFCurrent.Banks[ibank] != null) { for (int ipreset = 0; ipreset < ImSFCurrent.Banks[ibank].Presets.Length; ipreset++) { MPTK_CountPresetLoaded++; if (ImSFCurrent.Banks[ibank].Presets[ipreset] != null) { LoadSamples(ibank, ipreset); } } } } timeToLoadWave = DateTime.Now - start; } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } } if (OnEventPresetLoaded != null) { OnEventPresetLoaded.Invoke(); } }