/// <summary> /// Returns the sequence of notes generated by this scale when moving from start to finish. /// </summary> /// <param name="start">The first note in the traversal.</param> /// <param name="finish">The last note in the traversal.</param> /// <returns>The sequence of notes. The result always includes start and finish, and then /// includes whichever intervening notes are implied by scale when moving in that direction. /// </returns> /// <exception cref="ArgumentOutOfRangeException">start or finish is out-of-range. /// </exception> public List <Note> Traverse(Note start, Note finish) { start.Validate(); finish.Validate(); List <Note> result = new List <Note>(); if (finish > start) { for (Note n = start; n <= finish; ++n) { if (n == start || n == finish || ContainsWhenAscending(n)) { result.Add(n); } } } else if (finish < start) { for (Note n = start; n >= finish; --n) { if (n == start || n == finish || ContainsWhenDescending(n)) { result.Add(n); } } } else { result.Add(start); } return(result); }
/// <summary> /// Encodes a Note On short message. /// </summary> /// <param name="channel">The channel.</param> /// <param name="note">The note.</param> /// <param name="velocity">The velocity 0..127.</param> /// <returns>A value that can be passed to midiOutShortMsg.</returns> public static UInt32 EncodeNoteOn(Channel channel, Note note, int velocity) { channel.Validate(); note.Validate(); if (velocity < 0 || velocity > 127) { throw new ArgumentOutOfRangeException("Velocity is out of range."); } return (UInt32)(0x90 | ((int)channel) | ((int)note << 8) | (velocity << 16)); }
/// <summary> /// Encodes a Note On short message. /// </summary> /// <param name="channel">The channel.</param> /// <param name="note">The note.</param> /// <param name="velocity">The velocity 0..127.</param> /// <returns>A value that can be passed to midiOutShortMsg.</returns> public static UInt32 EncodeNoteOn(Channel channel, Note note, int velocity) { channel.Validate(); note.Validate(); if (velocity < 0 || velocity > 127) { throw new ArgumentOutOfRangeException("Velocity is out of range."); } return((UInt32)(0x90 | ((int)channel) | ((int)note << 8) | (velocity << 16))); }
/// <summary> /// Protected constructor. /// </summary> protected NoteMessage(DeviceBase device, Channel channel, Note note, int velocity, float beatTime) : base(device, channel, beatTime) { note.Validate(); if (velocity < 0 || velocity > 127) { throw new ArgumentOutOfRangeException("velocity"); } this.note = note; this.velocity = velocity; }
/// <summary> /// Returns the family of the specified note. /// </summary> /// <param name="note">The note.</param> /// <returns>The note's family. For example, C4's family is C.</returns> /// <exception cref="ArgumentOutOfRangeException">The note is out-of-range.</exception> public static NoteFamily Family(this Note note) { note.Validate(); return((NoteFamily)((int)note % 12)); }
/// <summary> /// Returns the name of the specified note. /// </summary> /// <param name="note">The note.</param> /// <returns>The note's name. For example, note 60 is "C4", and note 61 is "C#4".</returns> /// <exception cref="ArgumentOutOfRangeException">The note is out-of-range.</exception> public static string Name(this Note note) { note.Validate(); return(note.Family().Name() + note.Octave().ToString()); }
/// <summary> /// Returns the octave number of the given note. /// </summary> /// <param name="note">The note.</param> /// <returns>The octave. For example, "C4"'s octave is 4.</returns> /// <exception cref="ArgumentOutOfRangeException">The note is out-of-range.</exception> public static int Octave(this Note note) { note.Validate(); return((int)note / 12 - 1); }
/// <summary> /// Returns the sequence of notes generated by this scale when moving from start to finish. /// </summary> /// <param name="start">The first note in the traversal.</param> /// <param name="finish">The last note in the traversal.</param> /// <returns>The sequence of notes. The result always includes start and finish, and then /// includes whichever intervening notes are implied by scale when moving in that direction. /// </returns> /// <exception cref="ArgumentOutOfRangeException">start or finish is out-of-range. /// </exception> public List<Note> Traverse(Note start, Note finish) { start.Validate(); finish.Validate(); List<Note> result = new List<Note>(); if (finish > start) { for (Note n = start; n <= finish; ++n) { if (n == start || n == finish || ContainsWhenAscending(n)) result.Add(n); } } else if (finish < start) { for (Note n = start; n >= finish; --n) { if (n == start || n == finish || ContainsWhenDescending(n)) result.Add(n); } } else { result.Add(start); } return result; }