Пример #1
0
        /// <summary>
        /// From startMsPosition to (not including) endMsPosition,
        /// replace all MidiChordDefs or InputChordDefs by UniqueMidiRestDefs, then aglommerate the rests.
        /// </summary>
        public void Erase(int startMsPosition, int endMsPosition)
        {
            int beginIndex = FindIndexAtMsPosition(startMsPosition);
            int endIndex   = FindIndexAtMsPosition(endMsPosition);

            for (int i = beginIndex; i < endIndex; ++i)
            {
                MidiChordDef  mcd = this[i] as MidiChordDef;
                InputChordDef icd = this[i] as InputChordDef;
                IUniqueDef    iud = (mcd == null) ? (IUniqueDef)icd : (IUniqueDef)mcd;
                if (iud != null)
                {
                    RestDef umrd = new RestDef(iud.MsPosition, iud.MsDuration);
                    RemoveAt(i);
                    Insert(i, umrd);
                }
            }

            AgglomerateRests();
        }
Пример #2
0
        private InputVoiceDef GetBar1InputVoiceDef(Seq bar1Seq)
        {
            InputVoiceDef ivd = new InputVoiceDef(0, 0, new List<IUniqueDef>());
            ivd.MsPositionReContainer = bar1Seq.AbsMsPosition;

            Trk leadTrk = null;
            foreach(Trk trk in bar1Seq.Trks)
            {
                if(trk.MidiChannel == 0)
                {
                    leadTrk = trk;
                    break;
                }

            }
            Debug.Assert(leadTrk != null);
            foreach(IUniqueDef tIud in leadTrk)
            {
                RestDef tRestDef = tIud as RestDef;
                MidiChordDef tmcd = tIud as MidiChordDef;
                if(tRestDef != null)
                {
                    RestDef iRestDef = new RestDef(tRestDef.MsPositionReFirstUD, tRestDef.MsDuration);
                    ivd.Add(iRestDef);
                }
                else if(tmcd != null)
                {
                    List<TrkRef> trkRefs = new List<TrkRef>();

                    foreach(Trk trk in bar1Seq.Trks)
                    {
                        trkRefs.Add(new TrkRef((byte)trk.MidiChannel, bar1Seq.AbsMsPosition + tmcd.MsPositionReFirstUD, 1, null));
                    }
                    SeqRef seqRef = new SeqRef(trkRefs, null);
                    NoteOn noteOn = new NoteOn(seqRef);
                    List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>();
                    foreach(byte notatedMidiPitch in tmcd.NotatedMidiPitches)
                    {
                        inputNoteDefs.Add(new InputNoteDef((byte)(notatedMidiPitch + 36), noteOn, null));
                    }
                    InputChordDef icd = new InputChordDef(tIud.MsPositionReFirstUD, tIud.MsDuration, inputNoteDefs, M.Dynamic.none, null);
                    ivd.Add(icd);
                }
            }

            return ivd;
        }
Пример #3
0
        /// <summary>
        /// Returns a list having the position and duration of the originalRest.
        /// The iLmdds have been put in(side) the original rest, either at the beginning, middle, or end. 
        /// </summary>
        private List<IUniqueDef> GetReplacementList(IUniqueDef originalRest, VoiceDef iVoiceDef)
        {
            Debug.Assert(originalRest is RestDef);
            Debug.Assert(iVoiceDef[0] is MidiChordDef || iVoiceDef[0] is InputChordDef);
            Debug.Assert(iVoiceDef[iVoiceDef.Count - 1] is MidiChordDef || iVoiceDef[iVoiceDef.Count - 1] is InputChordDef);

            List<IUniqueDef> rList = new List<IUniqueDef>();
            if(iVoiceDef[0].MsPositionReFirstUD > originalRest.MsPositionReFirstUD)
            {
                RestDef rest1 = new RestDef(originalRest.MsPositionReFirstUD, iVoiceDef[0].MsPositionReFirstUD - originalRest.MsPositionReFirstUD);
                rList.Add(rest1);
            }
            rList.AddRange(iVoiceDef.UniqueDefs);
            int iudEndMsPosReFirstIUD = iVoiceDef[iVoiceDef.Count - 1].MsPositionReFirstUD + iVoiceDef[iVoiceDef.Count - 1].MsDuration;
            int originalRestEndMsPosReFirstIUD = originalRest.MsPositionReFirstUD + originalRest.MsDuration;
            if(originalRestEndMsPosReFirstIUD > iudEndMsPosReFirstIUD)
            {
                RestDef rest2 = new RestDef(iudEndMsPosReFirstIUD, originalRestEndMsPosReFirstIUD - iudEndMsPosReFirstIUD);
                rList.Add(rest2);
            }

            return rList;
        }
Пример #4
0
        private void Transform(Trk section, Dictionary<string, int> msPositions, List<int> strandIndices)
        {
            List<int> strandDurations = GetStrandDurations(section, strandIndices);

            int extraTime = 750;
            int diff = extraTime / section.Count;
            for(int i = section.Count - 1; i > 0; --i)
            {
                if(strandIndices.Contains(i))
                {
                    RestDef umrd = new RestDef(section[i].MsPositionReTrk, strandDurations[strandIndices.IndexOf(i)] + extraTime);
                    extraTime -= diff;
                    section.Insert(i, umrd);
                }
            }

            section.MsPositionReSeq = msPositions["furies2FinaleStart"];

            //double factor = 10;

            //section.AdjustMsDurations(factor);

            section.CreateAccel(0, section.Count, 0.25);

            //section.RemoveBetweenMsPositions(msPositions["interlude4End"], int.MaxValue);
            section.RemoveBetweenMsPositions(msPositions["finalWindChord"], int.MaxValue);

            if(section[section.Count - 1] is RestDef)
            {
                //section[section.Count - 1].MsDuration = msPositions["interlude4End"] - section[section.Count - 1].MsPosition;
                section[section.Count - 1].MsDuration = msPositions["endOfPiece"] - section[section.Count - 1].MsPositionReTrk;
            }
        }
Пример #5
0
 /// <summary>
 /// A VoiceDef beginning at MsPosition = 0, and containing a single RestDef having msDuration
 /// </summary>
 /// <param name="msDuration"></param>
 internal Furies2(int midiChannel, int msDuration)
     : base(midiChannel)
 {
     RestDef lmRestDef = new RestDef(0, msDuration);
     _uniqueDefs.Add(lmRestDef);
 }
