3 var <>addr, <cmdName, <>action;
4 var <cmdNameWithoutSlash;
6 *new { arg addr, cmdName, action;
7 ^super.new.init(addr, cmdName, action);
14 init { arg argAddr, argCmdName, argAction;
17 this.cmdName = argCmdName;
20 cmdName_ { arg string;
21 string = string.asString;
22 if(string[0] == $/) { string = string.drop(1) };
23 cmdNameWithoutSlash = string.asSymbol;
24 cmdName = ("/" ++ string).asSymbol;
28 *respond { arg time, addr, msg;
29 var cmdName, hit = false;
33 (resp.cmdName === cmdName)
35 { resp.cmdNameWithoutSlash === cmdName }
36 and: { addr.matches(resp.addr) }
38 resp.value(time, msg, addr);
47 old = all.findMatch(responder);
48 if(old.notNil,{ all.remove(old) });
51 *remove { arg responder;
52 all.remove(responder);
54 *removeAddr { arg addr;
55 all = all.reject({ arg item;
60 value { arg time, msg, addr;
61 action.value(time, this, msg, addr);
64 ^that respondsTo: #[\cmdName, \addr]
65 and: { cmdName == that.cmdName and: { addr == that.addr }}
68 ^addr.hash bitXor: cmdName.hash
70 add { this.class.add(this); }
71 remove { all.remove(this) }
75 action = { arg time, responder, msg, addr;
76 func.value(time, responder, msg, addr);
83 //used to manage OSCresponderNodes. do not use directly.
85 OSCMultiResponder : OSCresponder {
88 value { arg time, msg, addr;
90 iterlist = nodes.copy;
91 iterlist.do({ arg node; node.value(time, msg, addr) });
93 isEmpty { ^nodes.size == 0 }
98 OSCresponderNode : OSCresponder {
105 made = OSCMultiResponder(addr, cmdName);
106 found = all.findMatch(made);
107 if(found.isNil, { made.nodes = [this]; made.add; added = true; ^this });
108 if (found.class === OSCresponder, {
110 made.nodes = [found, this];
113 found.nodes = found.nodes.add(this)
122 action = { arg time, responder, msg, addr;
123 func.value(time, responder, msg, addr);
129 var resp, alreadyThere;
130 resp = OSCMultiResponder(addr, cmdName);
131 alreadyThere = all.findMatch(resp);
132 if(alreadyThere.notNil)
134 alreadyThere.nodes.remove(this);
135 if(alreadyThere.isEmpty, { alreadyThere.remove });
140 value { arg time, msg, addr;
141 action.value(time, this, msg, addr);