subcollider.jsv0.1.1

sc

Array

Number

Pattern

RGen

Scale

Tuning

  • Array
  • Number

abs

absolute value

Arguments:

none

Example:

 (-10).abs(); // => 10
 [ -2, -1, 0, 1, 2 ].abs(); // => [ 2, 1, 0, 1, 2 ]
  • Array
  • Number

absdif

(a - b).abs()

Arguments:

(number)

Example:

 sc.absdif(10, 15); // => 5
  • Array
  • Number

acos

Arccosine

Arguments:

none
  • Array

add

Adds an item to an Array if there is space. This method may return a new Array.

Arguments:

(item)

Example:

 [1,2,3].add(4); // => [ 1, 2, 3, 4 ]
  • Array

addAll

Adds all the elements of items to the contents of the receiver. This method may return a new Array.

Arguments:

(items)

Aliases:

concat, ++

Example:

 [1, 2, 3, 4].addAll([7, 8, 9]); // => [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
  • Array

addFirst

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

Arguments:

(item)

Example:

 [1, 2, 3, 4].addFirst(999); // [ 999, 2, 3, 4 ]
  • Array

addIfNotNil

  • Array
  • Number

amclip

0 when b <= 0, a*b when b > 0

Arguments:

(number)
  • Array
  • Number

ampdb

Convert a linear amplitude to decibels.

Arguments:

none

Example:

 [0.5, 1, 2].ampdb(); // => [ -6.0205, 0, 6.0205 ]
  • Array

any

Answer whether function answers True for any item in the receiver. The function is passed two arguments, the item and an integer index.

Arguments:

(function)

Example:

 [1, 2, 3, 4].any("even"); // => true
 [1, 2, 3, 4].any(function(x) { return x > 10; }); // => false
  • Function
  • String
  • Array
  • Boolean
  • Number

asArray

Returns a new Array base upon this

Arguments:

none

Example:

 (1).asArray(); // => [ 1 ]
 [1, 2, 3].asArray(); // => [ 1, 2, 3 ]
  • Function
  • String
  • Array
  • Boolean
  • Number

asBoolean

Returns a new Boolean based upon this

Arguments:

none

Example:

 (0).asBoolean(); // false
 (1).asBoolean(); // true
 [ ].asBoolean(); // false
 [0].asBoolean(); // true
  • String
  • Array
  • Number

asFloat

Arguments:

none

Example:

 "0.5".asFloat(); // => 0.5
 [1, 2, 3.14].asFloat(); // => [1, 2, 3.14]
  • Array

asFloat32Array

Returns a new Float32Array based upon this
  • Array

asFloat64Array

Returns a new Float64Array based upon this
  • Function
  • String
  • Array
  • Number

asFunction

Returns a new Function based upon this

Arguments:

none

Example:

 (1).asFunction()(); // => 1
  • Array

asInt16Array

Returns a new Int16Array based upon this
  • Array

asInt32Array

Returns a new Int32Array based upon this
  • Array

asInt8Array

Returns a new Int8Array based upon this
  • String
  • Array
  • Number

asInteger

Arguments:

none

Example:

 "0.5".asInteger(); // => 0
 [1, 2, 3.14].asInteger(); // => [1, 2, 3]
  • String
  • Array
  • Boolean
  • Number

asJSON

Returns new a JSON string based upon this

Arguments:

none
  • Function
  • String
  • Array
  • Boolean
  • Number

asNumber

Returns new a Number based upon this

Arguments:

none

Example:

 (true).asNumber(); // => 1
 ["a", 10, 3.14].asNumber(); => 10
  • Function
  • String
  • Array
  • Boolean
  • Number

asString

Returns a new String based upon this
  • Array

asUint16Array

Returns a new Uint16Array based upon this
  • Array

asUint32Array

Returns a new Uint32Array based upon this
  • Array

asUint8Array

Returns a new Uint8Array based upon this
  • Array
  • Number

asin

Arcsine

Arguments:

none
  • Array

at

Return the item at index.

Arguments:

(index)

Aliases:

@

Example:

 x = [10,20,30];
 y = [0,0,2,2,1];
 x.at(y); // returns [ 10, 10, 30, 30, 20 ]
  • Array

atDec

  • Array

atInc

  • Array

atModify

  • Array
  • Number

atan

Arctangent

Arguments:

none
  • Array
  • Number

atan2

Arctangent of ( this / number )

Arguments:

(number)
  • Array
  • Number

biexp

  • Array
  • Number

bilin

  • Array
  • Number

bilinrand

Bilateral linearly distributed random number from -this to +this.

Arguments:

none
  • Boolean
  • Array
  • Number

binaryValue

  • Array
  • Number

bitAnd

performs a bitwise and with aNumber

Arguments:

(number)

Aliases:

&
  • Array
  • Number

bitNot

ones complement

Arguments:

none

Aliases:

~
  • Array
  • Number

bitOr

performs a bitwise or with aNumber

Arguments:

(number)

Aliases:

|
  • Array
  • Number

bitTest

true if bit at index aNumber is set.

Arguments:

(bit)
  • Array
  • Number

bitXor

Bitwise Exclusive Or

Arguments:

(number)

Aliases:

^
  • Array

blendAt

Returns a linearly interpolated value between the two closest indices.

Arguments:

(index [, method="clipAt"])

Example:

  [2, 5, 6].blendAt(0.4); // => 3.2
  • Number
  • Array

bubble

  • Array
  • Number

ceil

next larger integer.

Arguments:

none
  • Array

choose

Choose an element from the collection at random.

Arguments:

none

Example:

 [1, 2, 3, 4].choose();
  • Array
  • Number

clip

If the receiver is less than minVal then answer minVal, else if the receiver is greater than maxVal then answer maxVal, else answer the receiver.

Arguments:

([lo=-1, hi=1])

Example:

 [ -0.6, -0.3, 0, 0.3, 0.6 ].clip(-0.5, 0.5); // => [ -0.5, -0.3, 0, 0.3, 0.5 ]
  • Array
  • Number

clip2

clips receiver to +/- aNumber

Arguments:

([number=1])

Example:

 [ -0.6, -0.3, 0, 0.3, 0.6 ].clip2(0.5); // => [ -0.5, -0.3, 0, 0.3, 0.5 ]
  • Array

clipAt

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

Arguments:

(index)

Aliases:

|@|

Example:

 [ 1, 2, 3 ].clipAt(13); // => 3
 [ 1, 2, 3 ].clipAt([ 0, 1, 2, 3 ]); // => [ 1, 2, 3, 3 ]
  • Array

clipExtend

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

Arguments:

(size)

Example:

 [ 1, 2, 3 ].clipExtend(9); // => [ 1, 2, 3, 3, 3, 3, 3, 3, 3 ]
  • Array

clipPut

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

Arguments:

(index, item)
  • Array

clipSwap

Same as swap, but values for index greater than the size of the Array will be clipped to the last index.

Arguments:

(i, j)
  • Array

clump

Separates the collection into sub-collections by separating every groupSize elements.

Arguments:

(groupSize)

Example:

  [1, 2, 3, 4, 5, 6, 7, 8].clump(3); // => [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]
  • Array

clumps

Separates the collection into sub-collections by separating elements into groupings whose size is given by integers in the groupSizeList.

Arguments:

(groupSizeList)

Example:

  [1, 2, 3, 4, 5, 6, 7, 8].clumps([1, 2]);
  // => [ [ 1 ], [ 2, 3 ], [ 4 ], [ 5, 6 ], [ 7 ], [ 8 ] ]
  • Array
  • Number

coin

Answers a Boolean which is the result of a random test whose probability of success in a range from zero to one is this.

Arguments:

none
  • Array
  • Number

collect

Answer a new array 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.

Arguments:

(function)

Example:

 [ 1, 2, 3, 4 ].collect("reciprocal"); // => [ 1, 0.5, 0.3333, 0.25 ]
 (3).collect(function(x) { return x * 100; }); // => [ 0, 100, 200 ]
  • Function
  • String
  • Array
  • Boolean
  • Number

copy

Make a copy of the receiver. (shallow copy)

Arguments:

none
  • String
  • Array

copyFromStart

Return a new Array which is a copy of the indexed slots of the receiver from the start of the collection to end.

Arguments:

(end)
  • String
  • Array

copyRange

Return a new Array which is a copy of the indexed slots of the receiver from start to end.

Arguments:

(start, end)

Example:

 [1, 2, 3, 4, 5].copyRange(1, 3); // [ 2, 3, 4 ]
  • Array

copySeries

Return a new Array consisting of the values starting at first, then every step of the distance between first and second, up until last.

Arguments:

(first, second, last)

Example:

  [1, 2, 3, 4, 5, 6].copySeries(0, 2, 5); // => [ 1, 3, 5 ]
  • String
  • Array

copyToEnd

Return a new Array which is a copy of the indexed slots of the receiver from start to the end of the collection
  • Array
  • Number

cos

Cosine

Arguments:

none
  • Array
  • Number

cosh

Hyperbolic cosine

Arguments:

none
  • Array

count

Answer the number of items for which function answers True. The function is passed two arguments, the item and an integer index.

Arguments:

(function)

Example:

  [1, 2, 3, 4].count("even"); // => 2
  [1, 2, 3, 4].count(function(x, i) { return x & i; }); // => 1
  • Array
  • Number

cpsmidi

Convert cycles per second to MIDI note.

Arguments:

none

Returns:

midi note

Example:

 (440).cpsmidi(); // => 69
 sc.Range("440, 550..880").cpsmidi(); // => [69, 72.8631, 76.0195, 78.6882, 81 ]
  • Array
  • Number

cpsoct

Convert cycles per second to decimal octaves.

Arguments:

none

Example:

  (440).cpsoct(); // => 4.75
  sc.Range("440, 550..880").cpsoct(); // => [ 4.75, 5.0719, 5.3349, 5.5573, 5.75 ]
  • Array
  • Number

cubed

the cube of the number

Arguments:

none
  • Array

curdle

Separates the array into sub-array by randomly separating elements according to the given probability.

Arguments:

([probability=0.5])
  • Array
  • Number

curvelin

map the receiver from an assumed curve-exponential input range (inMin..inMax) to a linear output range (outMin..outMax). If the input exceeds the assumed input range.

Arguments:

([inMin=0, inMax=1, outMin=0, outMax=1, curve=-4, clip="minmax"])

Example:

  [0, 2, 4, 6, 8, 10].curvelin(0, 10, -1, 1);
  // => [ -1, 0.2222, 0.2905, 0.3846, 0.5375, 1 ]
  • Array
  • Number

dbamp

Convert a decibels to a linear amplitude.

Arguments:

none

Example:

  (12).dbamp(); // => 3.981071705534973
  [-6, -3, 0, 3, 6].dbamp(); // => [ 0.5011, 0.7079, 1, 1.412, 1.9952 ]
  • Array
  • Number

degrad

converts degree to radian

Arguments:

none
  • Array
  • Number

degreeToKey

Arguments:

(scale [, stepsPerOctave=12])
  • Array

delimit

  • Array

detect

Answer the first item in the receiver for which function answers True. The function is passed two arguments, the item and an integer index.

Arguments:

(function)

Example:

 [1, 2, 3, 4].detect("even"); // => 2
 [1, 2, 3, 4].detect(function(x, i) { return x & i; }); // => 3
  • Array

detectIndex

Similar to detect but returns the index instead of the item itself.

Arguments:

(function)
  • Array

difference

Return the set of all items which are elements of this, but not of that.

Arguments:

(that)

Example:

 [1, 2, 3].difference([2, 3, 4, 5]); // => [ 1 ]
  • Array

differentiate

Returns an array with the pairwise difference between all elements.

Arguments:

none

Example:

  [3, 4, 1, 1].differentiate(); // => [ 3, 1, -3, 0 ]
  • Array
  • Number

difsqr

(a * a) - (b * b)

Arguments:

(number)
  • Array
  • Number

distort

a nonlinear distortion function.

Arguments:

none

Example:

  (1).distort(); // => 0.5
  [0, 1, 5, 10].distort(); // => [ 0, 0.5, 0.8333, 0.9090 ]
  • Array
  • Number

div

Integer Division

Arguments:

(number)

Example:

 (10).div(3);       // => 3
 [10,20,30].div(3); // => [ 3, 6, 10 ]
  • Array
  • Number

do

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

Arguments:

(function)
  • Array

doAdjacentPairs

Calls function for every adjacent pair of elements in the Array. The function is passed the two adjacent elements and an index.

Arguments:

(function)
  • Array

drop

Drop the first n items of the array. If n is negative, drop the last -n items.

Arguments:

(number)

Example:

  [1, 2, 3, 4, 5].drop( 3); // [ 4, 5 ]
  [1, 2, 3, 4, 5].drop(-3); // [ 1, 2 ]
  • Function
  • String
  • Array
  • Boolean
  • Number

dup

Duplicates the receiver n times.

Arguments:

([n=2])

Example:

  (2).dup(5); // => [ 2, 2, 2, 2, 2 ]
  [1, 2, 3].dup(3) // => [ [1, 2, 3], [1, 2, 3], [1, 2, 3] ]
  • Array
  • Number

equalWithPrecision

  • Function
  • String
  • Array
  • Boolean
  • Number

equals

  • Array
  • Number

even

true if dividable by 2 with no rest

Arguments:

none
  • Array

every

Aliases:

sc_every
  • Array
  • Number

excess

Returns the difference of the receiver and its clipped form.

Arguments:

(number)
  • Array
  • Number

exclusivelyBetween

whether the receiver is greater than minVal and less than maxVal.

Arguments:

(lo, hi)
  • Array
  • Number

exp

e to the power of the receiver.

Arguments:

none
  • Array
  • Number

expexp

map the receiver from an assumed exponential input range (inMin..inMax) to an exponential output range (outMin..outMax). If the input exceeds the assumed input range.

Arguments:

(inMin, inMax, outMin, outMax [, clip="minmax"])
  • Array
  • Number

explin

map the receiver from an assumed exponential input range (inMin..inMax) to a linear output range (outMin..outMax). If the input exceeds the assumed input range.

Arguments:

