Skip to content

Instantly share code, notes, and snippets.

@pjstadig
Forked from alandipert/midirepl.clj
Created July 13, 2012 19:57
Show Gist options
  • Save pjstadig/3107028 to your computer and use it in GitHub Desktop.
Save pjstadig/3107028 to your computer and use it in GitHub Desktop.
Midi REPL
(import '(javax.sound.midi MidiSystem Synthesizer))
(def keymaps
'{:colemak {a 60
r 62
s 64
t 65
d 66
h 67
n 68
e 69
i 70
o 71}
:qwerty {a 60
s 62
d 64
f 65
g 66
h 67
j 68
k 69
l 70}
:dvorak {a 60
o 62
e 64
u 65
i 66
d 67
h 68
t 69
n 70}})
(defn midi-rpl [layout]
(with-open [synth (doto (MidiSystem/getSynthesizer) .open)]
(let [channel (aget (.getChannels synth) 0)]
(prn "Type " :q " to quit.")
(loop []
(print "midi: ")
(flush)
(when-let [form (read)]
(when (not= form :q)
(if (= 1 (count (str form)))
(.noteOn channel (get layout form 60) 127)
(doseq [note (map (comp symbol str) (str form))]
(.noteOn channel (get layout note 60) 127)))
(recur)))))))
(midi-rpl (:qwerty keymaps))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment