ChucK Standard Libraries API
these libraries are provide by default with ChucK - new ones can also
be imported with ChucK dynamic linking (soon to be documented...). The
existing libraries are organized by namespaces in ChucK. They are as
follows.
namespace: Std
Std is a standard library in ChucK, which includes utility functions including
absolute values, unit conversions, pitch-frequency conversions. (NOTE: the random number
generator functions—which used to be in Std—are now in the Math library below.)
[example]
// infinite time-loop
while( true )
{
// generate random MIDI note number
Math.random2(60,84) => int pitch;
// convert pitch to frequency
pitch => Std.mtof => float frequency;
// print both
<<< pitch, frequency >>>;
// wait a bit
100::ms => now;
}
[function]:
int setenv ( string key, string value );
namespace: Machine
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.
----------
namespace: Math
Math contains the standard math functions, including all trignometric functions expects angles
to be in radians, as well as random number generators.
[example]
// print sine of pi/2
<<<< Math.sin( Math.PI / 2.0 ) >>>;
[example 2]
// infinite time-loop
while( true )
{
// generate random float (and print)
<<< Math.random2f( 100.0, 1000.0 ) >>>;
// wait a bit
50::ms => now;
}
[function]:
float random2f ( float min, float max );
Next: Chuck Standard Unit Generators
Return to Programming Guide
|