Created
April 1, 2015 21:13
-
-
Save alandipert/bb1bdf55efd927a7704c 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
(import '(javax.sound.midi MidiSystem Synthesizer)) | |
(defn play-note [synth channel note-map] | |
(let [{:keys [note velocity duration] | |
:or {note 60 | |
velocity 127 | |
duration 1000}} note-map] | |
(. channel noteOn note velocity) | |
(Thread/sleep duration) | |
(. channel noteOff note))) | |
(defn play-notes | |
[notes] | |
(with-open [synth (doto (MidiSystem/getSynthesizer) .open)] | |
(let [channel (aget (.getChannels synth) 0)] | |
(doseq [note notes] | |
(play-note synth channel note))))) | |
(defn play-c-major-scale [] | |
(let [c-major [0 2 4 5 7 9 11 12] | |
c-major-notes (map #(hash-map :note (+ % 60) :duration 100) c-major)] | |
(play-notes (cycle (concat c-major-notes | |
(rest (reverse c-major-notes))))))) | |
(play-c-major-scale) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment