Array:
Filter:
Classes | Collections > Ordered

Array : ArrayedCollection : SequenceableCollection : Collection : Object

fixed size collection
Source: Array.sc

Description

Arrays are ArrayedCollections whose slots may contain any object. Arrays have a fixed maximum size beyond which they cannot grow. For expandable arrays, use the List class.

Literal Arrays can be created at compile time, and are very efficient. See Literals for information.

For handling multidimensional arrays, there are specific methods which are covered in the helpfile J concepts in SC.

NOTE: For Arrays, the add method may or may not return the same Array object. It will add the argument to the receiver if there is space, otherwise it returns a new Array object with the argument added. Thus the proper usage of add with an Array is to always assign the result as follows:

This allows an efficient use of resources, only growing the array when it needs to. The List class manages the Array internally, and in many cases is more suitable.

Items can be put into an existing slot with a.put(2, obj) and accessed with a.at(2) or a[2].

NOTE: Arrays use 0-based indexing, meaning the first item is accessed with index 0. Therefore, the index 2 in a.put(2, obj), a.at(2), and a[2] refers to the third item.

See ArrayedCollection for the principal methods: at, put, clipAt, wrapAt, etc.

Class Methods

Array.new(maxSize: 0)

From superclass: Object

Create a new array with size 0 that can grow up to the fixed size.

Arguments:

maxSize

The maximum size of the array.

Array.newClear(indexedSize: 0)

From superclass: ArrayedCollection

Create a new array with all slots filled with nils.

Arguments:

indexedSize

The size of the array.

Array.with( ... args)

Create a new Array whose slots are filled with the given arguments. This is the same as the method in ArrayedCollection, but is reimplemented here to be more efficient.

Array.fill(size, function)

From superclass: Collection

Creates a Collection of the given size, the elements of which are determined by evaluation the given function. The function is passed the index as an argument.

Arguments:

size

The size of the collection which is returned. If nil, it returns an empty collection. If an array of sizes is given, the resulting collection has the appropriate dimensions (see: *fillND).

function

The function which is called for each new element - the index is passed in as a first argument. The function be anything that responds to the message "value".

Array.fill2D(rows, cols, function)

From superclass: Collection

Creates a 2 dimensional Collection of the given sizes. The items are determined by evaluation of the supplied function. The function is passed row and column indexes as arguments. See J concepts in SC

Array.fillND(dimensions, function, args: [])

From superclass: Collection

Creates a N dimensional Collection where N is the size of the array dimensions. The items are determined by evaluation of the supplied function. The function is passed N number of indexes as arguments. See J concepts in SC

Array.newFrom(aCollection)

From superclass: Collection

Creates a new Collection from another collection. This supports the interface for the method "as".

Array.geom(size, start, grow)

From superclass: SequenceableCollection

Fill an ArrayedCollection with a geometric series.

Array.series(size, start: 0, step: 1)

From superclass: SequenceableCollection

Fill an ArrayedCollection with an arithmetic series.

Array.iota( ... sizes)

From superclass: ArrayedCollection

Fills an ArrayedCollection with a counter. See J concepts in SC for more examples.

Array.interpolation(size, start: 0.0, end: 1.0)

From superclass: SequenceableCollection

Fill a SequenceableCollection with the interpolated values between the start and end values.

Array.rand(size, minVal, maxVal)

From superclass: SequenceableCollection

Fill a SequenceableCollection with random values in the range minVal to maxVal.

Array.rand2(size, val)

From superclass: SequenceableCollection

Fill a SequenceableCollection with random values in the range -val to +val.

Array.linrand(size, minVal, maxVal)

From superclass: SequenceableCollection

Fill a SequenceableCollection with random values in the range minVal to maxVal with a linear distribution.

Array.exprand(size, minVal, maxVal)

From superclass: SequenceableCollection

Fill a SequenceableCollection with random values in the range minVal to maxVal with exponential distribution.

Array.fib(size, a: 0.0, b: 1.0)

From superclass: SequenceableCollection

Fill a SequenceableCollection with a fibonacci series.

Arguments:

size

the number of values in the collection

a

the starting step value

b

the starting value

Array.regularPolygon: METHOD NOT FOUND!

Fill an array with radian values representing the vertices of a regular convex polygon.

Arguments:

size

The number of vertices.

orientation

A value in radians specifying the first vertex. Or, by keyword:

\vertex0.0
\sidepi / size
\pointSynonym for \vertex
\flatSynonym for \side
wrap