Пример #6
0
        /// <summary>
        /// Returns two bars. The first is the beginning of the argument bar up to absoluteSplitPos,
        /// The second is the end of the argument bar beginning at absoluteSplitPos.
        /// The final UniqueMidiDurationDef in each voice.UniqueMidiDurationDefs list is converted
        /// to a FinalLMDDInVoice object containing an MsDurationToBarline property.
        /// If a chord or rest overlaps a barline, a LocalizedCautionaryChordDef object is created at the
        /// start of the voice.UniqueMidiDurationDefs in the second bar. A LocalizedCautionaryChordDef
        /// object is a kind of chord which is used while justifying systems, but is not displayed and
        /// does not affect performance.
        /// ClefChangeDefs are placed at the end of the first bar, not at the start of the second bar.
        /// </summary>
        protected List<List<VoiceDef>> SplitBar(List<VoiceDef> originalBar, int absoluteSplitPos)
        {
            List<List<VoiceDef>> twoBars = new List<List<VoiceDef>>();
            List<VoiceDef> firstBar = new List<VoiceDef>();
            List<VoiceDef> secondBar = new List<VoiceDef>();
            twoBars.Add(firstBar);
            twoBars.Add(secondBar);
            int originalBarStartPos = originalBar[0].UniqueDefs[0].MsPosition;
            int originalBarEndPos =
                originalBar[0].UniqueDefs[originalBar[0].UniqueDefs.Count - 1].MsPosition +
                originalBar[0].UniqueDefs[originalBar[0].UniqueDefs.Count - 1].MsDuration;

            VoiceDef firstBarVoice;
            VoiceDef secondBarVoice;
            foreach(VoiceDef voice in originalBar)
            {
                TrkDef outputVoice = voice as TrkDef;
                if(outputVoice != null)
                {
                    firstBarVoice = new TrkDef(outputVoice.MidiChannel,new List<IUniqueDef>());
                    firstBar.Add(firstBarVoice);
                    secondBarVoice = new TrkDef(outputVoice.MidiChannel, new List<IUniqueDef>());
                    secondBar.Add(secondBarVoice);
                }
                else
                {
                    firstBarVoice = new InputVoiceDef();
                    firstBar.Add(firstBarVoice);
                    secondBarVoice = new InputVoiceDef();
                    secondBar.Add(secondBarVoice);
                }
                foreach(IUniqueDef iUnique in voice.UniqueDefs)
                {
                    int udMsDuration = iUnique.MsDuration;
                    IUniqueSplittableChordDef uniqueChordDef = iUnique as IUniqueSplittableChordDef;
                    if(uniqueChordDef != null)
                    {
                        udMsDuration = (uniqueChordDef.MsDurationToNextBarline == null) ? iUnique.MsDuration : (int)uniqueChordDef.MsDurationToNextBarline;
                    }

                    int udEndPos = iUnique.MsPosition + udMsDuration;

                    if(iUnique.MsPosition >= absoluteSplitPos)
                    {
                        if(iUnique.MsPosition == absoluteSplitPos && iUnique is ClefChangeDef)
                        {
                            firstBarVoice.UniqueDefs.Add(iUnique);
                        }
                        else
                        {
                            Debug.Assert(udEndPos <= originalBarEndPos);
                            secondBarVoice.UniqueDefs.Add(iUnique);
                        }
                    }
                    else if(udEndPos > absoluteSplitPos)
                    {
                        int durationAfterBarline = udEndPos - absoluteSplitPos;
                        if(iUnique is RestDef)
                        {
                            // This is a rest. Split it.
                            RestDef firstRestHalf = new RestDef(iUnique.MsPosition, absoluteSplitPos - iUnique.MsPosition);
                            firstBarVoice.UniqueDefs.Add(firstRestHalf);

                            RestDef secondRestHalf = new RestDef(absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondRestHalf);
                        }
                        else if(iUnique is CautionaryChordDef)
                        {
                            // This is a cautionary chord. Set the position of the following barline, and
                            // Add an LocalizedCautionaryChordDef at the beginning of the following bar.
                            iUnique.MsDuration = absoluteSplitPos - iUnique.MsPosition;
                            firstBarVoice.UniqueDefs.Add(iUnique);

                            CautionaryChordDef secondLmdd = new CautionaryChordDef((IUniqueChordDef)iUnique, absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondLmdd);
                        }
                        else
                        {
                            // This is a MidiChordDef or a InputChordDef.
                            // Set the position of the following barline, and add a CautionaryChordDef at the beginning
                            // of the following bar.
                            if(uniqueChordDef != null)
                            {
                                uniqueChordDef.MsDurationToNextBarline = absoluteSplitPos - iUnique.MsPosition;
                            }

                            firstBarVoice.UniqueDefs.Add((IUniqueDef)uniqueChordDef);

                            CautionaryChordDef secondLmdd = new CautionaryChordDef((IUniqueChordDef)uniqueChordDef,
                                absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondLmdd);
                        }
                    }
                    else
                    {
                        Debug.Assert(udEndPos <= absoluteSplitPos && iUnique.MsPosition >= originalBarStartPos);
                        firstBarVoice.UniqueDefs.Add(iUnique);
                    }
                }
            }
            return twoBars;
        }
Пример #7
0
        private void GetSnores(int firstRestMsDuration, Clytemnestra clytemnestra, Trk wind1, Palette snoresPalette)
        {
            List<IUniqueDef> snores = new List<IUniqueDef>();
            int msPosition = 0;

            IUniqueDef firstRest = new RestDef(msPosition, firstRestMsDuration);
            snores.Add(firstRest);
            msPosition += firstRestMsDuration;

            #region prelude + verse1
            int[] transpositions1 = { 0, 0, 0, 0, 0, 1, 0 };
            for(int i = 0; i < 7; ++i)
            {
                IUniqueDef snore = snoresPalette.UniqueDurationDef(i);
                snore.MsPositionReTrk = msPosition;
                msPosition += snore.MsDuration;
                MidiChordDef iumdd = snore as MidiChordDef;
                if(iumdd != null)
                {
                    iumdd.Transpose(transpositions1[i]);
                    iumdd.PitchWheelDeviation = 3;
                }
                snores.Add(snore);

                RestDef rest = new RestDef(msPosition, 2500);
                msPosition += rest.MsDuration;
                snores.Add(rest);
            }
            #endregion

            double factor;
            double msDuration;
            double restDuration;
            int[] transpositions2 = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
            double[] factors = { 0.93, 0.865, 0.804, 0.748, 0.696, 0.647, 0.602, 0.56, 0.52, 0.484 };
            for(int i = 0; i < 10; ++i)
            {
                IUniqueDef snore = snoresPalette.UniqueDurationDef(i / 2);
                snore.MsPositionReTrk = msPosition;
                factor = factors[i];
                msDuration = snore.MsDuration * factor;
                snore.MsDuration = (int)msDuration;
                msPosition += snore.MsDuration;
                MidiChordDef iumdd = snore as MidiChordDef;
                if(iumdd != null)
                {
                    iumdd.Transpose(transpositions2[i]);
                    iumdd.PitchWheelDeviation = 20;
                }
                //iumdd.MidiVelocity = (byte)((double)snore.MidiVelocity * factor * factor);
                snores.Add(snore);

                restDuration = 2500 / factor;
                RestDef rest = new RestDef(msPosition, (int)restDuration);
                msPosition += rest.MsDuration;
                snores.Add(rest);
            }

            snores[snores.Count - 1].MsDuration = clytemnestra.EndMsPosition - snores[snores.Count - 1].MsPositionReTrk;

            this._uniqueDefs = snores;

            AdjustVelocitiesHairpin(13, Count, 0.25);

            #region alignments before Interlude3
            AlignObjectAtIndex(7, 8, 9, clytemnestra[3].MsPositionReTrk);
            AlignObjectAtIndex(8, 9, 10, clytemnestra[7].MsPositionReTrk);
            AlignObjectAtIndex(9, 10, 11, clytemnestra[16].MsPositionReTrk);
            AlignObjectAtIndex(10, 11, 12, clytemnestra[24].MsPositionReTrk);
            AlignObjectAtIndex(11, 12, 13, clytemnestra[39].MsPositionReTrk);
            AlignObjectAtIndex(12, 13, 14, clytemnestra[42].MsPositionReTrk);
            AlignObjectAtIndex(14, 34, Count, wind1[38].MsPositionReTrk); // rest at start of Interlude3
            #endregion

            RemoveScorePitchWheelCommands(0, 13); // pitchwheeldeviation is 20 for R2M
        }
Пример #8
0
        /// <summary>
        /// A VoiceDef beginning at MsPosition = 0, and containing a single UniqueMidiRestDef having msDuration
        /// </summary>
        /// <param name="msDuration"></param>
        public VoiceDef(int msDuration)
        {
            RestDef lmRestDef = new RestDef(0, msDuration);

            _uniqueDefs.Add(lmRestDef);
        }
Пример #9
0
        private Trk GetFlutter1(Palette palette)
        {
            List<IUniqueDef> flutter1 = new List<IUniqueDef>();
            int msPosition = 0;

            for(int i = 0; i < 7; ++i)
            {
                int[] contour = K.Contour(7, 11, 7);
                IUniqueDef flutter = palette.UniqueDurationDef(contour[i] - 1);
                flutter.MsPositionReTrk = msPosition;
                msPosition += flutter.MsDuration;
                flutter1.Add(flutter);

                if(i != 3 && i != 5)
                {
                    RestDef rest = new RestDef(msPosition, flutter.MsDuration);
                    msPosition += rest.MsDuration;
                    flutter1.Add(rest);
                }
            }

            Trk furies3FlutterSequence1 = new Trk(this.MidiChannel, flutter1);

            return furies3FlutterSequence1;
        }
Пример #10
0
        /// <summary>
        /// Creates a "bar" which is a list of voiceDefs containing IUniqueDefs that begin before barlineEndMsPosition,
        /// and removes these IUniqueDefs from the current block.
        /// </summary>
        /// <param name="endBarlineAbsMsPosition"></param>
        /// <returns>The popped bar</returns>
        private List<VoiceDef> PopBar(int endBarlineAbsMsPosition)
        {
            Debug.Assert(AbsMsPosition < endBarlineAbsMsPosition);
            AssertNonEmptyBlockConsistency();

            List<VoiceDef> poppedBar = new List<VoiceDef>();
            List<VoiceDef> remainingBar = new List<VoiceDef>();
            int currentBlockAbsEndPos = this.AbsMsPosition + this.MsDuration;

            bool isLastBar = (currentBlockAbsEndPos == endBarlineAbsMsPosition);

            VoiceDef poppedBarVoice;
            VoiceDef remainingBarVoice;
            foreach(VoiceDef voiceDef in _voiceDefs)
            {
                Trk outputVoice = voiceDef as Trk;
                InputVoiceDef inputVoice = voiceDef as InputVoiceDef;
                if(outputVoice != null)
                {
                    poppedBarVoice = new Trk(outputVoice.MidiChannel);
                    poppedBar.Add(poppedBarVoice);
                    remainingBarVoice = new Trk(outputVoice.MidiChannel);
                    remainingBar.Add(remainingBarVoice);
                }
                else
                {
                    poppedBarVoice = new InputVoiceDef(inputVoice.MidiChannel);
                    poppedBar.Add(poppedBarVoice);
                    remainingBarVoice = new InputVoiceDef(inputVoice.MidiChannel);
                    remainingBar.Add(remainingBarVoice);
                }
                foreach(IUniqueDef iud in voiceDef.UniqueDefs)
                {
                    int iudMsDuration = iud.MsDuration;
                    int iudAbsStartPos = this.AbsMsPosition + iud.MsPositionReFirstUD;
                    int iudAbsEndPos = iudAbsStartPos + iudMsDuration;

                    if(iudAbsStartPos >= endBarlineAbsMsPosition)
                    {
                        Debug.Assert(iudAbsEndPos <= currentBlockAbsEndPos);
                        if(iud is ClefChangeDef && iudAbsStartPos == endBarlineAbsMsPosition)
                        {
                            poppedBarVoice.UniqueDefs.Add(iud);
                        }
                        else
                        {
                            remainingBarVoice.UniqueDefs.Add(iud);
                        }
                    }
                    else if(iudAbsEndPos > endBarlineAbsMsPosition)
                    {
                        int durationBeforeBarline = endBarlineAbsMsPosition - iudAbsStartPos;
                        int durationAfterBarline = iudAbsEndPos - endBarlineAbsMsPosition;
                        if(iud is RestDef)
                        {
                            // This is a rest. Split it.
                            RestDef firstRestHalf = new RestDef(iudAbsStartPos, durationBeforeBarline);
                            poppedBarVoice.UniqueDefs.Add(firstRestHalf);

                            RestDef secondRestHalf = new RestDef(endBarlineAbsMsPosition, durationAfterBarline);
                            remainingBarVoice.UniqueDefs.Add(secondRestHalf);
                        }
                        else if(iud is CautionaryChordDef)
                        {
                            // This is a cautionary chord. Set the position of the following barline, and
                            // Add a CautionaryChordDef at the beginning of the following bar.
                            iud.MsDuration = endBarlineAbsMsPosition - iudAbsStartPos;
                            poppedBarVoice.UniqueDefs.Add(iud);

                            Debug.Assert(remainingBarVoice.UniqueDefs.Count == 0);
                            CautionaryChordDef secondLmdd = new CautionaryChordDef((IUniqueChordDef)iud, 0, durationAfterBarline);
                            remainingBarVoice.UniqueDefs.Add(secondLmdd);
                        }
                        else if(iud is MidiChordDef || iud is InputChordDef)
                        {
                            IUniqueSplittableChordDef uniqueChordDef = iud as IUniqueSplittableChordDef;
                            uniqueChordDef.MsDurationToNextBarline = durationBeforeBarline;
                            poppedBarVoice.UniqueDefs.Add(uniqueChordDef);

                            Debug.Assert(remainingBarVoice.UniqueDefs.Count == 0);
                            CautionaryChordDef ccd = new CautionaryChordDef(uniqueChordDef, 0, durationAfterBarline);
                            remainingBarVoice.UniqueDefs.Add(ccd);
                        }
                    }
                    else
                    {
                        Debug.Assert(iudAbsEndPos <= endBarlineAbsMsPosition && iudAbsStartPos >= AbsMsPosition);
                        poppedBarVoice.UniqueDefs.Add(iud);
                    }
                }
            }

            this.AbsMsPosition = endBarlineAbsMsPosition;

            this._voiceDefs = remainingBar;
            SetMsPositions();

            if(!isLastBar)
            {
                // _voiceDefs is not empty
                AssertNonEmptyBlockConsistency();
            }

            return poppedBar;
        }
