/// <summary> /// /// </summary> /// <param name="patch"></param> /// <param name="atLeastOnePatchIsPasted">Or-s the value with True if the patch is pasted</param> /// <returns></returns> bool PasteToSelectedPatch(IPatch patch, ref bool atLeastOnePatchIsPasted) { if ((patch.IsEmptyOrInit || (PcgClipBoard.PastePcgMemory == SelectedPcgMemory)) && !PcgClipBoard.ProtectedPatches.Contains(patch)) { IClipBoardPatches clipBoardPatches = null; var overwriteAllowed = CheckOverwriteallowedForPatches(patch, ref clipBoardPatches); IClipBoardPatch clipBoardPatchToPaste = null; if (clipBoardPatches != null) // Can happen when not allowed to overwrite { clipBoardPatchToPaste = PcgClipBoard.GetFirstPatchToPaste(clipBoardPatches.CopiedPatches); } if (clipBoardPatchToPaste == null) { if (overwriteAllowed) { return(false); // Finished pasting (this kind of patches) } } else { atLeastOnePatchIsPasted = true; PcgClipBoard.PastePatch(clipBoardPatchToPaste, patch); } } return(true); }
/// <summary> /// 3b. Search for a like named patch if Like Named Patches is selected, on same location. /// </summary> /// <param name="clipBoardPatch"></param> /// <param name="bank"></param> /// <param name="sameLocationPatch"></param> /// <returns></returns> private bool SearchLikeNamedPatch(IClipBoardPatch clipBoardPatch, IBank bank, IPatch sameLocationPatch) { if (Settings.Default.CopyPaste_PatchDuplicationName == (int)CopyPaste.PatchDuplication.LikeNamedNames) { if (sameLocationPatch != null) { if (sameLocationPatch.IsNameLike(clipBoardPatch.OriginalLocation.Name)) { clipBoardPatch.PasteDestination = sameLocationPatch; PcgClipBoard.ProtectedPatches.Add(sameLocationPatch); return(true); } } // 2b. Search for an identical name patch, on first occurence. foreach (var patch in bank.Patches.Where( patch => patch.IsNameLike(clipBoardPatch.OriginalLocation.Name))) { clipBoardPatch.PasteDestination = patch; PcgClipBoard.ProtectedPatches.Add(patch); return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="clipBoardPatches"></param> private void FixPasteProgramReferencesInCombis(IEnumerable <IClipBoardPatch> clipBoardPatches) { foreach (IClipBoardPatch program in clipBoardPatches) { foreach (IClipBoardPatch clipBoardPatch in Combis.CopiedPatches) { IClipBoardCombi combi = (IClipBoardCombi)clipBoardPatch; for (int timbreIndex = 0; timbreIndex < combi.References.CopiedPatches.Count; timbreIndex++) { IClipBoardPatch timbre = combi.References.CopiedPatches[timbreIndex]; if (timbre != program) { continue; } // Program used by timbre in combi. if ((program.PasteDestination != null) && (combi.PasteDestination != null)) { // When pasting to the same file, then it is not wanted to fix references, // because a duplicate program/combi can exist before the original reference // so it will be changed unnecessarily. if (program.OriginalLocation.Root != PastePcgMemory) { ((ICombi)(combi.PasteDestination)).Timbres.TimbresCollection[timbreIndex].UsedProgram = (IProgram)program.PasteDestination; } combi.References.CopiedPatches[timbreIndex] = null; // Prevent fixing it again } } } } }
/// <summary> /// 1 First search for bytewise duplicate patch, if found -> don't paste. /// 2 Than and if 'Equally Named Patches' is selected, search for an equally named patch and reference to that. /// 3 Otherwise, if 'Like-Named Pathces' is selected, remove the ignore characters and find a like-named patch and /// reference to that. /// For all searches above, if a patch is found on the same location (a), prefer that, otherwise find the first occurence (b). /// </summary> /// <param name="clipBoardPatch"></param> /// <param name="bank"></param> /// <returns>True if a duplicate is found.</returns> private bool CheckForDuplicate(IClipBoardPatch clipBoardPatch, IBank bank) { Debug.Assert(!(clipBoardPatch is IClipBoardSetListSlot)); // If the source patch is present in the source PCG file, check if it is present in the target PCG. if (clipBoardPatch.Data.Length != 0) { IPatch sameLocationPatch; if (SearchByteWiseEqualPatchSameLocation(clipBoardPatch, bank, out sameLocationPatch)) { return(true); } if (SearchByteWiseEqualPatchFirstOccurence(clipBoardPatch, bank)) { return(true); } if (SearchIdenticalNamePatch(clipBoardPatch, bank, sameLocationPatch)) { return(true); } if (SearchLikeNamedPatch(clipBoardPatch, bank, sameLocationPatch)) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="otherPatch"></param> /// <param name="includingName"></param> /// <param name="maxDiffs"></param> /// <returns></returns> public virtual int CalcByteDifferences(IClipBoardPatch otherPatch, bool includingName, int maxDiffs) { var patchSize = ByteLength; Debug.Assert(patchSize == otherPatch.Data.Length); var diffs = 0; var startIndex = includingName ? 0 : MaxNameLength; for (var index = startIndex; index < patchSize; index++) { if (UseIndexForDifferencing(index)) { if (PcgRoot.Content[ByteOffset + index] != otherPatch.Data[index]) { diffs++; } if (diffs > maxDiffs) { break; } } } return(diffs); }
/// <summary> /// Changes all references of the original location of patch to program. /// Only used for cut/paste. /// </summary> /// <param name="patch"></param> /// <param name="program"></param> static void FixReferencesToProgram(IClipBoardPatch patch, IProgram program) { var memory = patch.OriginalLocation.Root as IPcgMemory; Debug.Assert(memory != null); FixProgramReferencesToCombi(patch, program, memory); FixProgramReferencesToSetLists(patch, program, memory); }
/// <summary> /// 1b. Search for a bytewise equal patch, on first occurence. /// </summary> /// <param name="clipBoardPatch"></param> /// <param name="bank"></param> /// <returns></returns> private bool SearchByteWiseEqualPatchFirstOccurence(IClipBoardPatch clipBoardPatch, IBank bank) { foreach (var patch in bank.Patches.Where(patch => patch.CalcByteDifferences(clipBoardPatch, true, 1) == 0)) { clipBoardPatch.PasteDestination = patch; PcgClipBoard.ProtectedPatches.Add(patch); return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="otherPatch"></param> /// <param name="includingName"></param> /// <param name="maxDiffs"></param> /// <returns></returns> public override int CalcByteDifferences(IClipBoardPatch otherPatch, bool includingName, int maxDiffs) { ClipBoardProgram otherProgram = otherPatch as ClipBoardProgram; Debug.Assert(otherProgram != null); int diffs = base.CalcByteDifferences(otherPatch, includingName, maxDiffs); return(diffs); }
/// <summary> /// /// </summary> /// <param name="otherPatch"></param> /// <param name="includingName"></param> /// <param name="maxDiffs"></param> /// <returns></returns> public override int CalcByteDifferences(IClipBoardPatch otherPatch, bool includingName, int maxDiffs) { ClipBoardSetListSlot otherSetListSlot = otherPatch as ClipBoardSetListSlot; Debug.Assert(otherSetListSlot != null); int diffs = base.CalcByteDifferences(otherPatch, includingName, maxDiffs); return(diffs); }
/// <summary> /// Returns the patch on the same location (if existing). /// </summary> /// <param name="clipBoardPatch"></param> /// <param name="bank"></param> /// <returns></returns> private static IPatch GetPatchOnSameLocation(IClipBoardPatch clipBoardPatch, IBank bank) { // Check if banks are equal. if (((IBank)(clipBoardPatch.OriginalLocation.Parent)).Id != (bank).Id) { return(null); } // Get same index. var index = clipBoardPatch.OriginalLocation.Index; return(bank.Patches.Count > index ? bank[index] : null); }
/// <summary> /// /// </summary> /// <param name="programToFind"></param> /// <returns></returns> private IClipBoardPatch FindProgram(IPatch programToFind) { for (int index = 0; index < (int)ProgramBank.SynthesisType.Last; index++) { IClipBoardPatch program = FindProgram(Programs[index].CopiedPatches, programToFind); if (program != null) { return(program); } } return(null); }
/// <summary> /// /// </summary> /// <param name="patchToPaste"></param> /// <param name="patch"></param> public override void CopyPatch(IClipBoardPatch patchToPaste, IPatch patch) { // Copy PRG1 content. base.CopyPatch(patchToPaste, patch); if (Model.OsVersion == Models.EOsVersion.Kronos15_16) { if (patch is KronosProgram) { // Copy PRG2 content. ClipBoardProgram programToPaste = (ClipBoardProgram)patchToPaste; for (int parameter = 0; parameter < programToPaste.KronosOs1516Content.Length; parameter++) { int patchParameterOffset = ((KronosProgramBank)(patch.Parent)).GetParameterOffsetInPbk2( patch.Index, parameter); Debug.Assert(patchParameterOffset >= 4); // Don't overwrite KORG header Root.Content[patchParameterOffset] = programToPaste.KronosOs1516Content[parameter]; } } else if (patch is KronosCombi) { // Copy CBK2 content. ClipBoardCombi combiToPaste = (ClipBoardCombi)patchToPaste; for (int parameter = 0; parameter < KronosCombiBanks.ParametersInCbk2Chunk; parameter++) { for (int timbre = 0; timbre < KronosTimbres.TimbresPerCombiConstant; timbre++) { int patchParameterOffset = ((KronosCombiBank)(patch.Parent)).GetParameterOffsetInCbk2( patch.Index, timbre, parameter); Debug.Assert(patchParameterOffset >= 4); // Don't overwrite KORG header Root.Content[patchParameterOffset] = combiToPaste.KronosOs1516Content[ parameter + (timbre * KronosCombiBanks.ParametersInCbk2Chunk)]; } } } else { KronosSetListSlot slot = patch as KronosSetListSlot; if (slot != null) { Util.SetInt(this, Content, slot.Stl2BankOffset, 1, ((ClipBoardSetListSlot)patchToPaste).KronosOs1516Bank); Util.SetInt(this, Content, slot.Stl2PatchOffset, 1, ((ClipBoardSetListSlot)patchToPaste).KronosOs1516Patch); } } patch.RaisePropertyChanged(string.Empty, false); } }
/// <summary> /// 1a. Search for a bytewise equal patch, on same location. /// </summary> /// <param name="clipBoardPatch"></param> /// <param name="bank"></param> /// <param name="sameLocationPatch"></param> /// <returns></returns> private bool SearchByteWiseEqualPatchSameLocation(IClipBoardPatch clipBoardPatch, IBank bank, out IPatch sameLocationPatch) { sameLocationPatch = GetPatchOnSameLocation(clipBoardPatch, bank); if (sameLocationPatch != null) { if (sameLocationPatch.CalcByteDifferences(clipBoardPatch, true, 1) == 0) { clipBoardPatch.PasteDestination = sameLocationPatch; PcgClipBoard.ProtectedPatches.Add(sameLocationPatch); return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="patch"></param> /// <param name="program"></param> /// <param name="memory"></param> private static void FixProgramReferencesToSetLists(IClipBoardPatch patch, IProgram program, IPcgMemory memory) { // Change set list slots (only which are present in the current file). if (memory.SetLists != null) { foreach (var slot in memory.SetLists.BankCollection.Where( bank => bank.IsWritable && !bank.IsFromMasterFile). SelectMany(list => list.Patches, (list, patch1) => (ISetListSlot)patch1). Where(slot => (slot.SelectedPatchType == SetListSlot.PatchType.Program) && (slot.UsedPatch == patch.OriginalLocation))) { slot.UsedPatch = program; } } }
/// <summary> /// Fix drum pattern references in programs (clipBoardPatches). /// </summary> /// <param name="drumPattern"></param> private void FixPasteDrumPatternReferencesInPrograms(IClipBoardPatch drumPattern) { return; //TODO /* * * for (var index = 0; index < (int)ProgramBank.SynthesisType.Last; index++) * { * foreach (var clipBoardPatch in Programs[index].CopiedPatches) * { * var program = (IClipBoardProgram)clipBoardPatch; * //TODOfor (var drumPatternIndex = 0; drumPatternIndex < program.ReferencedDrumPatterns.CopiedPatches.Count; * //TODO drumPatternIndex++) * { * //TODOvar usedDrumPattern = program.ReferencedDrumPatterns.CopiedPatches[drumPatternIndex]; * //TODOif (usedDrumPattern != drumPattern) * { * continue; * } * * // DrumPattern used by usedDrumPattern in program. * if ((drumPattern.PasteDestination != null) && (program.PasteDestination != null)) * { * // When pasting to the same file, then it is not wanted to fix references, * // because a duplicate drumPattern/program can exist before the original reference * // so it will be changed unnecessarily. * if (drumPattern.OriginalLocation.Root != PastePcgMemory) * { * var changes = new Dictionary<IDrumPattern, IDrumPattern> * { * { * ((IProgram) (program.PasteDestination)).UsedDrumPatterns[drumPatternIndex], * (IDrumPattern) drumPattern.PasteDestination * } * }; * * ((IProgram)(program.PasteDestination)).ReplaceDrumPattern(changes); * } * //TODOprogram.ReferencedDrumPatterns.CopiedPatches[drumPatternIndex] = null; // Prevent fixing it again * } * } * } * } */ }
/// <summary> /// /// </summary> /// <param name="drumKits"></param> /// <param name="drumKitToFind"></param> /// <returns></returns> static IClipBoardDrumKit FindDrumKit(IEnumerable <IClipBoardPatch> drumKits, IPatch drumKitToFind) { IClipBoardPatch patch = null; foreach (var drumKit in drumKits) { Debug.Assert(drumKitToFind.ByteLength == drumKit.Data.Length); if (Util.ByteCompareEqual( drumKitToFind.PcgRoot.Content, drumKitToFind.ByteOffset, drumKit.Data, drumKitToFind.ByteLength)) { patch = drumKit; break; } } return(patch as IClipBoardDrumKit); }
/// <summary> /// /// </summary> /// <param name="programs"></param> /// <param name="programToFind"></param> /// <returns></returns> static IClipBoardPatch FindProgram(IEnumerable <IClipBoardPatch> programs, IPatch programToFind) { IClipBoardPatch patch = null; foreach (var program in programs) { Debug.Assert(programToFind.ByteLength == program.Data.Length); if (Util.ByteCompareEqual( programToFind.PcgRoot.Content, programToFind.ByteOffset, program.Data, programToFind.ByteLength)) { patch = program; break; } } return(patch); }
/// <summary> /// /// </summary> /// <param name="patch"></param> /// <param name="program"></param> /// <param name="memory"></param> private static void FixProgramReferencesToCombi(IClipBoardPatch patch, IProgram program, IPcgMemory memory) { // Change combis (only which are present in the current file). if (memory.CombiBanks != null) { foreach (var timbre in from bank in memory.CombiBanks.BankCollection.Where( bank => bank.IsWritable && !bank.IsFromMasterFile) from patch1 in bank.Patches select(ICombi) patch1 into combi from timbre in combi.Timbres.TimbresCollection where timbre.UsedProgram == patch.OriginalLocation select timbre) { timbre.UsedProgram = program; } } }
/// <summary> /// /// </summary> /// <param name="otherPatch"></param> /// <param name="includingName"></param> /// <param name="maxDiffs"></param> /// <returns></returns> public override int CalcByteDifferences(IClipBoardPatch otherPatch, bool includingName, int maxDiffs) { ClipBoardSetListSlot otherSetListSlot = otherPatch as ClipBoardSetListSlot; Debug.Assert(otherSetListSlot != null); int diffs = base.CalcByteDifferences(otherPatch, includingName, maxDiffs); // Take SLS2 differences into account. if (PcgRoot.Model.OsVersion == Models.EOsVersion.Kronos15_16) { diffs += (Util.GetInt(PcgRoot.Content, Stl2BankOffset, 1) != otherSetListSlot.KronosOs1516Bank) ? 1 : 0; diffs += (Util.GetInt(PcgRoot.Content, Stl2PatchOffset, 1) != otherSetListSlot.KronosOs1516Patch) ? 1 : 0; } return(diffs); }
/// <summary> /// Changes all references of the original location of patch to combi. /// Only used for cut/paste. /// </summary> /// <param name="patch"></param> /// <param name="combi"></param> static void FixReferencesToCombi(IClipBoardPatch patch, ICombi combi) { var memory = patch.OriginalLocation.Root as IPcgMemory; Debug.Assert(memory != null); // Change set list slots (if present and not from master file). if (memory.SetLists != null) { foreach (var slot in memory.SetLists.BankCollection.Where( bank => bank.IsWritable && !bank.IsFromMasterFile).SelectMany( list => list.Patches, (list, patch1) => (ISetListSlot)patch1).Where( slot => (slot.SelectedPatchType == SetListSlot.PatchType.Combi) && (slot.UsedPatch == patch.OriginalLocation))) { slot.UsedPatch = combi; } } }
/// <summary> /// /// </summary> /// <param name="drumPatterns"></param> /// <param name="drumPatternToFind"></param> /// <returns></returns> private static IClipBoardDrumPattern FindDrumPattern(IEnumerable <IClipBoardPatch> drumPatterns, IPatch drumPatternToFind) { IClipBoardPatch patch = null; foreach (IClipBoardPatch drumPattern in drumPatterns) { Debug.Assert(drumPatternToFind.ByteLength == drumPattern.Data.Length); if (Util.ByteCompareEqual( drumPatternToFind.PcgRoot.Content, drumPatternToFind.ByteOffset, drumPattern.Data, drumPatternToFind.ByteLength)) { patch = drumPattern; break; } } return(patch as IClipBoardDrumPattern); }
/// <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) { var program = patch as IProgram; if (program != null) { FixReferencesToProgram(patchToPaste, program); } else { var combi = patch as ICombi; if (combi != null) { FixReferencesToCombi(patchToPaste, combi); } else { var drumKit = patch as IDrumKit; if (drumKit != null) { FixReferencesToDrumKit(patchToPaste, drumKit); } else { var drumPattern = patch as IDrumPattern; if (drumPattern != null) { FixReferencesToDrumPattern(patchToPaste, drumPattern); } } } } // If it is a set list slot do nothing. } }
/// <summary> /// Fix drum kit references in programs (clipBoardPatches). /// </summary> /// <param name="drumKit"></param> private void FixPasteDrumKitReferencesInPrograms(IClipBoardPatch drumKit) { for (var index = 0; index < (int)ProgramBank.SynthesisType.Last; index++) { foreach (var clipBoardPatch in Programs[index].CopiedPatches) { var program = (IClipBoardProgram)clipBoardPatch; for (var drumKitIndex = 0; drumKitIndex < program.ReferencedDrumKits.CopiedPatches.Count; drumKitIndex++) { var usedDrumKit = program.ReferencedDrumKits.CopiedPatches[drumKitIndex]; if (usedDrumKit != drumKit) { continue; } // DrumKit used by usedDrumKit in program. if ((drumKit.PasteDestination != null) && (program.PasteDestination != null)) { // When pasting to the same file, then it is not wanted to fix references, // because a duplicate drumkit/program can exist before the original reference // so it will be changed unnecessarily. if (drumKit.OriginalLocation.Root != PastePcgMemory) { var changes = new Dictionary <IDrumKit, IDrumKit> { { ((IProgram)(program.PasteDestination)).UsedDrumKits[drumKitIndex], (IDrumKit)drumKit.PasteDestination } }; ((IProgram)(program.PasteDestination)).ReplaceDrumKit(changes); } program.ReferencedDrumKits.CopiedPatches[drumKitIndex] = null; // Prevent fixing it again } } } } }
/// <summary> /// /// </summary> /// <param name="otherPatch"></param> /// <param name="includingName"></param> /// <param name="maxDiffs"></param> /// <returns></returns> public override int CalcByteDifferences(IClipBoardPatch otherPatch, bool includingName, int maxDiffs) { ClipBoardCombi otherCombi = otherPatch as ClipBoardCombi; Debug.Assert(otherCombi != null); int diffs = base.CalcByteDifferences(otherPatch, includingName, maxDiffs); // Take CBK2 differences into account. if (((KronosCombiBank)(Parent)).Cbk2PcgOffset != 0) { for (int parameterIndex = 0; parameterIndex < KronosCombiBanks.ParametersInCbk2Chunk; parameterIndex++) { for (int timbre = 0; timbre < Timbres.TimbresCollection.Count; timbre++) { int patchIndex = ((KronosCombiBank)Parent).GetParameterOffsetInCbk2(Index, timbre, parameterIndex); diffs += (Util.GetInt(PcgRoot.Content, patchIndex, 1) != otherCombi.KronosOs1516Content[parameterIndex]) ? 1 : 0; } } } return(diffs); }
/// <summary> /// Changes all references of the original location of patch to drum pattern. /// Only used for cut/paste. /// </summary> /// <param name="patchToPaste"></param> /// <param name="drumPattern"></param> private static void FixReferencesToDrumPattern(IClipBoardPatch patchToPaste, IDrumPattern drumPattern) { 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 <IDrumPattern, IDrumPattern> { { (IDrumPattern)(patchToPaste.OriginalLocation), drumPattern } }; // TODO ((IProgram)program).ReplaceDrumPattern(changes); } } } }
/// <summary> /// /// </summary> /// <param name="otherPatch"></param> /// <param name="includingName"></param> /// <param name="maxDiffs"></param> /// <returns></returns> public override int CalcByteDifferences(IClipBoardPatch otherPatch, bool includingName, int maxDiffs) { var otherProgram = otherPatch as ClipBoardProgram; Debug.Assert(otherProgram != null); var diffs = base.CalcByteDifferences(otherPatch, includingName, maxDiffs); // Take PBK2 differences into account. if (((KronosProgramBank)(Parent)).Pbk2PcgOffset != 0) { for (var parameterIndex = 0; parameterIndex < KronosProgramBanks.ParametersInPbk2Chunk; parameterIndex++) { var patchIndex = ((KronosProgramBank)Parent).GetParameterOffsetInPbk2(Index, parameterIndex); diffs += (Util.GetInt(PcgRoot.Content, patchIndex, 1) != otherProgram.KronosOs1516Content[parameterIndex]) ? 1 : 0; } } return(diffs); }
/* * /// <summary> * /// Fix drum kit references in programs (clipBoardPatches). * /// </summary> * /// <param name="clipBoardPatches"></param> * private void FixPasteDrumKitReferencesInPrograms(IEnumerable<IClipBoardPatch> clipBoardPatches) * { * foreach (var clipBoardPatch in clipBoardPatches) * { * var program = (IClipBoardProgram) clipBoardPatch; * foreach (var clipBoardDrumKit in DrumKits.CopiedPatches) * { * var drumKits = program.ReferencedDrumKits; * for (var drumKitIndex = 0; drumKitIndex < drumKits.CopiedPatches.Count(); drumKitIndex++) * { * var drumKit = program.ReferencedDrumKits.CopiedPatches[drumKitIndex]; * if (drumKit != clipBoardDrumKit) * { * continue; * } * * if ((drumKit.PasteDestination != null) && (program.PasteDestination != null)) * { * // When pasting to the same file, then it is not wanted to fix references, * // because a duplicate drumkit/program can exist before the original reference * // so it will be changed unnecessarily. * if (drumKit.OriginalLocation.Root != PastePcgMemory) * { * var changes = new Dictionary<IDrumKit, IDrumKit> * { * * * * //xxx * * * * * * {(IDrumKit) (drumKit.OriginalLocation), * (IDrumKit) (drumKit.PasteDestination)} * }; * * ((IProgram) (program.PasteDestination)).ReplaceDrumKit(changes); * } * program.ReferencedDrumKits.CopiedPatches[drumKitIndex] = null; // Prevent fixing it again * } * } * } * } * } */ /// <summary> /// /// </summary> private void FixPastePatchInSetListSlotsReferences() { foreach (IClipBoardPatch clipBoardPatch in SetListSlots.CopiedPatches) { IClipBoardSetListSlot clipBoardSetListSlot = (IClipBoardSetListSlot)clipBoardPatch; ISetListSlot setListSlot = (ISetListSlot)(clipBoardSetListSlot.PasteDestination); if ((setListSlot != null) && (clipBoardSetListSlot.Reference != null)) { // Fix reference to program/combi. IClipBoardPatch clipBoardReference = clipBoardSetListSlot.Reference; // When pasting to the same file (second condition below), then it is not wanted to fix references, // because a duplicate program/combi can exist before the original reference so it will be changed // unnecessarily. if ((clipBoardReference.PasteDestination != null) && (clipBoardSetListSlot.Reference.OriginalLocation.Root != PastePcgMemory)) { if (clipBoardReference.PasteDestination is IProgram) { IProgram program = (IProgram)(clipBoardReference.PasteDestination); setListSlot.UsedPatch = program; } else if (clipBoardReference.PasteDestination is ICombi) { ICombi combi = (ICombi)(clipBoardReference.PasteDestination); setListSlot.UsedPatch = combi; } else { throw new ApplicationException("Illegal clip board reference"); } setListSlot.RaisePropertyChanged(string.Empty, false); } } } }
/// <summary> /// Copy a patch to the clipboard. /// </summary> /// <param name="patchToPaste"></param> /// <param name="patch"></param> public virtual void CopyPatch(IClipBoardPatch patchToPaste, IPatch patch) { Util.CopyBytes(this, patchToPaste.Data, patch.Root.Content, patch.ByteOffset, patch.ByteLength); patch.RaisePropertyChanged(string.Empty, false); }