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.

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

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

Inherited class methods

Instance Methods

.at(index)

From superclass: ArrayedCollection

Return the item at index.

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

.put(index, item)

From superclass: ArrayedCollection

Put item at index, replacing what is there.

.insert(index, item)

From superclass: ArrayedCollection

Inserts the item into the contents of the receiver. 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.

.clipAt(index)

From superclass: ArrayedCollection

Same as -at, but values for index greater than the size of the ArrayedCollection will be clipped to the last index.

.wrapAt(index)

From superclass: ArrayedCollection

Same as -at, but values for index greater than the size of the ArrayedCollection will be wrapped around to 0.

.foldAt(index)

From superclass: ArrayedCollection

Same as -at, but values for index greater than the size of the ArrayedCollection will be folded back.

.clipPut(index, item)

From superclass: ArrayedCollection

Same as -put, but values for index greater than the size of the ArrayedCollection will be clipped to the last index.

.wrapPut(index, item)

From superclass: ArrayedCollection

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

.foldPut(index, item)

From superclass: ArrayedCollection

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

.swap(i, j)

From superclass: ArrayedCollection

Swap the values at indices i and j.

.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 element at index, 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 wrapExtend if needed.

.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.

.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)

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 must be a bundle.

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.

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)

.interlace(clumpSize: 1)

.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)