private Patch LoadMyPatch(Stream stream, string patchName, string directory) { DescriptorList description; Patch patch; using (StreamReader reader = new StreamReader(stream)) { if (!AssertCorrectVersion(ReadNextLine(reader)).Equals("patch")) { throw new FormatException("Invalid patch version. Current version is: v" + string.Format("{0:0.000}", BankVersion) + " Patch ID: " + patchName); } string patchTypeString = ReadNextLine(reader); Type type; if (patchTypes.TryGetValue(patchTypeString, out type)) { patch = (Patch)Activator.CreateInstance(type, new object[] { patchName }); } else { throw new InvalidDataException("Invalid patch type \"" + patchTypeString + "\"! Patch ID: " + patchName); } description = new DescriptorList(reader); } LoadSampleAssets(patchName, directory, description); patch.Load(description, assets); return(patch); }
private void LoadSampleAssets(string patchName, string directory, DescriptorList description) { for (int x = 0; x < description.GenDescriptions.Length; x++) { if (description.GenDescriptions[x].SamplerType == WaveformEnum.SampleData && !description.GenDescriptions[x].AssetName.Equals("null")) { assets.LoadSampleAsset(description.GenDescriptions[x].AssetName, patchName, directory); } } }
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; }