1 CLASS::SequenceableCollection
2 summary::Abstract superclass of integer indexable collections
3 categories::Collections>Ordered
6 SequenceableCollection is a subclass of Collection whose elements can be indexed by an Integer. It has many useful subclasses; link::Classes/Array:: and link::Classes/List:: are amongst the most commonly used.
10 copymethod:: Collection *fill
13 Fill a SequenceableCollection with an arithmetic series.
15 Array.series(5, 10, 2);
19 Fill a SequenceableCollection with a geometric series.
25 Fill a SequenceableCollection with a fibonacci series.
28 Array.fib(5, 2, 32); // start from 32 with step 2.
31 the number of values in the collection
33 the starting step value
38 Fill a SequenceableCollection with random values in the range strong::minVal:: to strong::maxVal::.
40 Array.rand(8, 1, 100);
44 Fill a SequenceableCollection with random values in the range -strong::val:: to +strong::val::.
50 Fill a SequenceableCollection with random values in the range strong::minVal:: to strong::maxVal:: with a linear distribution.
52 Array.linrand(8, 1, 100);
56 Fill a SequenceableCollection with random values in the range strong::minVal:: to strong::maxVal:: with exponential distribution.
58 Array.exprand(8, 1, 100);
62 Fill a SequenceableCollection with the interpolated values between the strong::start:: and strong::end:: values.
64 Array.interpolation(5, 3.2, 20.5);
73 synonym for link::Classes/ArrayedCollection#-clipAt::.
79 synonym for link::Classes/ArrayedCollection#-wrapAt::.
87 synonym for link::Classes/ArrayedCollection#-foldAt::.
93 Return the first element of the collection.
99 Return the last element of the collection.
104 method::putFirst, putLast
105 Place strong::item:: at the first / last index in the collection. Note that if the collection is empty (and therefore has no indexed slots) the item will not be added.
107 [3, 4, 5].putFirst(100);
108 [3, 4, 5].putLast(100);
112 Return the index of an strong::item:: in the collection, or nil if not found.
114 [3, 4, 100, 5].indexOf(100);
115 [3, 4, \foo, \bar].indexOf(\foo);
119 Return the index of something in the collection that equals the strong::item::, or nil if not found.
121 [3, 4, "foo", "bar"].indexOfEqual("foo");
124 method::indicesOfEqual
125 Return an array of indices of things in the collection that equal the strong::item::, or nil if not found.
127 y = [7, 8, 7, 6, 5, 6, 7, 6, 7, 8, 9];
132 method::indexOfGreaterThan
133 Return the first index containing an strong::item:: which is greater than strong::item::.
135 y = List[ 10, 5, 77, 55, 12, 123];
136 y.indexOfGreaterThan(70);
139 copymethod:: Collection -maxIndex
141 copymethod:: Collection -minIndex
145 If the strong::sublist:: exists in the receiver (in the specified order), at an offset greater than or equal to the initial strong::offset::, then return the starting index.
147 y = [7, 8, 7, 6, 5, 6, 7, 6, 7, 8, 9];
152 Similar to link::#-find:: but returns an array of all the indices at which the sequence is found.
154 y = [7, 8, 7, 6, 5, 6, 7, 6, 7, 8, 9];
159 Returns the closest index of the value in the collection (collection must be sorted).
161 [2, 3, 5, 6].indexIn(5.2);
164 method::indexInBetween
165 Returns a linearly interpolated float index for the value (collection must be sorted). Inverse operation is link::#-blendAt::.
167 x = [2, 3, 5, 6].indexInBetween(5.2);
168 [2, 3, 5, 6].blendAt(x);
172 Returns a linearly interpolated value between the two closest indices. Inverse operation is link::#-indexInBetween::.
174 x = [2, 5, 6].blendAt(0.4);
178 Return a new SequenceableCollection which is a copy of the indexed slots of the receiver from strong::start:: to strong::end::.
179 code::x.copyRange(a, b):: can also be written as code::x[a..b]::
184 y = z.copyRange(1, 3);
191 Return a new SequenceableCollection which is a copy of the indexed slots of the receiver from strong::start:: to the end of the collection.
192 code::x.copyToEnd(a):: can also be written as code::x[a..]::
194 method::copyFromStart
195 Return a new SequenceableCollection which is a copy of the indexed slots of the receiver from the start of the collection to strong::end::.
196 code::x.copyFromStart(a):: can also be written as code::x[..a]::
199 Remove strong::item:: from collection.
202 Remove and return strong::item:: from collection. The last item in the collection will move to occupy the vacated slot (and the collection size decreases by one). See also takeAt, defined for link::Classes/ArrayedCollection#-takeAt::.
204 a = [11, 12, 13, 14, 15];
210 Keep the first strong::n:: items of the array. If strong::n:: is negative, keep the last -strong::n:: items.
218 Drop the first strong::n:: items of the array. If strong::n:: is negative, drop the last -strong::n:: items.
226 Returns a link::Classes/String:: formed by connecting all the elements of the receiver, with strong::joiner:: inbetween. See also link::Classes/String#-split:: as the complementary operation.
228 ["m", "ss", "ss", "pp", ""].join("i").postcs;
229 "mississippi".split("i").postcs;
233 Returns a collection from which all nesting has been flattened.
235 [[1, 2, 3], [[4, 5], [[6]]]].flat;
239 Returns a collection from which strong::numLevels:: of nesting has been flattened.
241 [[1, 2, 3], [[4, 5], [[6]]]].flatten(1).postcs;
242 [[1, 2, 3], [[4, 5], [[6]]]].flatten(2).postcs;
246 Invert rows and colums in a two dimensional Collection (turn inside out). See also: link::Classes/Function::.
248 [[1, 2, 3], [4, 5, 6]].flop;
249 [[1, 2, 3], [4, 5, 6], [7, 8]].flop; // shorter array wraps
250 [].flop; // result is always 2-d.
252 Note that the innermost arrays are not copied:
255 x = [[[a, 5], [a, 10]], [[a, 50, 60]]].flop;
257 x // pi is everywhere
262 Flop with a user defined function. Can be used to collect over several collections in parallel.
264 [[1, 2, 3], [4, 5, 6]].flopWith(_+_);
265 [[1, 2, 3], 1, [7, 8]].flopWith{ |a,b,c| a+b+c }; // shorter array wraps
267 // typical use case (pseudocode)
268 [synths, buffers].flopWith{ |a,b| a.set(\buf, b) }
271 A function taking as many arguments as elements in the array.
274 Invert rows and colums in a an array of dimensional Collections (turn inside out), so that they all match up in size, but remain separated.
278 [[1, 2, 3], [4, 5, 6, 7, 8]] * 100,
279 [[1, 2, 3], [4, 5, 6], [7, 8]],
284 a.collect(_.size); // sizes are the same
285 a.collect(_.shape) // shapes can be different
290 Fold dimensions in a multi-dimensional Collection (turn inside out).
293 The depth (dimension) from which the array is inverted inside-out.
296 [[1, 2, 3], [[41, 52], 5, 6]].flopDeep(2);
297 [[1, 2, 3], [[41, 52], 5, 6]].flopDeep(1);
298 [[1, 2, 3], [[41, 52], 5, 6]].flopDeep(0);
299 [[1, 2, 3], [[41, 52], 5, 6]].flopDeep; // without argument, flop from the deepest level
301 [[[10, 100, 1000], 2, 3], [[41, 52], 5, 6]].flopDeep(2); // shorter array wraps
302 [].flopDeep(1); // result is always one dimension higher.
306 note::Note that, just like in flop, the innermost arrays (deeper than rank) are not copied.::
310 x = [[[a, 5], [a, 10]], [[a, 50, 60]]].flopDeep(1);
312 x // pi is everywhere
315 method::maxSizeAtDepth
316 Returns the maximum size of all subarrays at a certain depth (dimension)
319 The depth at which the size of the arrays is measured
322 [[1, 2, 3], [[41, 52], 5, 6], 1, 2, 3].maxSizeAtDepth(2);
323 [[1, 2, 3], [[41, 52], 5, 6], 1, 2, 3].maxSizeAtDepth(1);
324 [[1, 2, 3], [[41, 52], 5, 6], 1, 2, 3].maxSizeAtDepth(0);
325 [].maxSizeAtDepth(0);
326 [[]].maxSizeAtDepth(0);
327 [[]].maxSizeAtDepth(1);
331 Returns the maximum depth of all subarrays.
334 Internally used only.
337 [[1, 2, 3], [[41, 52], 5, 6], 1, 2, 3].maxDepth
341 Returns a new Collection of the desired length, with values resampled evenly-spaced from the receiver without interpolation.
343 [1, 2, 3, 4].resamp0(12);
344 [1, 2, 3, 4].resamp0(2);
348 Returns a new Collection of the desired length, with values resampled evenly-spaced from the receiver with linear interpolation.
350 [1, 2, 3, 4].resamp1(12);
351 [1, 2, 3, 4].resamp1(3);
355 Choose an element from the collection at random.
361 Choose an element from the collection at random using a list of probabilities or weights. The weights must sum to 1.0.
363 [1, 2, 3, 4].wchoose([0.1, 0.2, 0.3, 0.4]);
367 Sort the contents of the collection using the comparison function argument. The function should take two elements as arguments and return true if the first argument should be sorted before the second argument. If the function is nil, the following default function is used. { arg a, b; a < b }
369 [6, 2, 1, 7, 5].sort;
370 [6, 2, 1, 7, 5].sort({ arg a, b; a > b }); // reverse sort
374 Sort the contents of the collection using the key strong::key::, which is assumed to be found inside each element of the receiver.
378 Dictionary[\a->5, \b->1, \c->62],
379 Dictionary[\a->2, \b->9, \c->65],
380 Dictionary[\a->8, \b->5, \c->68],
381 Dictionary[\a->1, \b->3, \c->61],
382 Dictionary[\a->6, \b->7, \c->63]
390 Return an array of indices that would sort the collection into order. strong::function:: is treated the same way as for the link::#-sort:: method.
392 [6, 2, 1, 7, 5].order;
396 Swap two elements in the collection at indices strong::i:: and strong::j::.
399 Calls function for each subsequent pair of elements in the SequentialCollection. The function is passed the two elements and an index.
401 [1, 2, 3, 4, 5].pairsDo({ arg a, b; [a, b].postln; });
404 method::doAdjacentPairs
405 Calls function for every adjacent pair of elements in the SequentialCollection. The function is passed the two adjacent elements and an index.
407 [1, 2, 3, 4, 5].doAdjacentPairs({ arg a, b; [a, b].postln; });
411 Separates the collection into sub-collections by calling the function for each adjacent pair of elements. If the function returns true, then a separation is made between the elements.
413 [1, 2, 3, 5, 6, 8, 10].separate({ arg a, b; (b - a) > 1 }).postcs;
417 Separates the collection into sub-collections at the separator element or subarray. The separator is a link::Classes/Collection::, or anything that can be converted into the class this method is called on. It is strong::not:: included in the output array. The default separator is $/, for the common use in link::Classes/String::.
419 [1, 2, 1, 2, 3, 1, 2, 1, 3].split([2, 1])
423 Separates the collection into sub-collections by separating every groupSize elements.
425 [1, 2, 3, 4, 5, 6, 7, 8].clump(3).postcs;
429 Separates the collection into sub-collections by separating elements into groupings whose size is given by integers in the groupSizeList.
431 [1, 2, 3, 4, 5, 6, 7, 8].clumps([1, 2]).postcs;
435 Separates the collection into sub-collections by randomly separating elements according to the given probability.
437 [1, 2, 3, 4, 5, 6, 7, 8].curdle(0.3).postcs;
441 Returns a collection with the incremental sums of all elements.
443 [3, 4, 1, 1].integrate;
446 method::differentiate
447 Returns a collection with the pairwise difference between all elements.
449 [3, 4, 1, 1].differentiate;
453 Applies the method named by operator to the first and second elements of the collection - then applies the method to the result and to the third element of the collection - then applies the method to the result and to the fourth element of the collection - and so on, until the end of the array.
455 [3, 4, 5, 6].reduce('*'); // this is the same as [3, 4, 5, 6].product
456 [3, 4, 5, 6].reduce(\lcm); // Lowest common multiple of the whole set of numbers
457 ["d", "e", (0..9), "h"].reduce('++'); // concatenation
458 [3, 4, 5, 6].reduce({ |a, b| sin(a) * sin(b) }); // product of sines
461 may be a link::Classes/Function:: or a link::Classes/Symbol::.
463 method::convertDigits
464 Returns an integer resulting from interpreting the elements as digits to a given base (default 10). See also asDigits in link::Classes/Integer#asDigits:: for the complementary method.
466 [1, 0, 0, 0].convertDigits;
467 [1, 0, 0, 0].convertDigits(2);
468 [1, 0, 0, 0].convertDigits(3);
471 method::hammingDistance
472 Returns the count of array elements that are not equal in identical positions. http://en.wikipedia.org/wiki/Hamming_distance
474 The collections are not wrapped - if one array is shorter than the other, the difference in size should be included in the count.
476 [0, 0, 0, 1, 1, 1, 0, 1, 0, 0].hammingDistance([0, 0, 1, 1, 0, 0, 0, 0, 1, 1]);
477 "SuperMan".hammingDistance("SuperCollider");
480 subsection::Math Support - Unary Messages
482 All of the following messages send the message link::#-performUnaryOp:: to the receiver with the unary message selector as an argument.
484 method::neg, reciprocal, bitNot, abs, asFloat, asInt, ceil, floor, frac, sign, squared, cubed, sqrt, exp, midicps, cpsmidi, midiratio, ratiomidi, ampdb, dbamp, octcps, cpsoct, log, log2, log10, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, rand, rand2, linrand, bilinrand, sum3rand, distort, softclip, coin, even, odd, isPositive, isNegative, isStrictlyPositive, real, imag, magnitude, magnitudeApx, phase, angle, rho, theta, asFloat, asInteger
486 method::performUnaryOp
487 Creates a new collection of the results of applying the selector to all elements in the receiver.
490 [1, 2, 3, 4].reciprocal;
493 subsection::Math Support - Binary Messages
495 All of the following messages send the message link::#-performBinaryOp:: to the receiver with the binary message selector and the second operand as arguments.
497 method::+, -, *, /, div, %, **, min, max, <, <=, >, >=, &, |, bitXor, lcm, gcd, round, trunc, atan2, hypot, >>, +>>, ring1, ring2, ring3, ring4, difsqr, sumsqr, sqrdif, absdif, amclip, scaleneg, clip2, excess, <!, rrand, exprand
499 method::performBinaryOp
500 Creates a new collection of the results of applying the selector with the operand to all elements in the receiver. If the operand is a collection then elements of that collection are paired with elements of the receiver.
503 ([1, 2, 3, 4] * [4, 5, 6, 7]);
506 subsection::Multichannel wrappers
507 All of the following messages are performed on the elements of this collection, using link::Classes/Object#-multiChannelPerform::.
509 The result depends on the objects in the collection, but the main use case is for link::Classes/UGen::s.
511 See also link::Guides/Multichannel-Expansion::
513 method::clip, wrap, fold, prune, linlin, linexp, explin, expexp, lincurve, curvelin, range, exprange, unipolar, bipolar, lag, lag2, lag3, lagud, lag2ud, lag3ud, varlag, slew, blend, checkBadValues
514 Calls code:: this.multiChannelPerform(selector, *args) :: where selector is the name of the message.
516 method::multichannelExpandRef
517 This method is called internally on inputs to UGens that take multidimensional arrays, like link::Classes/Klank:: and it allows proper multichannel expansion even in those cases. For SequenceableCollection, this returns the collection itself, assuming that it contains already a number of Refs. See link::Classes/Ref:: for the corresponding method implementation.
519 The depth at which the list is expanded. For instance the Klank spec has a rank of 2. For more examples, see link::Classes/SequenceableCollection#-flopDeep::
521 `([[[100, 200], 500], nil, [[[0.01, 0.3], 0.8]]]).multichannelExpandRef(2);
522 [`[[100, 200], nil, [0.2, 0.8]], `[[130, 202], nil, [0.2, 0.5]]].multichannelExpandRef(2);
525 subsection:: Rhythm-lists
526 method:: convertRhythm
527 Convert a rhythm-list to durations.
529 supports a variation of Mikael Laurson's rhythm list RTM-notation. footnote::
530 see Laurson and Kuuskankare's 2003, "From RTM-notation to ENP-score-notation"
531 http://jim2003.agglo-montbeliard.fr/articles/laurson.pdf
534 The method converts a collection of the form code:: [beat-count, [rtm-list], repeats] :: to a link::Classes/List:: of link::Classes/Float::s. A negative integer within the rtm-list equates to a value tied over to the duration following. The method is recursive in that any subdivision within the rtm-list can itself be a nested convertRhythm collection (see example below). The repeats integer has a default value of 1.
536 If the divisions in the rtm-list are events, the event durations are interpreted as relative durations, and a list of events is returned.
538 // using numbers as score
539 [3, [1, 2, 1], 1].convertRhythm; // List[ 0.75, 1.5, 0.75 ]
540 [2, [1, 3, [1, [2, 1, 1, 1]], 1, 3], 1].convertRhythm;
541 [2, [1, [1, [2, 1, 1, 1]]], 1].convertRhythm;
542 [2, [1, [1, [2, 1, 1, 1]]], 2].convertRhythm; // repeat
543 [2, [1, [1, [2, 1, 1, -1]]], 2].convertRhythm; // negative value is tied over.
546 Pbind(\degree, Pseries(0, 1, inf), \dur, Pseq([2, [1, [1, [2, 1, 1, -1]]], 2].convertRhythm)).play;