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
|
(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]
|
(defn midi-message [command channel data1 data2]
|
||||||
{:command command
|
{:command command
|
||||||
@ -12,11 +19,25 @@
|
|||||||
|
|
||||||
(def default-receiver (MidiSystem/getReceiver))
|
(def default-receiver (MidiSystem/getReceiver))
|
||||||
|
|
||||||
(defn get-device-named [name]
|
(defn list-system-devices []
|
||||||
(MidiSystem/getMidiDevice
|
(vec (map (fn [info]
|
||||||
(first
|
(let [device (MidiSystem/getMidiDevice info)]
|
||||||
(filter #(= name (.getName %))
|
{:type (class device)
|
||||||
(MidiSystem/getMidiDeviceInfo)))))
|
: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]
|
(defn send-midi [rcvr midi-message]
|
||||||
(.send rcvr (map->ShortMessage midi-message) -1))
|
(.send rcvr (map->ShortMessage midi-message) -1))
|
||||||
|
Loading…
Reference in New Issue
Block a user