(inMin, inMax, outMin, outMax [, clip="minmax"])
  • Array

*exprand

Fill an Array with random values in the range minVal to maxVal with exponential distribution.

Arguments:

(size [, minVal=0, maxVal=1])

Example:

 Array.exprand(8, 1, 100);
  • Array
  • Number

exprand

an exponentially distributed random number in the interval ]a, b[.

Arguments:

(number)
  • Array

extend

Extends the object to match size by adding a number of items. If size is less than receiver size then truncate. This method may return a new Array.

Arguments:

(size, item)

Example:

 [1, 2, 3, 4].extend(10, 9); // => [ 1, 2, 3, 4, 9, 9, 9, 9, 9, 9 ]
  • Array
  • Number

factorial

the factorial of this.

Arguments:

none
  • Array
  • Number

factors

the prime factors as array.

Arguments:

none

Example:

 (2000).factors(); // => [ 2, 2, 2, 2, 5, 5, 5 ]
  • Number

fib

Arguments:

([a=0, b=1])

Returns:

an array with a fibonacci series of this size beginning with a and b.

Example:

 (5).fib(2, 32); // => [ 32, 34, 66, 100, 166 ]
  • Array

*fib

Fill an Array with a fibonacci series.

Arguments:

(size [, a=0, b=1])

Example:

 Array.fib(5); // => [ 1, 1, 2, 3, 5 ]
  • Array

*fill

Creates an Array of the given size, the elements of which are determined by evaluation the given function.

Arguments:

(size [, function=nil])

Example:

 Array.fill(3, 5); // => [ 5, 5, 5 ]
 Array.fill(3, function(i) { return (i * 2 + 60).midicps(); });
 // => [ 440, 493.8833, 554.3652 ]
  • Array

fill

Inserts the item into the contents of the receiver.

Arguments:

(item)

Example:

 [1, 2, 3, 4].fill(4); // [ 4, 4, 4, 4 ]
  • Array

*fill2D

Creates a 2 dimensional Array of the given sizes. The items are determined by evaluation of the supplied function. The function is passed row and column indexes as arguments.

Arguments:

(rows, cols [, function=nil])

Example:

 Array.fill2D(3, 3, 1);
 // => [ [ 1, 1, 1 ],
 //      [ 1, 1, 1 ],
 //      [ 1, 1, 1 ] ]
  • Array

*fill3D

Creates a 3 dimensional Array of the given sizes. The items are determined by evaluation of the supplied function. The function is passed plane, row and column indexes as arguments.

Arguments:

(planes, rows, cols [, function=nil])

Example:

 Array.fill3D(3, 3, 3, 1);
 // => [ [ [ 1, 1, 1 ],[ 1, 1, 1 ],[ 1, 1, 1 ] ],
 //      [ [ 1, 1, 1 ],[ 1, 1, 1 ],[ 1, 1, 1 ] ],
 //      [ [ 1, 1, 1 ],[ 1, 1, 1 ],[ 1, 1, 1 ] ] ]
  • Array

*fillND

Creates a N dimensional Array 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.

Arguments:

(dimensions [, function=nil])

Example:

  Array.fillND([1, 2, 3, 4], function(a, b, c, d) { return a+b+c+d; }); // => 4D
  • Array

find

Finds the starting index of a number of elements contained in the array.

Arguments:

(sublist [, offset=0])

Example:

  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].find([4, 5, 6]); // => 4
  • Array

findAll

Similar to find but returns an array of all the indices at which the sequence is found.

Arguments:

(sublist [, offset=0])

Example:

  [7, 8, 7, 6, 5, 6, 7, 6, 7, 8, 9].findAll([7, 6]); // => [ 2, 6 ]
  • Array

first

Return the first element of the collection.

Arguments:

none

Example:

 [3, 4, 5].first(); // => 3
  • Array

flat

Returns a collection from which all nesting has been flattened.

Arguments:

none

Example:

  [[1, 2, 3], [[4, 5], [[6]]]].flat(); // => [ 1, 2, 3, 4, 5, 6 ]
  • Array

flatIf

  • Array

flatSize

  • Array

flatten

Returns an array from which numLevels of nesting has been flattened.

Arguments:

([numLevels=1])

Example:

 [[1, 2, 3], [[4, 5], [[6]]]].flatten(1); // => [ 1, 2, 3, [ 4, 5 ], [ [ 6 ] ] ]
 [[1, 2, 3], [[4, 5], [[6]]]].flatten(2); // => [ 1, 2, 3, 4, 5, [ 6 ] ]
  • Array
  • Number

floor

next smaller integer

Arguments:

none
  • Array

flop

Invert rows and colums in a two dimensional Array (turn inside out).

Arguments:

none

Example:

 [[1, 2, 3], [4, 5, 6]].flop(); // => [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
  • Array
  • Number

fold

the folded value, a bitwise or with aNumber

Arguments:

(lo, hi)
  • Array
  • Number

fold2

the folded value, a bitwise or with aNumber

Arguments:

(number)
  • Array

foldAt

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

Arguments:

(index)

Aliases:

@|@

Example:

 [ 1, 2, 3 ].foldAt(5); // => 2
 [ 1, 2, 3 ].foldAt([ 0, 1, 2, 3 ]); // => [ 1, 2, 3, 2 ]
  • Array

foldExtend

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

Arguments:

(size)

Example:

 [ 1, 2, 3 ].foldExtend(9); // => [ 1, 2, 3, 2, 1, 2, 3, 2, 1 ]
  • Array

foldPut

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

Arguments:

(index, item)
  • Array

foldSwap

Same as swap, but the sequences fold back on the list elements.

Arguments:

(i, j)
  • Number

for

Executes function for all integers from this to endval, inclusive.

Arguments:

(endval, function)
  • Number

forBy

Executes function for all integers from this to endval, inclusive, stepping each time by stepval.

Arguments:

(endval, stepval, function)
  • Number

forSeries

Calls function for numbers from this up to endval stepping each time by a step specified by second.

Arguments:

(second, last, function)
  • Array
  • Number

frac

fractional part

Arguments:

none
  • Array
  • Number

gauss

a gaussian distributed random number.

Arguments:

(upperLimit)
  • Array
  • Number

gaussCurve

map the receiver onto a gauss function.

Arguments:

([a=1, b=0, c=1])
  • Array
  • Number

gcd

Greatest common divisor

Arguments:

(number)

Example:

 [3, 6, 9, 12, 15].gcd(100); // => [ 1, 2, 1, 4, 5 ]
  • Array

*geom

Fill an Array with a geometric series.

Arguments:

(size [, start=1, grow=2])

Example:

 Array.geom(5, 1, 3) // => [ 1, 3, 9, 27, 81 ]
  • Number

geom

Arguments:

(start, grow)

Returns:

an array with a geometric series of this size from start.

Example:

 (5).geom(1, 3) // => [ 1, 3, 9, 27, 81 ]
  • Array
  • Number

greater

greater than

Arguments:

(number)

Aliases:

>
  • Array
  • Number

greaterThan

greater or equal than

Arguments:

(number)

Aliases:

>=
  • Array
  • Number

half

  • Array
  • Number

hanWindow

a value for a hanning window function between 0 and 1.

Arguments:

none
  • Array

histo

  • Array
  • Number

hypot

Square root of the sum of the squares.

Arguments:

(number)
  • Array
  • Number

hypotApx

  • Array

includes

Return a boolean indicating whether the collection contains anything matching item.

Arguments:

(item)
  • Array

includesAll

Answer whether all items in list are contained in the receiver.

Arguments:

(list)

Example:

 [1, 2, 3, 4].includesAll([2, 4]); // => true
 [1, 2, 3, 4].includesAll([4, 5]); // => false
  • Array

includesAny

Answer whether any item in list is contained in the receiver.

Arguments:

(list)

Example:

 [1, 2, 3, 4].includesAny([4, 5]); // => true
 [1, 2, 3, 4].includesAny([5, 6]); // => false
  • Array
  • Number

inclusivelyBetween

whether the receiver is greater than or equal to minVal and less than or equal to maxVal.

Arguments:

(lo, hi)
  • Array

indexIn

Returns the closest index of the value in the array (collection must be sorted).

Arguments:

(item)

Example:

 [2, 3, 5, 6].indexIn(5.2); // => 2
  • Array

indexInBetween

Returns a linearly interpolated float index for the value (collection must be sorted). Inverse operation is blendAt.

Arguments:

(item)

Example:

 [2, 3, 5, 6].indexInBetween(5.2); // => 2.2
  • Array

indexOf

Return the index of an item in the collection, or -1 if not found.

Arguments:

(item [, offset=0])

Aliases:

sc_indexOf
  • Array

indexOfEqual

Return the index of something in the collection that equals the item, or -1 if not found.

Arguments:

(item [, offset=0])

Example:

 [[3], [4], [5]].indexOfEqual([5]); // => 2
  • Array

indexOfGreaterThan

Return the first index containing an item which is greater than item.

Arguments:

(item)

Example:

 [10, 5, 77, 55, 12, 123].indexOfGreaterThan(70); // => 2
  • Array
  • Number

indexOfPrime

the index of a prime number less than or equal to the receiver up to 65521. If the receiver is not a prime, the answer is -1.

Arguments:

none
  • Array

indicesOf

Return an array of indices of things in the collection that equal the item, or [] if not found.

Arguments:

(item [, offset=0])

Example:

 [7, 8, 7, 6, 5, 6, 7, 6, 7, 8, 9].indicesOf(7); // => [ 0, 2, 6, 8 ]
  • Array

indicesOfEqual

Same as indicesOf, but use equals method.

Arguments:

(item [, offset=0])

Example:

 [[7], [8], [5], [6], 7, 6, [7], 9].indicesOfEqual([7]); // => [ 0, 6 ]
  • Array

inject

reduce

Arguments:

(thisValue, function)

Example:

  [1, 2, 3, 4, 5].inject(0, "+"); // => 15
  • Array

injectr

reduce right

Arguments:

(thisValue, function)

Example:

  [1, 2, 3, 4, 5].injectr([], "++"); // => [ 5, 4, 3, 2, 1 ]
  • Array

insert

Inserts the item into the contents of the receiver. This method may return a new Array.

Arguments:

(index, item)

Example:

 [1, 2, 3, 4].insert(1, 999); // [ 1, 999, 3, 4 ]
  • Array

instill

  • Array

*interpolation

Fill an Array with the interpolated values between the start and end values.

Arguments:

(size [, start=0, end=1])

Example:

 Array.interpolation(5, 3.2, 20.5); // => [3.2, 7.525, 11.850, 16.175, 20.5]
  • Array

invert

  • Function
  • String
  • Array
  • Boolean
  • Number

isArray

Checks if the receiver is an array.
  • Function
  • String
  • Array
  • Boolean
  • Number

isBoolean

Checks if the receiver is a boolean value.
  • Array

isEmpty

Checks if the receiver is empty.
  • Function
  • String
  • Array
  • Boolean
  • Number

isFunction

Checks if the receiver is a function.
  • Array
  • Number

isNaN

Checks if the receiver is NaN.
  • Array
  • Number

isNegative

Checks if the receiver is < 0.
  • Function
  • String
  • Array
  • Boolean
  • Number

isNumber

Checks if the receiver is a number.
  • Array
  • Number

isPositive

Checks if the receiver is >= 0.
  • Array
  • Number

isPowerOfTwo

the whether the receiver is a power of two.
  • Array
  • Number

isPrime

whether the receiver is prime.

Arguments:

none

Example:

 (13).isPrime(); // => true
  • Array
  • Number

isStrictlyPositive

Checks if the receiver is > 0.
  • Function
  • String
  • Array
  • Boolean
  • Number

isString

Checks if the receiver is a string.
  • Array

isSubsetOf

Returns True if all elements of this are also elements of that

Arguments:

(that)

Example:

 [1, 2].isSubsetOf([ 1, 2, 3, 4]); // => true
 [1, 5].isSubsetOf([ 1, 2, 3, 4]); // => false
  • Array
  • Number

iwrap

  • Array

keep

Keep the first n items of the array. If n is negative, keep the last -n items.

Arguments:

(n)

Example:

 [1, 2, 3, 4, 5].keep( 3); // => [ 1, 2, 3 ]
 [1, 2, 3, 4, 5].keep(-3); // => [ 3, 4, 5 ]
  • Array
  • Number

keyToDegree

inverse of degreeToKey.

Arguments:

(scale [, stepsPerOctave=12])

Example:

 l = [0, 1, 5, 9, 11]; // pentatonic scale
 sc.Range("60..73").collect(function(i) { return i.keyToDegree(l); });
 // => [ 25, 26, 26.25, 26.5, 26.75, 27, 27.25, 27.5, 27.75, 28, 28.5, 29, 30, 31 ]
  • Array

lace

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.

Arguments:

(size)

Example:

 [[1, 2, 3], [0]].lace(10); // => [ 1, 0, 2, 0, 3, 0, 1, 0, 2, 0 ]
  • Array

last

Return the last element of the collection.

Arguments:

none

Example:

 [3, 4, 5].last(); // => 5
  • Array

lastForWhich

  • Array

lastIndex

  • Array

lastIndexForWhich

  • Array
  • Number

lcm

Least common multiple

Arguments:

(number)

Example:

   [3, 6, 12, 24, 48].lcm(20); // => [ 60, 60, 60, 120, 240 ]
  • Array
  • Number

lcurve

map the receiver onto an L-curve.

Arguments:

([a=1, m=0, n=1, tau=1])
  • Array
  • Number

leftShift

performs a binary left shift

Arguments:

(number)

Aliases:

<<
  • Array
  • Number

less

less than

Arguments:

(number)

Aliases:

<
  • Array
  • Number

lessThan

smaller or equal than

Arguments:

(number)

Aliases:

<=
  • Array
  • Number

lincurve

map the receiver from an assumed linear input range (inMin..inMax) to an exponential curve output range (outMin..outMax).

Arguments:

([inMin=0, inMax=1, outMin=0, outMax=1, curve=-4, clip="minmax"])
  • Array
  • Number

linexp

map the receiver from an assumed linear input range (inMin..inMax) to an exponential output range (outMin..outMax).

