예제 #1
0
        /// <summary>
        /// Copies combi and set list slot.
        /// </summary>
        /// <param name="setListTarget"></param>
        /// <param name="combiBankTarget"></param>
        /// <param name="mainMidiChannel"></param>
        /// <param name="secondaryMidiChannel"></param>
        /// <param name="sourceSetListSlot"></param>
        /// <param name="currentTargetCombiIndex"></param>
        /// <param name="finishedPrematurely"></param>
        /// <param name="currentTargetSetListSlotIndex"></param>
        /// <returns></returns>
        private static bool CopySecondaryPatches(ISetList setListTarget, ICombiBank combiBankTarget, int mainMidiChannel,
                                                 int secondaryMidiChannel, ISetListSlot sourceSetListSlot, ref int currentTargetCombiIndex,
                                                 ref bool finishedPrematurely, ref int currentTargetSetListSlotIndex)
        {
            ICombi sourceCombi = (ICombi)sourceSetListSlot.UsedPatch;

            if (sourceCombi.UsesMidiChannel(secondaryMidiChannel))
            {
                // Create second combi with changed name and MIDI channels switched.
                if (currentTargetCombiIndex >= combiBankTarget.CountPatches)
                {
                    finishedPrematurely = true;
                    return(true);
                }
                sourceCombi.PcgRoot.CopyPatch(sourceCombi, combiBankTarget.Patches[currentTargetCombiIndex]);
                ICombi combi = (ICombi)combiBankTarget.Patches[currentTargetCombiIndex];
                combi.SetNameSuffix($"/MC{secondaryMidiChannel}");
                combi.SwitchMidiChannels(mainMidiChannel, secondaryMidiChannel);
                currentTargetCombiIndex++;

                // Copy set list slot with changed name and referencing to combi.
                if (currentTargetSetListSlotIndex >= setListTarget.Patches.Count)
                {
                    finishedPrematurely = true;
                    return(true);
                }

                sourceSetListSlot.PcgRoot.CopyPatch(sourceSetListSlot, setListTarget.Patches[currentTargetSetListSlotIndex]);
                ISetListSlot setListSlotSecondary = (ISetListSlot)setListTarget.Patches[currentTargetSetListSlotIndex];
                setListSlotSecondary.SetNameSuffix($"/MC{secondaryMidiChannel}");
                setListSlotSecondary.UsedPatch = combi;
                currentTargetSetListSlotIndex++;
            }
            return(false);
        }
