File: Array.sc

package info (click to toggle)
supercollider 1%3A3.10.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,496 kB
  • sloc: cpp: 283,513; lisp: 74,040; ansic: 72,252; sh: 23,016; python: 7,175; makefile: 1,087; perl: 766; java: 677; yacc: 314; lex: 175; ruby: 136; objc: 65; xml: 15
file content (305 lines) | stat: -rw-r--r-- 7,003 bytes parent folder | download | duplicates (3)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
Array[slot] : ArrayedCollection {

	*with { arg ... args;
		// return an array of the arguments given
		// cool! the interpreter does it for me..
		^args
	}
	reverse {
		_ArrayReverse
		^this.primitiveFailed
	}
	scramble {
		_ArrayScramble
		^this.primitiveFailed
	}
	mirror {
		_ArrayMirror
		^this.primitiveFailed
	}
	mirror1 {
		_ArrayMirror1
		^this.primitiveFailed
	}
	mirror2 {
		_ArrayMirror2
		^this.primitiveFailed
	}
	stutter { arg n=2;
		_ArrayStutter
		^this.primitiveFailed
	}
	rotate { arg n=1;
		_ArrayRotate
		^this.primitiveFailed
	}
	pyramid { arg patternType=1; // an integer from 1-10
		_ArrayPyramid
		^this.primitiveFailed
	}
	pyramidg { arg patternType=1;
		var list = [];
		var lastIndex = this.lastIndex;
		if (patternType == 1) {
			for (0,lastIndex) {|i| list = list.add(this[0..i]) };
			^list
		};
		if (patternType == 2) {
			for (0,lastIndex) {|i| list = list.add(this[lastIndex-i..lastIndex]) };
			^list
		};
		if (patternType == 3) {
			for (lastIndex,0) {|i| list = list.add(this[0..i]) };
			^list
		};
		if (patternType == 4) {
			for (0,lastIndex) {|i| list = list.add(this[i..lastIndex]) };
			^list
		};
		if (patternType == 5) {
			for (0,lastIndex)   {|i| list = list.add(this[0..i]) };
			for (lastIndex-1,0) {|i| list = list.add(this[0..i]) };
			^list
		};
		if (patternType == 6) {
			for (0,lastIndex)   {|i| list = list.add(this[lastIndex-i..lastIndex]) };
			for (lastIndex-1,0) {|i| list = list.add(this[lastIndex-i..lastIndex]) };
			^list
		};
		if (patternType == 7) {
			for (lastIndex,0) {|i| list = list.add(this[0..i]) };
			for (1,lastIndex) {|i| list = list.add(this[0..i]) };
			^list
		};
		if (patternType == 8) {
			for (0,lastIndex)   {|i| list = list.add(this[i..lastIndex]) };
			for (lastIndex-1,0) {|i| list = list.add(this[i..lastIndex]) };
			^list
		};
		if (patternType == 9) {
			for (0,lastIndex) {|i| list = list.add(this[0..i]) };
			for (1,lastIndex) {|i| list = list.add(this[i..lastIndex]) };
			^list
		};
		if (patternType == 10) {
			for (0,lastIndex)   {|i| list = list.add(this[lastIndex-i..lastIndex]) };
			for (lastIndex-1,0) {|i| list = list.add(this[0..i]) };
			^list
		};
	}
	sputter { arg probability=0.25, maxlen = 100;
		var i=0;
		var list = Array.new;
		var size = this.size;
		probability = 1.0 - probability;
		while { (i < size) and: { list.size < maxlen }}{
			list = list.add(this[i]);
			if (probability.coin) { i = i + 1; }
		};
		^list
	}

	lace { arg length;
		_ArrayLace
		^this.primitiveFailed
	}
	permute { arg nthPermutation;
		_ArrayPermute
		^this.primitiveFailed
	}
	allTuples { arg maxTuples = 16384;
		_ArrayAllTuples
		^this.primitiveFailed
	}
	wrapExtend { arg length;
		_ArrayExtendWrap
		^this.primitiveFailed
	}
	foldExtend { arg length;
		_ArrayExtendFold
		^this.primitiveFailed
	}
	clipExtend { arg length;
		_ArrayExtendLast
		^this.primitiveFailed
	}
	slide { arg windowLength=3, stepSize=1;
		_ArraySlide
		^this.primitiveFailed
	}
	containsSeqColl {
		_ArrayContainsSeqColl
		^this.primitiveFailed
	}

	//************** inconsistent argnames, see SequenceableColllection unlace!
	unlace { arg clumpSize=2, numChan=1, clip=false;
		^if(clip) {
			super.unlace(clumpSize, numChan, true)
		} {
			this.prUnlace(clumpSize, numChan) // clip not yet implemented in primitive
		}
	}
	prUnlace { arg clumpSize=2, numChan=1;
		_ArrayUnlace
		^this.primitiveFailed;
	}
	interlace { arg clumpSize=1;
		//_ArrayInterlace
		//^this.primitiveFailed;
		Error("interlace was replaced by lace\n").throw
	}
	deinterlace { arg clumpSize=2, numChan=1;
		//_ArrayUnlace
		//^this.primitiveFailed;
		Error("deinterlace was replaced by unlace\n").throw
	}

	// multiChannelExpand and flop do the same thing.
	flop {
		_ArrayMultiChannelExpand
		^super.flop
	}
	multiChannelExpand {
		_ArrayMultiChannelExpand
		^super.flop
	}
	envirPairs {
		// given an array of symbols, this returns an array of pairs of symbol, value
		// from the current environment
		var result;
		this.do {|name|
			var value = name.envirGet;
			value !? { result = result.add(name).add(value); };
		};
		^result
	}

	shift { arg n, filler = 0.0;
		var fill = Array.fill(n.abs, filler);
		var remain = this.drop(n.neg);
		^if (n<0) { remain ++ fill } { fill ++ remain }
	}

	powerset {
		var arrSize = this.size;
		var powersize = (2 ** arrSize).asInteger;
		var powersOf2 = ({ |i| 2 ** i }).dup(arrSize);

		^Array.fill(powersize, { |i|
			var elemArr = Array.new;
			powersOf2.do { |mod, j|
				if (i div: mod % 2 != 0) {
					elemArr = elemArr.add(this[j])
				};
			};
			elemArr;
		});
	}

	// UGen support:
	source {
		// returns the source UGen from an Array of OutputProxy(s)
		var elem = this.at(0);
		if (elem.isKindOf(OutputProxy), {
			^elem.source
		},{
			Error("source: Not an Array of OutputProxy(s)\n").throw;
		});
	}
	asUGenInput { arg for; ^this.collect(_.asUGenInput(for)) }
	asAudioRateInput { arg for; ^this.collect(_.asAudioRateInput(for)) }
	asControlInput { ^this.collect(_.asControlInput) }

	isValidUGenInput { ^true }
	numChannels { ^this.size }

	// multichannel UGen-poll
	poll { arg trig = 10, label, trigid = -1;
		if(label.isNil){ label = this.size.collect{|index| "UGen Array [%]".format(index) } };
		^Poll(trig, this, label, trigid)
	}
	dpoll { arg label, run = 1, trigid = -1;
		if(label.isNil){ label = this.size.collect{|index| "UGen Array [%]".format(index) } };
		^Dpoll(this, label, run, trigid)
	}

	envAt { arg time;
		_ArrayEnvAt
		^this.primitiveFailed
	}

//	// 2D array support
//	*newClear2D { arg rows=1, cols=1;
//		^super.fill(rows, { Array.newClear(cols) });
//	}
//	*new2D { arg rows=1, cols=1;
//		^this.newClear2D(rows, cols);
//	}
//	at2D { arg row, col; ^this.at(row).at(col) }
//	put2D { arg row, col, val; ^this.at(row).put(col, val) }
//	fill2D { arg val;
//		this.do({ arg row;
//			row.size.do({ arg i;
//				row.put(i, val)
//			})
//		})
//	}


	// IdentitySet support
	atIdentityHash { arg argKey;
		_Array_AtIdentityHash
		^this.primitiveFailed
	}
	// IdentityDictionary support
	atIdentityHashInPairs { arg argKey;
		_Array_AtIdentityHashInPairs
		^this.primitiveFailed
	}

	asSpec { ^ControlSpec( *this ) }

	// threads
	fork { arg join (this.size), clock, quant=0.0, stackSize=64;
		var count = 0;
		var cond = Condition({ count >= join });
		this.do({ arg func;
			Routine({ arg time;
				func.value(time);
				count = count + 1;
				cond.signal;
			}).play(clock, quant);
		});
		cond.wait;
	}

	// UGen support
	madd { arg mul = 1.0, add = 0.0;
		^MulAdd(this, mul, add);
	}

	// OSC
	asRawOSC {
		_Array_OSCBytes
		^this.primitiveFailed;
	}

	printOn { arg stream;
		if (stream.atLimit, { ^this });
		stream << "[ " ;
		this.printItemsOn(stream);
		stream << " ]" ;
	}
	storeOn { arg stream;
		if (stream.atLimit, { ^this });
		stream << "[ " ;
		this.storeItemsOn(stream);
		stream << " ]" ;
	}
	prUnarchive { arg slotArray;
		slotArray.pairsDo {|index, slots| this[index].setSlots(slots) };
		this.do {|obj| obj.initFromArchive };
		^this.first
	}
}