Ejemplo n.º 1
0
        private List <IUniqueDef> GetTicksSequence(Palette ticksPalette)
        {
            List <IUniqueDef> ticksSequence = new List <IUniqueDef>();
            int msPosition = 0;

            int[] transpositions = { 12, 14, 17 };

            for (int i = 0; i < 3; ++i)
            {
                int[] contour = K.Contour(7, 4, 10 - i);
                for (int j = 6; j >= 0; --j)
                {
                    IUniqueDef ticks = ticksPalette.UniqueDurationDef(contour[j] - 1);
                    ticks.MsPosition = msPosition;
                    msPosition      += ticks.MsDuration;
                    MidiChordDef iumdd = ticks as MidiChordDef;
                    if (iumdd != null)
                    {
                        iumdd.Transpose(transpositions[i] + contour[j]);
                        iumdd.AdjustVelocities(0.6);
                    }

                    ticksSequence.Add(ticks);
                }
            }

            return(ticksSequence);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The clefType must be one of the following strings "t", "t1", "t2", "t3", "b", "b1", "b2", "b3"
        /// The followingUniqueMidiChordOrRestDef must be a MidiChordDef or UniqueMidiRestDef.
        /// </summary>
        public ClefChangeDef(string clefType, IUniqueDef followingUniqueChordOrRestDef)
            : base()
        {
            #region check args
            if (String.Equals(clefType, "t") == false &&
                String.Equals(clefType, "t1") == false &&
                String.Equals(clefType, "t2") == false &&
                String.Equals(clefType, "t3") == false &&
                String.Equals(clefType, "b") == false &&
                String.Equals(clefType, "b1") == false &&
                String.Equals(clefType, "b2") == false &&
                String.Equals(clefType, "b3") == false)
            {
                Debug.Assert(false, "Unknown clef type.");
            }

            if (!(followingUniqueChordOrRestDef is MidiChordDef) &&
                !(followingUniqueChordOrRestDef is InputChordDef) &&
                !(followingUniqueChordOrRestDef is RestDef))
            {
                Debug.Assert(false, "Clef change must be followed by a chord or rest.");
            }
            #endregion

            _id       = "clefChange" + UniqueClefChangeIDNumber.ToString();
            _clefType = clefType;
            _followingChordOrRestDef = followingUniqueChordOrRestDef;
        }
Ejemplo n.º 3
0
        private TrkDef 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.MsPosition = 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);
                }
            }

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

            return(furies3FlutterSequence1);
        }
