File: List.sc

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (123 lines) | stat: -rw-r--r-- 3,275 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
List : SequenceableCollection {
	var <>array;

	*new { arg size = 8; ^super.new.setCollection(Array.new(size)); }
	*newClear { arg size = 0;
		if ( size == 0, {
			^super.new.setCollection(Array.new(8));
		},{
			^super.new.setCollection(Array.newClear(size));
		});
	}
	*copyInstance { arg aList; ^super.new.array_( aList.array.copy ) }
	*newUsing { arg anArray;
		// an array is supplied to use directly
		^super.new.setCollection( anArray )
	}

	asArray { ^array.copy }
	copy { ^this.class.copyInstance(this) }
	copyRange { arg start, end; ^this.class.newUsing(array.copyRange(start, end)) }
	copySeries { arg first, second, last;
		^this.class.newUsing(array.copySeries(first, second, last))
	}
	putSeries { arg first, second, last, value;
		array.putSeries(first, second, last, value);
	}

	grow { arg sizeIncrease; array = array.grow(sizeIncrease); }
	size { ^array.size }
	dump { "List's array:\n".post; array.dump }

	clear {
		this.setCollection(Array.new(8));
	}

	// accessing

	at { arg i; ^array.at(i) }
	clipAt { arg i; i = i.asInteger.clip(0, this.size - 1); ^array.at(i) }
	wrapAt { arg i; i = i.asInteger.wrap(0, this.size - 1); ^array.at(i) }
	foldAt { arg i; i = i.asInteger.fold(0, this.size - 1); ^array.at(i) }

	put { arg i, item; array.put(i, item) }
	clipPut { arg i, item; i = i.asInteger.clip(0, this.size - 1); ^array.put(i, item) }
	wrapPut { arg i, item; i = i.asInteger.wrap(0, this.size - 1); ^array.put(i, item) }
	foldPut { arg i, item; i = i.asInteger.fold(0, this.size - 1); ^array.put(i, item) }

	add { arg item; array = array.add(item); }
	addFirst { arg item; array = array.addFirst(item); }
	insert { arg index, item; array = array.insert(index, item); }
	removeAt { arg index; ^array.removeAt(index); }
	pop { ^array.pop }
	first { if (this.size > 0, { ^array.at(0) }, { ^nil }) }
	last { if (this.size > 0, { ^array.at(this.size - 1) }, { ^nil }) }
	fill { arg item; array.fill(item) }

	// enumerating
	do { arg function;
		array.do(function);
	}
	reverseDo { arg function;
		array.reverseDo(function);
	}
	pairsDo { arg function;
		array.pairsDo(function);
	}
	doAdjacentPairs { arg function;
		array.doAdjacentPairs(function);
	}

	// ordering
	swap { arg i,j; array.swap(i, j) }

	reverse {
		^this.class.newUsing(array.reverse);
	}
	rotate { arg n=1;
		^this.class.newUsing(array.rotate(n));
	}
	stutter { |n=2|
		^this.dupEach(n);
	}
	dupEach { |n=2|
		^this.class.newUsing(array.dupEach(n));
	}
	mirror {
		^this.class.newUsing(array.mirror);
	}
	mirror2 {
		^this.class.newUsing(array.mirror2);
	}
	mirror1 {
		^this.class.newUsing(array.mirror1);
	}
	scramble {
		^this.class.newUsing(array.scramble);
	}
	permute { arg nthPermutation;
		^this.class.newUsing(array.permute(nthPermutation));
	}
	wrapExtend { arg length;
		^this.class.newUsing(array.wrapExtend(length));
	}
	foldExtend { arg length;
		^this.class.newUsing(array.foldExtend(length));
	}
	pyramid { arg patternType=1; // an integer from 1-10
		^this.class.newUsing(array.pyramid(patternType));
	}
	lace { arg length;
		^this.class.newUsing(array.lace(length))
	}
	slide { arg windowLength=3, stepSize=1;
		^this.class.newUsing(array.slide(windowLength, stepSize));
	}

	// PRIVATE:
	setCollection { arg aColl;
		array = aColl.asArray;
	}

	asList { ^this }
}