Skip to content

Instantly share code, notes, and snippets.

@pcsanwald
Created May 28, 2012 22:52
Show Gist options
  • Save pcsanwald/2821539 to your computer and use it in GitHub Desktop.
Save pcsanwald/2821539 to your computer and use it in GitHub Desktop.
demo your computer's builtin synthesizer sounds using middle C
(import 'javax.sound.midi.Synthesizer 'javax.sound.midi.MidiSystem)
; plays a middle C for 2 seconds, then pauses for 500ms
(defn play [channel]
(do
(.noteOn channel 67 1)
(Thread/sleep 2000)
(.allNotesOff channel)
(Thread/sleep 500)))
; why doesn't with-open work here?
(def synth (doto (MidiSystem/getSynthesizer) .open))
(for [x (range (count (.getChannels ^Synthesizer synth)))]
(let [channel (aget (.getChannels ^Synthesizer synth) x)]
(play channel)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment