Add helper function to get system MIDI devices
This commit is contained in:
parent
a01e932c29
commit
5263395c50
@ -1,5 +1,12 @@
|
||||
(ns midi-playground.midi
|
||||
(:import [javax.sound.midi MidiSystem ShortMessage Receiver Sequencer Synthesizer]))
|
||||
(:import [javax.sound.midi
|
||||
MidiSystem
|
||||
ShortMessage
|
||||
Receiver
|
||||
Sequencer
|
||||
Synthesizer
|
||||
Transmitter]
|
||||
[com.sun.media.sound MidiInDevice MidiOutDevice]))
|
||||
|
||||
(defn midi-message [command channel data1 data2]
|
||||
{:command command
|
||||
@ -12,11 +19,25 @@
|
||||
|
||||
(def default-receiver (MidiSystem/getReceiver))
|
||||
|
||||
(defn get-device-named [name]
|
||||
(MidiSystem/getMidiDevice
|
||||
(first
|
||||
(filter #(= name (.getName %))
|
||||
(MidiSystem/getMidiDeviceInfo)))))
|
||||
(defn list-system-devices []
|
||||
(vec (map (fn [info]
|
||||
(let [device (MidiSystem/getMidiDevice info)]
|
||||
{:type (class device)
|
||||
:name (.getName info)
|
||||
:device device}))
|
||||
(MidiSystem/getMidiDeviceInfo))))
|
||||
|
||||
(defn get-devices-of-type [type]
|
||||
(filter #(instance? type (:device %))
|
||||
(list-system-devices)))
|
||||
|
||||
(defn get-system-device [type name]
|
||||
(when-let [device-info (first
|
||||
(filter #(and (instance? type (:device %))
|
||||
(= (:name %) name))
|
||||
(list-system-devices)))]
|
||||
(:device device-info)))
|
||||
|
||||
|
||||
(defn send-midi [rcvr midi-message]
|
||||
(.send rcvr (map->ShortMessage midi-message) -1))
|
||||
|
Loading…
Reference in New Issue
Block a user