Arguments:

([inMin=0, inMax=1, outMin=0, outMax=1, clip="minmax"])
  • Array
  • Number

linlin

map the receiver from an assumed linear input range to a linear output range.

Arguments:

([inMin=0, inMax=1, outMin=0, outMax=1, clip="minmax"])
  • Array
  • Number

linrand

Arguments:

none

Returns:

a linearly distributed random number from zero to this.

Example:

 (10).linrand();
  • Array

*linrand

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

Arguments:

(size [, minVal=0, maxVal=1])

Example:

 Array.linrand(8, 1, 100);
  • Array
  • Number

log

Base e logarithm.

Arguments:

none
  • Array
  • Number

log10

Base 10 logarithm.

Arguments:

none
  • Array
  • Number

log2

Base 2 logarithm.

Arguments:

none
  • Array
  • Number

log2Ceil

  • Array
  • Number

madd

this * mul + add

Arguments:

(mul, add)
  • Array
  • Number

max

Maximum

Arguments:

(number)
  • Array

maxDepth

Returns the maximum depth of all subarrays.

Arguments:

none

Example:

[[1, 2, 3], [[41, 52], 5, 6], 1, 2, 3].maxDepth(); // => 3
  • Array

maxIndex

Answer the index of the maximum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index. If function is nil, then answer the maximum of all items in the receiver.

Arguments:

([func=nil])

Example:

 [3.2, 12.2, 13, 0.4].maxIndex(); // => 2
  • Array

maxSizeAtDepth

Returns the maximum size of all subarrays at a certain depth (dimension)

Arguments:

(rank)
  • Array

maxValue

Answer the maximum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index.

Arguments:

([function=nil])

Aliases:

maxItem

Example:

 [ 1, 5, 2, 4, 3 ].maxValue(); // => 5
  • Array

mean

  • Array

middle

  • Array

middleIndex

  • Array
  • Number

midicps

Convert MIDI note to cycles per second

Returns:

cycles per second

Example:

 (69).midicps(); // => 440
 sc.Range("69..81").midicps(); // => [ 440, 466.1637, ... , 830.6093, 880 ]
  • Array
  • Number

midiratio

Convert an interval in semitones to a ratio.

Arguments:

none

Returns:

a ratio

Example:

 sc.Range("0..12").midiratio(); // => [1, 1.0594, ... , 1.8877, 2]
  • Array
  • Number

min

Minumum

Arguments:

(number)
  • Array

minIndex

Answer the index of the minimum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index. If function is nil, then answer the minimum of all items in the receiver.

Arguments:

([function=nil])

Example:

 [3.2, 12.2, 13, 0.4].minIndex(); // => 3
  • Array

minValue

Answer the minimum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index.

Arguments:

([function=nil])

Aliases:

minItem

Example:

 [ -1, -5, -2, -4, -3 ].minValue("abs"); // => -1
  • Array

mirror

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

Arguments:

none

Example:

 [1, 2, 3, 4].mirror(); // => [1, 2, 3, 4, 3, 2, 1]
  • Array

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.

Arguments:

none

Example:

 [1, 2, 3, 4].mirror1(); // => [1, 2, 3, 4, 3, 2]
  • Array

mirror2

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

Arguments:

none

Example:

 [1, 2, 3, 4].mirror2(); // => [1, 2, 3, 4, 4, 3, 2, 1]
  • Array
  • Number

mod

Integer Modulo

Arguments:

(number)

Example:

 (10).mod(3); // => 1
 [10,20,30].mod(3); // => [ 1, 2, 0 ]
  • Array

mode

  • Array
  • Number

nearestInList

the value in the list closest to this

Arguments:

(list)

Example:

 l = [0, 0.5, 0.9, 1];
 sc.Range("0, 0.1..1").collect(function(i) { return i.nearestInList(l); });
 // => [ 0, 0, 0, 0.5, 0.5, 0.5, 0.5, 0.9, 0.9, 0.9, 1 ]
  • Array
  • Number

nearestInScale

the value in the collection closest to this, assuming an octave repeating table of note values.

Arguments:

(scale [, stepsPerOctave=12])

Example:

 l = [0, 1, 5, 9, 11]; // pentatonic scale
 sc.Range("60, 61..76").collect(function(i) { return i.nearestInScale(l, 12); });
 // => [ 60, 61, 61, 65, 65, 65, 65, 69, 69, 69, 71, 71, 72, 73, 73, 77, 77 ]
  • Array
  • Number

neg

negation

Arguments:

none
  • Array
  • Number

nextPowerOf

the next power of aNumber

Arguments:

(base)
  • Array
  • Number

nextPowerOfThree

the next power of three

Arguments:

none
  • Array
  • Number

nextPowerOfTwo

the number relative to this that is the next power of 2

Arguments:

none
  • Array
  • Number

nextPrime

the next prime less than or equal to the receiver up to 65521.

Arguments:

none

Example:

 (25).nextPrime(); // => 27
  • Array

normalize

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

Arguments:

([min=0, max=1])

Example:

 [1, 2, 3].normalize(-20, 10); // => [ -20, -5, 10 ]
  • Array

normalizeSum

Returns the Array resulting from this[i] / this.sum(), so that the array will sum to 1.0.

Arguments:

none

Example:

 [1, 2, 3].normalizeSum(); // => [ 0.1666, 0.3333, 0.5 ]
  • Array

notEmpty

Checks is the receiver is not empty.
  • Function
  • String
  • Array
  • Number

notEquals

  • Array
  • Number

nthPrime

the nth prime number. The receiver must be from 0 to 6541.

Arguments:

none

Example:

[0, 1, 2, 3, 4, 5].nthPrime(); // => [ 2, 3, 5, 7, 11, 13 ]
  • Array
  • Number

numBits

number of required bits

Arguments:

none
  • Array

obtain

  • Array

occurrencesOf

Answer the number of items in the receiver which are equal to anObject.

Arguments:

(item)

Example:

 [1, 2, 3, 3, 4, 3, 4, 3].occurrencesOf(3); // => 4
  • Array
  • Number

octcps

Convert decimal octaves to cycles per second.

Arguments:

none
  • Array
  • Number

odd

true if not dividable by 2 with no rest

Arguments:

none
  • Array
  • Number

opAdd

Addition

Aliases:

+

Example:

 (10).opAdd(2); // => 12
 [10,20,30].sc("+")(10); // => [ 20, 30, 40 ]
  • Array
  • Number

opDiv

Division

Aliases:

/

Example:

 (10).opDiv(2); // => 5
 [10,20,30].sc("/")(10); // => [ 1, 2, 3 ]
  • Array
  • Number

opMod

Modulo

Aliases:

%

Example:

 (10).opMod(3); // => 1
 [10,20,30].sc("%")(3); // => [ 1, 2, 0 ]
  • Array
  • Number

opMul

Multiplication

Aliases:

*

Example:

 (10).opMul(2); // => 20
 [10,20,30].sc("*")(10); // => [ 100, 200, 300 ]
  • Array
  • Number

opSub

Subtraction

Aliases:

-