Пример #11
0
        public override IUniqueDef DeepClone()
        {
            RestDef umrd = new RestDef(this.MsPosition, this.MsDuration);

            return(umrd);
        }
Пример #12
0
        /// <summary>
        /// Sets Clytamnestra's _uniqueDefs for the whole piece including rests.
        /// Barline positions are set later.
        /// </summary>
        private void SetUniqueDefs(Trk wind3)
        {
            Debug.Assert(_momentDefsListPerVerse.Count == 5);

            List<int> verseMsPositions = new List<int>();
            verseMsPositions.Add(wind3[8].MsPositionReTrk);
            verseMsPositions.Add(wind3[20].MsPositionReTrk);
            verseMsPositions.Add(wind3[33].MsPositionReTrk);
            verseMsPositions.Add(wind3[49].MsPositionReTrk);
            verseMsPositions.Add(wind3[70].MsPositionReTrk);

            int currentVerseMsPosition = 0;
            int currentEndMsPosition = 0;
            IUniqueDef interludeRestDef = null;

            for(int verseIndex = 0; verseIndex < 5; ++verseIndex)
            {
                currentVerseMsPosition = verseMsPositions[verseIndex];

                interludeRestDef = new RestDef(currentEndMsPosition, currentVerseMsPosition - currentEndMsPosition);

                _uniqueDefs.Add(interludeRestDef);

                List<MomentDef> momentDefs = _momentDefsListPerVerse[verseIndex];

                for(int momentDefIndex = 0; momentDefIndex < momentDefs.Count; ++momentDefIndex)
                {
                    MomentDef momentDef = momentDefs[momentDefIndex];
                    momentDef.MsPosition += currentVerseMsPosition;

                    int restWidth = momentDef.MsWidth - momentDef.MaximumMsDuration;
                    IUniqueDef lmrd = null;
                    if(restWidth > 0)
                    {
                        momentDef.MsWidth -= restWidth;
                        lmrd = new RestDef(momentDef.MsPosition + momentDef.MsWidth, restWidth);
                        Debug.Assert(lmrd.MsDuration > 0);
                    }

                    MidiChordDef mcd = momentDef.MidiChordDefs[0];
                    IUniqueDef lmcd = mcd.Clone();
                    lmcd.MsPositionReTrk = momentDef.MsPosition;
                    lmcd.MsDuration = momentDef.MsWidth;
                    Debug.Assert(lmcd.MsDuration > 0);

                    _uniqueDefs.Add(lmcd);

                    if(lmrd != null)
                    {
                        _uniqueDefs.Add(lmrd);
                    }
                    currentEndMsPosition = _uniqueDefs[_uniqueDefs.Count - 1].MsPositionReTrk +
                        _uniqueDefs[_uniqueDefs.Count - 1].MsDuration;
                }
            }
            interludeRestDef = new RestDef(currentEndMsPosition, wind3.EndMsPosition - currentEndMsPosition);
            _uniqueDefs.Add(interludeRestDef);
        }
Пример #13
0
        private void WriteVoiceMidiDurationDefs1(Trk trk, Palette palette)
        {
            trk.MsPositionReContainer = 0;

            int msPositionReFirstIUD = 0;
            int bar1ChordMsSeparation = 1500;
            for(int i = 0; i < palette.Count; ++i)
            {
                IUniqueDef durationDef = palette.UniqueDurationDef(i);
                durationDef.MsPositionReFirstUD = msPositionReFirstIUD;
                RestDef restDef = new RestDef(msPositionReFirstIUD + durationDef.MsDuration, bar1ChordMsSeparation - durationDef.MsDuration);
                msPositionReFirstIUD += bar1ChordMsSeparation;
                trk.UniqueDefs.Add(durationDef);
                trk.UniqueDefs.Add(restDef);
            }
        }
