Example #1
0
        public void Flattened_WhenDecrementing_ShouldReturnCorrectOctaveShift(AbstractMusicNote initialAbstractMusicNote, int decrementQuantity, int expectedOctaveShift)
        {
            int returnedOctaveShift;

            initialAbstractMusicNote.Flattened(decrementQuantity, out returnedOctaveShift);
            Assert.AreEqual(expectedOctaveShift, returnedOctaveShift);
        }
Example #2
0
        /// <summary>
        /// Returns an <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/> sharpened by
        /// <paramref name="incrementQuantity"/> semitones.
        /// </summary>
        /// <param name="initialAbstractMusicNote">
        /// The starting <see cref="AbstractMusicNote"/> that will be
        /// sharpened.
        /// </param>
        /// <param name="incrementQuantity">
        /// An <see cref="int"/> representing the number of semitones to
        /// sharpen <paramref name="initialAbstractMusicNote"/> by.
        /// </param>
        /// <param name="octaveShift">
        /// An <see cref="int"/> out value representing how many octaves
        /// <paramref name="initialAbstractMusicNote"/> has shifted.
        /// </param>
        /// <returns>
        /// A new <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/>
        /// sharpened by <paramref name="incrementQuantity"/> semitones.
        /// </returns>
        public static AbstractMusicNote Sharpened(this AbstractMusicNote initialAbstractMusicNote, int incrementQuantity, out int octaveShift)
        {
            int returnedOctaveShift;

            var sharpenedAbstractMusicNote = GetShiftedAbstractMusicNote(initialAbstractMusicNote, incrementQuantity, out returnedOctaveShift);

            octaveShift = returnedOctaveShift;

            return(sharpenedAbstractMusicNote);
        }
Example #3
0
        /// <summary>
        /// Returns an <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/> flattened by
        /// <paramref name="decrementQuantity"/> semitones.
        /// </summary>
        /// <param name="initialAbstractMusicNote">
        /// The starting <see cref="AbstractMusicNote"/> that will be
        /// flattened.
        /// </param>
        /// <param name="decrementQuantity">
        /// An <see cref="int"/> representing the number of semitones to
        /// flatten <paramref name="initialAbstractMusicNote"/> by.
        /// </param>
        /// <param name="octaveShift">
        /// An <see cref="int"/> out value representing how many octaves
        /// <paramref name="initialAbstractMusicNote"/> has shifted.
        /// </param>
        /// <returns>
        /// A new <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/> flattened by
        /// <paramref name="decrementQuantity"/> semitones.
        /// </returns>
        public static AbstractMusicNote Flattened(this AbstractMusicNote initialAbstractMusicNote, int decrementQuantity, out int octaveShift)
        {
            int returnedOctaveShift;

            decrementQuantity = -decrementQuantity;

            var flattenedAbstractMusicNote = GetShiftedAbstractMusicNote(initialAbstractMusicNote, decrementQuantity, out returnedOctaveShift);

            octaveShift = returnedOctaveShift;

            return(flattenedAbstractMusicNote);
        }
Example #4
0
        /// <summary>
        /// Returns a new flattened instance of the current
        /// <see cref="MusicNote"/>.
        /// </summary>
        /// <param name="decrementQuantity">
        /// An <see cref="int"/> representing the number of semitones to
        /// flatten this instance of <see cref="MusicNote"/> by.
        /// </param>
        /// <returns>
        /// A new flattened instance of the current <see cref="MusicNote"/>.
        /// </returns>
        /// <remarks>
        /// Depending on the starting <see cref="MusicNote"/> and the
        /// <paramref name="decrementQuantity"/>, both <see cref="Value"/> and
        /// <see cref="Octave"/> may be changed. This is based on whether the
        /// new <see cref="MusicNote"/> <see cref="Value"/> would cross over an
        /// octave boundary, therefore modifying the related
        /// <see cref="Octave"/>.
        /// </remarks>
        public MusicNote Flattened(int decrementQuantity)
        {
            int returnedOctaveShift;

            AbstractMusicNote flattenedAbstractMusicNote = Value.Flattened(decrementQuantity, out returnedOctaveShift);

            if (HasOctave())
            {
                return(new MusicNote(flattenedAbstractMusicNote, Octave + returnedOctaveShift));
            }
            else
            {
                return(new MusicNote(flattenedAbstractMusicNote, null));
            }
        }
Example #5
0
        /// <summary>
        /// Returns a new sharpened instance of the current
        /// <see cref="MusicNote"/>.
        /// </summary>
        /// <param name="incrementQuantity">
        /// An <see cref="int"/> representing the number of semitones to
        /// sharpen this instance of <see cref="MusicNote"/> by.
        /// </param>
        /// <returns>
        /// A new sharpened instance of the current <see cref="MusicNote"/>.
        /// </returns>
        /// <remarks>
        /// Depending on the starting <see cref="MusicNote"/> and the
        /// <paramref name="incrementQuantity"/>, both <see cref="Value"/> and
        /// <see cref="Octave"/> may be changed. This is based on whether the
        /// new <see cref="MusicNote"/> <see cref="Value"/> would cross over an
        /// octave boundary, therefore modifying the related
        /// <see cref="Octave"/>.
        /// </remarks>
        public MusicNote Sharpened(int incrementQuantity)
        {
            int returnedOctaveShift;

            AbstractMusicNote sharpenedAbstractMusicNote = Value.Sharpened(incrementQuantity, out returnedOctaveShift);

            if (HasOctave())
            {
                return(new MusicNote(sharpenedAbstractMusicNote, Octave + returnedOctaveShift));
            }
            else
            {
                return(new MusicNote(sharpenedAbstractMusicNote, null));
            }
        }
