Class: Function

Environment: Siren
Superclass: Siren.DurationEvent
Category: Music-Functions
Instance variables: data range domain scale offset
Indexed variables: objects

Instances of of Function and its subclasses represent abstractions of 1- or n-dimensional functions of 1 variable (e.g., time).
Class Function is concrete and represents functions that are described by a array of data points assumed to lie equally-spaced in the unit interval.
Functions are normally created from an array of values over the unit interval; x varies from 0.0 to 1.0 and y is free over that range.
One can address them within the unit interval with atX: or one can address them with integer indeces up to the data set's size with atIndex: (can be dangerous).

Examples are a ramp from 0 to 1 such as:
[(LinearFunction from: #((0 0) (1 2))) at: 0.33]
or a spline that traces a sine-like path centered around 1:
[(SplineFunction from: #((0 1) (0.33 2) (0.67 0) (1 1))) at: 0.35]

InstanceVariables:
data
the data values or breakpoints of the function
domain the x-range
range the y-range

ui

edit
Open a function view on the receiver.

edit: extent
Open a function view on the receiver.

updateSelector

processing

averagedTo: size
Answer an averaged version of the receiver of the given size.

freeData
Release the receiver's 'data'.

maxTo: size win: wsize
Answer a version of the receiver of the given size taking the maximum value of each window.

sampledTo: size
Answer a down-sampled version of the receiver of the given size.

smoothed
Answer a version of the receiver smoothed to about 32 points.

updateRange

accessing

add: aValue
Add the argument to the receiver's point collection.

at: anIndex
Answer the value at the given index (between 0 and 1 -or- 1 and data size).

at: anIndex put: aValue
Put the given value at the given index (between 0 and 1).

atX: anIndex
Answer the value at the given index (between 0 and 1).

data
Answer the receiver's 'data'.

data: anObject
Set the receiver's instance variable 'data' to be anObject.

dataClass
Answer the class of the elements in the receiver's data collection.

domain
Answer the receiver's 'domain'.

domain: anObject
Set the receiver's instance variable 'domain' to be anObject.

duration
Answer the domain of the receiver's collection of breakpoints.

nextXMoreThan: delta from: thisIndex
Answer the next X value after index whose Y value is more than delta from the value at thisIndex

nextXMoreThan: delta from: thisIndex step: step
Answer the next X value after thisIndex whose Y value is more than delta from the value at thisIndex

offset: offVal
Set the receiver's 'offset'.

pointAt: index
Answer the given value in the receiver's breakpoint collection.

pointAt: index put: value
Assign the given values in the receiver's breakpoint collection.

points
Answer the receiver's 'data'.

range
Answer the receiver's 'range'.

range: anObject
Set the receiver's instance variable 'range' to be anObject.

realPointAt: index
Answer the given value in the receiver's breakpoint collection (this is not overridden in ExpSeg).

sampleAt: anIndex
Answer the value at the given index (between 0 and 1).

scale
Answer the receiver's 'scale'.

scale: scaleVal
Set the receiver's 'scale'.

selection

size
Answer the size of the receiver's collection of breakpoints.

printing

printOn: aStream
Format and print the receiver on the argument.

storeOn: aStream
Format and print the receiver on the argument.

enumerating

detect: aBlock ifNone: exceptionBlock
Evaluate aBlock with each of the receiver's elements as the argument.
Answer the first element for which aBlock evaluates to true.

do: aBlock
Evaluate aBlock with each of the receiver's elements as the argument.

isEmpty

initialize-release

initialize: size
Initialize the receiver for the given size.

geometry

hasPointNear: anXValue
Answer whether or not the receiver has a function breakpoint near the given x value.

indexOfPointNearestX: anXValue
Answer the receiver`s point nearest the given x value.

arithmetic

* aFcnOrNum
Answer a function graph with the argument multiplied by the receiver

+ aFcnOrNum
Answer a function graph with the argument added to the receiver

- aFcnOrNum
Answer a function graph with the argument subtracted from the receiver

/ aFcnOrNum
Answer a function graph with the receiver divided by the argument

MetaClass: Function class

standard functions

exponentialADSR1
Answer a exponential attack/decay/sustain/release envelope.

exponentialADSR2
Answer a exponential attack/decay/sustain/release envelope.

linearADSR1
Answer a linear attact/decat/sustain/release envelope.

linearADSR2
Answer a linear attact/decat/sustain/release envelope.

spline
Answer a generic spline curve.

sumOfSines
Answer a simple Fourier summation.

instance creation

default
Answer a default instance of the receiver class.

from: anArray
Answer a function with the given array of collections, points, or data values.

fromFile: fName
Load 1 or more functions from a text file.

new
Answer an instance of the receiver class.

ofSize: size
Answer an instance of the receiver class of the requested size.

randomOfSize: size from: low to: high
Answer a function with the given number of data points in the given range.

randomWalkSize: size from: low to: high
Answer a function with the given number of data points in the given range.

readFloatsFrom: filename
Answer a function with the given points.

examples

averagedFunctionFileExample
Function usage example; read a function from a binary file and view it.

fileExample
Function usage example; read a function from a binary file and view it.

functionFileExample
Function usage example; read a function from a binary file and view it.

functionPlayExample
Function usage example; make a roll-type eventList and apply a crescendo/decrescendo to it

functionViewExample
Function usage example; make a z-z function and view it.

maxedFunctionFileExample
Function usage example; read a function from a binary file and view it.

randomViewExample
Function usage example; make a random walk fcn and view it.

randomViewExample2
Function usage example; make a random walk fcn and view it.

class constants

defaultSize
Answer the default size for the instances' storage array.