Skip to content

Instantly share code, notes, and snippets.

@grav
Created February 25, 2023 15:19
Show Gist options
  • Save grav/37572295bde4540ed9edc92cf8855c52 to your computer and use it in GitHub Desktop.
Save grav/37572295bde4540ed9edc92cf8855c52 to your computer and use it in GitHub Desktop.
Simple Midi example for Clojure
;; Adapted from https://stackoverflow.com/a/36466737/202538
;; Run with `clj -M miditest.clj`
(ns miditest
(:import (javax.sound.midi
Synthesizer
MidiSystem
Instrument
MidiChannel
MidiUnavailableException)))
(let [midi-synth (MidiSystem/getSynthesizer)
_ (.open midi-synth)
instruments (.getInstruments (.getDefaultSoundbank midi-synth))
midi-channels (.getChannels midi-synth)]
(.loadInstrument midi-synth (first instruments))
(.noteOn (first midi-channels) 60 100)
(Thread/sleep 1000)
(.noteOff (first midi-channels) 60))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment