;; markov-create-rules.sal -- building a Markov model from MIDI file ;; (c) 2008 by Roger B. Dannenberg ;; read in a score from a MIDI file define variable teribus = score-read-smf("teribus.mid") ;; pitches will be accumulated here define variable pitches = nil define function extract-pitch(time, dur, expr) begin set pitches @= expr-get-attr(expr, keyword(pitch)) return list(time, dur, expr) end ;; call extract-pitch on each note in the score exec score-apply(teribus, quote(extract-pitch)) ;; some score elements have no pitch, so there are some ;; nil items in pitches; remove them here set pitches = remove(nil, reverse(pitches)) ;; build Markov rules from the list of pitches set rules = markov-create-rules(pitches, 1, t) ;; print the rules to see what we got exec pprint(rules) ;; make some music begin with pitches = make-markov(rules, past: {69}), tatum = 60.0 / (100 * 6), ; shortest note duration iois = make-cycle(list(tatum * 6, tatum , tatum, tatum, tatum, tatum, tatum)) exec score-gen(save: quote(markov-midi), score-len: 71, pitch: next(pitches), ioi: next(iois), vel: 100) exec score-play(markov-midi) end