Пример #14
0
        /// <summary>
        /// This function creates only one bar, using Trk objects. 
        /// </summary>
        private Seq CreateBar2Seq()
        {
            List<Trk> bar = new List<Trk>();

            byte channel = 0;
            foreach(Palette palette in _palettes)
            {
                Trk trk = palette.NewTrk(channel);
                trk.MsPositionReContainer = 0;
                trk.MsDuration = 6000; // stretches or compresses the trk duration to 6000ms
                bar.Add(trk);
                ++channel;
            }

            int maxMsPosReBar = 0;
            // insert rests at the start of the Trks
            int restMsDuration = 0;
            foreach(Trk trk in bar)
            {
                if(restMsDuration > 0)
                {
                    RestDef restDef = new RestDef(0, restMsDuration);
                    trk.Insert(0, restDef);
                }
                restMsDuration += 1500;
                maxMsPosReBar = trk.EndMsPositionReFirstIUD;
            }

            // add the final rest in the bar
            foreach(Trk trk in bar)
            {
                int trkEndMsPosReBar = trk.EndMsPositionReFirstIUD;
                if(maxMsPosReBar > trkEndMsPosReBar)
                {
                    RestDef restDef = new RestDef(trkEndMsPosReBar, maxMsPosReBar - trkEndMsPosReBar);
                    trk.Add(restDef);
                }
            }

            Seq seq = new Seq(0, bar, MidiChannelIndexPerOutputVoice);

            return seq;
        }
Пример #15
0
        List<VoiceDef> CreateBar1()
        {
            List<VoiceDef> bar = new List<VoiceDef>();

            byte channel = 0;
            foreach(Palette palette in _palettes)
            {
                TrkDef trkDef = new TrkDef(channel, new List<IUniqueDef>());
                bar.Add(trkDef);
                WriteVoiceMidiDurationDefs1(trkDef, palette);
                ++channel;
            }

            InputVoiceDef inputVoiceDef = new InputVoiceDef();
            VoiceDef bottomOutputVoice = bar[0];

            foreach(IUniqueDef iud in bottomOutputVoice.UniqueDefs)
            {
                MidiChordDef mcd = iud as MidiChordDef;
                RestDef rd = iud as RestDef;
                if(mcd != null)
                {
                    List<IUniqueDef> iuds = new List<IUniqueDef>() { (IUniqueDef)mcd };

                    // Note that the msPosition of the trkDef is trkDef.StartMsPosition (= iuds[0].msPosition),
                    // which may be greater than the InputChordDef's msPosition
                    TrkDef trkDef = new TrkDef(bottomOutputVoice.MidiChannel, iuds);

                    // If non-null, arg2 overrides the inputControls attached to the InputNote or InputChord.
                    TrkOn trkRef = new TrkOn(trkDef, null);
                    List<TrkOn> trkRefs = new List<TrkOn>() { trkRef };
                    TrkOns trkOns = new TrkOns(trkRefs, null);

                    byte displayPitch = (byte)(mcd.NotatedMidiPitches[0] + 36);
                    Pressure pressure = new Pressure(0, null);
                    Pressures pressures = new Pressures(new List<Pressure>() {pressure}, null);
                    TrkOff trkOff = new TrkOff(trkRef.TrkMidiChannel, mcd.MsPosition, null);
                    List<TrkOff> noteOffTrkOffs = new List<TrkOff>() { trkOff };
                    TrkOffs trkOffs = new TrkOffs(noteOffTrkOffs, null);

                    InputNoteDef inputNoteDef = new InputNoteDef(displayPitch,
                                                                    trkOns, null,
                                                                    pressures,
                                                                    null, trkOffs,
                                                                    null);

                    List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>() { inputNoteDef };

                    // The InputChordDef's msPosition must be <= the msPosition of any of the contained trkRefs
                    InputChordDef icd = new InputChordDef(mcd.MsPosition, mcd.MsDuration, inputNoteDefs);

                    inputVoiceDef.UniqueDefs.Add(icd);
                }
                else if(rd != null)
                {
                    RestDef newRest = new RestDef(rd.MsPosition, rd.MsDuration);
                    inputVoiceDef.UniqueDefs.Add(newRest);
                }
            }

            #region set cascading inputControls on the first InputChordDef  (for testing)
            InputChordDef inputChordDef1 = inputVoiceDef.UniqueDefs[0] as InputChordDef; // no need to check for null here.

            InputControls chordInputControls = new InputControls();

            chordInputControls.VelocityOption = VelocityOption.overridden;
            chordInputControls.MinimumVelocity = 19;
            inputChordDef1.InputControls = chordInputControls;

            InputControls noteInputControls = new InputControls();
            noteInputControls.VelocityOption = VelocityOption.scaled;
            noteInputControls.MinimumVelocity = 20;
            inputChordDef1.InputNoteDefs[0].InputControls = noteInputControls;

            #endregion

            bar.Add(inputVoiceDef);

            return bar;
        }
Пример #16
0
        /// <summary>
        /// Returns either a new RestDef or a new MidiChordDef
        /// In both cases, MsPosition is set to zero, Lyric is set to null.
        /// </summary>
        private DurationDef GetDurationDef(int index)
        {
            DurationDef rval = null;
            BasicChordMidiSettings bcms = _basicChordMidiSettings;

            if(bcms.MidiPitches[index].Count == 0)
            {
                /// RestDefs are immutable, and have no MsPosition property.
                /// UniqueRestDefs are mutable RestDefs with both MsPositon and MsDuration properties.
                int restMsDuration = bcms.Durations[index];
                rval = new RestDef(0, restMsDuration);
            }
            else
            {
                /// Create a new MidiChordDef (with msPosition=0, lyric=null)
                bool hasChordOff = BoolOrDefaultValue(bcms.ChordOffs, index, M.DefaultHasChordOff); // true
                int duration = bcms.Durations[index];
                List<byte> rootMidiPitches = bcms.MidiPitches[index];
                List<byte> rootMidiVelocities = bcms.Velocities[index];

                byte? bankIndex = ByteOrNull(_bankIndices, index);
                byte? patchIndex = ByteOrNull(_patchIndices, index);
                byte pitchwheelDeviation = ByteOrDefaultValue(_pitchwheelDeviations, index, M.DefaultPitchWheelDeviation); // 2
                List<byte> pitchwheelEnvelope = ListByte(_pitchwheelEnvelopes, index);
                List<byte> panEnvelope = ListByte(_panEnvelopes, index);
                List<byte> modulationWheelEnvelope = ListByte(_modulationWheelEnvelopes, index);
                List<byte> expressionEnvelope = ListByte(_expressionEnvelopes, index);

                MidiChordSliderDefs midiChordSliderDefs =
                    new MidiChordSliderDefs(pitchwheelEnvelope,
                                            panEnvelope,
                                            modulationWheelEnvelope,
                                            expressionEnvelope);

                OrnamentSettings os = _ornamentSettings;
                List<BasicMidiChordDef> basicMidiChordDefs = new List<BasicMidiChordDef>();
                int ornamentNumber;
                if(os == null || _ornamentNumbers[index] == 0)
                {
                    ornamentNumber = 0;
                    BasicMidiChordDef bmcd = new BasicMidiChordDef(duration, bankIndex, patchIndex, hasChordOff, rootMidiPitches, rootMidiVelocities);
                    basicMidiChordDefs.Add(bmcd);
                }
                else
                {
                    ornamentNumber = _ornamentNumbers[index];
                    int ornamentMinMsDuration = IntOrDefaultValue(_ornamentMinMsDurations, index, M.DefaultOrnamentMinimumDuration); // 1

                    List<int> ornamentValues = os.OrnamentValues[_ornamentNumbers[index] - 1];

                    for(int i = 0; i < ornamentValues.Count; ++i)
                    {
                        int oIndex = ornamentValues[i] - 1;
                        bool oHasChordOff = BoolOrDefaultValue(os.BasicChordMidiSettings.ChordOffs, oIndex, M.DefaultHasChordOff);
                        int oDuration = os.BasicChordMidiSettings.Durations[oIndex];
                        List<byte> oMidiPitches = os.BasicChordMidiSettings.MidiPitches[oIndex];
                        List<byte> oVelocities = os.BasicChordMidiSettings.Velocities[oIndex];
                        byte? oBank = ByteOrNull(os.BankIndices, oIndex);
                        byte? oPatch = ByteOrNull(os.PatchIndices, oIndex);

                        BasicMidiChordDef bmcd = new BasicMidiChordDef(oDuration, oBank, oPatch, oHasChordOff, oMidiPitches, oVelocities);
                        basicMidiChordDefs.Add(bmcd);
                    }

                    // The basicMidiChordDefs currently contain the values from the ornaments form.
                    // All oBank and oPatch values will be null if the corresponding field in the ornament form was empty.
                    // The durations, pitches and velocities are relative to the main palette's values.

                    RemoveDuplicateBankAndPatchValues(basicMidiChordDefs);

                    if(basicMidiChordDefs[0].BankIndex == null)
                        basicMidiChordDefs[0].BankIndex = bankIndex; // can be null
                    if(basicMidiChordDefs[0].PatchIndex == null)
                        basicMidiChordDefs[0].PatchIndex = patchIndex;

                    Debug.Assert(basicMidiChordDefs[0].PatchIndex != null);

                    basicMidiChordDefs = Moritz.Spec.MidiChordDef.FitToDuration(basicMidiChordDefs, duration, ornamentMinMsDuration);

                    foreach(BasicMidiChordDef b in basicMidiChordDefs)
                    {
                        List<byte> combinedPitches = new List<byte>();
                        foreach(byte pitch in b.Pitches)
                        {
                            foreach(byte rootMidiPitch in rootMidiPitches)
                            {
                                combinedPitches.Add(M.MidiValue(rootMidiPitch + pitch));
                            }
                        }
                        b.Pitches = combinedPitches;

                        List<byte> combinedVelocities = new List<byte>();
                        foreach(byte velocity in b.Velocities)
                        {
                            foreach(byte rootMidiVelocity in rootMidiVelocities)
                            {
                                combinedVelocities.Add(M.MidiValue(rootMidiVelocity + velocity));
                            }
                        }
                        b.Velocities = combinedVelocities;
                    }
                }

                rval = new MidiChordDef(
                    duration,
                    pitchwheelDeviation,
                    hasChordOff,
                    rootMidiPitches,
                    rootMidiVelocities,
                    ornamentNumber,
                    midiChordSliderDefs,
                    basicMidiChordDefs);
            }
            return rval;
        }
Пример #17
0
        private TrkDef GetF1FinalePart1(Palette palette, Krystal krystal, List<int> strandIndices, Dictionary<string, int> msPositions)
        {
            TrkDef f1FinalePart1 = palette.NewTrkDef(0, krystal);

            List<int> f1eStrandDurations = GetStrandDurations(f1FinalePart1, strandIndices);

            int extraTime = 1000;
            int diff = extraTime / f1FinalePart1.Count;
            for(int i = f1FinalePart1.Count - 1; i > 0; --i)
            {
                if(strandIndices.Contains(i))
                {
                    RestDef umrd = new RestDef(f1FinalePart1[i].MsPosition, f1eStrandDurations[strandIndices.IndexOf(i)] + extraTime);
                    extraTime -= diff;
                    f1FinalePart1.Insert(i, umrd);
                }
            }

            f1FinalePart1.StartMsPosition = msPositions["interlude3Bar2"];

            f1FinalePart1.RemoveBetweenMsPositions(msPositions["verse4EsCaped"], int.MaxValue);

            if(f1FinalePart1[f1FinalePart1.Count - 1] is RestDef)
            {
                f1FinalePart1[f1FinalePart1.Count - 1].MsDuration = msPositions["verse4EsCaped"] - f1FinalePart1[f1FinalePart1.Count - 1].MsPosition;
            }

            return f1FinalePart1;
        }
Пример #18
0
        private TrkDef GetF1FinalePart2(Palette f1FinalePalette2, Krystal krystal, List<int> strandIndices, Dictionary<string, int> msPositions)
        {
            TrkDef f1FinalePart2 = f1FinalePalette2.NewTrkDef(this.MidiChannel, krystal);

            List<int> f1eStrandDurations = GetStrandDurations(f1FinalePart2, strandIndices);

            int extraTime = 500;
            int diff = extraTime / f1FinalePart2.Count;
            for(int i = f1FinalePart2.Count - 1; i > 0; --i)
            {
                if(strandIndices.Contains(i))
                {
                    RestDef umrd = new RestDef(f1FinalePart2[i].MsPosition, f1eStrandDurations[strandIndices.IndexOf(i)] + extraTime);
                    extraTime -= diff;
                    f1FinalePart2.Insert(i, umrd);
                }
            }

            f1FinalePart2.StartMsPosition = msPositions["verse4EsCaped"];
            f1FinalePart2.RemoveBetweenMsPositions(msPositions["verse5Calls"], int.MaxValue);

            if(f1FinalePart2[f1FinalePart2.Count - 1] is RestDef)
            {
                f1FinalePart2[f1FinalePart2.Count - 1].MsDuration = msPositions["postlude"] - f1FinalePart2[f1FinalePart2.Count - 1].MsPosition;
            }

            return f1FinalePart2;
        }
