Created
February 25, 2023 15:19
-
-
Save grav/37572295bde4540ed9edc92cf8855c52 to your computer and use it in GitHub Desktop.
Simple Midi example for Clojure
This file contains 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
;; 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