From a01e932c29798809ee3d4661574206f445f822ca Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 9 Nov 2019 16:04:54 -0500 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ deps.edn | 1 + src/midi-playground/midi.clj | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 .gitignore create mode 100644 deps.edn create mode 100644 src/midi-playground/midi.clj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e1296b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.nrepl-port +.cpcache \ No newline at end of file diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/deps.edn @@ -0,0 +1 @@ +{} diff --git a/src/midi-playground/midi.clj b/src/midi-playground/midi.clj new file mode 100644 index 0000000..0eb6669 --- /dev/null +++ b/src/midi-playground/midi.clj @@ -0,0 +1,22 @@ +(ns midi-playground.midi + (:import [javax.sound.midi MidiSystem ShortMessage Receiver Sequencer Synthesizer])) + +(defn midi-message [command channel data1 data2] + {:command command + :channel channel + :data1 data1 + :data2 data2}) + +(defn map->ShortMessage [{:keys [command channel data1 data2]}] + (ShortMessage. command channel data1 data2)) + +(def default-receiver (MidiSystem/getReceiver)) + +(defn get-device-named [name] + (MidiSystem/getMidiDevice + (first + (filter #(= name (.getName %)) + (MidiSystem/getMidiDeviceInfo))))) + +(defn send-midi [rcvr midi-message] + (.send rcvr (map->ShortMessage midi-message) -1))