Angle wrap, in radians.

Array.zeroFill: METHOD NOT FOUND!

Create a new array with all slots filled with 0.0.

Inherited class methods

Instance Methods

.at(index)

From superclass: ArrayedCollection

Returns the item at index, specified as an integer (or float) starting from 0.

The index can also be an Array of indices to extract specified elements:

Float indices are also supported with the following behavior:

A sound example:

.put(index, item)

From superclass: ArrayedCollection

Put item at index starting from 0, replacing what is there. index can be an array of indices. If a float is used as index, it will be truncated.

Example:

.insert(index, item)

From superclass: ArrayedCollection

Inserts the item into the contents of the receiver at the specified index, which is an integer starting from 0. This method may return a new ArrayedCollection. For this reason, you should always assign the result of insert to a variable - never depend on add changing the receiver.

.boundedInsert(index, item)

From superclass: ArrayedCollection

Changes the receiver but maintains its size, therefore unlike .insert it is not necessary to reassign the result of .boundedInsert.

.clipAt(index)

From superclass: ArrayedCollection

Similar to -at, but guarantees that any value for index is valid by clipping values outside the collection's bounds. Values greater than size - 1 are clipped to that last index, and values below 0 (negative) are clipped to 0. The index can also be an array of indices to extract the specified elements. SequenceableCollection: -|@| is its syntactic shortcut.

.wrapAt(index)

From superclass: ArrayedCollection

Similar to -at, but guarantees that any value for index is valid by wrapping values outside the collection's bounds. If the index exceeds size - 1, it wraps back around to 0. Similarly, if the index is below 0 (negative), it wraps to access elements from the end of the collection. this.wrapAt(index) is equivalent to this.at(index mod: size), ensuring the index is always within the valid range of the collection. The index can also be an array of indices to extract the specified elements. SequenceableCollection: -@@ is its syntactic shortcut.

.foldAt(index)

From superclass: ArrayedCollection

Similar to -at, but guarantees that any value for index is valid by reflecting values outside the collection's bounds. Values greater than size - 1 are reflected back toward lower indices. Similarly, if the index is below 0 (negative), it folds in the opposite direction. This creates a symmetrical mapping of any index within the collection's boundaries. The index can also be an array of indices to extract the specified elements. SequenceableCollection: -@|@ is its syntactic shortcut.

.clipPut(index, item)

From superclass: ArrayedCollection

Same as -put, but values for index greater than the ArrayedCollection instance size minus one will be clipped to size - 1, which is the last index.

.wrapPut(index, item)

From superclass: ArrayedCollection

Same as -put, but values for index greater than the ArrayedCollection instance size minus one will be wrapped around to 0.

.foldPut(index, item)

From superclass: ArrayedCollection

Same as -put, but values for index greater than the ArrayedCollection instance size minus one will be folded back.

.swap(i, j)

From superclass: ArrayedCollection

Swap the values at indices i and j, both specified as integers starting from 0.

.replace(find, replace)

From superclass: ArrayedCollection

Return a new array in which a number of elements have been replaced by another. Elements are checked for equality (not for identity).

this method is inherited by String :

++(anArray)

From superclass: ArrayedCollection

Concatenate the contents of the two collections into a new ArrayedCollection.

.add(item)

From superclass: ArrayedCollection

Adds an item to an ArrayedCollection if there is space. This method may return a new ArrayedCollection. For this reason, you should always assign the result of add to a variable - never depend on add changing the receiver.

.addAll(aCollection)

From superclass: ArrayedCollection

Adds all the elements of aCollection to the contents of the receiver. This method may return a new ArrayedCollection. For this reason, you should always assign the result of addAll to a variable - never depend on add changing the receiver.

.addFirst(item)

From superclass: ArrayedCollection

Inserts the item before the contents of the receiver, possibly returning a new collection.

.removeAt(index)

From superclass: ArrayedCollection

Remove and return the item at index, specified as an integer or a float starting from 0, shrinking the size of the ArrayedCollection.

.collect(function)

From superclass: Collection

Answer a new collection which consists of the results of function evaluated for each item in the collection. The function is passed two arguments, the item and an integer index. See Collection helpfile for examples.

.do(function)

From superclass: ArrayedCollection

Iterate over the elements in order, calling the function for each element. The function is passed two arguments, the element and an index.

.reverseDo(function)

From superclass: ArrayedCollection

