public static List <ImSample> GetImMultiSample(int idxbank, int idxpreset, int key, int vel) { List <ImSample> samples = new List <ImSample>(); try { if (ImSFCurrent.Banks[idxbank] != null) { ImPreset preset = ImSFCurrent.Banks[idxbank].Presets[idxpreset]; if (preset != null && preset.Instruments != null) { foreach (ImInstrument instrument in preset.Instruments) { if (!instrument.HasKey || (key >= instrument.KeyStart && key <= instrument.KeyEnd)) { if (!instrument.HasVel || (vel >= instrument.VelStart && vel <= instrument.VelEnd)) { foreach (ImSample sample in instrument.Samples) { if (sample.WaveFile != null) { if (!sample.HasKey || (key >= sample.KeyStart && key <= sample.KeyEnd)) { if (!sample.HasVel || (vel >= sample.VelStart && vel <= sample.VelEnd)) { samples.Add(sample); if (!MidiPlayerGlobal.CurrentMidiSet.ActiveSounFontInfo.MultiWaves) { return(samples); } } } } } } } } } } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } return(samples); }
/// <summary> /// Load samples associated to a patch /// </summary> /// <param name="ibank"></param> /// <param name="ipatch"></param> private static void LoadSamples(int ibank, int ipatch) { try { float start = Time.realtimeSinceStartup; //Debug.Log(">>> Load Preset - b:" + ibank + " p:" + ipatch); if (ImSFCurrent != null) { ImPreset preset = ImSFCurrent.Banks[ibank].Presets[ipatch]; //Debug.Log("Loading Preset - " + index + " '" + preset.Name + "'"); // Load each sample associated with this preset in DicAudioClip foreach (ImInstrument inst in preset.Instruments) { foreach (ImSample smpl in inst.Samples) { if (smpl.WaveFile != null) { if (!DicAudioClip.Exist(smpl.WaveFile)) { AudioClip ac = Resources.Load <AudioClip>(WavePath + "/" + Path.GetFileNameWithoutExtension(smpl.WaveFile)); if (ac != null) { DicAudioClip.Add(smpl.WaveFile, ac); MPTK_CountWaveLoaded++; } //else Debug.LogWarning("Wave " + smpl.WaveFile + " not found"); } } } } //Debug.Log("--- Loaded Preset - " + ipatch + " '" + preset.Name + "' " + count + " samples loaded"); } else { Debug.Log("Presets not loaded "); } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
static public void SfOptim(List <PatchOptim> filters) { try { if (MidiPlayerGlobal.ImSFCurrent != null) { for (int b = 0; b < MidiPlayerGlobal.ImSFCurrent.Banks.Length; b++) { ImBank bank = MidiPlayerGlobal.ImSFCurrent.Banks[b]; if (bank != null) { for (int p = 0; p < bank.Presets.Length; p++) { ImPreset preset = bank.Presets[p]; if (preset != null) { bool found = false; foreach (PatchOptim optim in filters) { if (b == optim.Bank && p == optim.Patch && optim.Selected) { found = true; break; } } if (!found) { bank.Presets[p] = null; } } } } } } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } }
/// <summary> /// Return sample to play according preset, key and velocity /// </summary> /// <param name="idxbank"></param> /// <param name="idxpreset"></param> /// <param name="key"></param> /// <param name="vel"></param> /// <returns></returns> public static ImSample GetImSample(int idxbank, int idxpreset, int key, int vel) { try { if (ImSFCurrent.Banks[idxbank] != null) { ImPreset preset = ImSFCurrent.Banks[idxbank].Presets[idxpreset]; if (preset != null && preset.Instruments != null) { foreach (ImInstrument instrument in preset.Instruments) { if (!instrument.HasKey || (key >= instrument.KeyStart && key <= instrument.KeyEnd)) { if (!instrument.HasVel || (vel >= instrument.VelStart && vel <= instrument.VelEnd)) { foreach (ImSample sample in instrument.Samples) { if (sample.WaveFile != null) { if (!sample.HasKey || (key >= sample.KeyStart && key <= sample.KeyEnd)) { if (!sample.HasVel || (vel >= sample.VelStart && vel <= sample.VelEnd)) { return(sample); } } } } } } } } } } catch (System.Exception ex) { MidiPlayerGlobal.ErrorDetail(ex); } return(null); }