Skip to content

Instantly share code, notes, and snippets.

@dandaka
Created December 6, 2015 15:21
Show Gist options
  • Save dandaka/dd5963c5c700ca3ff7ea to your computer and use it in GitHub Desktop.
Save dandaka/dd5963c5c700ca3ff7ea to your computer and use it in GitHub Desktop.
lights.my-show=> sync-midi-clock
sync-midi-clock
#object[lights.my_show$sync_midi_clock 0x1679fcb8 "lights.my_show$sync_midi_clock@1679fcb8"]
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
IllegalArgumentException No MIDI clock sources matching "Network midi-net" were found. afterglow.midi/sync-to-midi-clock (midi.clj:544)
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
IllegalArgumentException No MIDI clock sources matching "Network midi-net" were found. afterglow.midi/sync-to-midi-clock (midi.clj:544)
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
IllegalArgumentException No MIDI clock sources matching "Network midi-net" were found. afterglow.midi/sync-to-midi-clock (midi.clj:544)
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
IllegalArgumentException No MIDI clock sources matching "Network midi-net" were found. afterglow.midi/sync-to-midi-clock (midi.clj:544)
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
IllegalArgumentException No MIDI clock sources matching "Network midi-net" were found. afterglow.midi/sync-to-midi-clock (midi.clj:544)
lights.my-show=> (afterglow.midi/identify-mapping)
(afterglow.midi/identify-mapping)
15-Dec-06 18:20:08 dandaka-mbp.local INFO [afterglow.midi] - Opened MIDI input: {:name "Bus 1", :description "IAC Driver Bus 1", :vendor "Apple Inc.", :version "Unknown version", :sources 2147483647, :sinks 0, :info #object[com.sun.media.sound.MidiInDeviceProvider$MidiInDeviceInfo 0xd4ab636 "Bus 1"], :device #object[com.sun.media.sound.MidiInDevice 0x45d7769f "com.sun.media.sound.MidiInDevice@45d7769f"]}
15-Dec-06 18:20:08 dandaka-mbp.local INFO [afterglow.midi] - Opened MIDI input: {:name "midi-net", :description "Network midi-net", :vendor "Unknown vendor", :version "Unknown version", :sources 2147483647, :sinks 0, :info #object[com.sun.media.sound.MidiInDeviceProvider$MidiInDeviceInfo 0x1e54faa2 "midi-net"], :device #object[com.sun.media.sound.MidiInDevice 0x44ace48b "com.sun.media.sound.MidiInDevice@44ace48b"]}
(sync-midi-clock)
nil
lights.my-show=> (sync-midi-clock)
NullPointerException java.util.regex.Matcher.getTextLength (Matcher.java:1140)
lights.my-show=>
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
NullPointerException java.util.regex.Matcher.getTextLength (Matcher.java:1140)
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
NullPointerException java.util.regex.Matcher.getTextLength (Matcher.java:1140)
lights.my-show=> (afterglow.midi/identify-mapping)
(afterglow.midi/identify-mapping)
nil
lights.my-show=>
lights.my-show=>
lights.my-show=>
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
NullPointerException java.util.regex.Matcher.getTextLength (Matcher.java:1140)
lights.my-show=> (sync-midi-clock)
(sync-midi-clock)
#afterglow.midi.ClockSync{:metronome #afterglow.rhythm.Metronome{:start #object[clojure.lang.Ref 0x5ba78787 {:status :ready, :val 1449414005304}], :bpm #object[clojure.lang.Ref 0x53b2df13 {:status :ready, :val 120}], :bpb #object[clojure.lang.Ref 0x4538353 {:status :ready, :val 4}], :bpp #object[clojure.lang.Ref 0x6d2c05d {:status :ready, :val 8}]}, :midi-clock-source {:name "midi-net", :description "Network midi-net", :vendor "Unknown vendor", :version "Unknown version", :sources 2147483647, :sinks 0, :info #object[com.sun.media.sound.MidiInDeviceProvider$MidiInDeviceInfo 0x1e54faa2 "midi-net"], :device #object[com.sun.media.sound.MidiInDevice 0x44ace48b "com.sun.media.sound.MidiInDevice@44ace48b"], :transmitter #object[com.sun.media.sound.MidiInDevice$MidiInTransmitter 0x6d9bc9a2 "com.sun.media.sound.MidiInDevice$MidiInTransmitter@6d9bc9a2"]}, :timestamps #object[clojure.lang.Ref 0x2404b1af {:status :ready, :val #amalloy/ring-buffer [30 ()]}], :means #object[clojure.lang.Ref 0x302d6aa2 {:status :ready, :val #amalloy/ring-buffer [30 ()]}], :traktor-info #object[clojure.lang.Ref 0x75b3ca63 {:status :ready, :val {:master nil}}]}
lights.my-show=>
@brunchboy
Copy link

I have a suspicion about what might be going on here. Could you try calling

(afterglow.midi/open-inputs-if-needed!)

and waiting a few seconds before trying your (sync-midi-clock)? Your code looks fine to me, and I think that when I rewrote my MIDI clock finder code to be more efficient (by always running in the background), I also inadvertently got rid of the code which used to call this for you, which breaks the examples. I did not notice this because I have always been using either the Ableton Push or Web interfaces, and both of those open the MIDI inputs.

@brunchboy
Copy link

Yes, that looks likely to be your problem. I looked at an older version of sync-to-midi-clock. It used to call watch-for-clock-sources, which called open-inputs-if-needed! but in the current version, clock sources are always watched for in the background, so watch-for-clock-sources was removed. Unfortunately, that also removed the call to open-inputs-if-needed!, so you probably had no MIDI devices hooked up in Afterglow. I just deployed a new snapshot build that calls open-inputs-if-needed! directly from sync-to-midi-clock, so they will be opened if necessary. Hopefully this will make it work for you even in cases where you’ve not connected the MIDI inputs before calling it.

This new snapshot seems to work properly for me even if trying to sync to a MIDI clock is the first thing I do after creating the show. Before making this change, I was able to reproduce what looked like your problem if I did that without connecting a MIDI controller or starting up the web UI. (There is now a pause the first time you call sync-to-midi-clock if the Java MIDI environment was not yet set up.)

If it still doesn't work, what does (afterglow.midi/current-clock-sources) show? Here is what it looks like for me, with Traktor running:

#{{:name "Traktor Virtual Output", :description "Traktor Virtual Output", :vendor "Unknown vendor",
   :version "Unknown version", :sources 2147483647, :sinks 0,
   :info #object[com.sun.media.sound.MidiInDeviceProvider$MidiInDeviceInfo 0x4aea4615 "Traktor Virtual Output"],
   :device #object[com.sun.media.sound.MidiInDevice 0x4c49f034 "com.sun.media.sound.MidiInDevice@4c49f034"],
   :transmitter #object[com.sun.media.sound.MidiInDevice$MidiInTransmitter 0x69b8fb55
    "com.sun.media.sound.MidiInDevice$MidiInTransmitter@69b8fb55"]}}

When you pull the latest version of [afterglow "0.1.6-SNAPSHOT"] you should also edit your project.clj to depend on the latest release candidate of Clojure 1.8, because I am now building and testing Afterglow against that: replace [org.clojure/clojure "1.7.0"] with [org.clojure/clojure "1.8.0-RC3"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment