From 5722ab88112a215e3a41bfe967cb5c7e32c31084 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 26 Jul 2014 15:13:24 -0400 Subject: [PATCH] unique subscribers wtf this is so god-damned janky --- metronome.ck | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/metronome.ck b/metronome.ck index 0ca9328..0b2e053 100644 --- a/metronome.ck +++ b/metronome.ck @@ -7,7 +7,8 @@ OscRecv recv; port => recv.port; recv.listen(); recv.event("/subscribe, si") @=> OscEvent subscribeEvent; -OscSend @ listeners[64]; OscSend send; +OscSend @ listeners[64]; +string addies[64]; fun void subscribe() { while (true) { @@ -22,12 +23,50 @@ fun void subscribe() { } spork ~ subscribe(); +fun string formatAddress(string host, int port) { + return host + "_" + Std.itoa(port); +} + +fun int hasAddress(string host, int port) { + formatAddress(host, port) => string addy; + for (0 => int i; i < addies.size(); i++) { + if (addies[i] == null || addies[i] == "") { + <<< "address ", addy, " is UNKNOWN 1" >>>; + return false; + } + if (addies[i] == addy) { + <<< "address ", addy, " is KNOWN" >>>; + return true; + } else { + <<< addies[i], " != ", addy >>>; + } + } + <<< "address ", addy, " is UNKNOWN 2" >>>; + return false; // I don't think we can even get here. +} + +fun void addAddress(string host, int port) { + for (0 => int i; i < addies.size(); i++) { + if (addies[i] == null || addies[i] == "") { + formatAddress(host, port) => addies[i]; + <<< "add address ", formatAddress(host, port), " at index ", i >>>; + return; + } + } +} + fun void addListener(string host, int port) { + if (hasAddress(host, port)) { + <<< "already subscribed: ", host, port >>>; + return; + } + for (0 => int i; i < listeners.size(); i++) { if (listeners[i] == null) { OscSend listener; listener.setHost(host, port); listener @=> listeners[i]; + addAddress(host, port); return; } }