Reads a midi file and returns a list structure represeting that midi-file. the stucture is one list per track. each track list is seperated into lists of start-times pitches volumes and durations(in beats). trying reading a simple midi-file and printing the result to the log.
;; setup audio unit graph
(define synth (au:make-node "aumu" "dls " "appl"))
(au:connect-node synth 0 *au:output-node* 0)
;; send program change to dls audio units
(au:midi-out (now) synth *midi-pc* 68 0) ; oboe
(au:midi-out (now) synth *midi-pc* 71 1) ; clarinet
(au:midi-out (now) synth *midi-pc* 60 2) ; horn
(au:midi-out (now) synth *midi-pc* 70 3) ; bassoon
;; read midi file
(define chorale (io:read-midi-file "/tmp/bach.mid"))
; Events can have a marker number attached to them
; to allow us to mute/ignore them even after they have been
; scheduled. (See below).
(define marker 100)
;; Play a MIDI track
; The list-ref function is an Impromptu function that
; allows the acceesing of elements within a list by index.
; The consing of the play-note time and marker attaches
; the marker number of the note events (start and stop).
(define (play-seq time inst midi-track chan)
(map (lambda (t p v r)
(play-note (cons (+ time (* t *second*)) marker) inst p v (* r *second*) chan))
(list-ref midi-track 0)
(list-ref midi-track 1)
(list-ref midi-track 2)
(list-ref midi-track 3)))
;; Play the first four tracks
(define (chorale-player time score)
(play-seq time synth (list-ref score 3) 0)
(play-seq time synth (list-ref score 2) 1)
(play-seq time synth (list-ref score 1) 2)
(play-seq time synth (list-ref score 0) 3))
;; Start - give play-seq 2 seconds to load the file.
(chorale-player (+ (now) (* *second* 2)) chorale)
Back to index