예제 #2
0
        public void ChangeSetListSlotNotTooMany()
        {
            IPcgMemory pcg = CreatePcg();

            IProgram     programIa000      = (IProgram)pcg.ProgramBanks[0][0];
            ISetListSlot setListSlot000000 = (ISetListSlot)(pcg.SetLists[0])[0];

            setListSlot000000.SelectedPatchType = SetListSlot.PatchType.Program;
            setListSlot000000.UsedPatch         = programIa000;

            IProgram     programIa001      = (IProgram)pcg.ProgramBanks[0][1];
            ISetListSlot setListSlot000001 = (ISetListSlot)(pcg.SetLists[0])[1];

            setListSlot000001.SelectedPatchType = SetListSlot.PatchType.Program;
            setListSlot000001.UsedPatch         = programIa001;

            ReferenceChanger referenceChanger = new ReferenceChanger(pcg);
            RuleParser       ruleParser       = new RuleParser(pcg);

            referenceChanger.ParseRules(ruleParser, "I-A000->I-B000");
            referenceChanger.ChangeReferences();

            Debug.Assert(setListSlot000000.UsedPatch == pcg.ProgramBanks[1][0]); // Changed
            Debug.Assert(setListSlot000001.UsedPatch == programIa001);           // Not changed
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="setListSlot"></param>
        public ClipBoardSetListSlot(ISetListSlot setListSlot)
            : base(setListSlot.PcgRoot.Content, setListSlot.ByteOffset, setListSlot.ByteLength)
        {
            OriginalLocation = setListSlot;

            if ((setListSlot.Root is KronosPcgMemory memory) && (memory.PcgRoot.Model.OsVersion == Models.EOsVersion.Kronos15_16))
            {
                KronosOs1516Bank  = Util.GetInt(memory.Content, ((KronosSetListSlot)setListSlot).Stl2BankOffset, 1);
                KronosOs1516Patch = Util.GetInt(memory.Content, ((KronosSetListSlot)setListSlot).Stl2PatchOffset, 1);
            }
        }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rule"></param>
 private void ChangeReferencesInSetListSlots(KeyValuePair <IPatch, IPatch> rule)
 {
     foreach (IBank setList in _memory.SetLists.BankCollection.Where(setList => setList.IsFilled))
     {
         for (int index = 0; index < setList.Patches.Count; index++)
         {
             ISetListSlot setListSlot = (ISetListSlot)setList[index];
             if ((setListSlot.SelectedPatchType == SetListSlot.PatchType.Program) &&
                 (setListSlot.UsedPatch == rule.Key) &&
                 !_processedSetListSlots.Contains(setListSlot))
             {
                 setListSlot.UsedPatch = rule.Value;
                 _processedSetListSlots.Add(setListSlot);
             }
         }
     }
 }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="setListSlot"></param>
        /// <param name="clearAfterCopy"></param>
        public void CopySetListSlotToClipBoard(ISetListSlot setListSlot, bool clearAfterCopy)
        {
            // Copy set list slot.
            if (setListSlot.PcgRoot.Content != null)
            {
                var clipBoardSetListSlot = new ClipBoardSetListSlot(setListSlot);
                SetListSlots.CopiedPatches.Add(clipBoardSetListSlot);

                if (clearAfterCopy)
                {
                    setListSlot.Clear();
                }

                // Copy program of combi (do not copy song).
                if (!CutPasteSelected)
                {
                    var usedPatch = setListSlot.UsedPatch;
                    if ((usedPatch != null) &&
                        (Settings.Default.CopyPaste_CopyPatchesFromMasterFile || !usedPatch.IsFromMasterFile))
                    {
                        if (setListSlot.UsedPatch is IProgram)
                        {
                            var program = (IProgram)usedPatch;
                            if (((IProgramBank)(program.Parent)).Type != BankType.EType.Gm)
                            {
                                clipBoardSetListSlot.Reference = CopyProgramToClipBoard(program, false);
                            }
                        }
                        else if (setListSlot.UsedPatch is ICombi)
                        {
                            var combi = (ICombi)usedPatch;
                            clipBoardSetListSlot.Reference = CopyCombiToClipBoard(combi, false);
                        }
                    }
                }
            }
        }
예제 #6
0
        /*
         * /// <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);
                    }
                }
            }
        }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="patch"></param>
 public WindowEditMultipleSetListSlot(ISetListSlot patch)
 {
     InitializeComponent();
     _patch = patch;
 }
예제 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="patch"></param>
 public WindowEditSingleSetListSlot(ISetListSlot patch)
 {
     _patch = patch;
     InitializeComponent();
 }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="setListSource"></param>
        /// <param name="setListTarget"></param>
        /// <param name="combiBankTarget"></param>
        /// <param name="mainMidiChannel"></param>
        /// <param name="secondaryMidiChannel"></param>
        internal void Process(ISetList setListSource, ISetList setListTarget,
                              Model.Common.Synth.PatchCombis.ICombiBank combiBankTarget,
                              int mainMidiChannel, int secondaryMidiChannel)
        {
            int currentTargetSetListSlotIndex = 0;
            int currentTargetCombiIndex       = 0;

            bool   finishedPrematurely = false;
            string errorText           = string.Empty;

            if (!setListSource.IsLoaded)
            {
                finishedPrematurely = true;
                errorText           = PcgToolsResources.Strings.KeyboardSetupErrorSetListsNotPresent; //TODO page 178 manual
            }
            else if (setListTarget.CountFilledPatches > 0)
            {
                finishedPrematurely = true;
                errorText           = PcgToolsResources.Strings.KeyboardSetupErrorTargetSetListNotEmpty;
            }
            else if (!combiBankTarget.IsWritable)
            {
                finishedPrematurely = true;
                errorText           = PcgToolsResources.Strings.KeyboardSetupErrorTargetCombiBankNotPresent;
            }
            else
            {
                foreach (Model.Common.Synth.Meta.IPatch patch in setListSource.Patches.Where(patch => !((ISetListSlot)patch).IsEmptyOrInit))
                {
                    ISetListSlot sourceSetListSlot = (ISetListSlot)patch;
                    if (currentTargetSetListSlotIndex >= setListTarget.Patches.Count)
                    {
                        finishedPrematurely = true;
                        errorText           = PcgToolsResources.Strings.KeyboardSetupErrorNotEnoughSetListSlotsInTargetSetList;
                        break;
                    }

                    // copy set list slot to target set list.
                    // change suffix sourcemidi
                    sourceSetListSlot.PcgRoot.CopyPatch(sourceSetListSlot, setListTarget.Patches[currentTargetSetListSlotIndex]);
                    Model.Common.Synth.Meta.IPatch targetSetListSlot = setListTarget.Patches[currentTargetSetListSlotIndex];
                    targetSetListSlot.SetNameSuffix($"/MC{mainMidiChannel}");
                    currentTargetSetListSlotIndex++;

                    if (sourceSetListSlot.SelectedPatchType == SetListSlot.PatchType.Combi)
                    {
                        if (CopySecondaryPatches(setListTarget, combiBankTarget, mainMidiChannel, secondaryMidiChannel,
                                                 sourceSetListSlot,
                                                 ref currentTargetCombiIndex, ref finishedPrematurely, ref currentTargetSetListSlotIndex))
                        {
                            break;
                        }
                    }
                }
            }

            if (finishedPrematurely)
            {
                // Show message box.
                Console.WriteLine(errorText);
            }
        }