scide: LookupDialog - redo lookup on classes after partial lookup
[supercollider.git] / SCClassLibrary / Common / Audio / InOut.sc
blob3f3ded2a0b4d679f7abb7424336b21f7560b19d6
1 ControlName
3         var <>name, <>index, <>rate, <>defaultValue, <>argNum, <>lag;
5         *new { arg name, index, rate, defaultValue, argNum, lag;
6                 ^super.newCopyArgs(name.asSymbol, index, rate, defaultValue, argNum, lag ? 0.0)
7         }
9         numChannels {
10                 ^defaultValue.asArray.size;
11         }
13         printOn { arg stream;
14                 stream << "ControlName  P " << index.asString;
15                 if (name.notNil) { stream << " " << name; };
16                 if (rate.notNil) { stream << " " << rate; };
17                 if (defaultValue.notNil) { stream << " " << defaultValue; };
18                 //stream << "\n"
19         }
23 Control : MultiOutUGen {
24         var <values;
26         *names { arg names;
27                 var synthDef, index;
28                 synthDef = UGen.buildSynthDef;
29                 index = synthDef.controlIndex;
30                 names = names.asArray;
31                 names.do { |name, i|
32                         synthDef.addControlName(
33                                 ControlName(name, index + i, 'control',
34                                         nil, synthDef.allControlNames.size)
35                         );
36                 };
37         }
38         *kr { arg values;
39                 ^this.multiNewList(['control'] ++ values.asArray)
40         }
41         *ir { arg values;
42                 ^this.multiNewList(['scalar'] ++ values.asArray)
43         }
44         init { arg ... argValues;
45                 var ctlNames, lastControl;
46                 values = argValues;
47                 if (synthDef.notNil) {
48                         specialIndex = synthDef.controls.size;
49                         synthDef.controls = synthDef.controls.addAll(values);
50                         ctlNames = synthDef.controlNames;
52                         if (ctlNames.size > 0) {
53                                         // the current control is always the last added, so:
54                                 lastControl = synthDef.controlNames.last;
55                                 if(lastControl.defaultValue.isNil) {
56                                                 // only write if not there yet:
57                                         lastControl.defaultValue_(values.unbubble);
58                                 }
59                         };
61                         synthDef.controlIndex = synthDef.controlIndex + values.size;
63                 };
64                 ^this.initOutputs(values.size, rate)
65         }
66         *isControlUGen { ^true }
70 AudioControl : MultiOutUGen {
71         var <values;
73         *names { arg names;
74                 var synthDef, index;
75                 synthDef = UGen.buildSynthDef;
76                 index = synthDef.controlIndex;
77                 names = names.asArray;
78                 names.do { |name, i|
79                         synthDef.addControlName(
80                                 ControlName(name, index + i, 'audio',
81                                         nil, synthDef.allControlNames.size)
82                         );
83                 };
84         }
85         *ar { arg values;
86                 ^this.multiNewList(['audio'] ++ values.asArray)
87         }
88         init { arg ... argValues;
89                 values = argValues;
90                 if (synthDef.notNil) {
91                         specialIndex = synthDef.controls.size;
92                         synthDef.controls = synthDef.controls.addAll(values);
93                         synthDef.controlIndex = synthDef.controlIndex + values.size;
94                 };
95                 ^this.initOutputs(values.size, rate)
96         }
97         *isAudioControlUGen { ^true }
98         *isControlUGen { ^true }
101 TrigControl : Control {}
103 LagControl : Control {
104         *kr { arg values, lags;
105                 var outputs;
107                 values = values.asArray;
109                 if (lags.isNumber) {
110                         lags = lags ! values.size
111                 } {
112                         lags = lags.asArray;
113                 };
115                 if (values.size != lags.size, {
116                         "LagControl values.size != lags.size".error;
117                         ^nil
118                 });
119                 values = values.clump(16);
120                 lags = lags.clump(16);
121                 outputs = [];
122                 values.size.do({ arg i;
123                         outputs = outputs ++ this.multiNewList(['control'] ++ values.at(i) ++ lags.at(i));
124                 });
125                 ^outputs
126         }
127         *ir {
128                 ^this.shouldNotImplement(thisMethod)
129         }
130         init { arg ... stuff;
131                 var lags, size, size2;
132                 size = stuff.size;
133                 size2 = size >> 1;
134                 values = stuff[ .. size2-1];
135                 inputs = stuff[size2 .. size-1];
136                 if (synthDef.notNil, {
137                         specialIndex = synthDef.controls.size;
138                         synthDef.controls = synthDef.controls.addAll(values);
139                         synthDef.controlIndex = synthDef.controlIndex + values.size;
140                 });
141                 ^this.initOutputs(values.size, rate)
142         }
145 AbstractIn : MultiOutUGen {
146         *isInputUGen { ^true }
149 In : AbstractIn {
150         *ar { arg bus = 0, numChannels = 1;
151                 ^this.multiNew('audio', numChannels, bus)
152         }
153         *kr { arg bus = 0, numChannels = 1;
154                 ^this.multiNew('control', numChannels, bus)
155         }
156         init { arg numChannels ... argBus;
157                 inputs = argBus.asArray;
158                 ^this.initOutputs(numChannels, rate)
159         }
162 LocalIn : AbstractIn {
163         *ar { arg numChannels = 1, default = 0.0;
164                 ^this.multiNew('audio', numChannels, *default)
165         }
166         *kr { arg numChannels = 1, default = 0.0;
167                 ^this.multiNew('control', numChannels, *default)
168         }
169         init { arg numChannels ... default;
170                 inputs = default.wrapExtend(numChannels);
171                 ^this.initOutputs(numChannels, rate)
172         }
176 LagIn : AbstractIn {
177         *kr { arg bus = 0, numChannels = 1, lag = 0.1;
178                 ^this.multiNew('control', numChannels, bus, lag)
179         }
180         init { arg numChannels ... argInputs;
181                 inputs = argInputs.asArray;
182                 ^this.initOutputs(numChannels, rate)
183         }
186 InFeedback : AbstractIn {
187         *ar { arg bus = 0, numChannels = 1;
188                 ^this.multiNew('audio', numChannels, bus)
189         }
190         init { arg numChannels ... argBus;
191                 inputs = argBus.asArray;
192                 ^this.initOutputs(numChannels, rate)
193         }
196 InTrig : AbstractIn {
197         *kr { arg bus = 0, numChannels = 1;
198                 ^this.multiNew('control', numChannels, bus)
199         }
200         init { arg numChannels ... argBus;
201                 inputs = argBus.asArray;
202                 ^this.initOutputs(numChannels, rate)
203         }
206 AbstractOut : UGen {
207         numOutputs { ^0 }
208         writeOutputSpecs {}
209         checkInputs {
210                 if (rate == 'audio', {
211                         for(this.class.numFixedArgs, inputs.size - 1, { arg i;
212                                 if (inputs.at(i).rate != 'audio', {
213                                         ^(" input at index " + i +
214                                                 "(" + inputs.at(i) + ") is not audio rate");
215                                 });
216                         });
217                 });
218                 ^this.checkValidInputs
219         }
221         *isOutputUGen { ^true }
222         *numFixedArgs { ^this.subclassResponsibility(thisMethod) }
224         numAudioChannels {
225                 ^inputs.size - this.class.numFixedArgs
226         }
228         writesToBus { ^this.subclassResponsibility(thisMethod) }
231 Out : AbstractOut {
232         *ar { arg bus, channelsArray;
233                 channelsArray = this.replaceZeroesWithSilence(channelsArray.asArray);
234                 this.multiNewList(['audio', bus] ++ channelsArray)
235                 ^0.0            // Out has no output
236         }
237         *kr { arg bus, channelsArray;
238                 this.multiNewList(['control', bus] ++ channelsArray.asArray)
239                 ^0.0            // Out has no output
240         }
241         *numFixedArgs { ^1 }
242         writesToBus { ^true }
245 ReplaceOut : Out {}
246 OffsetOut : Out {
247         *kr { ^this.shouldNotImplement(thisMethod) }
250 LocalOut : AbstractOut {
251         *ar { arg channelsArray;
252                 channelsArray = this.replaceZeroesWithSilence(channelsArray.asArray);
253                 this.multiNewList(['audio'] ++ channelsArray)
254                 ^0.0            // LocalOut has no output
255         }
256         *kr { arg channelsArray;
257                 this.multiNewList(['control'] ++ channelsArray.asArray)
258                 ^0.0            // LocalOut has no output
259         }
260         *numFixedArgs { ^0 }
261         writesToBus { ^false }
265 XOut : AbstractOut {
266         *ar { arg bus, xfade, channelsArray;
267                 channelsArray = this.replaceZeroesWithSilence(channelsArray.asArray);
268                 this.multiNewList(['audio', bus, xfade] ++ channelsArray)
269                 ^0.0            // Out has no output
270         }
271         *kr { arg bus, xfade, channelsArray;
272                 this.multiNewList(['control', bus, xfade] ++ channelsArray.asArray)
273                 ^0.0            // Out has no output
274         }
275         *numFixedArgs { ^2 }
276         checkInputs {
277                 if (rate == 'audio', {
278                         for(2, inputs.size - 1, { arg i;
279                                 if (inputs.at(i).rate != 'audio', {
280                                         ^(" input at index " + i +
281                                                 "(" + inputs.at(i) + ") is not audio rate");
282                                 });
283                         });
284                 });
285                 ^this.checkValidInputs
286         }
287         writesToBus { ^true }
291 SharedOut : AbstractOut {
292         *kr { arg bus, channelsArray;
293                 warn("SharedOut is deprecated and will be removed. Please use Bus-getSynchronous instead.");
294                 this.multiNewList(['control', bus] ++ channelsArray.asArray)
295                 ^0.0            // Out has no output
296         }
297         *numFixedArgs { ^1 }
298         writesToBus { ^false }
301 SharedIn : AbstractIn {
302         *kr { arg bus = 0, numChannels = 1;
303                 warn("SharedIn is deprecated and will be removed. Please use Bus-setSynchronous instead.");
304                 ^this.multiNew('control', numChannels, bus)
305         }
306         init { arg numChannels ... argBus;
307                 inputs = argBus.asArray;
308                 ^this.initOutputs(numChannels, rate)
309         }