play-note


Play a note by sending a note-on then a note-off event seperated by duration to au. Duration is in samples. Pitch values falling outside of 0-127 are ignored (so you can use negative numbers as rests if you like). If for some reason you need to send pitch values outside of 0-127 you can call au:midi-out which does not bounds checking.

Usage

(play-note time au pitch volume duration [midi-channel]) ==> boolean

au:audiounit
duration:in samples
midi-channel:optional midi-channel defaults to 0
pitch:0-127 midi
time:time in samples to play note
volume:0-127 midi


Examples

;; first define an instrument
(define dls (au:make-node "aumu" "dls " "appl"))
;; next connect dls to the default output node
(au:connect-node dls 0 *au:output-node* 0)
;; lastly update the audio graph to reflect the connection
(au:update-graph)

;; play one note by itself
(play-note (now) inst 60 80 (* *second* 1.0))

;; play three notes together
(dotimes (i 3)
(play-note (now) inst (random 60 80) 80 (* *second* 1.0)))

;; play a looping sequence of random notes
(define loop
(lambda (time)
(play-note time inst (random 40 80) 80 1000)
(callback (+ time 8000) 'loop (+ time 10000))))

;; start the loop
(loop (now))

;; stop the loop by defining loop to be null
(define loop '())

;; define a new loop to play a repeating sequence of notes
;; with a small random twist
(define loop
(lambda (time pitches)
(play-note time inst (car pitches) (random 40 80) 8000)
(callback (+ time 4000) 'loop (+ time 5000)
(if (null? (cdr pitches))
(list 60 63 62 (random 65 68) 68 59)
(cdr pitches)))))

(loop (now) '(60 63 62 67 68 59))

;; stop the loop by defining loop to be null
(define loop '())

;; define a new loop to play a sequence of chords
(define loop
(lambda (time chord)
(for-each (lambda (p)
(play-note time inst p 60 *second*))
chord)
(callback (+ time 40000) 'loop (+ time *second*)
(cdr (assoc chord '(((60 63 67) 58 62 65)
((58 62 65) 60 63 67)))))))

(loop (now) '(60 63 67))

(define loop '())


Related

au:play-note play-sound play


Back to Index