Iterate over the elements in reverse order, calling the function for each element. The function is passed two arguments, the element and an index.

.deepCollect(depth: 1, function, index: 0, rank: 0)

From superclass: ArrayedCollection

The same as -collect, but can look inside sub-arrays up to the specified depth.

.reshape( ... shape)

From superclass: ArrayedCollection

For a multidimensional array, rearranges the data using the desired number of elements along each dimension. The data may be extended using Array: -wrapExtend if needed. This will always return a rectangular array, see -isRectangular.

.windex

From superclass: ArrayedCollection

Interprets the array as a list of probabilities which should sum to 1.0 and returns a random index value based on those probabilities. The random index is taken from the receiver's index, starting from 0.

.size

From superclass: ArrayedCollection

Return the number of elements the ArrayedCollection.

.normalize(min: 0.0, max: 1.0)

From superclass: ArrayedCollection

Returns a new Array with the receiver items normalized between min and max.

.normalizeSum

From superclass: ArrayedCollection

Returns the Array resulting from :

so that the array will sum to 1.0.

This is useful for using with windex or wchoose.

.plot(name, bounds, discrete: false, numChannels, minval, maxval, separately: true, parent)

From superclass: ArrayedCollection

Plot values in a GUI window. See plot for more details. When the receiver contains nil items, the plot fails with an error.

.reverse

Returns a new Array whose elements are reversed. The receiver is unchanged.

.scramble

Returns a new Array whose elements have been scrambled. The receiver is unchanged.

.mirror

Return a new Array which is the receiver made into a palindrome. The receiver is unchanged.

.mirror1

Return a new Array which is the receiver made into a palindrome with the last element removed. This is useful if the list will be repeated cyclically, the first element will not get played twice. The receiver is unchanged. If the receiver is a single-element array, a copy is returned.

.mirror2

Return a new Array which is the receiver concatenated with a reversal of itself. The center element is duplicated. The receiver is unchanged.

.stutter(n: 2)

NOTE: It is recommended to use dupEach instead. This method is retained for backwards compatibility.

Return a new Array whose elements are repeated n times. The receiver is unchanged.

Arguments:

n

Number of repeats.

.dupEach(n: 2)

Return a new Array whose elements are repeated n times. The receiver is unchanged.

Arguments:

n

Number of repeats.

.rotate(n: 1)

Return a new Array whose elements are in rotated order. The receiver is unchanged.

Arguments:

n

Number of elements to rotate. Negative n values rotate left, positive n values rotate right.

.pyramid(patternType: 1)

Return a new Array whose elements have been reordered via one of 10 "counting" algorithms. Run the examples to see the algorithms.

Arguments:

patternType

Choose counting algorithm. The algorithms are numbered 1 through 10.

.pyramidg(patternType: 1)

Like pyramid, but keep the resulting values grouped in subarrays.

.sputter(probability: 0.25, maxlen: 100)

Return a new Array of length maxlen with the items partly repeated (random choice of given probability).

Arguments:

probability

Probability of repeat.

maxlen

The length of the new Array.

.lace(length)

Returns a new Array whose elements are interlaced sequences of the elements of the receiver's subcollections, up to size length. The receiver is unchanged.

.permute(nthPermutation)

Returns a new Array whose elements are the nthPermutation of the elements of the receiver. The receiver is unchanged.

.allTuples(maxTuples: 16384)

Returns a new Array whose elements contain all possible combinations of the receiver's subcollections.

.wrapExtend(length)

Returns a new Array whose elements are repeated sequences of the receiver, up to size length. The receiver is unchanged.

.foldExtend(length)

Same as wrapExtend but the sequences fold back on the list elements.

.clipExtend(length)

Same as wrapExtend but the sequences "clip" (return their last element) rather than wrapping.

.slide(windowLength: 3, stepSize: 1)

Return a new Array whose elements are repeated subsequences from the receiver. Easier to demonstrate than explain.

.shift(n, filler: 0.0)

Shift the values of the array n steps to the right (n positive) or to the left(n negative), dropping the excess and filling empty space with zero.

.containsSeqColl

Returns true if the receiver Array contains any instance of SequenceableCollection

.powerset

Returns all possible combinations of the array's elements.

powerset is also supported in Collection:

.envirPairs

Given an array of symbols, this returns an array of pairs of (symbol, value) from the current environment. This can then be used as arguments for a Synth, or in an OSC message.

.flop

Invert rows and columns in a two dimensional Array (turn inside out). See also: Function, SequenceableCollection.

