forked from scztt/Connection.quark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextCollection.sc
72 lines (58 loc) · 1.52 KB
/
extCollection.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
+SequenceableCollection {
connectAll {
|...dependants|
^ConnectionList.newFrom(
this.collect(_.connectTo(*dependants))
)
}
connectEach {
|signalNameOrFunc, dependantList, methodNameOrFunc|
var tempVal;
if (this.size != dependantList.size) {
Error("connectEach requires collections of equal size (this.size = %, other.size = %)".format(this.size, dependantList.size)).throw;
};
if (signalNameOrFunc.notNil && signalNameOrFunc.isKindOf(Function).not) {
tempVal = signalNameOrFunc;
signalNameOrFunc = { |o| o.signal(tempVal) };
};
if (methodNameOrFunc.notNil && methodNameOrFunc.isKindOf(Function).not) {
tempVal = methodNameOrFunc;
methodNameOrFunc = { |o| o.methodSlot(tempVal) };
};
^this.collectAs({
|object, i|
var dependant = dependantList[i];
if (methodNameOrFunc.notNil) {
dependant = methodNameOrFunc.value(dependant);
};
if (signalNameOrFunc.notNil) {
object = signalNameOrFunc.value(object);
};
object.connectTo(dependant);
}, ConnectionList)
}
eachMethodSlot {
|method|
^this.collect(_.methodSlot(method));
}
eachValueSlot {
|setter|
^this.collect(_.valueSlot(setter));
}
eachInputSlot {
^this.collect(_.inputSlot());
}
eachArgSlot {
|argName|
^this.collect(_.argSlot(argName));
}
signalsDo {
|signal, func|
this.collect(_.signal(signal)).do(func);
}
signalsCollect {
|signal, func|
func = func ? {|s|s}; // IMPORTANT: we want the function, not the evaluated result
^this.collect(_.signal(signal)).collect(func);
}
}