ChucK Class Library Reference

Standard Classes and Libraries

Object

@array

string

Event

Std

Machine

Math

Shred

RegEx


@array

: Object

The array class is used to store linear sequences of data, also providing capabilities for stack and map data structures.

examples

member functions

int cap()

Return current capacity of the array (number of elements that can be held without reallocating internal buffer).

void clear()

Clear the contents of the array.

int erase(string key)

Erase all elements with the specified key.

int find(string key)

Return number of elements with the specified key.

void popBack()

Remove the last item of the array

void reset()

Reset array to original state; clears the array and sets capacity to 8.

int size()

Return the number of elements in the array.

int size(int newSize)

Set the size of the array. If the new size is less than the current size, elements will be deleted from the end; if the new size is larger than the current size, 0 or null elements will be added to the end.


string

: Object

The string class holds textual data as a sequence of characters, and provides a number of functions for manipulating text.

member functions

int charAt(int index)

Return a character at the specified index.

void erase(int start, int length)

Erase length characters of the string from start position.

int find(int theChar)

Return the index of the first occurence of theChar, or -1 if theChar is not found.

int find(int theChar, int start)

Return the index of the first occurence of theChar at or after the start position, or -1 if theChar is not found.

int find(string str)

Return the index of the first occurence of str, or -1 if str is not found.

int find(string str, int start)

Return the index of the first occurence of str at or after the start position, or -1 if str is not found.

void insert(int position, string str)

Insert str at the specified position.

int length()

Return the number of characters of the string.

string lower()

Return a new string in which the uppercase characters of the original string have been converted to lowercase.

string ltrim()

Return a new string in which leading whitespace has been removed.

void replace(int position, string str)

Replace characters from the start position to the end of the string with str.

void replace(int position, int length, string str)

Replace length characters from the start position with str.

int rfind(int theChar)

Return the index of the last occurence of theChar, or -1 if theChar is not found.

int rfind(int theChar, int start)

Return the index of the last occurence of theChar at or before the start position, or -1 if theChar is not found.

int rfind(string str)

Return the index of the last occurence of str, or -1 if str is not found.

int rfind(string str, int start)

Return the index of the last occurence of str at or before the start position, or -1 if str is not found.

string rtrim()

Return a new string in which trailing whitespace has been removed.

int setCharAt(int index, int theChar)

Set the character at the specified index.

string substring(int start)

Return a new string containing the substring from the start index to the end of the string.

string substring(int start, int length)

Return a new string containing the substring from the start index of the specified length.

float toFloat()

Attempt to convert the contents of the string to an float and return the result, or 0 if conversion failed.

int toInt()

Attempt to convert the contents of the string to an integer and return the result, or 0 if conversion failed.

string toString()

No description available

string trim()

Return a new string in which leading and trailing whitespace has been removed.

string upper()

Return a new string in which the lowercase characters of the original string have been converted to uppercase.


Event

: Object

The Event class allows exact synchronization across an arbitrary number of shreds.

member functions

void broadcast()

Signal all shreds that are waiting on this event.

int can_wait()

Whether or not the event can be waited on. Currently always returns true.

void signal()

Signal one shred that is waiting on this event.

void wait(Shred me)

(Currently unsupported.)


Std

: Object

Std is a standard library in ChucK, which includes utility functions for random number generation, unit conversions, and absolute value.

static member functions

int abs(int value)

Return absolute value of integer.

float atof(string value)

Converts ascii (string) to floating point value (float).

int atoi(string value)

Converts ascii (string) to integer (int).

int clamp(int value, int min, int max)

Clamp integer to range [min, max].

float clampf(float value, float min, float max)

Clamp float to range [min, max].

float dbtolin(float value)

Convert decibels (dB) to linear amplitude.

float dbtopow(float value)

Convert decibels (dB) to signal power ratio.

float dbtorms(float value)

Convert decibels (dB) to rms.

float fabs(float value)

Return absolute value of float.

string ftoa(float f, int precision)

Converts floating point value (float) to ascii (string) with specified precision (number of decimal digits).

int ftoi(float f)

Convert float to int.

float ftom(float value)

Convert frequency (Hz) to MIDI note number space.

string getenv(string value)

Returns the value of an environment variable, such as of PATH.

string itoa(int i)

Converts integer (int) to ascii (string).

float lintodb(float value)

Convert linear amplitude to decibels (dB).

float mtof(float value)

Convert a MIDI note number to frequency (Hz). Note the input value is of type float (supports fractional note number).

float powtodb(float value)

Convert signal power ratio to decibels (dB).

int rand2(int min, int max)

Generates random integer in range [min, max]. (NOTE: soon-to-be-deprecated; use Math.random2()).

float rand2f(float min, float max)

Return random floating point number in the range [min, max]. (NOTE: soon-to-be-deprecated; use Math.random2f())

int rand()

Generates random integer between 0 and Std.RAND_MAX. (NOTE: soon-to-be-deprecated; use Math.random2()).

float randf()

Return random floating point number in the range [-1, 1]. (Note: soon-to-be-deprecated; use Math.randomf())

float rmstodb(float value)

Convert rms to decibels (dB).

float scalef(float value, float srcmin, float srcmax, float dstmin, float dstmax)

Scale a float from source range to destination range.

int setenv(string key, string value)

Set value of environment variable named key to value.

float sgn(float value)

Computes the sign of the input as -1.0 (negative), 0 (zero), or 1.0 (positive).

void srand(int seed)

Provide a seed to the random function. Different seeds will generate very different sequences of random numbers even if the seeds are close together. Alternatively, a sequence of random numbers can be repeated by setting the same seed.

int system(string cmd)

Pass a command to be executed in the shell (requires --caution-to-the-wind command-line flag).


Machine

: Object

Machine is ChucK runtime interface to the virtual machine. this interface can be used to manage shreds. They are similar to the On-the-fly Programming Commands, except these are invoked from within a ChucK program, and are subject to the timing mechanism.

static member functions

int add(string path)

Compile and spork a new shred from file at 'path' into the VM now, returns the shred ID.

void crash()

Literally causes the VM to crash. the very last resort; use with care. Thanks.

int intsize()

Return the bit size of an integer.

int remove(int id)

Remove shred from VM by shred ID (returned by Machine.add).

int replace(int id, string path)

Replace shred with new shred from file. Returns shred ID , or 0 on error.

int[] shreds()

Return an integer array containing the IDs of current Shred objects.

int status()

Display the current status of VM.


Math

: Object

Math contains the standard math functions, including all trignometric functions expects angles to be in radians, as well as random number generators.

static member variables

float E

No description available

float FLOAT_MAX

No description available

float FLOAT_MIN_MAG

No description available

complex I

No description available

float INFINITY

No description available

int INT_MAX

No description available

complex J

No description available

float PI

No description available

int RANDOM_MAX

No description available

float TWO_PI

No description available

float e

No description available

complex i

No description available

complex j

No description available

static member functions

int abs(int value)

Return absolute value of integer.

float acos(float x)

Return the arccosine of a float.

float asin(float x)

Return the arcsine of a float.

float atan2(float y, float x)

Return the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value.

float atan(float x)

Return the arctangent of a float.

float ceil(float x)

Round to smallest integral value (returned as float) not less than x.

float cos(float x)

Return the cosine of a float.

float cosh(float x)

Return the hyperbolic cosine of a float.

float dbtopow(float value)

Convert decibels (dB) to signal power ratio.

float dbtorms(float value)

Convert decibels (dB) to rms.

int ensurePow2(int n)

Return the integral (returned as int) smallest power of 2 greater than the value of x.

float exp(float x)

Return e^x, the base-e exponential of x.

float fabs(float value)

Return absolute value of float.

float floor(float x)

Round to largest integral value (returned as float) not greater than x.

float fmod(float x, float y)

Return the floating point remainder of x/y.

float ftom(float value)

Convert frequency (Hz) to MIDI note number space.

float gauss(float x, float mean, float sd)

No description available

float hypot(float x, float y)

Return the euclidean distance of the orthogonal vectors (x,0) and (0,y).

float im(complex value)

Return the imaginary component of a complex number.

int isinf(float x)

Return 1 if x is infinity, else return 0.

int isnan(float x)

Return 1 if x is not a number, else return 0.

float log10(float x)

Return the logarithm of a float to base 10.

float log2(float x)

Return the logarithm of a float to base 2.

float log(float x)

Return the natural log of a float.

float mag(polar value)

Return the magnitude of a polar value.

float max(float x, float y)

Return greater of two values.

float min(float x, float y)

Return lesser of two values.

float mtof(float value)

Convert a MIDI note number to frequency (Hz). Note the input value is of type float (supports fractional note number).

int nextpow2(int n)

Return the integral (returned as int) smallest power of 2 greater than the value of x.

float phase(polar value)

Return the phase of a polar value.

float pow(float x, float y)

Return x taken to the y-th power.

float powtodb(float value)

Convert signal power ratio to decibels (dB).

int ptor(polar[] from, complex[] to)

Convert an array of polar complex numbers to an array of rectangular complex numbers in place (the second argument is the array that is to be modified). The total number of conversions is returned as well.

int random2(int min, int max)

Return random integer in range [min, max].

float random2f(float min, float max)

Return random float in range [min, max].

int random()

Return random integer in range 0 and Math.RANDOM_MAX.

float randomf()

Return random float in range [0.0, 1.0].

float re(complex value)

Return the real component of a complex number.

float remainder(float x, float y)

Return r such that r = x - n * y, where n is the integer nearest the exact value of x / y. If there are two integers closest to x / y, n shall be the even one. If r is zero, it is given the same sign as x.

float rmstodb(float value)

Convert rms to decibels (dB).

float round(float x)

Round to nearest integral value (returned as float).

int rtop(complex[] from, polar[] to)

Convert an array of rectangular complex numbers to an array of polar complex numbers in place (the second argument is the array that is to be modified). The total number of conversions is returned as well

float sgn(float value)

Return the sign of the input as -1.0 (negative), 0 (zero), or 1.0 (positive).

float sin(float x)

Return the sine of a float.

float sinh(float x)

Return the hyperbolic sine of a float.

float sqrt(float x)

Return the square root of a float.

void srandom(int seed)

Provide a seed to the random function. Different seeds will generate very different sequences of random numbers even if the seeds are close together. Alternatively, a sequence of random numbers can be repeated by setting the same seed.

float tan(float x)

Return the tangent of a float.

float tanh(float x)

Return the hyperbolic tangent of a float.

float trunc(float x)

Round to largest integral value (returned as float) no greater in magnitude than x.


Shred

: Object

Shred facilitates various operations and interactions with shreds running in the ChucK virtual machine.

static member functions

Shred fromId(int id)

Return a Shred object corresponding to the provided shred ID.

member functions

string arg(int index)

Return the argument at the specified index.

int args()

Return the number of arguments provided to the shred.

void clone()

No description available

string dir()

Return the enclosing directory of the source code file from which this shred's code is derived (same as .sourceDir()).

string dir(int levelsUp)

Return the enclosing directory, the specified number of parent directories up.

int done()

Return true if the shred is done processing; false otherwise.

void exit()

Immediately halt the shred's operation and remove it from the virtual machine.

int id()

Return the unique numeric id of the shred.

string path()

Return the file path of the source code file from which this shred's code is derived (same as .sourcePath()).

int running()

Return true if the shred is currently running; false otherwise.

string sourceDir()

Return the enclosing directory of the source code file from which this shred's code is derived.

string sourcePath()

Return the path of the source code file from which this shred's code is derived.

void yield()

Cause the shred to temporarily stop processing, allowing other scheduled shreds to run as needed.


RegEx

: Object

Class for regular expression matching and replacing in strings. Regex style is POSIX-extended.

static member functions

int match(string pattern, string str)

Return true if match for pattern is found in str, false otherwise

int match(string pattern, string str, string[] matches)

Return the match and sub-patterns in matches. matches[0] in the entire matched pattern, matches[1] is the first sub-pattern (if any), and so on.

string replace(string pattern, string replacement, string str)

Replace the first instance of pattern in str with replacement, returning the result.

string replaceAll(string pattern, string replacement, string str)

Replace all instances of pattern in str with replacement, returning the result.