Пример #19
0
        private TrkDef GetF1Postlude(Palette f1PostludePalette, Krystal krystal, List<int> strandIndices, Dictionary<string, int> msPositions)
        {
            TrkDef f1p = f1PostludePalette.NewTrkDef(this.MidiChannel, krystal);

            List<int> f1eStrandDurations = GetStrandDurations(f1p, strandIndices);

            for(int i = f1p.Count - 1; i > 0; --i)
            {
                if(strandIndices.Contains(i))
                {
                    RestDef umrd = new RestDef(f1p[i].MsPosition, f1eStrandDurations[strandIndices.IndexOf(i)] / 4);
                    f1p.Insert(i, umrd);
                }
            }

            f1p.StartMsPosition = msPositions["postlude"];
            f1p.RemoveBetweenMsPositions(msPositions["endOfPiece"], int.MaxValue);

            return f1p;
        }
Пример #20
0
        /// <summary>
        /// There is currently still one bar per system.
        /// </summary>
        protected void ReplaceConsecutiveRestsInBars(List<List<VoiceDef>> voicesPerStaffPerSystem)
        {
            foreach(List<VoiceDef> voicesPerStaff in voicesPerStaffPerSystem)
            {
                foreach(VoiceDef voice in voicesPerStaff)
                {
                    // contains lists of consecutive rest indices
                    List<List<int>> restsToReplace = new List<List<int>>();
                    #region find the consecutive rests
                    List<int> consecRestIndices = new List<int>();
                    for(int i = 0; i < voice.UniqueDefs.Count - 1; i++)
                    {
                        MidiChordDef mcd1 = voice.UniqueDefs[i] as MidiChordDef;
                        MidiChordDef mcd2 = voice.UniqueDefs[i + 1] as MidiChordDef;
                        if(mcd1 == null && mcd2 == null)
                        {
                            if(!consecRestIndices.Contains(i))
                            {
                                consecRestIndices.Add(i);
                            }
                            consecRestIndices.Add(i + 1);
                        }
                        else
                        {
                            if(consecRestIndices != null && consecRestIndices.Count > 0)
                            {
                                restsToReplace.Add(consecRestIndices);
                                consecRestIndices = new List<int>();
                            }
                        }

                        if(i == voice.UniqueDefs.Count - 2 && consecRestIndices.Count > 0)
                        {
                            restsToReplace.Add(consecRestIndices);
                        }
                    }
                    #endregion
                    #region replace the consecutive rests
                    if(restsToReplace.Count > 0)
                    {
                        for(int i = restsToReplace.Count - 1; i >= 0; i--)
                        {
                            List<int> indToReplace = restsToReplace[i];
                            int msDuration = 0;
                            int msPosition = voice.UniqueDefs[indToReplace[0]].MsPosition;
                            for(int j = indToReplace.Count - 1; j >= 0; j--)
                            {
                                IUniqueDef iumdd = voice.UniqueDefs[indToReplace[j]];
                                Debug.Assert(iumdd.MsDuration > 0);
                                msDuration += iumdd.MsDuration;
                                voice.UniqueDefs.RemoveAt(indToReplace[j]);
                            }
                            RestDef replacementLmdd = new RestDef(msPosition, msDuration);
                            voice.UniqueDefs.Insert(indToReplace[0], replacementLmdd);
                        }
                    }
                    #endregion
                }
            }
        }
Пример #21
0
 public override IUniqueDef DeepClone()
 {
     RestDef umrd = new RestDef(this.MsPosition, this.MsDuration);
     return umrd;
 }
Пример #22
0
 public override object Clone()
 {
     RestDef umrd = new RestDef(this.MsPositionReFirstUD, this.MsDuration);
     return umrd;
 }
Пример #23
0
        /// <summary>
        /// This function creates only one bar, but with VoiceDef objects. 
        /// </summary>
        List<VoiceDef> CreateBar2(int bar2StartMsPos)
        {
            List<VoiceDef> bar = new List<VoiceDef>();

            byte channel = 0;
            List<TrkDef> trkDefs = new List<TrkDef>();
            foreach(Palette palette in _palettes)
            {
                bar.Add(new TrkDef(channel, new List<IUniqueDef>()));
                TrkDef trkDef = palette.NewTrkDef(channel);
                trkDef.SetMsDuration(6000);
                trkDefs.Add(trkDef);
                ++channel;
            }

            int msPosition = bar2StartMsPos;
            int maxBarMsPos = 0;
            int startMsDifference = 1500;
            for(int i = 0; i < trkDefs.Count; ++i)
            {
                int maxMsPos = WriteVoiceMidiDurationDefsInBar2(bar[i], trkDefs[i], msPosition, bar2StartMsPos);
                maxBarMsPos = maxBarMsPos > maxMsPos ? maxBarMsPos : maxMsPos;
                msPosition += startMsDifference;
            }

            // now add the final rest in the bar
            for(int i = 0; i < trkDefs.Count; ++i)
            {
                int mdsdEndPos = trkDefs[i].EndMsPosition;
                if(maxBarMsPos > mdsdEndPos)
                {
                    RestDef rest2Def = new RestDef(mdsdEndPos, maxBarMsPos - mdsdEndPos);
                    bar[i].UniqueDefs.Add(rest2Def);
                }
            }

            InputVoiceDef inputVoiceDef = new InputVoiceDef(maxBarMsPos - bar2StartMsPos);
            inputVoiceDef.StartMsPosition = bar2StartMsPos;
            int msPos = bar2StartMsPos;
            for(int i = 0; i < bar.Count; ++i)
            {
                TrkOn trkRef = new TrkOn((byte)i, msPos, 12, null);
                List<TrkOn> trkRefs = new List<TrkOn>() { trkRef };
                TrkOns seqDef = new TrkOns(trkRefs, null);

                InputNoteDef inputNoteDef = new InputNoteDef(64, seqDef, null, null);

                List<InputNoteDef> inputNoteDefs = new List<InputNoteDef>(){inputNoteDef};
                InputChordDef inputChordDef = new InputChordDef(msPos, startMsDifference, inputNoteDefs);
                inputVoiceDef.InsertInRest(inputChordDef);
                msPos += startMsDifference;
            }

            bar.Add(inputVoiceDef);
            return bar;
        }
