/// <summary> /// Replace drumkits. /// </summary> /// <param name="changes"></param> public override void ReplaceDrumKit(Dictionary <IDrumKit, IDrumKit> changes) { dynamic param = GetParam(ParameterNames.ProgramParameterName.OscMode).Value; // Only the first MS is used. if ((param == "Drums") || (param == "Double Drums")) { IDrumKit usedDrumKit = GetUsedDrumKit(0, 0); foreach (IDrumKit drumKit in changes.Keys.Where(drumKit => drumKit.Id == usedDrumKit.Id)) { SetUsedDrumKit(0, 0, changes[drumKit]); } } if (param == "Double Drums") { IDrumKit usedDrumKit = GetUsedDrumKit(1, 0); foreach (IDrumKit drumKit in changes.Keys.Where(drumKit => drumKit.Id == usedDrumKit.Id)) { SetUsedDrumKit(1, 0, changes[drumKit]); } } RaisePropertyChanged("ToolTip"); }
/// <summary> /// Returns the index from the drum kit. -1 if not found. /// </summary> /// <param name="drumKit"></param> /// <returns></returns> public int FindIndexOf(IDrumKit drumKit) { int foundIndex = 0; if (BankCollection == null) { return(-1); } foreach (IBank bank in BankCollection) { if (!bank.IsLoaded && !bank.IsFromMasterFile) { return(-1); } foreach (IPatch drumKitInBank in bank.Patches) { if (drumKitInBank == drumKit) { return(foundIndex); } foundIndex++; } } return(-1); }
/// <summary> /// /// </summary> /// <param name="drumKit"></param> /// <param name="clipBoardProgram"></param> public void CopyDrumKitOfProgramToClipBoard(IDrumKit drumKit, IClipBoardProgram clipBoardProgram) { IClipBoardDrumKit clipBoardDrumKitToAdd = FindDrumKit(drumKit) ?? CopyDrumKitToClipBoard(drumKit, false); clipBoardProgram.ReferencedDrumKits.CopiedPatches.Add(clipBoardDrumKitToAdd); }
/// <summary> /// /// </summary> /// <param name="drumKit"></param> public ClipBoardDrumKit(IDrumKit drumKit) : base(drumKit.PcgRoot.Content, drumKit.ByteOffset, drumKit.ByteLength) { OriginalLocation = drumKit; PcgMemory memory = drumKit.Root as PcgMemory; if ((memory != null) && (memory.PcgRoot.Model.OsVersion == Models.EOsVersion.Kronos15_16)) { KronosOs1516Bank = Util.GetInt(memory.Content, ((KronosDrumKit)drumKit).Drk2BankOffset, 1); KronosOs1516Patch = Util.GetInt(memory.Content, ((KronosDrumKit)drumKit).Drk2PatchOffset, 1); } }
/// <summary> /// Sets used drum kit. /// </summary> /// <param name="osc"></param> /// <param name="zone"></param> /// <param name="drumKit"></param> /// <returns></returns> private void SetUsedDrumKit(int osc, int zone, IDrumKit drumKit) { IntParameter parameter = new IntParameter(); parameter.SetMultiBytes(Root, Root.Content, GetZoneMsByteOffset(osc, zone) + 2, 2, // + 2: Number (bank unused, alwyas 0?) false, false, null); int index = PcgRoot.DrumKitBanks.FindIndexOf(drumKit); if (index >= 0) { parameter.Value = index; } }
/// <summary> /// Returns the drum kit used by osc (zero based) and MS zone (zero based). /// </summary> /// <param name="osc"></param> /// <param name="zone"></param> /// <returns></returns> protected IDrumKit GetUsedDrumKit(int osc, int zone) { IntParameter parameter = new IntParameter(); parameter.SetMultiBytes(Root, Root.Content, GetZoneMsByteOffset(osc, zone) + 2, 2, // + 2: Number (bank unused, always 0?) false, false, null); int index = parameter.Value; IDrumKit drumKit = null; if (PcgRoot.DrumKitBanks != null) { drumKit = PcgRoot.DrumKitBanks.GetByIndex(index); } return(drumKit); }
/// <summary> /// /// </summary> /// <param name="drumKit"></param> /// <param name="clearAfterCopy"></param> public IClipBoardDrumKit CopyDrumKitToClipBoard(IDrumKit drumKit, bool clearAfterCopy) { if ((drumKit == null) || !((IBank)drumKit.Parent).IsLoaded) { return(null); } var clipBoardDrumKit = new ClipBoardDrumKit(drumKit); DrumKits.CopiedPatches.Add(clipBoardDrumKit); if (clearAfterCopy) { drumKit.Clear(); } return(clipBoardDrumKit); }
/// <summary> /// /// </summary> /// <param name="patchToPaste"></param> /// <param name="patch"></param> public void PastePatch(IClipBoardPatch patchToPaste, IPatch patch) { // Copy patch from clipboard to PCG. patch.PcgRoot.CopyPatch(patchToPaste, patch); patchToPaste.PasteDestination = patch; ProtectedPatches.Add(patch); if (CutPasteSelected) { IProgram program = patch as IProgram; if (program != null) { FixReferencesToProgram(patchToPaste, program); } else { ICombi combi = patch as ICombi; if (combi != null) { FixReferencesToCombi(patchToPaste, combi); } else { IDrumKit drumKit = patch as IDrumKit; if (drumKit != null) { FixReferencesToDrumKit(patchToPaste, drumKit); } else { IDrumPattern drumPattern = patch as IDrumPattern; if (drumPattern != null) { FixReferencesToDrumPattern(patchToPaste, drumPattern); } } } } // If it is a set list slot do nothing. } }
/// <summary> /// Changes all references of the original location of patch to drum kit. /// Only used for cut/paste. /// </summary> /// <param name="patchToPaste"></param> /// <param name="drumKit"></param> private static void FixReferencesToDrumKit(IClipBoardPatch patchToPaste, IDrumKit drumKit) { var memory = patchToPaste.OriginalLocation.Root as IPcgMemory; Debug.Assert(memory != null); // Change programs (if present and not from master file). if (memory.ProgramBanks != null) { foreach (var programBank in memory.ProgramBanks.BankCollection.Where( bank => bank.IsWritable && !bank.IsFromMasterFile)) { foreach (var program in programBank.Patches) { var changes = new Dictionary <IDrumKit, IDrumKit> { { (IDrumKit)(patchToPaste.OriginalLocation), drumKit } }; ((IProgram)program).ReplaceDrumKit(changes); } } } }