Ejemplo n.º 4
0
 internal void RemoveDuplicateClefDefs()
 {
     if (_uniqueDefs.Count > 1)
     {
         for (int i = _uniqueDefs.Count - 1; i > 0; --i)
         {
             IUniqueDef iud1 = _uniqueDefs[i];
             if (iud1 is ClefDef)
             {
                 for (int j = i - 1; j >= 0; --j)
                 {
                     IUniqueDef iud2 = _uniqueDefs[j];
                     if (iud2 is ClefDef)
                     {
                         if (string.Compare(((ClefDef)iud1).ClefType, ((ClefDef)iud2).ClefType) == 0)
                         {
                             _uniqueDefs.RemoveAt(i);
                         }
                         break;
                     }
                 }
             }
         }
         AssertConsistency();
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns a deep clone of this TrkDef.
        /// </summary>
        public TrkDef DeepClone()
        {
            List <IUniqueDef> clonedLmdds = new List <IUniqueDef>();

            foreach (IUniqueDef iu in this._uniqueDefs)
            {
                IUniqueDef clone = iu.DeepClone();
                clonedLmdds.Add(clone);
            }

            // Clefchange symbols must point at the following object in their own VoiceDef
            for (int i = 0; i < clonedLmdds.Count; ++i)
            {
                ClefChangeDef clone = clonedLmdds[i] as ClefChangeDef;
                if (clone != null)
                {
                    Debug.Assert(i < (clonedLmdds.Count - 1));
                    ClefChangeDef replacement = new ClefChangeDef(clone.ClefType, clonedLmdds[i + 1]);
                    clonedLmdds.RemoveAt(i);
                    clonedLmdds.Insert(i, replacement);
                }
            }

            return(new TrkDef(this.MidiChannel, clonedLmdds));
        }
Ejemplo n.º 6
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
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// The clefType must be one of the following strings "t", "t1", "t2", "t3", "b", "b1", "b2", "b3"
        /// The followingUniqueMidiChordOrRestDef must be a MidiChordDef or UniqueMidiRestDef.
        /// </summary>
        public ClefChangeDef(string clefType, IUniqueDef followingUniqueChordOrRestDef)
            : base()
        {
            #region check args
            if(String.Equals(clefType, "t") == false
            && String.Equals(clefType, "t1") == false
            && String.Equals(clefType, "t2") == false
            && String.Equals(clefType, "t3") == false
            && String.Equals(clefType, "b") == false
            && String.Equals(clefType, "b1") == false
            && String.Equals(clefType, "b2") == false
            && String.Equals(clefType, "b3") == false)
            {
                Debug.Assert(false, "Unknown clef type.");
            }

            if(!(followingUniqueChordOrRestDef is MidiChordDef)
            && !(followingUniqueChordOrRestDef is InputChordDef)
            && !(followingUniqueChordOrRestDef is RestDef))
            {
                Debug.Assert(false, "Clef change must be followed by a chord or rest.");
            }
            #endregion

            _id = "clefChange" + UniqueClefChangeIDNumber.ToString();
            _clefType = clefType;
            _followingChordOrRestDef = followingUniqueChordOrRestDef;
        }
Ejemplo n.º 8
0
        private List <VoiceDef> WriteLowerStaff(int staffNumber, List <VoiceDef> topStaffBars)
        {
            List <VoiceDef>    consecutiveBars  = new List <VoiceDef>();
            Krystal            krystal          = _krystals[staffNumber - 1];
            Palette            palette          = _palettes[staffNumber - 1];
            List <List <int> > strandValuesList = krystal.GetValues(krystal.Level);

            Debug.Assert(topStaffBars.Count == strandValuesList.Count);

            for (int barIndex = 0; barIndex < strandValuesList.Count; barIndex++)
            {
                VoiceDef topStaffVoice     = topStaffBars[barIndex];
                VoiceDef newVoice          = new TrkDef((byte)(staffNumber - 1), new List <IUniqueDef>());
                int      currentMsPosition = topStaffVoice.UniqueDefs[0].MsPosition;

                List <int> lowerStaffValueSequence = strandValuesList[barIndex];
                List <int> lowerStaffMsDurations   = LowerStaffMsDurations(topStaffVoice, lowerStaffValueSequence.Count);
                for (int valueIndex = 0; valueIndex < lowerStaffValueSequence.Count; valueIndex++)
                {
                    int        value   = lowerStaffValueSequence[valueIndex];
                    IUniqueDef noteDef = palette.UniqueDurationDef(value - 1);
                    noteDef.MsDuration = lowerStaffMsDurations[valueIndex];
                    noteDef.MsPosition = currentMsPosition;
                    currentMsPosition += noteDef.MsDuration;
                    newVoice.UniqueDefs.Add(noteDef);
                }

                consecutiveBars.Add(newVoice);
            }
            return(consecutiveBars);
        }
Ejemplo n.º 9
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].MsPosition > originalRest.MsPosition)
            {
                RestDef rest1 = new RestDef(originalRest.MsPosition, iVoiceDef[0].MsPosition - originalRest.MsPosition);
                rList.Add(rest1);
            }
            rList.AddRange(iVoiceDef.UniqueDefs);
            int iLmddsEndMsPos       = iVoiceDef[iVoiceDef.Count - 1].MsPosition + iVoiceDef[iVoiceDef.Count - 1].MsDuration;
            int originalRestEndMsPos = originalRest.MsPosition + originalRest.MsDuration;

            if (originalRestEndMsPos > iLmddsEndMsPos)
            {
                RestDef rest2 = new RestDef(iLmddsEndMsPos, originalRestEndMsPos - iLmddsEndMsPos);
                rList.Add(rest2);
            }

            return(rList);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Multiplies the MsDuration of each T from beginIndex to endIndex (exclusive) by factor.
        /// If a MsDuration becomes less than minThreshold, the T (chord or rest) is removed.
        /// The total duration of this VoiceDef changes accordingly.
        /// </summary>
        protected void AdjustMsDurations <T>(int beginIndex, int endIndex, double factor, int minThreshold = 100)
        {
            M.Assert(!(Container is Bar), "Cannot AdjustChordMsDurations inside a Bar.");

            if (CheckIndices(beginIndex, endIndex))
            {
                M.Assert(factor >= 0);
                for (int i = beginIndex; i < endIndex; ++i)
                {
                    IUniqueDef iumdd = _uniqueDefs[i];
                    if (iumdd is T)
                    {
                        iumdd.MsDuration = (int)((double)iumdd.MsDuration * factor);
                    }
                }

                for (int i = _uniqueDefs.Count - 1; i >= 0; --i)
                {
                    IUniqueDef iumdd = _uniqueDefs[i];
                    if (iumdd.MsDuration < minThreshold)
                    {
                        _uniqueDefs.RemoveAt(i);
                    }
                }

                SetMsPositionsReFirstUD();

                AssertConsistency();
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// removes the iUniqueDef from the list, and then resets the positions of all the iUniques in the list.
 /// </summary>
 public void Remove(IUniqueDef iUniqueDef)
 {
     Debug.Assert(_uniqueDefs.Count > 0);
     Debug.Assert(_uniqueDefs.Contains(iUniqueDef));
     _uniqueDefs.Remove(iUniqueDef);
     SetMsPositions();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Removes the iUniqueMidiDurationDef at index from the list, and then inserts the replacement at the same index.
 /// </summary>
 protected void _Replace(int index, IUniqueDef replacementIUnique)
 {
     Debug.Assert(index >= 0 && index < _uniqueDefs.Count);
     _uniqueDefs.RemoveAt(index);
     _uniqueDefs.Insert(index, replacementIUnique);
     SetMsPositions();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Multiplies the MsDuration of each T from beginIndex to (not including) endIndex by factor.
        /// If a MsDuration becomes less than minThreshold, the T (chord or rest) is removed.
        /// The total duration of this VoiceDef changes accordingly.
        /// </summary>
        protected void AdjustMsDurations <T>(int beginIndex, int endIndex, double factor, int minThreshold = 100)
        {
            CheckIndices(beginIndex, endIndex);
            Debug.Assert(factor >= 0);

            for (int i = 0; i < _uniqueDefs.Count; ++i)
            {
                IUniqueDef iumdd = _uniqueDefs[i];
                if (i >= beginIndex && i < endIndex && iumdd is T)
                {
                    iumdd.MsDuration = (int)((double)iumdd.MsDuration * factor);
                }
            }

            for (int i = _uniqueDefs.Count - 1; i >= 0; --i)
            {
                IUniqueDef iumdd = _uniqueDefs[i];
                if (iumdd.MsDuration < minThreshold)
                {
                    _uniqueDefs.RemoveAt(i);
                }
            }

            SetMsPositions();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets Clytamnestra's _uniqueMidiDurationDefs for the whole piece including rests.
        /// Barline positions are set later.
        /// </summary>
        private void SetUniqueMidiDurationDefs(TrkDef wind3)
        {
            Debug.Assert(_momentDefsListPerVerse.Count == 5);

            List <int> verseMsPositions = new List <int>();

            verseMsPositions.Add(wind3[8].MsPosition);
            verseMsPositions.Add(wind3[20].MsPosition);
            verseMsPositions.Add(wind3[33].MsPosition);
            verseMsPositions.Add(wind3[49].MsPosition);
            verseMsPositions.Add(wind3[70].MsPosition);

            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.DeepClone();
                    lmcd.MsPosition = 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].MsPosition +
                                           _uniqueDefs[_uniqueDefs.Count - 1].MsDuration;
                }
            }
            interludeRestDef = new RestDef(currentEndMsPosition, wind3.EndMsPosition - currentEndMsPosition);
            _uniqueDefs.Add(interludeRestDef);
        }
Ejemplo n.º 15
0
        protected void _Add(IUniqueDef iUniqueDef)
        {
            Debug.Assert(_uniqueDefs.Count > 0);
            IUniqueDef lastLmdd = _uniqueDefs[_uniqueDefs.Count - 1];

            iUniqueDef.MsPosition = lastLmdd.MsPosition + lastLmdd.MsDuration;
            _uniqueDefs.Add(iUniqueDef);
        }
Ejemplo n.º 16
0
 public RestSymbol(Voice voice, IUniqueDef iumdd, int minimumCrotchetDurationMS, float fontHeight)
     : base(voice, iumdd.MsDuration, iumdd.MsPosition, minimumCrotchetDurationMS, fontHeight)
 {
     if (iumdd is CautionaryChordDef)
     {
         Console.WriteLine("rest is CautionaryChordDef!");
     }
     LocalCautionaryChordDef = iumdd as CautionaryChordDef;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// removes the iUniqueDef from the list, and then resets the positions of all the iUniqueDefs in the list.
        /// </summary>
        public void Remove(IUniqueDef iUniqueDef)
        {
            M.Assert(_uniqueDefs.Count > 0);
            M.Assert(_uniqueDefs.Contains(iUniqueDef));
            _uniqueDefs.Remove(iUniqueDef);
            SetMsPositionsReFirstUD();

            AssertConsistency();
        }
Ejemplo n.º 18
0
        protected void _Insert(int index, IUniqueDef iUniqueDef)
        {
            M.Assert(!(Container is Bar && iUniqueDef.MsDuration > 0), "Cannot Insert IUniqueDefs that have msDuration inside a Bar.");

            _uniqueDefs.Insert(index, iUniqueDef);
            SetMsPositionsReFirstUD();

            AssertConsistency();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Returns the position of the end of the last UniqueMidiDurationDef
        /// in the bar's first voice's UniqueMidiDurationDefs list.
        /// </summary>
        protected int GetEndMsPosition(List <VoiceDef> bar)
        {
            Debug.Assert(bar != null && bar.Count > 0 && bar[0].UniqueDefs.Count > 0);
            List <IUniqueDef> lmdd     = bar[0].UniqueDefs;
            IUniqueDef        lastLmdd = lmdd[lmdd.Count - 1];
            int endMsPosition          = lastLmdd.MsPosition + lastLmdd.MsDuration;

            return(endMsPosition);
        }
Ejemplo n.º 20
0
 public RestSymbol(Voice voice, IUniqueDef iumdd, int minimumCrotchetDurationMS, float fontHeight)
     : base(voice, iumdd.MsDuration, iumdd.MsPosition, minimumCrotchetDurationMS, fontHeight)
 {
     if(iumdd is CautionaryChordDef)
     {
         Console.WriteLine("rest is CautionaryChordDef!");
     }
     LocalCautionaryChordDef = iumdd as CautionaryChordDef;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Remove the IUniques which start between startMsPos and (not including) endMsPos
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        public void RemoveBetweenMsPositions(int startMsPos, int endMsPos)
        {
            IUniqueDef iumdd = _uniqueDefs.Find(f => (f.MsPosition >= startMsPos) && (f.MsPosition < endMsPos));

            while (iumdd != null)
            {
                _uniqueDefs.Remove(iumdd);
                iumdd = _uniqueDefs.Find(f => (f.MsPosition >= startMsPos) && (f.MsPosition < endMsPos));
            }
            SetMsPositions();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Old constructor, currently not used (03.05.2020), but retained for future inspection
        /// </summary>
        public RestSymbol(Voice voice, IUniqueDef iumdd, int absMsPosition, int minimumCrotchetDurationMS, double fontHeight)
            : base(voice, iumdd.MsDuration, absMsPosition, minimumCrotchetDurationMS, fontHeight)
        {
            M.Assert(false); // 03.05.2020: don't use this constructor (to be inspected once work on midi info begins).

            if (iumdd is CautionaryChordDef)
            {
                Console.WriteLine("rest is CautionaryChordDef!");
            }
            LocalCautionaryChordDef = iumdd as CautionaryChordDef;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Removes the iUniqueMidiDurationDef at index from the list, and then inserts the replacement at the same index.
        /// </summary>
        protected void _Replace(int index, IUniqueDef replacementIUnique)
        {
            M.Assert(!(Container is Bar), "Cannot Replace IUniqueDefs inside a Bar.");

            M.Assert(index >= 0 && index < _uniqueDefs.Count);
            _uniqueDefs.RemoveAt(index);
            _uniqueDefs.Insert(index, replacementIUnique);
            SetMsPositionsReFirstUD();

            AssertConsistency();
        }
Ejemplo n.º 24
0
 static void Drop(ElementCode context, string tableName, IUniqueDef unique)
 {
     if (unique == null)
     {
         return;
     }
     context.Add(SqlKeyword.AlterTable, SqlKeyword.IfExists);
     context.Concat(tableName);
     context.Add(SqlKeyword.DropConstraint, SqlKeyword.IfExists);
     context.Concat(unique.Name);
     context.Go();
 }
Ejemplo n.º 25
0
        /// <summary>
        /// There is still one system per bar.
        /// Each VoiceDef begins with an MNXCommon.Clef (taking small clefs into account).
        /// An Exception will be thrown if a SmallClefDef is found on the lower voiceDef in a staff in the systems input.
        /// Small clefs (if there are any) are copied from the top to the bottom voice (if there is one) on each staff.
        /// Small clefs on lower voices on a staff have IsVisible set to false.
        /// </summary>
        /// <param name="systems"></param>
        public void ConvertVoiceDefsToNoteObjects(List <SvgSystem> systems)
        {
            byte[] currentChannelVelocities = new byte[systems[0].Staves.Count];
            var    topVoiceSmallClefs       = new List <SmallClef>();

            int systemAbsMsPos = 0;

            for (int systemIndex = 0; systemIndex < systems.Count; ++systemIndex)
            {
                SvgSystem system = systems[systemIndex];
                system.AbsStartMsPosition = systemAbsMsPos;
                int msPositionReVoiceDef = 0;
                for (int staffIndex = 0; staffIndex < system.Staves.Count; ++staffIndex)
                {
                    Staff staff = system.Staves[staffIndex];
                    msPositionReVoiceDef = 0;
                    topVoiceSmallClefs.Clear();
                    for (int voiceIndex = 0; voiceIndex < staff.Voices.Count; ++voiceIndex)
                    {
                        Voice voice = staff.Voices[voiceIndex];
                        voice.VoiceDef.AgglomerateRests();

                        msPositionReVoiceDef = 0;
                        List <IUniqueDef> iuds = voice.VoiceDef.UniqueDefs;
                        M.Assert(iuds[0] is ClefDef || iuds[0] is MNX.Common.Clef); /** <-------------- **/

                        for (int iudIndex = 0; iudIndex < iuds.Count; ++iudIndex)
                        {
                            IUniqueDef iud           = voice.VoiceDef.UniqueDefs[iudIndex];
                            int        absMsPosition = systemAbsMsPos + msPositionReVoiceDef;

                            NoteObject noteObject =
                                SymbolSet.GetNoteObject(voice, absMsPosition, iud, iudIndex, ref currentChannelVelocities[staffIndex]);

                            if (noteObject is SmallClef smallClef)
                            {
                                if (voiceIndex == 0)
                                {
                                    if (staff.Voices.Count > 1)
                                    {
                                        topVoiceSmallClefs.Add(smallClef);
                                    }
                                }
                                else
                                {
                                    throw new Exception("SmallClefs may not be defined for a lower voice. They will be copied from the top voice");
                                }
                            }

                            if (iud is IUniqueSplittableChordDef iscd && iscd.MsDurationToNextBarline != null)
                            {
                                msPositionReVoiceDef += (int)iscd.MsDurationToNextBarline;
                            }
Ejemplo n.º 26
0
        /// <summary>
        /// Remove the IUniqueDefs which start between startMsPosReFirstIUD and (not including) endMsPosReFirstIUD
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        public void RemoveBetweenMsPositions(int startMsPosReFirstIUD, int endMsPosReFirstIUD)
        {
            IUniqueDef iumdd = _uniqueDefs.Find(f => (f.MsPositionReFirstUD >= startMsPosReFirstIUD) && (f.MsPositionReFirstUD < endMsPosReFirstIUD));

            while (iumdd != null)
            {
                _uniqueDefs.Remove(iumdd);
                iumdd = _uniqueDefs.Find(f => (f.MsPositionReFirstUD >= startMsPosReFirstIUD) && (f.MsPositionReFirstUD < endMsPosReFirstIUD));
            }
            SetMsPositionsReFirstUD();

            AssertConsistency();
        }
Ejemplo n.º 27
0
        private void WriteDurationSymbolsForStrandInTopStaff(VoiceDef voice, int barIndex, List <int> originalStrandValues, ref int msPosition)
        {
            Palette palette = _palettes[0]; // top templateDefs

            for (int valueIndex = 0; valueIndex < originalStrandValues.Count; valueIndex++)
            {
                int        value   = originalStrandValues[valueIndex];
                IUniqueDef noteDef = palette.UniqueDurationDef(value - 1);
                noteDef.MsPosition = msPosition;
                msPosition        += noteDef.MsDuration;
                voice.UniqueDefs.Add(noteDef);
            }
        }
Ejemplo n.º 28
0
        private void InsertVoiceDefInRest(int restIndex, VoiceDef iVoiceDef)
        {
            List <IUniqueDef> lmdds       = _uniqueDefs;
            IUniqueDef        rest        = lmdds[restIndex];
            List <IUniqueDef> replacement = GetReplacementList(rest, iVoiceDef);
            int replacementStart          = replacement[0].MsPosition;
            int replacementEnd            = replacement[replacement.Count - 1].MsPosition + replacement[replacement.Count - 1].MsDuration;
            int restStart = rest.MsPosition;
            int restEnd   = rest.MsPosition + rest.MsDuration;

            Debug.Assert(restStart == replacementStart && restEnd == replacementEnd);
            lmdds.RemoveAt(restIndex);
            lmdds.InsertRange(restIndex, replacement);
        }
Ejemplo n.º 29
0
        private void WriteVoiceMidiDurationDefs1(TrkDef trkDef, Palette palette)
        {
            int msPosition            = 0;
            int bar1ChordMsSeparation = 1500;

            for (int i = 0; i < palette.Count; ++i)
            {
                IUniqueDef durationDef = palette.UniqueDurationDef(i);
                durationDef.MsPosition = msPosition;
                RestDef restDef = new RestDef(msPosition + durationDef.MsDuration, bar1ChordMsSeparation - durationDef.MsDuration);
                msPosition += bar1ChordMsSeparation;
                trkDef.UniqueDefs.Add(durationDef);
                trkDef.UniqueDefs.Add(restDef);
            }
        }
Ejemplo n.º 30
0
        public override NoteObject GetNoteObject(Voice voice, IUniqueDef iud, bool firstDefInVoice,
                                                 ref byte currentVelocity, float musicFontHeight)
        {
            NoteObject         noteObject         = null;
            CautionaryChordDef cautionaryChordDef = iud as CautionaryChordDef;
            MidiChordDef       midiChordDef       = iud as MidiChordDef;
            InputChordDef      inputChordDef      = iud as InputChordDef;
            RestDef            restDef            = iud as RestDef;
            ClefChangeDef      clefChangeDef      = iud as ClefChangeDef;

            PageFormat pageFormat              = voice.Staff.SVGSystem.Score.PageFormat;
            float      cautionaryFontHeight    = pageFormat.CautionaryNoteheadsFontHeight;
            int        minimumCrotchetDuration = pageFormat.MinimumCrotchetDuration;

            if (cautionaryChordDef != null && firstDefInVoice)
            {
                CautionaryChordSymbol cautionaryChordSymbol = new CautionaryChordSymbol(voice, cautionaryChordDef, cautionaryFontHeight);
                noteObject = cautionaryChordSymbol;
            }
            else if (midiChordDef != null)
            {
                OutputChordSymbol outputChordSymbol = new OutputChordSymbol(voice, midiChordDef, minimumCrotchetDuration, musicFontHeight);

                if (midiChordDef.MidiVelocity != currentVelocity)
                {
                    outputChordSymbol.AddDynamic(midiChordDef.MidiVelocity, currentVelocity);
                    currentVelocity = midiChordDef.MidiVelocity;
                }
                noteObject = outputChordSymbol;
            }
            else if (inputChordDef != null)
            {
                InputChordSymbol inputChordSymbol = new InputChordSymbol(voice, inputChordDef, minimumCrotchetDuration, musicFontHeight);
                noteObject = inputChordSymbol;
            }
            else if (restDef != null)
            {
                RestSymbol restSymbol = new RestSymbol(voice, iud, minimumCrotchetDuration, musicFontHeight);
                noteObject = restSymbol;
            }
            else if (clefChangeDef != null)
            {
                ClefChangeSymbol clefChangeSymbol = new ClefChangeSymbol(voice, clefChangeDef.ClefType, cautionaryFontHeight, ((IUniqueDef)iud).MsPosition);
                noteObject = clefChangeSymbol;
            }

            return(noteObject);
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Combines all consecutive rests.
 /// </summary>
 public void AgglomerateRests()
 {
     if (_uniqueDefs.Count > 1)
     {
         for (int i = _uniqueDefs.Count - 1; i > 0; --i)
         {
             IUniqueDef lmdd2 = _uniqueDefs[i];
             IUniqueDef lmdd1 = _uniqueDefs[i - 1];
             if (lmdd2 is RestDef && lmdd1 is RestDef)
             {
                 lmdd1.MsDuration += lmdd2.MsDuration;
                 _uniqueDefs.RemoveAt(i);
             }
         }
     }
 }
Ejemplo n.º 32
0
        /// <summary>
        /// Old constructor, currently not used (03.05.2020), but retained for future inspection
        /// </summary>
        public OutputRestSymbol(Voice voice, IUniqueDef iumdd, int absMsPosition, PageFormat pageFormat)
            : base(voice, iumdd, absMsPosition, pageFormat.MinimumCrotchetDuration, pageFormat.MusicFontHeight)
        {
            M.Assert(false); // 03.05.2020: don't use this constructor (to be inspected once work on midi info begins).

            if (iumdd is MidiRestDef mrd)
            {
                _midiRestDef = mrd;
            }

            // This needs testing!!
            if (iumdd is CautionaryChordDef ccd)
            {
                Console.WriteLine("rest is CautionaryChordDef!");
                LocalCautionaryChordDef = ccd;
            }
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Inserts the iUniqueDef in the list at the given index, and then
 /// resets the positions of all the uniqueDefs in the list.
 /// </summary>
 public override void Insert(int index, IUniqueDef iUniqueDef)
 {
     Debug.Assert(iUniqueDef is InputChordDef || iUniqueDef is RestDef || iUniqueDef is CautionaryChordDef);
     _Insert(index, iUniqueDef);
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Forbidden
 /// </summary>
 public override void Insert(int index, IUniqueDef iUniqueDef)
 {
     Debug.Assert(false, ForbiddenFunctionMsg);
 }
Ejemplo n.º 35
0
 public abstract NoteObject GetNoteObject(Voice voice, IUniqueDef iud, bool firstLmddInVoice,
     ref byte currentVelocity, float musicFontHeight);
Ejemplo n.º 36
0
 /// <summary>
 /// Forbidden
 /// </summary>
 public override void Replace(int index, IUniqueDef replacementIUnique)
 {
     Debug.Assert(false, ForbiddenFunctionMsg);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Appends the new iUniqueDef to the end of the list. Sets the MsPosition of the iUniqueDef re the first iUniqueDef in the list.
 /// Automatically sets the iUniqueDef's msPosition.
 /// Used by Block.PopBar(...), so accepts a CautionaryChordDef argument.
 /// </summary>
 /// <param name="iUniqueDef"></param>
 public override void Add(IUniqueDef iud)
 {
     Debug.Assert(iud is InputChordDef || iud is RestDef || iud is CautionaryChordDef || iud is ClefChangeDef);
     _Add(iud);
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Appends the new iUniqueDef to the end of the list.
 /// </summary>
 /// <param name="iUniqueDef"></param>
 public override void Add(IUniqueDef iUniqueDef)
 {
     Debug.Assert(!(iUniqueDef is MidiChordDef));
     _Add(iUniqueDef);
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Inserts the iUniqueDef in the list at the given index, and then
 /// resets the positions of all the uniqueDefs in the list.
 /// </summary>
 public override void Insert(int index, IUniqueDef iUniqueDef)
 {
     Debug.Assert(_gamut != null);
     AssertPitches(iUniqueDef);
     base.Insert(index, iUniqueDef);
     SetBeamEnd();
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Removes the iUniqueDef at index from the list, and then inserts the replacement at the same index.
 /// </summary>
 public override void Replace(int index, IUniqueDef replacementIUnique)
 {
     Debug.Assert(_gamut != null);
     AssertPitches(replacementIUnique);
     base.Replace(index, replacementIUnique);
     SetBeamEnd();
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Inserts the iUniqueDef in the list at the given index, and then
 /// resets the positions of all the uniqueDefs in the list.
 /// </summary>
 public override void Insert(int index, IUniqueDef iUniqueDef)
 {
     Debug.Assert(iUniqueDef is MidiChordDef || iUniqueDef is RestDef || iUniqueDef is ClefChangeDef);
     _Insert(index, iUniqueDef);
 }
Ejemplo n.º 42
0
        public override NoteObject GetNoteObject(Voice voice, int absMsPosition, IUniqueDef iud, bool firstDefInVoice,
            ref byte currentVelocity, float musicFontHeight)
        {
            NoteObject noteObject = null;
            CautionaryChordDef cautionaryChordDef = iud as CautionaryChordDef;
            MidiChordDef midiChordDef = iud as MidiChordDef;
            InputChordDef inputChordDef = iud as InputChordDef;
            RestDef restDef = iud as RestDef;
            ClefChangeDef clefChangeDef = iud as ClefChangeDef;

            PageFormat pageFormat = voice.Staff.SVGSystem.Score.PageFormat;
            float cautionaryFontHeight = pageFormat.CautionaryNoteheadsFontHeight;
            int minimumCrotchetDuration = pageFormat.MinimumCrotchetDuration;

            if(cautionaryChordDef != null && firstDefInVoice)
            {
                if(cautionaryChordDef.NotatedMidiVelocities != null)
                {
                    CautionaryOutputChordSymbol cautionaryOutputChordSymbol = new CautionaryOutputChordSymbol(voice, cautionaryChordDef, absMsPosition, cautionaryFontHeight);
                    noteObject = cautionaryOutputChordSymbol;
                }
                else
                {
                    CautionaryInputChordSymbol cautionaryInputChordSymbol = new CautionaryInputChordSymbol(voice, cautionaryChordDef, absMsPosition, cautionaryFontHeight);
                    noteObject = cautionaryInputChordSymbol;

                }
            }
            else if(midiChordDef != null)
            {
                OutputChordSymbol outputChordSymbol = new OutputChordSymbol(voice, midiChordDef, absMsPosition, minimumCrotchetDuration, musicFontHeight);

                if(this._coloredVelocities == true)
                {
                    outputChordSymbol.SetNoteheadColors();
                }
                else if(midiChordDef.NotatedMidiVelocities[0] != currentVelocity)
                {
                    outputChordSymbol.AddDynamic(midiChordDef.NotatedMidiVelocities[0], currentVelocity);
                    currentVelocity = midiChordDef.NotatedMidiVelocities[0];
                }
                noteObject = outputChordSymbol;
            }
            else if(inputChordDef != null)
            {
                InputChordSymbol inputChordSymbol = new InputChordSymbol(voice, inputChordDef, absMsPosition, minimumCrotchetDuration, musicFontHeight);
                noteObject = inputChordSymbol;
            }
            else if(restDef != null)
            {
                RestSymbol restSymbol = new RestSymbol(voice, iud, absMsPosition, minimumCrotchetDuration, musicFontHeight);
                noteObject = restSymbol;
            }
            else if(clefChangeDef != null)
            {
                ClefChangeSymbol clefChangeSymbol = new ClefChangeSymbol(voice, clefChangeDef.ClefType, absMsPosition, cautionaryFontHeight);
                noteObject = clefChangeSymbol;
            }

            return noteObject;
        }
Ejemplo n.º 43
0
 /// <summary>
 /// Removes the iUniqueDef at index from the list, and then inserts the replacement at the same index.
 /// </summary>
 public void Replace(int index, IUniqueDef replacementIUnique)
 {
     Debug.Assert(!(replacementIUnique is MidiChordDef));
     _Replace(index, replacementIUnique);
 }
Ejemplo n.º 44
0
 /// <summary>
 /// Forbidden
 /// </summary>
 public override void Add(IUniqueDef iUniqueDef)
 {
     Debug.Assert(false, ForbiddenFunctionMsg);
 }
Ejemplo n.º 45
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;
        }
Ejemplo n.º 46
0
 /// <summary>
 /// Inserts the iUniqueDef in the list at the given index, and then
 /// resets the positions of all the uniqueDefs in the list.
 /// </summary>
 public override void Insert(int index, IUniqueDef iUniqueDef)
 {
     Debug.Assert(!(iUniqueDef is MidiChordDef));
     _Insert(index, iUniqueDef);
 }
Ejemplo n.º 47
0
 /// <summary>
 /// A Debug.Assert fails if the iUniqueDef is a MidichordDef containing pitches that are not in the gamut
 /// or if the iUniqueDef is a CautionaryChordDef.
 /// </summary>
 /// <param name="iUniqueDef"></param>
 private void AssertPitches(IUniqueDef iUniqueDef)
 {
     MidiChordDef mcd = iUniqueDef as MidiChordDef;
     if(mcd != null)
     {
         Debug.Assert(_gamut.ContainsAllPitches(mcd));
     }
     if(iUniqueDef is CautionaryChordDef)
     {
         Debug.Assert(false, "Grps cannot contain CautionaryChordDefs");
     }
 }
Ejemplo n.º 48
0
 /// <summary>
 /// Removes the iUniqueDef at index from the list, and then inserts the replacement at the same index.
 /// </summary>
 public virtual void Replace(int index, IUniqueDef replacementIUnique)
 {
     Debug.Assert(replacementIUnique is MidiChordDef || replacementIUnique is RestDef);
     _Replace(index, replacementIUnique);
 }
Ejemplo n.º 49
0
 /// <summary>
 /// Appends a new MidiChordDef, RestDef, or ClefChangeDef to the end of the list.
 /// IUniqueDefs in Grps cannot be CautionaryChordDefs.
 /// Automatically sets the iUniqueDef's msPosition.
 /// Used by Block.PopBar(...), so accepts a CautionaryChordDef argument.
 /// CautionaryChordDefs are however not allowed in Grps.
 /// </summary>
 public override void Add(IUniqueDef iUniqueDef)
 {
     Debug.Assert(_gamut != null);
     AssertPitches(iUniqueDef);
     base.Add(iUniqueDef);
     SetBeamEnd();
 }
Ejemplo n.º 50
0
 /// <summary>
 /// Appends the new MidiChordDef, RestDef, CautionaryChordDef or ClefChangeDef to the end of the list.
 /// Automatically sets the iUniqueDef's msPosition.
 /// Used by Block.PopBar(...), so accepts a CautionaryChordDef argument.
 /// </summary>
 public override void Add(IUniqueDef iUniqueDef)
 {
     Debug.Assert(iUniqueDef is MidiChordDef || iUniqueDef is RestDef || iUniqueDef is CautionaryChordDef || iUniqueDef is ClefChangeDef);
     _Add(iUniqueDef);
 }