Пример #24
0
        /// <summary>
        /// Steals the ticks from furies 3, then agglommerates the remaining rests in furies3...
        /// </summary>
        private void GetFuries2Interlude2(Clytemnestra clytemnestra, Trk wind1, Trk furies3)
        {
            List<int> furies3TickIndices = new List<int>()
            {
                66,70,74,81,85,89,93,
                96,100,104,109,113,117,122,
                126,130,135,139,143,148,152
            };
            for(int i = 0; i < furies3TickIndices.Count; ++i)
            {
                int f3Index = furies3TickIndices[i];
                MidiChordDef ticksChord = furies3[f3Index] as MidiChordDef;
                Debug.Assert(ticksChord != null);
                RestDef ticksRest = new RestDef(ticksChord.MsPositionReTrk, ticksChord.MsDuration);
                furies3.Replace(f3Index, ticksRest);
                InsertInRest(ticksChord);
            }

            MidiChordDef lastTicksBeforeVerse3 = (MidiChordDef)((MidiChordDef)this[39]).Clone();
            lastTicksBeforeVerse3.MsPositionReTrk = furies3[155].MsPositionReTrk + furies3[155].MsDuration;
            lastTicksBeforeVerse3.MsDuration = clytemnestra[117].MsPositionReTrk - lastTicksBeforeVerse3.MsPositionReTrk;
            lastTicksBeforeVerse3.Transpose(10);
            InsertInRest(lastTicksBeforeVerse3);

            furies3.AgglomerateRests();
        }
Пример #25
0
        private void WriteVoiceMidiDurationDefs1(TrkDef trkDef, Palette palette)
        {
            int bar1ChordMsSeparation = 1500;
            int msPosition = 0;

            for(int i = 0; i < palette.Count;++i)
            {
                IUniqueDef noteDef = palette.UniqueDurationDef(i);
                noteDef.MsPosition = msPosition;
                RestDef restDef = new RestDef(msPosition + noteDef.MsDuration, bar1ChordMsSeparation - noteDef.MsDuration);
                msPosition += bar1ChordMsSeparation;
                trkDef.UniqueDefs.Add(noteDef);
                trkDef.UniqueDefs.Add(restDef);
            }
        }
Пример #26
0
 /// <summary>
 /// Adds the argument to the end of this VoiceDef.
 /// Sets the MsPositions of the appended UniqueDefs.
 /// </summary>
 public void Concat(InputVoiceDef inputVoiceDef)
 {
     int thisEndMsPositionReSeq = this.EndMsPositionReFirstIUD + this.MsPositionReContainer;
     if(inputVoiceDef.MsPositionReContainer > thisEndMsPositionReSeq)
     {
         RestDef rest = new RestDef(this.EndMsPositionReFirstIUD, inputVoiceDef.MsPositionReContainer - thisEndMsPositionReSeq);
         this.Add(rest);
     }
     _AddRange(inputVoiceDef);
 }
Пример #27
0
        /// <summary>
        /// Writes the first rest (if any) and the VoiceDef to the voice.
        /// Returns the endMsPos of the VoiceDef. 
        /// </summary>
        private int WriteVoiceMidiDurationDefsInBar2(VoiceDef voice, TrkDef trkDef, int msPosition, int bar2StartMsPos)
        {
            if(msPosition > bar2StartMsPos)
            {
                RestDef rest1Def = new RestDef(bar2StartMsPos, msPosition - bar2StartMsPos);
                voice.UniqueDefs.Add(rest1Def);
            }

            trkDef.StartMsPosition = msPosition;
            foreach(IUniqueDef iu in trkDef)
            {
                voice.UniqueDefs.Add(iu);
            }

            return trkDef.EndMsPosition;
        }
Пример #28
0
        /// <summary>
        /// Returns either a new RestDef or a new MidiChordDef
        /// In both cases, MsPosition is set to zero, Lyric is set to null.
        /// </summary>
        private DurationDef GetDurationDef()
        {
            DurationDef rval = null;

            if(this.ChordDensityTextBox.Text == "0")
            {
                int msDuration = 0;
                try
                {
                    msDuration = int.Parse(this.DurationTextBox.Text);
                }
                catch
                {
                    Debug.Assert(false);
                }
                Debug.Assert(msDuration > 0);
                rval = new RestDef(0, msDuration);
            }
            else
            {
                Palette palette = new Palette(this);
                rval = palette.MidiChordDef(0);
            }

            return rval;
        }
Пример #29
0
        /// <summary>
        /// This function creates only one bar, but with VoiceDef objects. 
        /// </summary>
        List<VoiceDef> CreateBar2(int bar2StartMsPos)
        {
            List<VoiceDef> bar = new List<VoiceDef>();

            byte channel = 0;
            List<TrkDef> trkDefs = new List<TrkDef>();
            foreach(Palette palette in _palettes)
            {
                bar.Add(new TrkDef(channel, new List<IUniqueDef>()));
                TrkDef trkDef = palette.NewTrkDef(channel);
                trkDef.SetMsDuration(6000);
                trkDefs.Add(trkDef);
                ++channel;
            }
            int msPosition = bar2StartMsPos;
            int maxBarMsPos = 0;
            for(int i = 0; i < trkDefs.Count; ++i)
            {
                int maxMsPos = WriteVoiceMidiDurationDefsInBar2(bar[i], trkDefs[i], msPosition, bar2StartMsPos);
                maxBarMsPos = maxBarMsPos > maxMsPos ? maxBarMsPos : maxMsPos;
                msPosition += 1500;
            }

            // now add the final rest in the bar
            for(int i = 0; i < trkDefs.Count; ++i)
            {
                int mdsdEndPos = trkDefs[i].EndMsPosition;
                if(maxBarMsPos > mdsdEndPos)
                {
                    RestDef rest2Def = new RestDef(mdsdEndPos, maxBarMsPos - mdsdEndPos);
                    bar[i].UniqueDefs.Add(rest2Def);
                }
            }
            return bar;
        }