Created
December 6, 2008 21:58
-
-
Save jvoorhis/32973 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; mmj: http://www.humatic.de/htools/mmj.htm | |
; rlwrap java -cp /usr/local/lib/clojure/clojure.jar:/usr/local/lib/mmj/mmj.jar -Djava.library.path=/usr/local/lib/mmj:/usr/lib/java clojure.lang.Repl | |
(ns org.jvoorhis.midi | |
(:import (de.humatic.mmj MidiSystem))) | |
(def out (MidiSystem/openMidiOutput 0)) | |
(defn make-note-on [c p v] | |
(let [msg (make-array (Byte/TYPE) 3)] | |
(aset-byte msg 0 (bit-or 0x90 c)) | |
(aset-byte msg 1 p) | |
(aset-byte msg 2 v) | |
msg)) | |
(defn make-note-off [c p] | |
(let [msg (make-array (Byte/TYPE) 3)] | |
(aset-byte msg 0 (bit-or 0x90 c)) | |
(aset-byte msg 1 p) | |
(aset-byte msg 2 0) | |
msg)) | |
(defn play [p d v] | |
(.sendMidi out (make-note-on 1 p v)) | |
(Thread/sleep (* d 1000)) | |
(.sendMidi out (make-note-off 1 p))) | |
(doseq p [60 64 67 72] (play p 0.5 64)) ; CMaj arpeggio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment