midi

[Class]
  `midi`

Generates MIDI note on and off pairs from a more general representation of key number, duration and amplitude.

`midi` supports the following slot initializations:

`:time` number
  The start time of the object.
`:channel` integer
  A MIDI channel number. The default value is 0.
`:keynum` {keynum | note}
  A MIDI key number or note name in the standard chromatic scale. Floating point key numbers are rounded to their closest integer key number unless channel tuning is enabled in the destination midi stream. If the value is less than zero or the symbol `r` (rest) then the event will not be output to the destination.
`:duration` number
  The duration of the note.
`:amplitude` number
  A floating-point logical amplitude 0.0-1.0, or an integer velocity 0-127. If the value is zero then the event will not be output to the destination. The default value is 64.

#### Examples:

Example 1. The `midi` event.

    ;;; a quiet middle C on channel 3

    (new midi :time 0 :duration .5 :channel 3
         :keynum 60 :amplitude .1)

    ;;; keynum specified as a note name

    (new midi :time 4 :keynum 'cs4 :duration 4)

Example 2. Generating untempered MIDI notes.

    (define (harms fund low high dur)
      ;; play harmonics low to high starting on fund
      (let ((f (hertz fund)))
        (process for i from low to high
                 output
                 (new midi :time (now)
                      ;; convert hertz to floating point keynum
                      :keynum (keynum (* f (/ i low)) :hz true)
                      :duration dur
                      :amplitude .5)
                 wait (+ dur .1))))

    ;;; set channel tuning of midi file to 4 steps per
    ;;; semi-tone, or 25 cents per step. this quantization
    ;;; size uses the first four channels of the synthesizer.

    ;;; play partials 4-16 staring on c3

    (events (harms 'c3 4 16 .5) "test.mid" :channel-tuning 4)
    ⇒ "test.mid"

    ;;; cancel channel-tuning

    (io "test.mid" :channel-tuning false)

#### See also:

- MIDI event classes [Topic]