SuperCollider CLASSES

AbstractFunction

An object which responds to a set of messages that represent mathematical functions
Source: /usr/local/share/SuperCollider/SCClassLibrary/Common/Core/AbstractFunction.sc
Inherits from: Object

Description

An AbstractFunction is an object which responds to a set of messages that represent mathematical functions. Subclasses override a smaller set of messages to respond to the mathematical functions. The intent is to provide a mechanism for functions that do not calculate values directly but instead compose structures for calculating.

Function, Pattern, Stream and UGen are subclasses of AbstractFunction. For example, if you multiply two UGens together the receiver responds by answering a new instance of class BinaryOpUGen which has the two operands as inputs.

For an overview of common operators, see Operators. To see which classes implements a specific method, see that method in the generated Methods overview.

Class Methods

Inherited class methods

Instance Methods

Unary Messages

All of the following messages send the message composeUnaryOp to the receiver with the unary message selector as an argument. See UnaryOpFunction.

-neg

-reciprocal

-bitNot

-abs

-asFloat

-asInt

From superclass: Object

-ceil

-floor

-frac

-sign

-squared

-cubed

-sqrt

-exp

-midicps

-cpsmidi

-midiratio

-ratiomidi

-ampdb

-dbamp

-octcps

-cpsoct

-log

-log2

-log10

-sin

-cos

-tan

-asin

-acos

-atan

-sinh

-cosh

-tanh

-rand

-rand2

-linrand

-bilinrand

-sum3rand

-distort

-softclip

-coin

-even

-odd

-isPositive

-isNegative

-isStrictlyPositive

-rho

-theta

Binary Messages

All of the following messages send the message composeBinaryOp to the receiver with the binary message selector and the second operand as arguments. See: BinaryOpFunction.

-+ (function, adverb)

-- (function, adverb)

-* (function, adverb)

-/ (function, adverb)

-div (function, adverb)

-% (that)

From superclass: Object

-** (that)

From superclass: Object

-min (function, adverb)

-max (function: 0, adverb)

-< (function, adverb)

-<= (function, adverb)

-> (function, adverb)

->= (function, adverb)

-& (that)

From superclass: Object

-| (that)

From superclass: Object

-lcm (function, adverb)

-gcd (function, adverb)

-round (function: 1, adverb)

-trunc (function: 1, adverb)

-atan2 (function, adverb)

-hypot (function, adverb)

-hypotApx (function, adverb)

->> (that)

From superclass: Object

-+>> (that)

From superclass: Object

-ring1 (function, adverb)

-ring2 (function, adverb)

-ring3 (function, adverb)

-ring4 (function, adverb)

-difsqr (function, adverb)

-sumsqr (function, adverb)

-sqrdif (function, adverb)

-absdif (function, adverb)

-amclip (function, adverb)

-scaleneg (function, adverb)

-clip2 (function: 1, adverb)

-excess (function: 1, adverb)

-<! (that)

From superclass: Object

-rrand (function, adverb)

-exprand (function, adverb)

-rotate (function)

-dist (function)

-bitAnd (function, adverb)

-bitOr (function, adverb)

-bitXor (function, adverb)

-bitHammingDistance (function, adverb)

-@ (function, adverb)

Messages with more arguments

All of the following messages send the message composeNAryOp to the receiver with the binary message selector and the other operands as arguments. See NAryOpFunction.

-clip (lo, hi)

-wrap (lo, hi)

-fold (lo, hi)

-blend (that, blendFrac: 0.5)

-linlin (inMin, inMax, outMin, outMax, clip: 'minmax')

-linexp (inMin, inMax, outMin, outMax, clip: 'minmax')

-explin (inMin, inMax, outMin, outMax, clip: 'minmax')

-expexp (inMin, inMax, outMin, outMax, clip: 'minmax')

other

-applyTo ( ... args)

Interface that allows us to combine selectors (Symbols) and Functions. Sends valueArray(args) to this.

Discussion:

// example:

f = [{ |a, b| a * b * 100.rand }, { |a, b| sin(a) * sin(b) }, '*', '/'];
f.choose.postcs.applyTo(3, 4);

// this is used in SequenceableCollection reduce:
(1..10).reduce('+');
(1..10).reduce({ |a, b| a * b * 1.0.rand });

-asUGenInput (for)

Returns:

the result of sending the value(for) message to this.

Discussion:

// example:
(
var f, g, product;
f = { SinOsc.ar(400) };
g = { LFPulse.kr(8)  };
product = f * g * 0.1;
{ Pan2.ar(product, SinOsc.kr(0.3)) }.play;
)

-sampled (n: 80, from: 0, to: 1)

Sample a function.

Discussion:

//sample a function
f = { |x| sin(3*x)*cos(8*x) }
f.plotGraph2(from:0,to:2);
f.sampled(10,0,2).plotGraph2(from:0,to:2);
f.sampled(80,0,2).plotGraph2(from:0,to:2);

//on complicated functions a sampled function is less cpy heavy.
f = { |x| 60.collect{ 2**((x-rrand(0.0,1.0))) }.sum/60 };
f.plotGraph2(from:0,to:1);
g = f.sampled(200);
g.plotGraph2(from:0,to:1);
{ 200.collect{ f.(rand(0.0,1.0)) } }.bench;
{ 200.collect{ g.(rand(0.0,1.0)) } }.bench;

Function Composition

When unary, binary or n-ary operators are applied to an abstract function, it returns an object that represents this operation, without evaluating the function: UnaryOpFunction, BinaryOpFunction, NAryOpFunction. Note that different subclasses like Pattern or UGen have their own composition scheme analogous to the one of AbstractFunction itself. For more about functions, see Function.

Inherited instance methods

Undocumented instance methods

-&& (function, adverb)

-<> (that)

-asAudioRateInput (for)

-asControlInput

-asInteger

-biexp (inCenter, inMin, inMax, outCenter, outMin, outMax, clip: 'minmax')

-bilin (inCenter, inMin, inMax, outCenter, outMin, outMax, clip: 'minmax')

-composeBinaryOp (aSelector, something, adverb)

-composeNAryOp (aSelector, anArgList)

-composeUnaryOp (aSelector)

-curvelin (inMin: 0, inMax: 1, outMin: 0, outMax: 1, curve: -4, clip: 'minmax')

-degrad

-degreeToKey (scale, stepsPerOctave: 12)

-eq (function, adverb)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/backwards_compatibility/extMethods.sc

-firstArg (function, adverb)

-fold2 (function: 1, adverb)

-hanWindow

-imag

-isValidUGenInput

-leftShift (function, adverb)

-lincurve (inMin: 0, inMax: 1, outMin: 0, outMax: 1, curve: -4, clip: 'minmax')

-mod (function, adverb)

-nand (function, adverb)

-ne (function, adverb)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/backwards_compatibility/extMethods.sc

-not

-performBinaryOpOnComplex (aSelector, aComplex, adverb)

-performBinaryOpOnSeqColl (aSelector, aSeqColl, adverb)

-performBinaryOpOnSignal (aSelector, aSignal, adverb)

-performBinaryOpOnSimpleNumber (aSelector, aNumber, adverb)

-plotGraph (n: 500, from: 0, to: 1, name, bounds, discrete: false, numChannels, minval, maxval, parent, labels: true)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Math/PlotView.sc

-pow (function, adverb)

-prepareForProxySynthDef

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

-raddeg

-ramp

-real

-rectWindow

-reduceFuncProxy (args)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/Patterns/extFunction.sc

-ref

-reverseComposeBinaryOp (aSelector, something, adverb)

-rightShift (function, adverb)

-roundUp (function: 1, adverb)

-scurve

-sqrsum (function, adverb)

-thresh (function, adverb)

-triWindow

-unsignedRightShift (function, adverb)

-welWindow

-wrap2 (function: 1, adverb)

-xor (function, adverb)

-|| (function, adverb)

Examples

// examples

a = { 1.0.rand } + 8;
a.value;


y = { 8 } + { 1.0.rand };
y.value;
// arguments are passed into both functions

y = { |x=0| x } + { 1.0.rand };
y.value(10);


y = { |x=0| x * 3 } + { |x=0| x + 1.0.rand };
y.value(10);

y.postcs;

y = { |x=0| x * 3 } + { |x=0| x + 1.0.rand } * { |x=0| [50, 100].choose + x } + 1.0;
y.value(10);
// environments can be used as a lookup with valueEnvir:

(
Environment.use {
    ~y = 10;
    ~x = 2;
    ~z = { |x=8| x } + { |y=0| y + 1.0.rand };
    ~z.valueEnvir;
}
)
// n-ary operators:

a = blend({ 3.0.rand }, { 1000.rand }, { |frac| frac });
a.value(0.5);

a.value((0, 0.06..1)); // creates a range of values..