Tags: Clojure, Overtone, Music
Today I'm playing with Open Sound Control (OSC), which is more general-purpose than midi but kinda similar idea. I have an android app on my phone named Control which has a few existing UIs, in my case I'm playing with the multi-touch. I set it to have two touch inputs.
In my Overtone REPL, I first set it up to listen for OSC events, and dump out whatever events it sees:
(def server (osc-server 44100 "osc-clj"))
(osc-listen server (fn [msg] (println msg)) :debug)
**Turn off with:** (osc-rm-listener server :debug)
I got both my laptop and phone on the wifi (which allows peer-to-peer communication) and told the Control app to connect to my laptop server (192.168.0.15 port 44100, in this case). Now when I touch the screen I get a bunch of messages about the generated OSC events. They look like:
{:src-port 45161, 192.168.0.25, /multi/1, ff, (0.36825398 0.3961456)}
From this I see that the path I want to react to is "/multi/1" and "/multi/2". Dragging my fingers around, the args are the x and y coordinates normalized to (0..1). For now I'll just make it beep a bit when it gets an event. I'm hooking the first touch up so the X axis generates a frequency, and the second touch up so that the Y axis generates a frequency (just as a test), giving:
(osc-handle server "/multi/1" (fn msg
(let
x (nth (:args msg) 0)
y (nth (:args msg) 1)
(demo 0.1 (saw (+ 100 (* 100 x))))
)
))
(osc-handle server "/multi/2" (fn msg
(let
x (nth (:args msg) 0)
y (nth (:args msg) 1)
(demo 0.1 (saw (+ 100 (* 100 y))))
)
))
Each touch plays for 1/10th of a second, so if I drag around these overlap a bunch. In fact, if I drag around a lot then something gets backed up and the sound is delayed.