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

;;

;; SIMPLE SCALE EXAMPLE

;;

;; Define and play a C Major scale.

;;

;; Try making your own melody by changing the values in

;; pitches, dynamics and rhythms.

;;

;; Be careful to make sure that the three lists

;; all contain the same number of values.

;;

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

; make sure that no audio units are already connected

(au:clear-graph)

; setup simple au graph

; piano -> output

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

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

(au:update-graph)

; print the status of the audiograph to the log view

; this is a way of checking what the current au:graph status is

(au:print-graph)

; define a C major scale as three separate lists

(define pitches '(60 62 64 65 67 69 71 72))

(define dynamics '(80 80 80 80 80 80 80 80))

(define rhythms '(0.5 0.25 0.25 0.25 0.25 0.25 0.25 0.5))

; print the list of pitches to the log view

; the "print" command can also be used inside functions

; to report progress and assist debugging.

(print pitches)

; Create a sequencer to play the notes

; incrementing 'time' by the previous rhythm value each time.

;

; Rhythm values (in beats) need to be multipled by

; *au:samplerate* to provide a number in samples.

; This math assumes that the tempo is 60 bpm

; i.e., 1.0 beats equals 1 second

(define play-sequence

(lambda (time inst plst dlst rlst)

(map (lambda (p d r)

(play-note time inst p d (* r *au:samplerate*))

(set! time (+ time (* r *au:samplerate*))))

plst

dlst

rlst)))

; START

; Try re-evaluating while a scale is already playing

(play-sequence (now) piano pitches dynamics rhythms)