1 AbstractOpPlug : AbstractFunction {
3 composeUnaryOp { arg aSelector;
4 ^UnaryOpPlug.new(aSelector, this)
6 composeBinaryOp { arg aSelector, something;
7 ^BinaryOpPlug.new(aSelector, this, something)
9 reverseComposeBinaryOp { arg aSelector, something;
10 ^BinaryOpPlug.new(aSelector, something, this)
12 composeNAryOp { arg aSelector, anArgList;
13 ^{ this.value(anArgList).performList(aSelector, anArgList) }
16 Error("use .ar or .kr to use within a synth.").throw;
22 UnaryOpPlug : AbstractOpPlug {
24 *new { arg operator, a;
25 ^super.newCopyArgs(operator, a)
28 isNeutral { ^a.isNeutral }
32 numChannels { arg max;
35 n = a.numChannels(max);
36 ^if(n.isNil, { nil }, { max(n, max) });
40 var rate, numChannels;
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)
47 a.initBus(rate, numChannels);
48 ^a.value(proxy).perform(operator)
51 initBus { arg rate, numChannels;
52 ^a.initBus(rate, numChannels)
58 prepareForProxySynthDef { arg proxy;
59 ^{ this.value(proxy) }
63 "UnaryOpPlug: Cannot calculate this value. Use direct mapping only.".warn;
69 BinaryOpPlug : AbstractOpPlug {
70 var >operator, <>a, <>b;
71 *new { arg operator, a, b;
72 ^super.newCopyArgs(operator, a, b)
76 var vala, valb, rate, numChannels;
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)
83 this.initBus(rate, numChannels);
84 vala = a.value(proxy);
85 valb = b.value(proxy);
86 ^vala.perform(operator, valb)
88 initBus { arg rate, numChannels;
89 ^a.initBus(rate, numChannels) and: { b.initBus(rate, numChannels) };
92 isNeutral { ^a.isNeutral && b.isNeutral }
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
100 numChannels { arg max;
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 })
114 "BinaryOpPlug: Cannot calculate this value. Use direct mapping only.".warn;