commit a69d9862018ecbcc79d9459b12dfac310d3b1a9c Author: Jordan Orelli Date: Sat Jul 12 18:54:08 2014 -0400 hi. diff --git a/metronome.ck b/metronome.ck new file mode 100644 index 0000000..ae6fba3 --- /dev/null +++ b/metronome.ck @@ -0,0 +1,51 @@ +9000 => port; // port to listen for osc subscribe messages +120 => int bpm; // beats per minute +0 => int count; // count (1 through 4) of the beat. + +OscRecv recv; +port => recv.port; +recv.listen(); +recv.event("/subscribe, si") @=> OscEvent subscribeEvent; +OscSend @ listeners[64]; OscSend send; + +fun void subscribe() { + while (true) { + subscribeEvent => now; + while (subscribeEvent.nextMsg() != 0) { + subscribeEvent.getString() => string host; + subscribeEvent.getInt() => int port; + addListener(host, port); + <<< "subscribe", host, port >>>; + } + } +} +spork ~ subscribe(); + +fun void addListener(string host, int port) { + for (0 => int i; i < listeners.size(); i++) { + if (listeners[i] == null) { + OscSend listener; + listener.setHost(host, port); + listener @=> listeners[i]; + return; + } + } +} + +fun void sendBeat(int count) { + for (0 => int i; i < listeners.size(); i++) { + if (listeners[i] != null) { + listeners[i].startMsg("/down, i"); + listeners[i].addInt(count); + } + } +} + +while (true) { + sendBeat(count+1); + 1 +=> count; + if (count % 4 == 0) { + 0 => count; + } + 1::minute / bpm => now; +}