Note priority in a monophonic synthesizer |
We can play a monophonic synthesizer with lowest or highest note
priority. The related VUGs are called MIDI-LOWEST-KEYNUM
and
MIDI-HIGHEST-KEYNUM
. For example:
(in-package :scratch)
SCRATCH> (set-rt-block-size 1)
(dsp! highest-note-test ((chan fixnum) a d s r)
"Highest priority monosynth (single trigger)."
(with ((keynum (midi-highest-keynum chan)))
(with-samples ((glide (exp-midi-cc chan 1 0.01 1.2))
(amp (midi-amp *linear-midi-table* chan keynum))
(amp-prev +sample-zero+)
(gate +sample-zero+))
(if (zerop amp)
(setf gate +sample-zero+ amp amp-prev) ; Note off.
(setf gate (sample 1) amp-prev amp))
(stereo (* (envelope (make-adsr a d s r) gate 1 #'identity)
(gbuzz (lag (midi-cps *default-tuning* keynum) glide)
(lag amp 0.02) 20 1 .6))))))
SCRATCH> (rt-start)
SCRATCH> (defvar *midiin* (pm:open (pm:get-default-input-device-id)))
SCRATCH> (recv-start *midiin*)
SCRATCH> (highest-note-test 0 .1 0.9 .7 .1 :id 123)
;; Change attack and release times.
SCRATCH> (set-controls 123 :a .01 :r .02)
SCRATCH> (free 123)
SCRATCH> (recv-stop *midiin*)
SCRATCH> (rt-stop)
SCRATCH> (pm:terminate)