Example:

 (10).opSub(2); // => 8
 [10,20,30].sc("-")(10); // => [ 0, 10, 20 ]
  • Array

pairsDo

Calls function for each subsequent pair of elements in the Array. The function is passed the two elements and an index.

Arguments:

(function)

Aliases:

keyValuesDo
  • Number

partition

randomly partition a number into parts of at least min size.

Arguments:

([parts=2, min=1])

Example:

 (75).partition(8, 3);
  • Array

performDegreeToKey

  • Array

performKeyToDegree

  • Array

performNearestInList

  • Array

performNearestInScale

  • Array

permute

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

Arguments:

(nthPermutation)
  • Array

pop

Remove and return the last element of the Array.

Arguments:

none

Example:

 [1, 2, 3].pop(); // 3
  • Function
  • String
  • Array
  • Boolean
  • Number

postln

  • Array
  • Number

pow

this to the power of aNumber

Arguments:

(number)

Aliases:

**
  • Array
  • Number

prevPrime

the next prime less than or equal to the receiver up to 65521.

Arguments:

none

Example:

 (25).prevPrime(); // => 23
  • Array
  • Number

previousPowerOf

the number relative to this that is the previous power of aNumber
  • Array

product

  • Array

put

Put item at index, replacing what is there.

Arguments:

(index, item)
  • Array

putEach

Put the values in the corresponding indices given by keys. If one of the two argument arrays is longer then it will wrap.

Arguments:

(keys, values)
  • Array

putFirst

Place item at the first index in the collection. Note that if the collection is empty (and therefore has no indexed slots) the item will not be added.

Arguments:

(item)

Example:

 [3, 4, 5].putFirst(100); // => [ 100, 4, 5 ]
 [].putFirst(100); // => []
  • Array

putLast

Place item at the last index in the collection. Note that if the collection is empty (and therefore has no indexed slots) the item will not be added.

Arguments:

(item)

Example:

 [3, 4, 5].putLast(100); // => [ 3, 4, 100 ]
 [].putLast(100); // => []
  • Array

pyramid

Return a new Array whose elements have been reordered via one of 10 "counting" algorithms.

Arguments:

(patternType)

Example:

 [1, 2, 3, 4].pyramid(0);
 // => [ 1, 1, 2, 1, 2, 3, 1, 2, 3, 4 ]
  • Array

pyramidg

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

Arguments:

(patternType)

Example:

 [1, 2, 3, 4].pyramidg(0);
 => [ [ 1 ], [ 1, 2 ], [ 1, 2, 3 ], [ 1, 2, 3, 4 ] ]
  • Array
  • Number

quantize

round the receiver to the quantum.

Arguments:

([quantum=1, tolerance=0.05, strength=1])

Example:

 sc.Range("0,0.1..1").quantize(1, 0.3, 0.5)
 // => [ 0, 0.05, 0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 0.95, 1 ]
  • Array
  • Number

raddeg

converts radian to degree

Arguments:

none
  • Array
  • Number

ramp

Map receiver onto a ramp starting at 0.

Arguments:

none
  • Array
  • Number

rand

Random number from zero up to the receiver, exclusive.

Arguments:

none
  • Array

*rand

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

Arguments:

(size [, minVal=0, maxVal=1])

Example:

 Array.rand(8, 1, 100);
  • Array

*rand2

Fill an Array with random values in the range -val to +val.

Arguments:

(size [, val=1])

Example:

 Array.rand2(8, 100);
  • Array
  • Number

rand2

Returns:

a random number from -this to +this.
  • Array
  • Number

ratiomidi

Convert a ratio to an interval in semitones.

Arguments:

none

Returns:

an interval in semitones

Example:

 sc.Range("1, 1.2..2").ratiomidi();
 // => [ 0, 3.1564, 5.8251, 8.1368, 10.1759, 11.9999 ]
  • Array
  • Number

reciprocal

1 / this

Arguments:

none
  • Array
  • Number

rectWindow

a value for a rectangular window function between 0 and 1.

Arguments:

none
  • Array

reject

Answer a new collection which consists of all items in the receiver for which function answers False. The function is passed two arguments, the item and an integer index.

Arguments:

(function)
  • Array

remove

Remove item from the receiver.

Arguments:

(item)
  • Array

removeAll

Remove all items in array from the receiver.

Arguments:

(list)
  • Array

removeAllSuchThat

Remove all items in the receiver for which function answers True. The function is passed two arguments, the item and an integer index.

Arguments:

(function)
  • Array

removeAt

Remove and return the element at index, shrinking the size of the Array.

Arguments:

(index)
  • Array

removeEvery

Remove all occurrences of the items in array from the receiver.

Arguments:

(list)
  • Array

removing

  • Array

replace

Return a new array in which a number of elements have been replaced by another.

Arguments:

(find, replace)
  • Array

resamp0

Returns a new Array of the desired length, with values resampled evenly-spaced from the receiver without interpolation.

Arguments:

(newSize)

Example:

 [1, 2, 3, 4].resamp0(12); // => [ 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4 ]
 [1, 2, 3, 4].resamp0( 2); // => [ 1, 4 ]
  • Array

resamp1

Returns a new Array of the desired length, with values resampled evenly-spaced from the receiver with linear interpolation.

Arguments:

(newSize)

Example:

 [1, 2, 3, 4].resamp1(12); // => [ 1, 1.2727, 1.5454, ... , 3.7272, 4 ]
 [1, 2, 3, 4].resamp1( 3); // => [ 1, 2.5, 4 ]
  • Array

reverse

Return a new Array whose elements are reversed.

Arguments:

none

Aliases:

sc_reverse
  • Number

reverseDo

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

Arguments:

(function)
  • Array
  • Number

rightShift

performs a binary right shift

Arguments:

(number)

Aliases:

>>
  • Array
  • Number

ring1

(a * b) + a

Arguments:

(number)
  • Array
  • Number

ring2

((a*b) + a + b)

Arguments:

(number)
  • Array
  • Number

ring3

(a * a *b)

Arguments:

(number)
  • Array
  • Number

ring4

((a * a * b) - (a * b * b))

Arguments:

(number)
  • Array

rotate

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

Arguments:

(n)

Example:

 [1, 2, 3, 4].rotate( 1); // => [ 4, 1, 2, 3 ]
 [1, 2, 3, 4].rotate(-1); // => [ 2, 3, 4, 1 ]
  • Array
  • Number

round

Round to multiple of aNumber

Arguments:

(number)
  • Array
  • Number

roundUp

round up to a multiply of aNumber

Arguments:

(number)
  • Array
  • Number

rrand

