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

;; 

;; MOUSE CIRCLE

;;

;; Demonstrating mouse interaction 

;; with the graphics window.

;;

;; Clicking inside the square plays

;; a different pitch to clicking

;; outside the square.

;;

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


; make sure that nothing is already connected

(au:clear-graph)


; define audio unit chain

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

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

(au:update-graph)

(au:midi-out (now) synth *io:midi-pc* 1 77 0)


; create a new canvas

(define *mouse-canvas* (gfx:make-canvas))

; register to receive mouse events from *mouse-canvas*

(io:register-mouse-events *mouse-canvas*)


; define a square path

(define *square* (gfx:make-circle 200 200 100))

; define a fill colour

(define *fill* '(1.0 0.5 0.1 1.0))

; define a stroke colour

(define *stroke* '(0.5 0.9 1.0 1.0))


(gfx:clear-canvas (+ (now) 10000) *mouse-canvas* '(0.0 0.0 0.0 1.0))

(gfx:draw-path (+ (now) 20000) *mouse-canvas* *square* *stroke* *fill* *gfx:whole-path*)


; override io:mouse-down function to receive

; mouse down events.  play pitch 80 when

; click is inside the bounds of the *square*

; otherwise play pitch 50.

(define (io:mouse-down x y)

   (if (gfx:point-in-path? *square* x y)

       (play-note (now) synth 74 80 5000 1)

       (play-note (now) synth 50 80 5000)))