.multiChannelExpand

Used by UGens to perform multi channel expansion. Same as flop.

.source

Some UGens return Arrays of OutputProxy when instantiated. This method allows you to get at the source UGen.

.fork(join, clock, quant: 0.0, stackSize: 64)

Used within Routines and assumes an array of functions, from which subroutines are created. The subroutines are played while the outer Routine carries on. The join parameter expresses after how many subroutines complete the outer Routine is allowed to go on. By default this happens after all subroutines have completed.

.poll(trig: 10, label, trigid: -1)

apply an array of Poll units to an array of UGens (see those helpfiles for more details).

.dpoll(label, run: 1, trigid: -1)

apply an array of Dpoll units to an array of UGens (see those helpfiles for more details).

.atIdentityHash(argKey)

This method is used by IdentitySet to search for a key among its members.

.atIdentityHashInPairs(argKey)

This method is used by IdentityDictionary to search for a key among its members.

.asString(limit: 512)

From superclass: Object

Returns a string representing the Array. May not be compilable due to elision (...) of excessive arguments.

.asCompileString

From superclass: Object

Returns a string that will compile to return an Array equal to the receiver.

.isValidUGenInput

Returns true. Arrays are valid UGen inputs.

.asRawOSC

Returns the OSC message as an Int8Array. Receiver can be a message or a bundle. See also Int8Array: -parseOSC.

Bela

.belaScope(scopeChannel, server)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Audio/Bela/BelaScope.sc

Send this Array's content to Bela's Oscilloscope (see BelaScope for required setup)

Arguments:

scopeChannel

Bela's oscilloscope channel to start scoping on. This has to be a non-negative number, and can't be changed after scoping starts.

server

The server on which BelaScope is running. If not specified, it looks for the first server for which BelaScope was already initialized. If none is found, it attempts to initialize a BelaScope instance on Server: *default.

Returns:

This Array.

Cycle

Browse Math/Cycle

Cycle includes the methods Array: -campanology, Array: -circPerm, Array: -interlace, Array: -kaprekar, Array: -kreuzspiel, Array: -pea, Array: -sieve, Array: -symGroup, Array: -symPerm, Integer: -campanology,Integer: -circPerm, Integer: -collatz, Integer: -discreteLog, Integer: -euclidean, Integer: -kaprekar, Integer: -pea, Number: -lorenz, Env: *collatz.

.campanology: METHOD NOT FOUND!

As a musical study of bells, campanology focuses on the ringing methods according to the two following rules:

  1. Each bell sounds exactly once in each row.
  2. In any change, each bell can move at most one position.

The algorithm provides a trivial solution – called the 'hunting group' – by permuting consecutive pairs and alternating the starting position between the first and the second position.

Reference: White, A., & Wilson, R. (1995). The Hunting Group. The Mathematical Gazette, 79(484), 5–16. https://doi.org/10.2307/3619985

Arguments:

mode

assigns the first switched couple as indices either 0 or 1.

rev

Boolean, stops the algorithm when its input is reversed.

sym

Boolean, 'escape from hunt' as a palindromic process for odd number of bells.

Returns:

the cycle itself.

Discussion:

.circPerm: METHOD NOT FOUND!

This algorithm consists of moving the first element of a list to the tail of this list. This is done n times with n equal to the length of the list according to a circular permutation cycle from a given radix to another.

Arguments:

iBase

initial base

cBase

circular base

Returns:

the cycle as a circular permutation according to the radix as arguments.

Discussion:

.interlace(clumpSize: 1)

Based on the principle of ornamental interlace, each array as a 'pattern' is repeated some times according to the least common multiple to generate a complete cycle.

Returns:

an array where each element groups the circular permutations of each array as a 'pattern' such as the number of voices equal to the number of arrays.

Discussion:

.kaprekar: METHOD NOT FOUND!

Apply the method Integer: -kaprekar to an array according to a given radix (10 by default).

Arguments:

base

Returns:

an array with the cycle itself prepended by its 'path' if it exists.

Discussion:

.kreuzspiel: METHOD NOT FOUND!

In 1951, Karlheinz Stockhausen wrotes Kreuzspiel (« Jeux croisés ») which uses the crossing technique inspired by Olivier Messiaen called « des extrêmes au centre » as a kind of retrogradation « en éventail ». This consists to take the first and the last values of a sequence and places them in the middle (or optionally at a given indexed place) by opposite crossing.

