Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Note"/> with the specified
        /// note number, length and absolute time.
        /// </summary>
        /// <param name="noteNumber">Number of the note (60 is middle C).</param>
        /// <param name="length">Length of the note in units defined by time division of a MIDI file.</param>
        /// <param name="time">Absolute time of the note in units defined by the time division of a MIDI file.</param>
        public Note(SevenBitNumber noteNumber, long length, long time)
        {
            _noteDefinition = NoteDefinition.Get(noteNumber);

            Length = length;
            Time   = time;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OctaveDefinition"/> with the
        /// specified octave number.
        /// </summary>
        /// <param name="octave">The number of an octave.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="octave"/> is out of valid range.</exception>
        private OctaveDefinition(int octave)
        {
            Debug.Assert(octave >= MinOctaveNumber && octave <= MaxOctaveNumber,
                         "An octave's number is out of range.");

            Number = octave;

            _notesDefinitions = Enum.GetValues(typeof(NoteName))
                                .Cast <NoteName>()
                                .Where(n => NoteUtilities.IsNoteValid(n, octave))
                                .ToDictionary(n => n,
                                              n => NoteDefinition.Get(n, octave));
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Note"/> with the specified
        /// Note On and Note Off timed events.
        /// </summary>
        /// <param name="timedNoteOnEvent">Wrapped <see cref="NoteOnEvent"/>.</param>
        /// <param name="timedNoteOffEvent">Wrapped <see cref="NoteOffEvent"/>.</param>
        internal Note(TimedEvent timedNoteOnEvent, TimedEvent timedNoteOffEvent)
        {
            Debug.Assert(timedNoteOnEvent != null);
            Debug.Assert(timedNoteOnEvent.Event is NoteOnEvent, "Timed event doesn't wrap a Note On event.");

            Debug.Assert(timedNoteOffEvent != null);
            Debug.Assert(timedNoteOffEvent.Event is NoteOffEvent, "Timed event doesn't wrap a Note Off event.");

            //

            var noteOnEvent  = (NoteOnEvent)timedNoteOnEvent.Event;
            var noteOffEvent = (NoteOffEvent)timedNoteOffEvent.Event;

            TimedNoteOnEvent  = timedNoteOnEvent;
            TimedNoteOffEvent = timedNoteOffEvent;

            _noteDefinition = NoteDefinition.Get(noteOnEvent.NoteNumber);

            Velocity    = noteOnEvent.Velocity;
            OffVelocity = noteOffEvent.Velocity;
            Channel     = noteOnEvent.Channel;
        }
Beispiel #4
0
 /// <summary>
 /// Sets note name and octave for current <see cref="Note"/>.
 /// </summary>
 /// <param name="noteName">Name of the note.</param>
 /// <param name="octave">Number of the octave in scientific pitch notation.</param>
 /// <remarks>
 /// Octave number is specified in scientific pitch notation which means that 4 must be
 /// passed to <paramref name="octave"/> to get the number of the middle C.
 /// </remarks>
 /// <exception cref="InvalidEnumArgumentException"><paramref name="noteName"/> specified an
 /// invalid value.</exception>
 /// <exception cref="ArgumentException">Note number is out of range for the specified note
 /// name and octave.</exception>
 public void SetNoteNameAndOctave(NoteName noteName, int octave)
 {
     _noteDefinition = NoteDefinition.Get(noteName, octave);
 }