@csound/browser
Api Documentation
Objects
-
CsoundObj :
object
-
CsoundObj API.
Functions
-
Csound([params]) ⇒
Promise.<(CsoundObj|undefined)>
-
The default entry for @csound/wasm/browser module. If loaded successfully, it returns CsoundObj, otherwise undefined.
-
getTable(tableNum) ⇒
Promise.<(Float64Array|undefined)>
Typedefs
object
CsoundObj : CsoundObj API.
Kind: global namespace
-
CsoundObj :
object
-
global
-
getTable(tableNum) ⇒
Promise.<(Float64Array|undefined)>
-
getTable(tableNum) ⇒
-
static
-
.fs :
IFs:memfs
-
.eventNames() ⇒
Array.<string>
-
.listenerCount() ⇒
number
-
.listeners(eventName) ⇒
Array.<function()>
-
.off(eventName, listener) ⇒
external:EventEmitter
-
.on(eventName, listener) ⇒
external:EventEmitter
-
.addListener(eventName, listener) ⇒
external:EventEmitter
-
.once(eventName, listener) ⇒
external:EventEmitter
-
.removeAllListeners(eventName) ⇒
external:EventEmitter
-
.removeListener(eventName, listener) ⇒
external:EventEmitter
-
.getSr() ⇒
Promise.<number>
-
.getKr() ⇒
Promise.<number>
-
.getKsmps() ⇒
Promise.<number>
-
.getNchnls() ⇒
Promise.<number>
-
.getNchnlsInput() ⇒
Promise.<number>
-
.get0dBFS() ⇒
Promise.<number>
-
.getA4() ⇒
Promise.<number>
-
.getCurrentTimeSamples() ⇒
Promise.<number>
-
.getSizeOfMYFLT() ⇒
Promise.<number>
-
.setOption(option) ⇒
Promise.<number>
-
.setParams(csoundParams) ⇒
Promise.<undefined>
-
.getParams() ⇒
Promise.<CSOUND_PARAMS>
-
.getDebug() ⇒
Promise.<number>
-
.setDebug(debug) ⇒
Promise.<undefined>
-
.inputMessage(scoreEvent) ⇒
Promise.<number>
-
.inputMessageAsync(scoreEvent) ⇒
Promise.<number>
-
.getControlChannel(channelName) ⇒
Promise.<undefined>
-
.setControlChannel(channelName, value) ⇒
Promise.<undefined>
-
.getStringChannel(channelName) ⇒
Promise.<undefined>
-
.setStringChannel(channelName, value) ⇒
Promise.<undefined>
-
.getOutputName() ⇒
Promise.<string>
-
.getInputName() ⇒
Promise.<string>
-
.destroy() ⇒
Promise.<undefined>
-
.getAPIVersion() ⇒
Promise.<number>
-
.getVersion() ⇒
Promise.<number>
-
.initialize() ⇒
Promise.<number>
-
.parseOrc(orc) ⇒
Promise.<object>
-
.compileTree(tree) ⇒
Promise.<number>
-
.compileOrc(orc) ⇒
Promise.<number>
-
.evalCode(orc) ⇒
Promise.<number>
-
.start() ⇒
Promise.<number>
-
.compileCsd(path) ⇒
Promise.<number>
-
.compileCsdText(orc) ⇒
Promise.<number>
-
.perform() ⇒
Promise.<number>
-
.performKsmps() ⇒
Promise.<number>
-
.performBuffer() ⇒
Promise.<number>
-
.stop() ⇒
Promise.<undefined>
-
.cleanup() ⇒
Promise.<number>
-
.reset() ⇒
Promise.<number>
-
.getInputBufferSize() ⇒
Promise.<number>
-
.getOutputBufferSize() ⇒
Promise.<number>
-
.getInputBuffer() ⇒
Promise.<number>
-
.getOutputBuffer() ⇒
Promise.<number>
-
.getSpin() ⇒
Promise.<number>
-
.getSpout() ⇒
Promise.<number>
-
.getMIDIDevList(isOutput) ⇒
Promise.<CS_MIDIDEVICE>
-
.getRtMidiName() ⇒
Promise.<string>
-
.midiMessage(midi, midi, midi) ⇒
Promise.<void>
-
.isScorePending() ⇒
Promise.<number>
-
.setScorePending(pending) ⇒
Promise.<undefined>
-
.readScore(score) ⇒
Promise.<undefined>
-
.getScoreTime() ⇒
Promise.<number>
-
.getScoreOffsetSeconds() ⇒
Promise.<number>
-
.setScoreOffsetSeconds(time) ⇒
Promise.<number>
-
.rewindScore() ⇒
Promise.<number>
-
.tableLength(tableNum) ⇒
Promise.<number>
-
.tableGet(tableNum, tableIndex) ⇒
Promise.<number>
-
.tableSet(tableNum, tableIndex, value) ⇒
Promise.<undefined>
-
.tableCopyIn(tableNum, tableIndex, array) ⇒
Promise.<undefined>
-
.tableCopyOut(tableNum) ⇒
Promise.<(Float64Array|undefined)>
-
.getTableArgs(tableNum) ⇒
Promise.<(Float64Array|undefined)>
-
.isNamedGEN(tableNum) ⇒
Promise.<number>
-
.getNamedGEN(tableNum) ⇒
Promise.<(string|undefined)>
-
.fs :
-
global
Promise.<(Float64Array|undefined)>
CsoundObjgetTable(tableNum) ⇒ Kind: global method of CsoundObj
Param | Type |
---|---|
tableNum | string |
IFs:memfs
CsoundObj.fs : The in-browser filesystem based on nodejs's built-in module "fs"
Kind: static property of CsoundObj
Array.<string>
CsoundObj.eventNames() ⇒ Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings.
Kind: static method of CsoundObj
number
CsoundObj.listenerCount() ⇒ Returns the number of listeners listening to the event named eventName.
Kind: static method of CsoundObj
Array.<function()>
CsoundObj.listeners(eventName) ⇒ Returns a copy of the array of listeners for the event named eventName.
Kind: static method of CsoundObj
Param | Type |
---|---|
eventName | PublicEvents |
external:EventEmitter
CsoundObj.off(eventName, listener) ⇒ Alias for removeListener()
Kind: static method of CsoundObj
Param | Type |
---|---|
eventName | PublicEvents |
listener | function |
external:EventEmitter
CsoundObj.on(eventName, listener) ⇒ Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.
Kind: static method of CsoundObj
Param | Type |
---|---|
eventName | PublicEvents |
listener | function |
external:EventEmitter
CsoundObj.addListener(eventName, listener) ⇒ Alias for "on"
Kind: static method of CsoundObj
Param | Type |
---|---|
eventName | PublicEvents |
listener | function |
external:EventEmitter
CsoundObj.once(eventName, listener) ⇒ Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.
Kind: static method of CsoundObj
Param | Type |
---|---|
eventName | PublicEvents |
listener | function |
external:EventEmitter
CsoundObj.removeAllListeners(eventName) ⇒ Removes all listeners, or those of the specified eventName. It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module. Returns a reference to the EventEmitter, so that calls can be chained.
Kind: static method of CsoundObj
Param | Type |
---|---|
eventName | PublicEvents |
external:EventEmitter
CsoundObj.removeListener(eventName, listener) ⇒ Removes the specified listener from the listener array for the event named eventName. removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance. Removes the specified listener from the listener array for the event named eventName.
Kind: static method of CsoundObj
Param | Type |
---|---|
eventName | PublicEvents |
listener | function |
Promise.<number>
CsoundObj.getSr() ⇒ Returns the sample rate from Csound instance
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getKr() ⇒ Returns the control rate from Csound instance
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getKsmps() ⇒ Returns the ksmps value (kr/sr) from Csound instance
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getNchnls() ⇒ Returns the number of output channels from Csound instance
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getNchnlsInput() ⇒ Returns the number of input channels from Csound instance
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.get0dBFS() ⇒ Returns the value of csoundGet0dBFS
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getA4() ⇒ Returns the A4 frequency reference
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getCurrentTimeSamples() ⇒ Return the current performance time in samples
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getSizeOfMYFLT() ⇒ Return the size of MYFLT in number of bytes
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.setOption(option) ⇒ Set a single csound option (flag), no spaces are allowed in the string.
Kind: static method of CsoundObj
Param | Type |
---|---|
option | string |
Promise.<undefined>
CsoundObj.setParams(csoundParams) ⇒ Configure Csound with a given set of parameters defined in the CSOUND_PARAMS structure. These parameters are the part of the OPARMS struct that are configurable through command line flags. The CSOUND_PARAMS structure can be obtained using csoundGetParams(). These options should only be changed before performance has started.
Kind: static method of CsoundObj
Param | Type | Description |
---|---|---|
csoundParams | CSOUND_PARAMS |
csoundParams object |
Promise.<CSOUND_PARAMS>
CsoundObj.getParams() ⇒ Get the current set of parameters from a Csound instance in a CSOUND_PARAMS structure.
Kind: static method of CsoundObj
Returns: Promise.<CSOUND_PARAMS>
- - CSOUND_PARAMS object
Promise.<number>
CsoundObj.getDebug() ⇒ Returns whether Csound is set to print debug messages sent through the DebugMsg() internal API function. Anything different to 0 means true.
Kind: static method of CsoundObj
Promise.<undefined>
CsoundObj.setDebug(debug) ⇒ Return the size of MYFLT in number of bytes
Kind: static method of CsoundObj
Param | Type |
---|---|
debug | number |
Promise.<number>
CsoundObj.inputMessage(scoreEvent) ⇒ Inputs an immediate score event without any pre-process parsing
Kind: static method of CsoundObj
Param | Type |
---|---|
scoreEvent | string |
Promise.<number>
CsoundObj.inputMessageAsync(scoreEvent) ⇒ Inputs an immediate score event without any pre-process parsing
Kind: static method of CsoundObj
Param | Type |
---|---|
scoreEvent | string |
Promise.<undefined>
CsoundObj.getControlChannel(channelName) ⇒ Retrieves the value of control channel identified by channelName. If the err argument is not NULL, the error (or success) code finding or accessing the channel is stored in it.
Kind: static method of CsoundObj
Param | Type |
---|---|
channelName | string |
Promise.<undefined>
CsoundObj.setControlChannel(channelName, value) ⇒ Sets the value of control channel identified by channelName
Kind: static method of CsoundObj
Param | Type |
---|---|
channelName | string |
value | number |
Promise.<undefined>
CsoundObj.getStringChannel(channelName) ⇒ Retrieves the string channel identified by channelName
Kind: static method of CsoundObj
Param | Type |
---|---|
channelName | string |
Promise.<undefined>
CsoundObj.setStringChannel(channelName, value) ⇒ Sets the string channel value identified by channelName
Kind: static method of CsoundObj
Param | Type |
---|---|
channelName | string |
value | string |
Promise.<string>
CsoundObj.getOutputName() ⇒ Returns the audio output name (-o)
Kind: static method of CsoundObj
Promise.<string>
CsoundObj.getInputName() ⇒ Returns the audio input name (-i)
Kind: static method of CsoundObj
Promise.<undefined>
CsoundObj.destroy() ⇒ Destroys an instance of Csound and frees memory
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getAPIVersion() ⇒ Returns the API version as int
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getVersion() ⇒ Returns the Csound version as int
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.initialize() ⇒ Initialise Csound with specific flags. This function is called internally by csoundCreate(), so there is generally no need to use it explicitly unless you need to avoid default initilization that sets signal handlers and atexit() callbacks.
Kind: static method of CsoundObj
Returns: Promise.<number>
- - Return value is zero on success,
positive if initialisation was done already, and negative on error.
Promise.<object>
CsoundObj.parseOrc(orc) ⇒ Parses a csound orchestra string
Kind: static method of CsoundObj
Param | Type |
---|---|
orc | string |
Promise.<number>
CsoundObj.compileTree(tree) ⇒ Compiles AST tree
Kind: static method of CsoundObj
Param | Type |
---|---|
tree | object |
Promise.<number>
CsoundObj.compileOrc(orc) ⇒ Compiles a csound orchestra string
Kind: static method of CsoundObj
Param | Type |
---|---|
orc | string |
Promise.<number>
CsoundObj.evalCode(orc) ⇒ Compiles a csound orchestra string
Kind: static method of CsoundObj
Param | Type |
---|---|
orc | string |
Promise.<number>
CsoundObj.start() ⇒ Prepares Csound for performance
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.compileCsd(path) ⇒ Compiles a Csound input file but does not perform it.
Kind: static method of CsoundObj
Param | Type |
---|---|
path | string |
Promise.<number>
CsoundObj.compileCsdText(orc) ⇒ Compiles a CSD string but does not perform it.
Kind: static method of CsoundObj
Param | Type |
---|---|
orc | string |
Promise.<number>
CsoundObj.perform() ⇒ Performs(plays) audio until end is reached
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.performKsmps() ⇒ Performs(plays) 1 ksmps worth of sample(s)
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.performBuffer() ⇒ Performs(plays) 1 buffer worth of audio
Kind: static method of CsoundObj
Promise.<undefined>
CsoundObj.stop() ⇒ Stops a csoundPerform
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.cleanup() ⇒ Prints information about the end of a performance, and closes audio and MIDI devices.
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.reset() ⇒ Prints information about the end of a performance, and closes audio and MIDI devices.
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getInputBufferSize() ⇒ Returns the number of samples in Csound's input buffer.
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getOutputBufferSize() ⇒ Returns the number of samples in Csound's output buffer.
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getInputBuffer() ⇒ Returns the address of the Csound audio input buffer.
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getOutputBuffer() ⇒ Returns the address of the Csound audio output buffer.
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getSpin() ⇒ Returns the address of the Csound audio input working buffer (spin). Enables external software to write audio into Csound before calling csoundPerformKsmps.
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getSpout() ⇒ Returns the address of the Csound audio output working buffer (spout). Enables external software to read audio from Csound after calling csoundPerformKsmps.
Kind: static method of CsoundObj
Promise.<CS_MIDIDEVICE>
CsoundObj.getMIDIDevList(isOutput) ⇒ This function can be called to obtain a list of available input or output midi devices. If list is NULL, the function will only return the number of devices (isOutput=1 for out devices, 0 for in devices).
Kind: static method of CsoundObj
Param | Type |
---|---|
isOutput | number |
Promise.<string>
CsoundObj.getRtMidiName() ⇒ This function can be called to obtain a list of available input or output midi devices. If list is NULL, the function will only return the number of devices (isOutput=1 for out devices, 0 for in devices).
Kind: static method of CsoundObj
Promise.<void>
CsoundObj.midiMessage(midi, midi, midi) ⇒ Emit a midi message with a given triplet of values in the range of 0 to 127.
Kind: static method of CsoundObj
Param | Type | Description |
---|---|---|
midi | number |
status value |
midi | number |
data1 |
midi | number |
data2 |
Promise.<number>
CsoundObj.isScorePending() ⇒ Sees whether Csound score events are performed or not, independently of real-time MIDI events
Kind: static method of CsoundObj
Promise.<undefined>
CsoundObj.setScorePending(pending) ⇒ Sets whether Csound score events are performed or not (real-time events will continue to be performed). Can be used by external software, such as a VST host, to turn off performance of score events (while continuing to perform real-time events), for example to mute a Csound score while working on other tracks of a piece, or to play the Csound instruments live.
Kind: static method of CsoundObj
Param | Type |
---|---|
pending | number |
Promise.<undefined>
CsoundObj.readScore(score) ⇒ Read, preprocess, and load a score from an ASCII string It can be called repeatedly, with the new score events being added to the currently scheduled ones.
Kind: static method of CsoundObj
Param | Type |
---|---|
score | string |
Promise.<number>
CsoundObj.getScoreTime() ⇒ Returns the current score time in seconds since the beginning of performance.
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.getScoreOffsetSeconds() ⇒ Returns the score time beginning at which score events will actually immediately be performed
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.setScoreOffsetSeconds(time) ⇒ Csound score events prior to the specified time are not performed, and performance begins immediately at the specified time (real-time events will continue to be performed as they are received). Can be used by external software, such as a VST host, to begin score performance midway through a Csound score, for example to repeat a loop in a sequencer, or to synchronize other events with the Csound score.
Kind: static method of CsoundObj
Param | Type |
---|---|
time | number |
Promise.<number>
CsoundObj.rewindScore() ⇒ Rewinds a compiled Csound score to the time specified with csoundObj.setScoreOffsetSeconds().
Kind: static method of CsoundObj
Promise.<number>
CsoundObj.tableLength(tableNum) ⇒ Returns the length of a function table (not including the guard point), or -1 if the table does not exist.
Kind: static method of CsoundObj
Param | Type |
---|---|
tableNum | string |
Promise.<number>
CsoundObj.tableGet(tableNum, tableIndex) ⇒ Returns the value of a slot in a function table. The table number and index are assumed to be valid.
Kind: static method of CsoundObj
Param | Type |
---|---|
tableNum | string |
tableIndex | string |
Promise.<undefined>
CsoundObj.tableSet(tableNum, tableIndex, value) ⇒ Sets the value of a slot in a function table. The table number and index are assumed to be valid.
Kind: static method of CsoundObj
Param | Type |
---|---|
tableNum | string |
tableIndex | string |
value | string |
Promise.<undefined>
CsoundObj.tableCopyIn(tableNum, tableIndex, array) ⇒ Copy the contents of an Array or TypedArray from javascript into a given csound function table. The table number is assumed to be valid, and the table needs to have sufficient space to receive all the array contents. The table number and index are assumed to be valid.
Kind: static method of CsoundObj
Param | Type |
---|---|
tableNum | string |
tableIndex | string |
array |
Array.<number> | ArrayLike.<number>
|
Promise.<(Float64Array|undefined)>
CsoundObj.tableCopyOut(tableNum) ⇒ Copies the contents of a function table from csound into Float64Array. The function returns a Float64Array if the table exists, otherwise it returns undefined.
Kind: static method of CsoundObj
Param | Type |
---|---|
tableNum | string |
Promise.<(Float64Array|undefined)>
CsoundObj.getTableArgs(tableNum) ⇒ Copies the contents of a function table from csound into Float64Array. The function returns a Float64Array if the table exists, otherwise it returns undefined.
Kind: static method of CsoundObj
Param | Type |
---|---|
tableNum | string |
Promise.<number>
CsoundObj.isNamedGEN(tableNum) ⇒ Checks if a given GEN number num is a named GEN if so, it returns the string length (excluding terminating NULL char). Otherwise it returns 0.
Kind: static method of CsoundObj
Param | Type |
---|---|
tableNum | string |
Promise.<(string|undefined)>
CsoundObj.getNamedGEN(tableNum) ⇒ Gets the GEN name from a number num, if this is a named GEN. If the table number doesn't represent a named GEN, it will return undefined.
Kind: static method of CsoundObj
Param | Type |
---|---|
tableNum | string |
enum
PublicEvents : Kind: global enum
Read only: true
Properties
Name | Type | Description |
---|---|---|
"play" | string |
called anytime performance goes from pause/stop to a running state. |
"pause" | string |
called after any successful csound.pause() calls. |
"stop" | string |
called after end of performance or after a successful csound.stop(). |
"realtimePerformanceStarted" | string |
called at the start of realtime performance but not on resume or render. |
"realtimePerformancePaused" | string |
only called if csound.pause() was successfully called during performance. |
"realtimePerformanceResumed" | string |
only called if csound.resume() was successfully called after a pause. |
"realtimePerformanceEnded" | string |
called after end of performance or after a successful csound.stop(). |
"renderStarted" | string |
called at the start of offline/non-realtime render to disk. |
"renderEnded" | string |
called at the end of offline/non-realtime render to disk. |
"onAudioNodeCreated" | string |
called when an audioNode is created from the AudioContext before realtime performance. the event callback will include the audioNode itself, which is needed if autoConnect is set to false. |
"message" | string |
the main entrypoint to csound's messaging (-m) system, a default event listener will print the message to the browser console, this default listener can be removed by the user. |
Promise.<(CsoundObj|undefined)>
Csound([params]) ⇒ The default entry for @csound/wasm/browser module. If loaded successfully, it returns CsoundObj, otherwise undefined.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
[params] | Object |
Initialization parameters | |
[params.audioContext] | AudioContext |
Optional AudioContext to use; if none given, an AudioContext will be created. | |
[params.inputChannelCount] | Number |
Optional input channel count for AudioNode used with WebAudio graph. Defaults to the value of nchnls_i in useWorker but 2 otherwise. | |
[params.outputChannelCount] | Number |
Optional output channel count AudioNode used with WebAudio graph. Defaults to the value of nchnls in useWorker but 2 otherwise. | |
[params.autoConnect] | Boolean |
true |
Set to configure Csound to automatically connect to the audioContext.destination output. |
[params.withPlugins] | Array.<Object> |
Array of WebAssembly Csound plugin libraries to use with Csound. | |
[params.useWorker] | Boolean |
false |
Configure to use backend using Web Workers to run Csound in a thread separate from audio callback. |
[params.useSAB] | Boolean |
true |
Configure to use SharedArrayBuffers for WebWorker communications if platform supports it. |
[params.useSPN] | Boolean |
false |
Configure to use explicitly request ScriptProcessorNode rather than AudioWorklet. Recommended only for debug testing purposes. |
CSOUND_PARAMS
Kind: global typedef
Properties
Name | Type |
---|---|
debug_mode | number |
buffer_frames | number |
hardware_buffer_frames | number |
displays | number |
ascii_graphs | number |
postscript_graphs | number |
message_level | number |
tempo | number |
ring_bell | number |
use_cscore | number |
terminate_on_midi | number |
heartbeat | number |
defer_gen01_load | number |
midi_key | number |
midi_key_cps | number |
midi_key_oct | number |
midi_key_pch | number |
midi_velocity | number |
CS_MIDIDEVICE
Kind: global typedef
Properties
Name | Type |
---|---|
device_name | string |
interface_name | string |
device_id | string |
midi_module | string |
isOutput | number |