;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;

;; QWERTY KEYBOARD INPUT

;;

;; Turn on caps lock to play AU with keyboard

;;

;; WARNING: You will not get text input

;; while the caps-key is pressed

;;

;; NOTE: You can receive text input as

;; well as sending keys to the caps-key-down

;; by setting (caps-key-through #t)

;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; clear any existing audio graph info

(au:clear-graph)


; setup simple au graph

(define inst (au:make-node "aumu" "dls " "appl"))

(au:connect-node inst 0 *au:output-node* 0)

(au:update-graph)

(au:midi-out (now) inst *io:midi-pc* 0 110 0)


; map keys to one octave keyboard

(define key-map

   '((#\z . 60)

     (#\s . 61)

     (#\x . 62)

     (#\d . 63)

     (#\c . 64)

     (#\v . 65)

     (#\g . 66)

     (#\b . 67)

     (#\h . 68)

     (#\n . 69)

     (#\j . 70)

     (#\m . 71)

     (#\, . 72)

     (#\q . 72)

     (#\2 . 73)

     (#\w . 74)

     (#\3 . 75)

     (#\e . 76)

     (#\r . 77)

     (#\5 . 78)

     (#\t . 79)

     (#\6 . 80)

     (#\y . 81)

     (#\7 . 82)

     (#\u . 83)

     (#\i . 84)))


; engage caps-lock to receive caps key strokes

; caps key down message

(define io:caps-key-down

   (lambda (key)

      (if (assoc key key-map)

          (au:start-sound (now) inst (cdr (assoc key key-map)) 80)

          (print "BAD KEY PRESS"))))


; engage caps-lock to receive caps key strokes

; caps key up message

(define io:caps-key-up

   (lambda (key)

      (if (assoc key key-map)

          (au:stop-sound (now) inst (cdr (assoc key key-map)))

          (print "BAD KEY PRESS"))))