class library: Reset has been renamed to OnError
[supercollider.git] / SCClassLibrary / JITLib / ProxySpace / operators.sc
blob7a5cda49e0acced2a10855e3b23b0b89a0d2b555
1 AbstractOpPlug : AbstractFunction {
3         composeUnaryOp { arg aSelector;
4                 ^UnaryOpPlug.new(aSelector, this)
5         }
6         composeBinaryOp { arg aSelector, something;
7                 ^BinaryOpPlug.new(aSelector, this, something)
8         }
9         reverseComposeBinaryOp { arg aSelector, something;
10                 ^BinaryOpPlug.new(aSelector, something, this)
11         }
12         composeNAryOp { arg aSelector, anArgList;
13                 ^{ this.value(anArgList).performList(aSelector, anArgList) }
14         }
15         writeInputSpec {
16                 Error("use .ar or .kr to use within a synth.").throw;
17         }
22 UnaryOpPlug : AbstractOpPlug {
23         var >operator, >a;
24         *new { arg operator, a;
25                 ^super.newCopyArgs(operator, a)
26         }
28         isNeutral { ^a.isNeutral }
30         rate { ^a.rate }
32         numChannels { arg max;
33                 var n, res;
34                 max = max ? 0;
35                 n = a.numChannels(max);
36                 ^if(n.isNil, { nil }, { max(n, max) });
37         }
39         value { arg proxy;
40                 var rate, numChannels;
41                 rate = this.rate;
42                 if(rate === 'stream') { rate = nil };  // cx defines rate of func as \stream
43                 numChannels = this.numChannels;
44                 if(rate.notNil and: { numChannels.notNil } and: { proxy.notNil }, {
45                         proxy.initBus(rate, numChannels)
46                 });
47                 a.initBus(rate, numChannels);
48                 ^a.value(proxy).perform(operator)
49         }
51         initBus { arg rate, numChannels;
52                 ^a.initBus(rate, numChannels)
53         }
54         wakeUp  {
55                 a.wakeUp;
56         }
58         prepareForProxySynthDef { arg proxy;
59                 ^{ this.value(proxy) }
60         }
62         asControlInput {
63                 "UnaryOpPlug: Cannot calculate this value. Use direct mapping only.".warn;
64                 ^this
65         }
69 BinaryOpPlug : AbstractOpPlug  {
70         var >operator, <>a, <>b;
71         *new { arg operator, a, b;
72                 ^super.newCopyArgs(operator, a, b)
73         }
75         value { arg proxy;
76                 var vala, valb, rate, numChannels;
77                 rate = this.rate;
78                 if(rate === 'stream') { rate = nil };  // cx defines rate of func as \stream
79                 numChannels = this.numChannels;
80                 if(rate.notNil and: { numChannels.notNil } and: { proxy.notNil }, {
81                         proxy.initBus(rate, numChannels)
82                 });
83                 this.initBus(rate, numChannels);
84                 vala = a.value(proxy);
85                 valb = b.value(proxy);
86                 ^vala.perform(operator, valb)
87         }
88         initBus { arg rate, numChannels;
89                 ^a.initBus(rate, numChannels) and: { b.initBus(rate, numChannels) };
90         }
92         isNeutral { ^a.isNeutral && b.isNeutral }
94         rate {
95                 if(a.isNeutral) { ^b.rate };
96                 if(b.isNeutral) { ^a.rate };
97                 ^if(a.rate !== \control) { a.rate } { b.rate } // as function.rate is defined as \stream
98         }
100         numChannels { arg max;
101                 var n1, n2, res;
102                 max = max ? 0;
103                 n1 = a.numChannels(max);
104                 if(n1.notNil, { max = n1 });
105                 n2 = b.numChannels(max);
106                 res = if(n1.isNil, { n2 }, { if(n2.isNil, { n1 }, { max(n1, n2) }) });
107                 ^if(res.notNil, { max(max,res) }, { nil })
108         }
109         wakeUp  {
110                 a.wakeUp;
111                 b.wakeUp;
112         }
113         asControlInput {
114                 "BinaryOpPlug: Cannot calculate this value. Use direct mapping only.".warn;
115                 ^this
116         }