Example #6
0
        /// <summary>
        /// Takes an <paramref name="initialAbstractMusicNote"/> and returns a new <see cref="AbstractMusicNote"/>
        /// that has been shifted by <paramref name="shiftQuantity"/> semitones.
        /// </summary>
        /// <param name="initialAbstractMusicNote">
        /// The initial <see cref="AbstractMusicNote"/> that the shift will
        /// start from.
        /// </param>
        /// <param name="shiftQuantity">
        /// An <see cref="int"/> representing the number of semitones to shift
        /// <paramref name="initialAbstractMusicNote"/>.
        /// </param>
        /// <param name="octaveShift">
        /// An <see cref="int"/> out value representing how many octaves
        /// <paramref name="initialAbstractMusicNote"/> has been shifted.
        /// </param>
        /// <returns>
        /// A new <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/>
        /// shifted by <paramref name="shiftQuantity"/> semitones.
        /// </returns>
        private static AbstractMusicNote GetShiftedAbstractMusicNote(AbstractMusicNote initialAbstractMusicNote, int shiftQuantity, out int octaveShift)
        {
            var numberOfElements       = GetNotesPerOctave();
            var abstractMusicNoteValue = (int)initialAbstractMusicNote;

            var modifiedAbstractMusicNoteValue = ((abstractMusicNoteValue + shiftQuantity) % numberOfElements);
            var totalOctaveShifts = (abstractMusicNoteValue + shiftQuantity) / numberOfElements;

            if (modifiedAbstractMusicNoteValue < 0)
            {
                modifiedAbstractMusicNoteValue = numberOfElements + modifiedAbstractMusicNoteValue;
                totalOctaveShifts -= 1;
            }

            octaveShift = totalOctaveShifts;
            return((AbstractMusicNote)modifiedAbstractMusicNoteValue);
        }
Example #7
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="MusicNote"/> class.
 /// </summary>
 /// <param name="value">
 /// The <see cref="AbstractMusicNote"/> to be assigned to the new
 /// instance.
 /// </param>
 /// <param name="octave">
 /// A nullable <see cref="int"/> representing an octave in scientific
 /// pitch notation. A value of null represents a
 /// <see cref="MusicNote"/> with no octave. Default value is null.
 /// </param>
 /// <remarks>
 /// MusicNotes that have no octave (octave is set to null) are
 /// considered to precede MusicNotes that have an octave when it comes
 /// to sort order.
 /// </remarks>
 public MusicNote(AbstractMusicNote value, int?octave = null)
 {
     Value  = value;
     Octave = octave;
 }
Example #8
0
        public void Flattened_WhenDecrementingWithOctaveShift_ShouldReturnCorrectAbstractMusicNote(AbstractMusicNote initialAbstractMusicNote, int decrementQuantity, AbstractMusicNote expectedAbstractMusicNote)
        {
            int returnedOctaveShift;

            Assert.AreEqual(expectedAbstractMusicNote, initialAbstractMusicNote.Flattened(decrementQuantity, out returnedOctaveShift));
        }
Example #9
0
        public void Sharpened_WhenIncrementingWithOctaveShift_ShouldReturnCorrectOctaveShift(AbstractMusicNote initialAbstractMusicNote, int incrementQuantity, int expectedOctaveShift)
        {
            int returnedOctaveShift;

            initialAbstractMusicNote.Sharpened(incrementQuantity, out returnedOctaveShift);
            Assert.AreEqual(expectedOctaveShift, returnedOctaveShift);
        }
Example #10
0
 public void Sharpened_WhenIncrementingWithoutOctaveShift_ShouldReturnCorrectAbstractMusicNote(AbstractMusicNote initialAbstractMusicNote, int incrementQuantity, AbstractMusicNote expectedAbstractMusicNote)
 {
     Assert.AreEqual(expectedAbstractMusicNote, initialAbstractMusicNote.Sharpened(incrementQuantity));
 }
Example #11
0
        /// <summary>
        /// Returns an <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/> flattened by
        /// <paramref name="decrementQuantity"/> semitones.
        /// </summary>
        /// <param name="initialAbstractMusicNote">
        /// The starting <see cref="AbstractMusicNote"/> that will be
        /// flattened.
        /// </param>
        /// <param name="decrementQuantity">
        /// An <see cref="int"/> representing the number of semitones to
        /// flatten <paramref name="initialAbstractMusicNote"/> by.
        /// </param>
        /// <returns>
        /// A new <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/> flattened by
        /// <paramref name="decrementQuantity"/> semitones.
        /// </returns>
        public static AbstractMusicNote Flattened(this AbstractMusicNote initialAbstractMusicNote, int decrementQuantity)
        {
            int returnedOctaveShift;

            return(Flattened(initialAbstractMusicNote, decrementQuantity, out returnedOctaveShift));
        }
Example #12
0
        /// <summary>
        /// Returns an <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/> sharpened by
        /// <paramref name="incrementQuantity"/> semitones.
        /// </summary>
        /// <param name="initialAbstractMusicNote">
        /// The starting <see cref="AbstractMusicNote"/> that will be
        /// sharpened.
        /// </param>
        /// <param name="incrementQuantity">
        /// An <see cref="int"/> representing the number of semitones to
        /// sharpen <paramref name="initialAbstractMusicNote"/> by.
        /// </param>
        /// <returns>
        /// A new <see cref="AbstractMusicNote"/> representing
        /// <paramref name="initialAbstractMusicNote"/> sharpened by
        /// <paramref name="incrementQuantity"/> semitones.
        /// </returns>
        public static AbstractMusicNote Sharpened(this AbstractMusicNote initialAbstractMusicNote, int incrementQuantity)
        {
            int returnedOctaveShift;

            return(Sharpened(initialAbstractMusicNote, incrementQuantity, out returnedOctaveShift));
        }