/// <summary>
        /// Returns an <see cref="IntervalDefinition"/> by the specified half steps number and
        /// interval's direction.
        /// </summary>
        /// <param name="interval">The interval as a number of half steps away.</param>
        /// <param name="direction">The direction of an interval (up or down).</param>
        /// <returns>An <see cref="IntervalDefinition"/> with the specified interval and direction.</returns>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="direction"/> specified an
        /// invalid value.</exception>
        public static IntervalDefinition Get(SevenBitNumber interval, IntervalDirection direction)
        {
            ThrowIfArgument.IsInvalidEnumValue(nameof(direction), direction);

            if (!_cache.TryGetValue(interval, out Dictionary <IntervalDirection, IntervalDefinition> intervalDefinitions))
            {
                _cache.Add(interval, intervalDefinitions = new Dictionary <IntervalDirection, IntervalDefinition>());
            }

            if (!intervalDefinitions.TryGetValue(direction, out IntervalDefinition intervalDefinition))
            {
                intervalDefinitions.Add(direction, intervalDefinition = new IntervalDefinition(interval, direction));
            }

            return(intervalDefinition);
        }
Beispiel #2
0
 /// <summary>
 /// Adds a note by the specified interval relative to the current root note using
 /// default length and specified velocity.
 /// </summary>
 /// <param name="intervalDefinition">The <see cref="IntervalDefinition"/> which defines
 /// a number of half steps from the current root note.</param>
 /// <param name="velocity">The velocity of a note.</param>
 /// <returns>The current <see cref="PatternBuilder"/>.</returns>
 /// <remarks>
 /// To set root note use <see cref="SetRootNote(NoteDefinition)"/> method. By default the root note is C4.
 /// To set default note length use <see cref="SetNoteLength(ILength)"/> method. By default the length
 /// is 1/4.
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="intervalDefinition"/> is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">The number of result note is out of valid range.</exception>
 public PatternBuilder Note(IntervalDefinition intervalDefinition, SevenBitNumber velocity)
 {
     return(Note(intervalDefinition, _noteLength, velocity));
 }
Beispiel #3
0
 /// <summary>
 /// Adds a note by the specified interval relative to the current root note using
 /// specified length and default velocity.
 /// </summary>
 /// <param name="intervalDefinition">The <see cref="IntervalDefinition"/> which defines
 /// a number of half steps from the current root note.</param>
 /// <param name="length">The length of a note.</param>
 /// <returns>The current <see cref="PatternBuilder"/>.</returns>
 /// <remarks>
 /// To set root note use <see cref="SetRootNote(NoteDefinition)"/> method. By default the root note is C4.
 /// To set default velocity use <see cref="SetVelocity(SevenBitNumber)"/> method. By default the
 /// velocity is 100.
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="intervalDefinition"/> is null. -or-
 /// <paramref name="length"/> is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">The number of result note is out of valid range.</exception>
 public PatternBuilder Note(IntervalDefinition intervalDefinition, ILength length)
 {
     return(Note(intervalDefinition, length, _velocity));
 }
Beispiel #4
0
        /// <summary>
        /// Adds a note by the specified interval relative to the current root note using
        /// specified length and velocity.
        /// </summary>
        /// <param name="intervalDefinition">The <see cref="IntervalDefinition"/> which defines
        /// a number of half steps from the current root note.</param>
        /// <param name="length">The length of a note.</param>
        /// <param name="velocity">The velocity of a note.</param>
        /// <returns>The current <see cref="PatternBuilder"/>.</returns>
        /// <remarks>
        /// To set root note use <see cref="SetRootNote(NoteDefinition)"/> method. By default the root note is C4.
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="intervalDefinition"/> is null. -or-
        /// <paramref name="length"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The number of result note is out of valid range.</exception>
        public PatternBuilder Note(IntervalDefinition intervalDefinition, ILength length, SevenBitNumber velocity)
        {
            ThrowIfArgument.IsNull(nameof(intervalDefinition), intervalDefinition);

            return(Note(_rootNote.Transpose(intervalDefinition), length, velocity));
        }
Beispiel #5
0
 /// <summary>
 /// Returns the current <see cref="NoteDefinition"/> transposed by the specified
 /// <see cref="IntervalDefinition"/>.
 /// </summary>
 /// <param name="intervalDefinition">The <see cref="IntervalDefinition"/> to transpose the current
 /// <see cref="NoteDefinition"/> by.</param>
 /// <returns>The current <see cref="NoteDefinition"/> transposed by the <paramref name="intervalDefinition"/>.</returns>
 /// <exception cref="ArgumentOutOfRangeException">Result note definition's note number is out of valid range.</exception>
 public NoteDefinition Transpose(IntervalDefinition intervalDefinition)
 {
     return(Get((SevenBitNumber)(NoteNumber + intervalDefinition.HalfSteps)));
 }
Beispiel #6
0
        /// <summary>
        /// Transposes the specified <see cref="NoteDefinition"/>.
        /// </summary>
        /// <param name="noteDefinition">The <see cref="NoteDefinition"/> to transpose.</param>
        /// <param name="halfSteps">The number of half steps to transpose the <paramref name="noteDefinition"/> by.</param>
        /// <returns>The <see cref="NoteDefinition"/> which is the <paramref name="noteDefinition"/>
        /// transposed by the <paramref name="halfSteps"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="noteDefinition"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Result note definition's note number is out of valid range.</exception>
        public static NoteDefinition operator +(NoteDefinition noteDefinition, int halfSteps)
        {
            ThrowIfArgument.IsNull(nameof(noteDefinition), noteDefinition);

            return(noteDefinition.Transpose(IntervalDefinition.FromHalfSteps(halfSteps)));
        }