a random number in the interval ]a, b[.

Arguments:

(number)
  • Array
  • Number

scaleneg

a * b when a < 0, otherwise a.

Arguments:

(number)
  • Array

scramble

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

Arguments:

none

Aliases:

shuffle
  • Array
  • Number

scurve

Map receiver in the onto an S-curve.

Arguments:

none
  • Array

sect

Return the set theoretical intersection of this and that.

Arguments:

(that)

Example:

 [1, 2, 3].sect([2, 3, 4, 5]); // => [ 2, 3 ]
  • Array

select

Answer a new collection which consists of all items in the receiver for which function answers True. The function is passed two arguments, the item and an integer index.

Arguments:

(function)
  • Array

separate

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.

Arguments:

(function)

Example:

 sc.Range("0..10").separate("isPrime");
 // => [ [0,1,2] , [3], [4,5], [6,7], [8,9,10] ]
  • Array

*series

Fill an Array with an arithmetic series.

Arguments:

(size [, start=0, step=1])

Example:

 Array.series(5, 10, 2); // => [ 10, 12, 14, 16, 18 ]
  • Number

series

return an artithmetic series from this over second to last.

Arguments:

(second, last)

Example:

 (5).series(7, 10); // => [ 5, 7, 9 ]
  • Array
  • Number

setBit

set nth bit to zero (bool = false) or one (bool = true)

Arguments:

(number, bool)
  • Array
  • Number

sign

Answer -1 if negative, +1 if positive or 0 if zero.

Arguments:

none
  • Array
  • Number

sin

Sine

Arguments:

none
  • Array
  • Number

sinh

Hyperbolic sine

Arguments:

none
  • Function
  • String
  • Array
  • Boolean
  • Number

size

Return the number of elements the receiver.

Arguments:

none
  • Array

slide

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

Arguments:

([windowLength=3, stepSize=1])

Example:

 [1, 2, 3, 4, 5, 6].slide(3, 1); // => [ 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6 ]
  • Array
  • Number

softclip

Distortion with a perfectly linear region from -0.5 to +0.5

Arguments:

none
  • Array

sputter

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

Arguments:

([probability=0.25, maxlen=100])
  • Array
  • Number

sqrdif

(a - b) ** 2

Arguments:

(number)
  • Array
  • Number

sqrsum

(a + b) ** 2

Arguments:

(number)
  • Array
  • Number

sqrt

the square root of the number.

Arguments:

none
  • Array
  • Number

squared

the square of the number

Arguments:

none
  • Array

stutter

Return a new Array whose elements are repeated n times.

Arguments:

(n)

Example:

 [1, 2, 3].stutter(2); // => [ 1, 1, 2, 2, 3, 3 ]
  • Array

sum

Answer the sum of the results of function evaluated for each item in the receiver. The function is passed two arguments, the item and an integer index.

Arguments:

(function)

Example:

 sc.Range("0..10").sum(); // => 55
  • Array
  • Number

sum3rand

This was suggested by Larry Polansky as a poor man's gaussian.

Arguments:

none
  • Array

sumabs

  • Array
  • Number

sumsqr

(a * a) + (b * b)

Arguments:

(number)
  • Array

swap

Swap two elements in the collection at indices i and j.

Arguments:

(i, j)

Example:

 [0,1,2,3,4,5].swap(2, 3); // => [0, 1, 3, 2, 4, 5]
  • Array

symmetricDifference

Return the set of all items which are not elements of both this and that. this -- that

Arguments:

(that)

Example:

 [1, 2, 3].symmetricDifference([2, 3, 4, 5]); // => [ 1, 4, 5 ]
  • Array

take

Remove and return item from collection. The last item in the collection will move to occupy the vacated slot (and the collection size decreases by one).

Arguments:

(item)

Example:

 a =  [11, 12, 13, 14, 15];
 a.take(12); // => 12
 a; => [ 11, 15, 13, 14 ]
  • Array

takeAt

Similar to removeAt, but does not maintain the order of the items following the one that was removed. Instead, the last item is placed into the position of the removed item and the array's size decreases by one.

Arguments:

(index)

Example:

 y = [ 1, 2, 3, 4, 5 ];
 y.takeAt(1); // => 2
 y; // => [ 1, 5, 3, 4 ]
  • Array

takeThese

Removes all items in the receiver for which the function answers true. The function is passed two arguments, the item and an integer index.

Arguments:

(function)

Example:

 y = [1, 2, 3, 4];
 y.takeThese("odd"); // => [ 4, 2 ]
 y; // => [ 4, 2 ]
  • Array
  • Number

tan

Tangent

Arguments:

none
  • Array
  • Number

tanh

Hyperbolic tangent

Arguments:

none
  • Array
  • Number

thresh

  • Array

transposeKey

  • Array
  • Number

triWindow

a value for a triangle window function between 0 and 1.

Arguments:

none
  • Array
  • Number

trunc

Truncate to multiple of aNumber

Arguments:

(number)
  • Array
  • Number

twice

  • Array

unbubble

  • Array

union

Return the set theoretical union of this and that.

Arguments:

(that)

Example:

 [1, 2, 3].union([2, 3, 4, 5]); // => [ 1, 2, 3, 4, 5 ]
  • Array

uniq

  • Array
  • Number

unsignedRightShift

performs an unsigned right shift

Arguments:

(number)

Aliases:

>>>
  • Function
  • String
  • Array
  • Boolean
  • Number

value

  • Function
  • String
  • Array
  • Boolean
  • Number

valueArray

  • Array

wchoose

Choose an element from the collection at random using a list of probabilities or weights. The weights must sum to 1.0.

Arguments:

(weights)

Example:

 [1, 2, 3, 4].wchoose([0.1, 0.2, 0.3, 0.4]);
  • Array
  • Number

welWindow

a value for a welsh window function between 0 and 1.

Arguments:

none
  • Array

*with

Create a new Array whose slots are filled with the given arguments.

Arguments:

(... args)
  • Array
  • Number

wrap

Wrapping at lo and hi.

Arguments:

(lo, hi)
  • Array
  • Number

wrap2

  • Array

wrapAt

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

Aliases:

@@

Example:

 [ 1, 2, 3 ].wrapAt(13); // => 2
 [ 1, 2, 3 ].wrapAt([ 0, 1, 2, 3 ]); // => [ 1, 2, 3, 1 ]
  • Array

wrapExtend

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

Arguments:

(size)

Example:

 [ 1, 2, 3 ].wrapExtend(9); // => [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
  • Array

wrapPut

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

Arguments:

(index, item)
  • Array

wrapSwap

Same as swap, but values for index greater than the size of the Array will be wrapped around to 0.

Arguments:

(i, j)
  • Number

xrand

a random value from zero to this, excluding the value exclude.

Arguments:

(exclude)
  • Number

xrand2

a random value from this.neg to this, excluding the value exclude.

Arguments:

(exclude)
  • Pattern

*Pgeom

Returns a stream that behaves like a geometric series.

Arguments:

([start=0, grow=1, length=inf])

Example:

 p = sc.Pgeom(1, 2, 5);
 p.next(); // => 1
 p.next(); // => 2
 p.next(); // => 4
 p.next(); // => 8
 p.next(); // => 16
 p.next(); // => null
  • Pattern

*Prand

Embed one item from the list at random for each repeat.

Arguments:

(list [, repeats=1, seed=nil])

Example:

 p = sc.Prand([1,2,3], 5, 12345);
 p.next(); // => 3
 p.next(); // => 1
 p.next(); // => 2
 p.next(); // => 1
 p.next(); // => 3
 p.next(); // => null
  • Pattern

*Pseq

Cycles over a list of values. The repeats variable gives the number of times to repeat the entire list.

Arguments:

(list [, repeat=1, offset=0])

Example:

 p = sc.Pseq([1,2,3], 2);
 p.next(); // => 1
 p.next(); // => 2
 p.next(); // => 3
 p.next(); // => 1
 p.next(); // => 2
 p.next(); // => 3
 p.next(); // => null
  • Pattern

*Pser

is like Pseq, however the repeats variable gives the number of items returned instead of the number of complete cycles

Arguments:

(list [, repeat=1, offset=0])

Example:

 p = sc.Pser([1,2,3], 4);
 p.next(); // => 1
 p.next(); // => 2
 p.next(); // => 3
 p.next(); // => 1
 p.next(); // => null
  • Pattern

*Pseries

Returns a stream that behaves like an arithmetric series.

Arguments:

([start=0, step=1, length=inf])

Example:

 p = sc.Pseries(0, 2, 5);
 p.next(); // => 0
 p.next(); // => 2
 p.next(); // => 4
 p.next(); // => 6
 p.next(); // => 8
 p.next(); // => null
  • Pattern

*Pshuf

Returns a shuffled version of the list item by item, with n repeats.

Arguments:

(list [, repeats=1, seed=nil])

Example:

 p = sc.Pshuf([1,2,3], 5, 12345);
 p.next(); // => 2
 p.next(); // => 1
 p.next(); // => 3
 p.next(); // => 2
 p.next(); // => 1
 p.next(); // => null
  • Rgen

*RGen

Random Generator

Arguments:

([seed])

Example:

 r = sc.RGen();
 r.next();
  • Rgen

next

return a number from 0.0 to 0.999...

Arguments:

none

Example:

 r = sc.RGen(100);
 r.next(); // => 0.6258506774902344
 r.next(); // => 0.4134453535079956
 r.next(); // => 0.13581514358520508
  • sc

Range

Creates an array of numbers (positive and/or negative) progressing from first up to last.

Arguments:

("[first[,second]]...?last")

Aliases:

R

Example:

 sc.Range(5); // => [ 0, 1, 2, 3, 4, 5 ]
 sc.Range("1..5"); // => [ 1, 2, 3, 4, 5 ]
 sc.Range("5..1"); // => [ 5, 4, 3, 2, 1 ]
 sc.Range("0, 2.5..10"); // => [ 0, 2.5, 5, 7.5, 10 ]
 sc.Range("0...10") // => [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
  • sc

use

Arguments:

(type)

Example:

 sc.use("global"); // install sc.functions to global namespace
 midicps(69); // => 40
  • Scale

*Scale

Scale supports arbitrary octave divisions and ratios, and (in conjunction with Tuning) can generate pitch information in various ways.

Example:

 sc.Scale.major(); // => Major Scale
 sc.Scale.dorian("Pythagorean"); // => Dorian Scale with Pythagorean Tuning
 sc.ScaleInfo.names(); // list of scale name
 sc.ScaleInfo.at("minor"); // => Minor Scale
  • Scale

*choose

Creates a random scale from the library, constrained by size and pitchesPerOctave if desired

Arguments:

([size=7, pitchesPerOctave=12])

Example:

 sc.Scale.choose(7);
  • Scale

at

Arguments:

(index)
  • Scale

cents

Returns a turned array of cent values

Arguments:

none
  • Scale

degreeToFreq

Returns a frequency based on current tuning and rootFreq argument.

Example:

 sc.Scale.major().degreeToFreq(2, (60).midicps(), 1); // => 659.25511...
 sc.Scale.major("just").degreeToFreq(2, (60).midicps(), 1); // => 654.06391...
  • Scale

degreeToFreq2

Same degreeToFreq, but use blendAt.

Example:

 sc.Scale.major().degreeToFreq2(2.5, (60).midicps(), 1); // => 678.8557...
 sc.Scale.major("just").degreeToFreq2(2.5, (60).midicps(), 1); // => 675.8660...
  • Scale

degreeToRatio

Returns a ratio based on current tuning.

Arguments:

(degree [, octave=0])

Example:

 sc.Scale.major().degreeToRatio(2, 1).round(0.001); // => 2.52
 sc.Scale.major("just").degreeToRatio(2, 1).round(0.001); // => 2.5
  • Scale

degreeToRatio2

Same as degreeToRatio, but use blendAt.

Arguments:

(degree [, octave=0])

Example:

 sc.Scale.major().degreeToRatio2(2.5, 1).round(0.001); // => 2.595
 sc.Scale.major("just").degreeToRatio2(2.5, 1).round(0.001); // => 2.583
  • Scale

degrees

  • Scale

octaveRatio

  • Scale

performDegreeToKey

Arguments:

(scaleDegree, stepsPerOctave [, accidental=0])
  • Scale

performKeyToDegree

Arguments:

(degree [, stepsPerOctave=12])
  • Scale

performNearestInList

Arguments:

(degree)
  • Scale

performNearestInScale

Arguments:

(degree [, stepsPerOctave=12])
  • Scale

pitchesPerOctave

Returns the size of the pitch class set from which the tuning is drawn

Arguments:

none

Example:

 sc.Scale.aeolian().pitchesPerOctave(); // 12
 sc.Scale.ajam().pitchesPerOctave(); // 24 (this is a quarter-tone scale)
  • Scale

ratios

Return a turned array of ratios

Arguments:

none
  • Scale

semitone

Returns a tuned array of semitone values

Arguments:

none
  • Scale

size

Returns the length of the scale.

Arguments:

none

Example:

 sc.Scale.ionian().size(); // 7
 sc.Scale.minorPentatonic().size(); // 5
  • Scale

stepsPerOctave

Usually 12, but may be different if the current tuning has a stretched or compressed octave. Needed for degreeToKey

Arguments:

none
  • Scale

tuning

Sets or gets the tuning of the Scale.

Arguments:

([inTuning])

Example:

 sc.Scale.major().tuning("just"); // set tuning
 sc.Scale.major().tuning(); // get tuning
  • Scale

wrapAt

These access the array generated by semitones.

Arguments:

(index)

Example:

 a = sc.Scale.major();
 a.wrapAt(4); // =>  7
 a.wrapAt([5, 6, 7]); // => [ 9, 11, 0 ]
  • Tuning

*Tuning

Represents a musical tuning (e.g. equal temperament, just intonation, etc.). Used in conjunction with Scale to generate pitch information.

Example:

 sc.Tuning.et12(); // => equal temperament
 sc.TuningInfo.names(); // => list of tuning name
 sc.TuningInfo.at("just"); // => Limit Just Intonation
  • Tuning

*choose

Creates a random tuning from the library, constrained by size (which defaults to 12)

Arguments:

([size=12])
  • Tuning

at

Arguments:

(index)
  • Tuning

cents

Returns a array of cent values for the pitch set

Arguments:

none
  • Tuning

equals

Arguments:

(that)
  • Tuning

octaveRatio

  • Tuning

ratios

Returns a tuned array of ratios for the pitch set

Arguments:

none
  • Tuning

semitones

Returns an array of semitone values for the pitch set

Arguments:

none
  • Tuning

size

  • Tuning

stepsPerOctave

  • Tuning

tuning

  • Tuning

wrapAt

Arguments:

(index)