diff --git a/src/midi-playground/midi.clj b/src/midi-playground/midi.clj index 0eb6669..83822e5 100644 --- a/src/midi-playground/midi.clj +++ b/src/midi-playground/midi.clj @@ -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))