Reference at http://hdl.handle.net/1773/23571

Arguments:

ind

as indice, (this.size/2).floor by default.

Returns:

The cycle itself.

Discussion:

.pea: METHOD NOT FOUND!

Primarily developed by John Conway, the pea pattern is a variation of a 'look-and-say' sequence by counting the elements of a seed from the lowest number to the highest iteratively until the effectiveness of a cycle.

Returns:

The cycle itself prepended by its 'path' if it exists.

Discussion:

.sieve: METHOD NOT FOUND!

Kind of Metabole according to Iannis Xenakis, rhythmic sieves rely on the construction of a matrix to generate two cycles: one by horizontal shift and one by vertical shift.

For instance, with i = 4 and j = 5, the shifting cycle is done according to the following matrix:

0123
0051015
1161611
2121727
3813183
4491419
NOTE: by convention, i should be strictly inferior to j. Also, this kind of matrix requires i.gcd(j) == 1.

Arguments:

field

set the maximum value of the matrix, this.maxItem by default.

i

as the x-axis of the matrix.

j

as the y-axis of the matrix.

optimize

requires one of the following symbols:

\no\nnearest solution of this.maxItem or field if set
\yes\ylook for the next solution in order to minimize (i-j).abs
\field\flook for the minimal (i-j).abs between this.maxItem and field

Returns:

an array of two cycles.

Discussion:

.symGroup: METHOD NOT FOUND!

The symmetric group allows to enumerate all cycles from a list of n elements according to their respective position of the same ordered list (i.e. { 1, 2, ..., n }) such as each set is a group of permutations as a bijective maps.

Returns:

a list of cycles.

Discussion:

.symPerm: METHOD NOT FOUND!

Highlighted by Olivier Messiaen, symmetric permutations constitute a system of numbered durations that consists in changing the order of its durations in order to obtain a limited number of rhythmic cells.

Arguments:

arrayCode

allows to re-order durations

Returns:

the cycle as a symmetric permutation according to an re-ordered array as arguments.

Discussion:

Extensions by DissonanceLib

.maxima: METHOD NOT FOUND!

Obtains all the relative maxima in an array of [freqs, mags] pairs such as that returned from FFT data. It operates on the magnitudes finding all the inflection points.

Returns:

[[freqs],[mags]]

.findNlargest: METHOD NOT FOUND!

Returns the n highest partials of a [freqs, mags] array such as returned from the maxima method. See Live Dissonance.

Extensions from FP Lib

.collectAccum: METHOD NOT FOUND!

The collectAccum function behaves like a combination of collect and inject; it applies a function to each element of an array, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new array.

Arguments:

init

Initial state

s

f

A function with first argument the previous value of the state, second argument the value from the array. It should return a Tuple2 with the new value of the state and a new value for the final array.

s -> b -> (s, c)

Returns:

T( s, [ c ] )

Discussion:

.scan: METHOD NOT FOUND!

scanl is similar to inject, but returns a list of successive reduced values.

Arguments:

init

initial value

s

f

function to combine the current state with the element of the array s -> a -> s

Returns:

[s]

Discussion:

.mreduce: METHOD NOT FOUND!

Fold a list using the monoidal zero and the monoidal binary operation

Discussion:

.asLazy: METHOD NOT FOUND!

convert to LazyList

.atOption: METHOD NOT FOUND!

if the index is valid return Some(element) if not return None()

Arguments:

i

index

.catOptions: METHOD NOT FOUND!

Transform an array of options into an array of values by dropping the None() values.

Discussion:

.catOptions2: METHOD NOT FOUND!

Transform an array of options into an array of values by dropping the None() values. If the array is empty returns None() otherwise returns Some( xs ) .

Discussion:

.traverse: METHOD NOT FOUND!

traverse an array with effects using applicative functors. see the haskell documentation

Inherited instance methods

Undocumented instance methods

.asAudioRateInput(for)

.asControlInput

.asSpec

.asUGenInput(for)

.buildForProxy(proxy, channelOffset: 0)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.deinterlace(clumpSize: 2, numChan: 1)

.envAt(time)

.madd(mul: 1.0, add: 0.0)

.numChannels

.prUnarchive(slotArray)

.prUnlace(clumpSize: 2, numChan: 1)

.proxyControlClass

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.scope(name: "UGen Scope", bufsize: 4096, zoom: 1.0)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Control/UGen-scope.sc

.unlace(clumpSize: 2, numChan: 1, clip: false)