midi-pitch-bend

[Class]
  `midi-pitch-bend`

A MIDI pitch bend event.

`midi-pitch-bend` supports the following slot initializations:

`:time` number
  The start time of the object.
`:channel` integer
  A MIDI channel number. The default value is 0.
`:bend` integer
  A pitch bend value from -8192 to 8191. Defaults to 0, or no bend.

#### Examples:

Example 1. Creating MIDI pitch bends.

    ;;; max bend down
    (new midi-pitch-bend :time 0 :channel 3 :bend -8192)

    ;;; cancel bend
    (new midi-pitch-bend :time 1 :channel 3 :bend 0)

Example 2. Determining pitch bend values.

    (define (step->bend value . width)
      ;; convert a value between +-width to a pitch
      ;; bend value ranging from -8192 to 8191
      (inexact->exact
       (floor (rescale value (- width) width -8192 8191))))

    ;;; bend one quarter-tone down (whole step max)
    (new midi-pitch-bend :bend (step->bend -.5 2))

    ;;; percentage bend
    (new midi-pitch-bend :bend (step->bend 75 100))

Example 3. Musical process generating random bends.

    (define (ranbends num dur )
      ;; output num bends dur apart, last bend 0.
      (process for i from 1 to num
               for b = (between -2.0 2.0)
               output (new midi-pitch-bend :time (now)
                          :bend (if (= i num)
                                  0
                                  (step->bend b)))
               wait dur))

    (define (random-bends reps )
      (process repeat reps
               for key = (between 30 90)
               for dur = (pick 1 2 3)
               for num = (between 2 8)
               for inc = (/ dur (+ num 1))
               output (new midi :time (now)
                          :duration dur
                          :keynum key)
               ;; sprout num bends starting inc ahead
               sprout (ranbends num inc) at (+ (now) inc)
               wait dur))

    (events (random-bends 20) "test.mid")
    ⇒ "test.mid"

#### See also:

- MIDI event classes [Topic]