Private
constructorPrivate internal constructor for a ChucK AudioWorklet Web Audio Node. Use public Init to create a ChucK instance.
Array of Files to preload into ChucK's filesystem
AudioContext to connect to
WebChucK WebAssembly binary
Number of output channels
ChucK AudioWorklet Node
Private
deferredPrivate
deferredPrivate
eventPrivate
eventPrivate
isPrivate
chuginsReadonly
parametersReadonly
portReadonly
contextReadonly
numberReadonly
numberStatic
initInitialize a ChucK AudioWorkletNode. By default, a new AudioContext is
created and ChucK is connected to the AudioContext destination.
Note: init() is overloaded to allow for a custom AudioContext,
custom number of output channels, and custom URL location of whereIsChuck
.
Skip an argument by passing in undefined
.
Array of auxiliary files to preload into ChucK's filesystem. These can be .wav files, .ck files, .etc. [{serverFilename: "./path/filename.wav", virtualFilename: "filename.wav"}...]
Optional
audioContext: AudioContextOptional parameter if you want to use your own AudioContext. Note: If an AudioContext is passed in, you will need to connect the ChucK instance to your own destination.
Optional custom number of output channels. Default is 2 channel stereo and the Web Audio API supports up to 32 channels.
Optional custom url to your WebChucK src
folder containing webchuck.js
and webchuck.wasm
. By default, whereIsChuck
is here.
WebChucK ChucK instance
// default initialization
theChuck = await Chuck.init([]);
// Initialize ChucK with a list of files to preload
theChuck = await Chuck.init([{serverFilename: "./path/filename.wav", virtualFilename: "filename.wav"}...]);
// Initialize ChucK with a local audioContext, connect ChucK to the context destination
var audioContext = new AudioContext();
theChuck = await Chuck.init([], audioContext));
theChuck.connect(audioContext.destination);
// Initialize ChucK using local webchuck.js and webchuck.wasm files in "./src"
theChuck = await Chuck.init([], undefined, undefined, "./src");
Static
loadLoad a single WebChugin (.chug.wasm) via url into WebChucK.
A list of publicly available WebChugins to load can be found in the webchugins folder.
Call this per chugin that you want to load.
Note: WebChugins must be loaded before theChuck
is initialized.
URL to webchugin to load
Chuck.loadChugin("https://url/to/myChugin.chug.wasm");
theChuck = await Chuck.init([]);
Private
nextCreate a virtual file in ChucK's filesystem. You should first locally fetch the contents of your file, then pass the data to this method. Alternatively, you can use loadFile to automatically fetch and load a file from a URL.
Virtual directory to create file in
Name of file to create
Data to write to the file
Replace the last currently running shred with string of ChucK code to execute.
ChucK code string to run and replace last shred
Promise to shred ID that is replaced
theChuck.replaceCode("SinOsc osc => dac; 1::second => now;");
Run a ChucK file that is already loaded in the WebChucK virtual file system. Note that the file must already have been loaded via filenamesToPreload, createFile, or loadFile
ChucK file to be run
Promise to running shred ID
await theChuck.loadFile("./myFile.ck"); // wait for file to load
theChuck.runFile("myFile.ck");
Run a ChucK file already loaded in the WebChucK virtual file system and pass in arguments.
e.g. Thie is the chuck command line equivalent of chuck myFile:1:2:foo
ChucK file to be run
Arguments to pass to the file separated by colons
Promise to running shred ID
theChuck.runFileWithArgs("myFile.ck", "1:2:foo");
Replace the last currently running shred with a Chuck file to execute. Note that the file must already have been loaded via filenamesToPreload, createFile, or loadFile
File to replace last shred
Promise to replaced shred ID
Replace the last running shred with a file to execute, passing arguments. Note that the file must already have been loaded via filenamesToPreload, createFile, or loadFile
File to be replace last running shred
Arguments to pass in to file
Promise to shred ID
Listen for a specific ChucK event to be signaled (through either signal() or broadcast()). Once signaled, the callback function is invoked. This can happen at most once per call.
ChucK global event variable to be signaled
JavaScript callback function
Listen for a specific ChucK event to be signaled (through either signal() or broadcast()). Each time the event is signaled, the callback function is invoked. This continues until stopListeningForEvent is called on the specific event.
ChucK global event variable to be signaled
JavaScript callback function
JavaScript callback ID
Stop listening to a specific ChucK event, undoing the process started by startListeningForEvent.
ChucK global event variable to be signaled
Callback ID returned by startListeningForEvent
Set the value (by key) of an associative int array in ChucK. Note that "associative array" is ChucK's version of a dictionary with string keys mapping to values (see ChucK documentation).
Name of global associative int array to set
The key index (string) of the associative array
The new value
theChucK.setAssociativeIntArrayValue("MY_INT_ASSOCIATIVE_ARRAY", "key", 5);
Get the value (by key) of an associative int array in ChucK. e.g. theChucK.getAssociateIntArrayValue("MY_INT_ASSOCIATIVE_ARRAY", "key");
Name of gobal associative int arry
The key index (string) to get
Promise with int array value
Get the float value of a global float arry at a particular index.
Name of global float array
Index of element
Promise of float value at index
theChucK.getFloatArray("MY_FLOAT_ARRAY", 1);
Set the value (by key) of an associative float array in ChucK. Note that "associative array" is ChucK's version of a dictionary with string keys mapping to values (see ChucK documentation).
Name of global associative float array to set
The key index (string) of the associative array
Float value to set
theChucK.setAssociateFloatArrayValue("MY_FLOAT_ASSOCIATIVE_ARRAY", "key", 5);
Get the value (by key) of an associative float array in ChucK.
Name of gobal associative float array
The key index (string) to get
Promise with float array value
theChucK.getAssociateFloatArrayValue("MY_FLOAT_ASSOCIATIVE_ARRAY", "key");
Callback function for Chuck to print a message string to console.
Override this method to redirect where ChucK console output goes. By default, Chuck prints to console.log()
.
Set your own method to display ChucK output or even use ChucK output as a message passing system.
Message that ChucK will print to console
// Override the default print method with our own callback print method
theChuck.chuckPrint = (message) => { console.log("ChucK says: " + message); }
// Now when ChucK prints, it will print to our callback method
theChuck.runCode(`<<< "Hello World!", "" >>>`);
// Output: "ChucK says: Hello World!"
Optional
options: boolean | AddEventListenerOptionsOptional
options: boolean | AddEventListenerOptionsOptional
options: boolean | EventListenerOptionsOptional
options: boolean | EventListenerOptions
WebChucK extends the Web Audio
AudioWorkletNode
class and provides an interface to interact with the ChucK Virtual Machine. Use init() to create a ChucK instance.theChuck
is a global variable that is used in the examples below.init()
will create a ChucK instance and an AudioContext if one is not provided.Note that many browsers do not let audio run until there has been user interaction (e.g. button press). You can check for a suspended audio context and resume like this: