private Patch LoadSfzPatch(Stream stream, string patchName, string directory) { SfzReader sfz = new SfzReader(stream, patchName); MultiPatch multi = new MultiPatch(patchName); multi.LoadSfz(sfz.Regions, assets, directory); return(multi); }
private static int LoadSfz(PatchInfo pInfo) { SfzReader sfz; using (FileStream fs = File.Open(patchPath + pInfo.Name, FileMode.Open, FileAccess.Read)) { sfz = new SfzReader(fs, pInfo.Name); } PatchInfo[] pInfos = new PatchInfo[sfz.Regions.Length]; int nameLen = sfz.Name.Length + 1 + sfz.Regions.Length.ToString().Length; if (nameLen > 20) { sfz.Name = sfz.Name.Remove(0, nameLen - 20); } for (int i = 0; i < pInfos.Length; i++) { pInfos[i] = new PatchInfo(sfz.Name + "_" + i, new PatchInterval(-1, 0, 0)); pInfos[i].Type = "sfz "; pInfos[i].Description = new DescriptorList(sfz.Regions[i]); } DescriptorList multiDesc = new DescriptorList(); multiDesc.CustomDescriptions = new CustomDescriptor[sfz.Regions.Length]; for (int i = 0; i < multiDesc.CustomDescriptions.Length; i++) { SfzRegion r = sfz.Regions[i]; multiDesc.CustomDescriptions[i] = new CustomDescriptor("mpat", pInfos[i].Name.Length + 14, new object[] { pInfos[i].Name, r.loChan, r.hiChan, r.loKey, r.hiKey, r.loVel, r.hiVel }); } pInfo.Type = "mult"; pInfo.Description = multiDesc; multiPatches.Add(pInfo); patches.Remove(pInfo); patches.InsertRange(0, pInfos); return(pInfos.Length - 1); }
private void LoadPatchData() { for (int x = 0; x < patches.Count; x++) { switch (Path.GetExtension(patches[x].Name).ToLower()) { case ".patch": using (StreamReader reader = new StreamReader(patchPath + patches[x].Name)) { string str = reader.ReadLine(); if (PatchBank.BankVersion != float.Parse(str.Substring(str.IndexOf("v") + 1))) { throw new Exception("The patch " + patches[x].Name + " has an incorrect version."); } patches[x].Type = reader.ReadLine().Trim().ToLower(); patches[x].Description = new DescriptorList(reader); } if (patches[x].Type.Equals("multi")) { PatchInfo pInfo = patches[x]; patches.RemoveAt(x); x--; multiPatches.Add(pInfo); //load sub patches for (int i = 0; i < pInfo.Description.CustomDescriptions.Length; x++) { if (!pInfo.Description.CustomDescriptions[i].ID.Equals("mpat")) { throw new Exception("Invalid multi patch: " + pInfo.Name); } string subPatchName = (string)pInfo.Description.CustomDescriptions[i].Objects[0]; if (ContainsPatch(subPatchName, patches) == false) { PatchInfo subPatch = new PatchInfo(subPatchName, new PatchInterval(-1, 0, 0)); patches.Add(subPatch); } } } break; case ".sfz": { SfzReader sfz = new SfzReader(patchPath + patches[x].Name); PatchInfo[] pInfos = new PatchInfo[sfz.Regions.Length]; int nameLen = sfz.Name.Length + 1 + sfz.Regions.Length.ToString().Length; if (nameLen > 20) { sfz.Name = sfz.Name.Remove(0, nameLen - 20); } for (int i = 0; i < pInfos.Length; i++) { pInfos[i] = new PatchInfo(sfz.Name + "_" + i, new PatchInterval(-1, 0, 0)); pInfos[i].Type = "sfz "; pInfos[i].Description = new DescriptorList(sfz.Regions[i]); } DescriptorList multiDesc = new DescriptorList(); multiDesc.CustomDescriptions = new CustomDescriptor[sfz.Regions.Length]; for (int i = 0; i < multiDesc.CustomDescriptions.Length; i++) { SfzRegion r = sfz.Regions[i]; multiDesc.CustomDescriptions[i] = new CustomDescriptor("mpat", pInfos[i].Name.Length + 14, new object[] { pInfos[i].Name, r.loChan, r.hiChan, r.loKey, r.hiKey, r.loVel, r.hiVel }); } patches[x].Type = "mult"; patches[x].Description = multiDesc; multiPatches.Add(patches[x]); patches.RemoveAt(x); patches.InsertRange(0, pInfos); x += pInfos.Length - 1; } break; } } }