Home

Awesome

chuck-max

chuck~ help

A project which embeds the ChucK 1.5.4.2-dev (chai) engine in a Max/MSP external.

This repository is itself a Max package which includes one external (chuck~) with the following features and limitations:

The package also includes the following:

For the impatient: download the chuck-max package with pre-compiled externals and chugins from the the project's Releases section and check out the cheatsheat.

Note that chuck-max has a sibling in the pd-chuck project.

Overview

It's recommended to choose 2 channels for stereo audio.

If a <filename> argument is given it will be searched for according to the following rules:

  1. Assume it's an absolute path, use it if it exists.

  2. Assume that it's a partial path with the package's examples folder as a prefix. So if stk/flute.ck is given as <filename>, the absolute path of the package examples folder is prepended to it and if the resulting path exists, it is used.

  3. Assume <filename> exists in the parent patcher's directory. Test that this is the case and if it is, use it. This is useful if you want to package patchers and chuck files together.

  4. Use Max's locatefile_extended search function to search for the <filename> in the Max search path. The first successul result will be used.

Core Messages

As of the current version, chuck~ implements the core Chuck vm messages as Max messages:

ActionMax msgMax msg (alias)
Add shred from fileadd <file> [arg1 arg2 .. ]+ <filepath> [args]
Run chuck file (save last used)run <file>
Eval code as shredeval <code>
Remove shredremove <shredID>- <shredID>
Remove last shredremove last
Remove all shredsremove all
Replace shredreplace <shredID> <file>= <shredID> <file>
List running shredsstatus
Clear vmclear vmreset
Clear globalsclear globals
Reset idreset id
Timetime

It's worth reading the ChucK Language Specification's section on Concurrency and Shreds to get a sense of what the above means. The first paragraph will be quoted here since it's quite informative:

ChucK is able to run many processes concurrently (the process behave as if they are running in parallel). A ChucKian process is called a shred. To spork a shred means creating and adding a new process to the virtual machine. Shreds may be sporked from a variety of places, and may themselves spork new shreds.

Utility Messages

The core set of chuck vm messesages is also extended in chuck-max with the following utility messages:

ActionMax msg
Set file attribute (does not run)file <path>
Set full path to editor attributeeditor <path>
Prevent running shreds when dsp is offrun_needs_audio
Open file in external editoredit <path>
Probe chuginschugins
Get/set loglevel (0-10)loglevel & loglevel <n>
Get state of chuck vmvm
Launch chuck docs in a browserdocs
Clear Max consoleclear console

Parameter Messages

Once a shred is running you can change its parameters by sending values from Max to the chuck~ object. To this end, ChucK makes available three mechanisms: global variables, global events, and callbacks which are triggered by events. chuck~ maps these chuck language elements to corresponding Max/MSP constructs as per the following table:

ActionChucKMax msg
Change param value (untyped)global variable<name> <value>
Dump global variables to consoleglobal variableglobals
Trigger named eventglobal eventsig <name>
Trigger named event all shredsglobal eventbroadcast <name>

You change a global variable by sending a <variable-name> <value> message to a chuck~ instance where the value can be an int, float, string, array of ints or floats, etc. You can also trigger events by sending sig or signal messages, broadcast messages as per the above table.

Note: You can't use the ChucK types of dur or time in Max. Also, while in the above case, the Max msg seems untyped, it must match the type of the chuck global variable. So if you connect a Max number or flownum object to a message box, it needs to match the type of the global variable (int/float).

See help/chuck~.maxhelp and patchers in the patchers/tests directory for a demonstration of current features.

Parameter Messages using Callbacks (Advanced Usage)

In addition to the typical way of changing parameters there is also an extensive callback system which includes listening / stop-listening for events associated with callbacks, triggering them via sig and broadcast messages and also setting typed global variables via messages and symmetrically getting their values via typed callbacks:

