Example #1
0
        /// <summary>
        /// Is this NotePair dissonant?
        /// </summary>
        /// <returns>Whether the NotePair is dissnont or not</returns>
        public bool IsDissonant()
        {
            var cantusFirmusScaleDegree = _scaleDegreeEvaluator.GetScaleDegreeFromNote(CantusFirmusNote);
            var counterPointScaleDegree = _scaleDegreeEvaluator.GetScaleDegreeFromNote(CounterPointNote);

            return(cantusFirmusScaleDegree.IsDissonantWith(counterPointScaleDegree));
        }
        /// <summary>
        /// Determines whether nor not the distance between two notes is a dissonant leap or not.
        /// </summary>
        /// <param name="currentNote">The current note</param>
        /// <param name="nextNote">The next note</param>
        /// <returns>Whether the distance between two notes is a dissonant leap or not</returns>
        private bool IsDissonantLeap(
            int currentNote,
            int nextNote
            )
        {
            if (_context.GetNoteMotionSpanFromNotes(currentNote, nextNote) != NoteMotionSpan.Leap)
            {
                return(false);
            }

            var currentScaleDegree = _scaleDegreeEvaluator.GetScaleDegreeFromNote(currentNote);
            var nextScaleDegree    = _scaleDegreeEvaluator.GetScaleDegreeFromNote(nextNote);

            return(currentScaleDegree.IsDissonantWith(nextScaleDegree));
        }
        public void GetCorrectScaleDegree(int pitch, ScaleDegree expectedScaleDegree)
        {
            var scaleDegreeEvaluator = new ScaleDegreeEvaluator();
            var scaleDegree          = scaleDegreeEvaluator.GetScaleDegreeFromNote(pitch);

            Assert.AreEqual(expectedScaleDegree, scaleDegree);
        }
        /// <inheritdoc />
        /// <summary>
        /// Evaluates a given composition for doubled notes.
        /// </summary>
        /// <param name="composition">The given composition to evaluate</param>
        /// <returns>The composition's total error count</returns>
        public int EvaluateComposition(Composition composition)
        {
            var errorCount = 0;

            for (var index = 1; index < composition.GetNotePairs().Count; index++)
            {
                var notePair = composition.GetNotePairs()[index];
                if (_scaleDegreeEvaluator.GetScaleDegreeFromNote(notePair.CantusFirmusNote) !=
                    _scaleDegreeEvaluator.GetScaleDegreeFromNote(notePair.CounterPointNote))
                {
                    continue;
                }

                notePair.IsDetrimental = true;
                errorCount            += 1;
            }

            return(errorCount);
        }
Example #5
0
        /// <inheritdoc />
        /// <summary>
        /// Decorates the composition based on the current and next notes.
        /// </summary>
        /// <param name="currentNote">The current note</param>
        /// <param name="nextNote">The next note</param>
        /// <returns>A list of decorative notes, possibly empty</returns>
        protected override List <int> GetPossibleDecorations(int currentNote, int nextNote)
        {
            var currentScaleDegree = ScaleDegreeEvaluator.GetScaleDegreeFromNote(currentNote);
            var nextScaleDegree    = ScaleDegreeEvaluator.GetScaleDegreeFromNote(nextNote);

            if (!currentScaleDegree.IsThirdWith(nextScaleDegree) || Random.Next(1, 3) % 2 != 0)
            {
                return(EmptyDecoration);
            }

            return(new List <int> {
                (currentNote + nextNote) / 2
            });
        }
Example #6
0
        /// <summary>
        /// CompositionContext constructor.
        /// </summary>
        /// <param name="previousNotes">The previous notes in the composition</param>
        /// <param name="currentNotes">The current notes in the composition</param>
        /// <param name="scaleDegreeEvaluator">ScaleDegreeEvaluator used to help initialize class properties</param>
        public CompositionContext(NotePair previousNotes, NotePair currentNotes,
                                  ScaleDegreeEvaluator scaleDegreeEvaluator)
        {
            CantusFirmusNoteScaleDegree = scaleDegreeEvaluator.GetScaleDegreeFromNote(currentNotes.CantusFirmusNote);
            CantusFirmusNoteMotion      = GetNoteMotionFromNotes(
                previousNotes.CantusFirmusNote,
                currentNotes.CantusFirmusNote
                );
            CantusFirmusNoteMotionSpan = GetNoteMotionSpanFromNotes(
                previousNotes.CantusFirmusNote,
                currentNotes.CantusFirmusNote
                );

            CounterPointNoteScaleDegree = scaleDegreeEvaluator.GetScaleDegreeFromNote(currentNotes.CounterPointNote);
            CounterPointNoteMotion      = GetNoteMotionFromNotes(
                previousNotes.CounterPointNote,
                currentNotes.CounterPointNote
                );
            CounterPointNoteMotionSpan = GetNoteMotionSpanFromNotes(
                previousNotes.CounterPointNote,
                currentNotes.CounterPointNote
                );
        }
        /// <inheritdoc />
        /// <summary>
        /// Decorates the composition based on the current and next notes.
        /// </summary>
        /// <param name="currentNote">The current note</param>
        /// <param name="nextNote">The next note</param>
        /// <returns>A list of decorative notes, possibly empty</returns>
        protected override List <int> GetPossibleDecorations(int currentNote, int nextNote)
        {
            var currentScaleDegree = ScaleDegreeEvaluator.GetScaleDegreeFromNote(currentNote);
            var nextScaleDegree    = ScaleDegreeEvaluator.GetScaleDegreeFromNote(nextNote);

            if (!currentScaleDegree.IsAdjacentTo(nextScaleDegree) || Random.Next(1, 3) % 2 != 0)
            {
                return(EmptyDecoration);
            }

            if (currentNote < nextNote)
            {
                return(new List <int> {
                    currentNote + 1, currentNote - 1, currentNote
                });
            }

            return(currentScaleDegree != ScaleDegree.Sixth
                ? new List <int> {
                currentNote - 1, currentNote + 1, currentNote
            }
                : EmptyDecoration);
        }
 /// <summary>
 /// Determines whether or not the given notes correctly resolve according to the ascending seventh rule.
 /// </summary>
 /// <param name="currentNote">The current note</param>
 /// <param name="nextNote">The next note</param>
 /// <param name="currentNoteArrivedFromNoteMotion">The note motion which the current note arrived from</param>
 /// <returns>Whether the given notes correctly resolve</returns>
 private bool IncorrectlyResolves(int currentNote, int nextNote, NoteMotion currentNoteArrivedFromNoteMotion)
 {
     return(_scaleDegreeEvaluator.GetScaleDegreeFromNote(currentNote) == ScaleDegree.Seventh &&
            currentNoteArrivedFromNoteMotion == NoteMotion.Ascending &&
            _scaleDegreeEvaluator.GetScaleDegreeFromNote(nextNote) != ScaleDegree.Root);
 }