FLOSS Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

ChucK

Overview

Overview

ChucK is a strongly-typed, strongly-timed, concurrent audio and multimedia programming language. It is compiled into virtual instructions, which is immediately run in the ChucK Virtual Machine. This guide documents the features of the Language, Compiler, and Virtual Machine for a ChucK programmer.

Running ChucK

Some quick notes:

  • You can install ChucK (see build instructions) or run it from a local directory.
  • ChucK is a command line application called chuck. (also see the Audicle and the miniAudicle)
  • Use the command line prompt/terminal to run ChucK: (e.g. Terminal or xterm on OS X, cmd or cygwin on Windows, on Linux, you surely have your preferred terminal.)

See VM options for a more complete guide to command line options.

To run ChucK with a program/patch called foo.ck simply run chuck and then the name of the file:

%>chuck foo.ck 

To run ChucK with multiple patches concurrently (or the same one multiple times):

%>chuck foo.ck bar.ck bar.ck boo.ck

There are several flags you can specify to control how ChucK operates, or to find out about the system. For example,the following probes the audio system and prints out all available audio devices and MIDI devices. You may then refer to them (by number usually) from the command line or from your program (again, see VM Options for a complete list).

%>chuck --probe

ChucK can be run in a different terminal as a host/listener that patches may be sent to. The server should invoke the --loop flag to specify that the virtual machine should not halt automatically (when the current programs exit).

%>chuck --loop 

(See the guide to On-the-fly Programming for more information)

If a ChucK listener is running, we can (from a second terminal) send a program/patch to to the listener by using the + command line option:

%>chuck + foo.ck

Similarly, you can use - and = to remove/replace a patch in the listener, and use ˆ to find out the status. Again, see On-the-fly Programming for more information.

To run most of the code or examples in this language specification, you only need to use the basic chuck program.

Comments

Comments are sections of code that are ignored by a compiler. These help other programmers (and yourself ) interpret and document your code. Double slashes indicate to the compiler to skip the rest of the line.

// this is a comment
int foo; // another comment 

Block comments are used to write comments that last more than one line, or less than an entire line. A slash followed by an asterisk starts a block comment. The block comment continues until the next asterisk followed by a slash.

/* this
is a
block
comment */
int /* another block comment */ foo;

Comments can also be used to temporarily disable sections of your program, without deleting it entirely. ChucK code that is commented-out will be ignored by the compiler, but can easily be brought back if you change your mind later. In the following example, the PRCRev UGen will be ignored, but we could easily re-insert it by deleting the block comment delimiters.

SinOsc s => /* PRCRev r => */ dac;

Debug Print

ChucK currently lacks a comprehensive system for writing to files or printing to the console. In its place we have provided a debug print syntax:

// prints out value of expression
<<< expression >>>;

This will print the values and types of any expressions placed within them. This debug print construction may be placed around any non-declaration expression ( non l-value ) and will not affect the execution of the code. Expressions which represent an object will print the value of that object’s reference address:

// assign 5 to a newly declared variable
5 => int i;

// prints "5 : (int)"
<<<i>>>;

// prints "hello! : (string)"
<<<"hello!">>>; //prints "hello! : (string)"

// prints "3.5 : (float)"
<<<1.0 + 2.5 >>>=> float x;

For more formatted data output, a comma-separated list of expressions will print only their respective values (with one space between):

// prints "the value of x is 3.5" (x from above)
<<<"the value of x is" , x >>>;

// prints "4 + 5 is 9"
<<<"4 + 5 is", 4 + 5>>>;

// prints "here are 3 random numbers ? ? ?"
<<<"here are 3 random numbers",
Std.rand2(0,9),
Std.rand2(0,9),
Std.rand2(0,9) >>>;

Reserved Words

Primitive types

  • int
  • float
  • time
  • dur
  • void
  • same (unimplemented)

Control structures

  • if
  • else
  • while
  • until
  • for
  • repeat
  • break
  • continue
  • return
  • switch (unimplemented)

Class keywords

  • class
  • extends
  • public
  • static
  • pure
  • this
  • super (unimplemented)
  • interface (unimplemented)
  • implements (unimplemented)
  • protected (unimplemented)
  • private (unimplemented)

Other ChucK keywords

  • function
  • fun
  • spork
  • const
  • new

Special values

  • now
  • true
  • false
  • maybe
  • null
  • NULL
  • me
  • pi

Special : Default durations

  • samp
  • ms
  • second
  • minute
  • hour
  • day
  • week

Special : Global UGens

  • dac
  • adc
  • blackhole

Operators

  • +
  • -
  • *
  • /
  • %
  • =>
  • =<
  • !=>
  • ||
  • &&
  • ==
  • &
  • |
  • ˜
  • ::
  • ++
  • – –
  • >
  • >=
  • <
  • <=
  • @=>
  • +=>
  • -=>
  • *=>
  • /=>
  • %=>

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.