ActionChucKMax msg
Listen to event (one shot)global eventlisten <name> or listen <name> 0
Listen to event (forever)global eventlisten <name> 1
Stop listening to eventglobal eventunlisten <name>
Trigger named callbackglobal eventsig <name>
Trigger named callback all shredsglobal eventbroadcast <name>
Get int variableglobal variableget int <name>
Get float variableglobal variableget float <name>
Get string variableglobal variableget string <name>
Get int arrayglobal variableget int[] <name>
Get float arrayglobal variableget float[] <name>
Get int array indexed valueglobal variableget int[i] <name> <index>
Get float array indexed valueglobal variableget float[i] <name> <index>
Get int associative array valueglobal variableget int[k] <name> <key>
Get float associative array valueglobal variableget float[k] <name> <key>
Set int variableglobal variableset int <name> <value>
Set float variableglobal variableset float <name> <value>
Set string variableglobal variableset string <name> <value>
Set int arrayglobal variableset int[] <name> v1, v2, ..
Set float arrayglobal variableset float[] <name> v1, v2, ..
Set int array indexed valueglobal variableset int[i] <name> <index> <value>
Set float array indexed valueglobal variableset float[i] <name> <index> <value>
Set int associative array valueglobal variableset int[k] <name> <key> <value>
Set float associative array valueglobal variableset float[k] <name> <key> <value>

Build Requirements and Options

Please note that this external is currently only developed and tested on macOS, although a Windows version is on the TODO list (any help on this front would be much appreciated).

A number of build variants have been made available to address platform-specific changes and library compatibility issues and also to provide for different levels of usage.

The following matrix shows feature coverage and also differences in compatibility among the different macOS versions:

feature/variantnativeuniversalbrewfullnomp3light
Externalxxxxxx
Base chuginsxxxxxx
Faust.chugxxxx
WarpBuf.chugxxxx
FluidSynth.chugx
.wavxxxxxx
.mp3xx
.flacxxx
.oggxxx
.opusxxx
.vorbisxxx
macOS 15 (Sequoia)xxxxxx
macOS 14 (Sonoma)xxxxxx
macOS 13 (Ventura)xxxxxx
macOS 12 (Monterey)xxxxxx
macOS 11 (Big Sur)xxxxx

A. The Base System

The base chuck-max system consists of a Max package with the chuck~ external, the base CCRMA chugins and extensive examples, tests and Max patchers.

Building it requires the following to be available on your machine:

  1. Xcode from the App store or Xcode Command Line Tools via xcode-select –install

  2. cmake

  3. bison

  4. flex

The last three can be installed using Homebrew as follows:

brew install cmake bison flex

The buildsystem consists of a minimal Makefile frontend with CMake driving the build on the backend.

To get up and running:

git clone https://github.com/shakfu/chuck-max.git
cd chuck-max
make setup

Note that make setup does two things: (1) retrieves max-sdk-base as a git submodule and makes the package and its contents available to be used by Max by creating a symlink of the chuck-max folder in $HOME/Documents/Max 8/Packages.

Now it should be possible to build the base system with either of the following two options:

B. The Advanced System

The advanced system consists of the base system + two advanced chugins, Faust.chug and WarpBuf.chug:

  1. The Fauck chugin contains the full llvm-based faust engine and dsp platform which makes it quite powerful and also quite large compared to other chugins (at around 45 MB stripped down). It requires at least 2 output channels to work properly. It also uses the libsndfile library.

  2. The WarpBuf chugin makes it possible to time-stretch and independently transpose the pitch of an audio file. It uses the rubberband, libsndfile, and libsamplerate libraries.

To build these two chugins, you will need some additional dependencies which can also be installed via Homebrew as follows:

brew install autoconf autogen automake flac libogg libtool libvorbis opus mpg123 lame rubberband libsamplerate

After these are installed, it should be possible, subject to the compatibility matrix above, to build the advanced system with one of the following options:

Usage

The chuck-max package consists of the following folders:

chuck-max
├── examples
│    ├── ai
│    ├── analysis
│    ├── ...
│    ├── **chugins**
│    ├── ...
│    ├── **fauck**
│    ├── **faust**
│    ├── ...
│    ├── **max**
│    ├── ...
│    ├── **test**
│    ├── ...
│    └── warpbuf
├── externals
│    └── chuck~.mxo
├── help
├── media
└── patchers
    ├── abstractions
    ├── contrib
    └── tests

Start with the chuck~.maxhelp file in the help folder for an overview of the external's features. The media folder also has a pdf cheatsheet of available chuck~ methods.

The examples directory contains all chuck examples from the chuck repo, and some additional folders: chugins containing chugin binaries, fauck, containing faust.chug examples, faust, containing the faust stdlib, max chuck files which are used by the max patchers, and test, chuck files used by max patcher test files.

In the patchers section, there are quite a few patchers demonstrating one feature or other in the tests folder, and the contrib folder contains excellents advanced examples of uses by chuck-max contributors.

Known Unresolved Bugs

Credits

This project thanks the following: