@csound/browser
TypeScript icon, indicating that this package has built-in type declarations

6.18.7 • Public • Published

@csound/browser

npm (scoped with tag) GitHub Workflow Status styled with prettier

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

CSOUND_PARAMS
CS_MIDIDEVICE

CsoundObj : object

CsoundObj API.

Kind: global namespace

CsoundObjgetTable(tableNum) ⇒ Promise.<(Float64Array|undefined)>

Kind: global method of CsoundObj

Param Type
tableNum string

CsoundObj.fs : IFs:memfs

The in-browser filesystem based on nodejs's built-in module "fs"

Kind: static property of CsoundObj

CsoundObj.eventNames() ⇒ Array.<string>

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

CsoundObj.listenerCount() ⇒ number

Returns the number of listeners listening to the event named eventName.

Kind: static method of CsoundObj

CsoundObj.listeners(eventName) ⇒ Array.<function()>

Returns a copy of the array of listeners for the event named eventName.

Kind: static method of CsoundObj

Param Type
eventName PublicEvents

CsoundObj.off(eventName, listener) ⇒ external:EventEmitter

Alias for removeListener()

Kind: static method of CsoundObj

Param Type
eventName PublicEvents
listener function

CsoundObj.on(eventName, listener) ⇒ external:EventEmitter

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

CsoundObj.addListener(eventName, listener) ⇒ external:EventEmitter

Alias for "on"

Kind: static method of CsoundObj

Param Type
eventName PublicEvents
listener function

CsoundObj.once(eventName, listener) ⇒ external:EventEmitter

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

CsoundObj.removeAllListeners(eventName) ⇒ external:EventEmitter

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

CsoundObj.removeListener(eventName, listener) ⇒ external:EventEmitter

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

CsoundObj.getSr() ⇒ Promise.<number>

Returns the sample rate from Csound instance

Kind: static method of CsoundObj

CsoundObj.getKr() ⇒ Promise.<number>

Returns the control rate from Csound instance

Kind: static method of CsoundObj

CsoundObj.getKsmps() ⇒ Promise.<number>

Returns the ksmps value (kr/sr) from Csound instance

Kind: static method of CsoundObj

CsoundObj.getNchnls() ⇒ Promise.<number>

Returns the number of output channels from Csound instance

Kind: static method of CsoundObj

CsoundObj.getNchnlsInput() ⇒ Promise.<number>

Returns the number of input channels from Csound instance

Kind: static method of CsoundObj

CsoundObj.get0dBFS() ⇒ Promise.<number>

Returns the value of csoundGet0dBFS

Kind: static method of CsoundObj

CsoundObj.getA4() ⇒ Promise.<number>

Returns the A4 frequency reference

Kind: static method of CsoundObj

CsoundObj.getCurrentTimeSamples() ⇒ Promise.<number>

Return the current performance time in samples

Kind: static method of CsoundObj

CsoundObj.getSizeOfMYFLT() ⇒ Promise.<number>

Return the size of MYFLT in number of bytes

Kind: static method of CsoundObj

CsoundObj.setOption(option) ⇒ Promise.<number>

Set a single csound option (flag), no spaces are allowed in the string.

Kind: static method of CsoundObj

Param Type
option string

CsoundObj.setParams(csoundParams) ⇒ Promise.<undefined>

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

CsoundObj.getParams() ⇒ Promise.<CSOUND_PARAMS>

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

CsoundObj.getDebug() ⇒ Promise.<number>

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

CsoundObj.setDebug(debug) ⇒ Promise.<undefined>

Return the size of MYFLT in number of bytes

Kind: static method of CsoundObj

Param Type
debug number

CsoundObj.inputMessage(scoreEvent) ⇒ Promise.<number>

Inputs an immediate score event without any pre-process parsing

Kind: static method of CsoundObj

Param Type
scoreEvent string

CsoundObj.inputMessageAsync(scoreEvent) ⇒ Promise.<number>

Inputs an immediate score event without any pre-process parsing

Kind: static method of CsoundObj

Param Type
scoreEvent string

CsoundObj.getControlChannel(channelName) ⇒ Promise.<undefined>

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

CsoundObj.setControlChannel(channelName, value) ⇒ Promise.<undefined>

Sets the value of control channel identified by channelName

Kind: static method of CsoundObj

Param Type
channelName string
value number

CsoundObj.getStringChannel(channelName) ⇒ Promise.<undefined>

Retrieves the string channel identified by channelName

Kind: static method of CsoundObj

Param Type
channelName string

CsoundObj.setStringChannel(channelName, value) ⇒ Promise.<undefined>

Sets the string channel value identified by channelName

Kind: static method of CsoundObj

Param Type
channelName string
value string

CsoundObj.getOutputName() ⇒ Promise.<string>

Returns the audio output name (-o)

Kind: static method of CsoundObj

CsoundObj.getInputName() ⇒ Promise.<string>

Returns the audio input name (-i)

Kind: static method of CsoundObj

CsoundObj.destroy() ⇒ Promise.<undefined>

Destroys an instance of Csound and frees memory

Kind: static method of CsoundObj

CsoundObj.getAPIVersion() ⇒ Promise.<number>

Returns the API version as int

Kind: static method of CsoundObj

CsoundObj.getVersion() ⇒ Promise.<number>

Returns the Csound version as int

Kind: static method of CsoundObj

CsoundObj.initialize() ⇒ Promise.<number>

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.

CsoundObj.parseOrc(orc) ⇒ Promise.<object>

Parses a csound orchestra string

Kind: static method of CsoundObj

Param Type
orc string

CsoundObj.compileTree(tree) ⇒ Promise.<number>

Compiles AST tree

Kind: static method of CsoundObj

Param Type
tree object

CsoundObj.compileOrc(orc) ⇒ Promise.<number>

Compiles a csound orchestra string

Kind: static method of CsoundObj

Param Type
orc string

CsoundObj.evalCode(orc) ⇒ Promise.<number>

Compiles a csound orchestra string

Kind: static method of CsoundObj

Param Type
orc string

CsoundObj.start() ⇒ Promise.<number>

Prepares Csound for performance

Kind: static method of CsoundObj

CsoundObj.compileCsd(path) ⇒ Promise.<number>

Compiles a Csound input file but does not perform it.

Kind: static method of CsoundObj

Param Type
path string

CsoundObj.compileCsdText(orc) ⇒ Promise.<number>

Compiles a CSD string but does not perform it.

Kind: static method of CsoundObj

Param Type
orc string

CsoundObj.perform() ⇒ Promise.<number>

Performs(plays) audio until end is reached

Kind: static method of CsoundObj

CsoundObj.performKsmps() ⇒ Promise.<number>

Performs(plays) 1 ksmps worth of sample(s)

Kind: static method of CsoundObj

CsoundObj.performBuffer() ⇒ Promise.<number>

Performs(plays) 1 buffer worth of audio

Kind: static method of CsoundObj

CsoundObj.stop() ⇒ Promise.<undefined>

Stops a csoundPerform

Kind: static method of CsoundObj

CsoundObj.cleanup() ⇒ Promise.<number>

Prints information about the end of a performance, and closes audio and MIDI devices.

Kind: static method of CsoundObj

CsoundObj.reset() ⇒ Promise.<number>

Prints information about the end of a performance, and closes audio and MIDI devices.

Kind: static method of CsoundObj

CsoundObj.getInputBufferSize() ⇒ Promise.<number>

Returns the number of samples in Csound's input buffer.

Kind: static method of CsoundObj

CsoundObj.getOutputBufferSize() ⇒ Promise.<number>

Returns the number of samples in Csound's output buffer.

Kind: static method of CsoundObj

CsoundObj.getInputBuffer() ⇒ Promise.<number>

Returns the address of the Csound audio input buffer.

Kind: static method of CsoundObj

CsoundObj.getOutputBuffer() ⇒ Promise.<number>

Returns the address of the Csound audio output buffer.

Kind: static method of CsoundObj

CsoundObj.getSpin() ⇒ Promise.<number>

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

CsoundObj.getSpout() ⇒ Promise.<number>

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

CsoundObj.getMIDIDevList(isOutput) ⇒ Promise.<CS_MIDIDEVICE>

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

CsoundObj.getRtMidiName() ⇒ Promise.<string>

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

CsoundObj.midiMessage(midi, midi, midi) ⇒ Promise.<void>

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

CsoundObj.isScorePending() ⇒ Promise.<number>

Sees whether Csound score events are performed or not, independently of real-time MIDI events

Kind: static method of CsoundObj

CsoundObj.setScorePending(pending) ⇒ Promise.<undefined>

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

CsoundObj.readScore(score) ⇒ Promise.<undefined>

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

CsoundObj.getScoreTime() ⇒ Promise.<number>

Returns the current score time in seconds since the beginning of performance.

Kind: static method of CsoundObj

CsoundObj.getScoreOffsetSeconds() ⇒ Promise.<number>

Returns the score time beginning at which score events will actually immediately be performed

Kind: static method of CsoundObj

CsoundObj.setScoreOffsetSeconds(time) ⇒ Promise.<number>

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

CsoundObj.rewindScore() ⇒ Promise.<number>

Rewinds a compiled Csound score to the time specified with csoundObj.setScoreOffsetSeconds().

Kind: static method of CsoundObj

CsoundObj.tableLength(tableNum) ⇒ Promise.<number>

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

CsoundObj.tableGet(tableNum, tableIndex) ⇒ Promise.<number>

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

CsoundObj.tableSet(tableNum, tableIndex, value) ⇒ Promise.<undefined>

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

CsoundObj.tableCopyIn(tableNum, tableIndex, array) ⇒ Promise.<undefined>

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>

CsoundObj.tableCopyOut(tableNum) ⇒ Promise.<(Float64Array|undefined)>

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

CsoundObj.getTableArgs(tableNum) ⇒ Promise.<(Float64Array|undefined)>

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

CsoundObj.isNamedGEN(tableNum) ⇒ Promise.<number>

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

CsoundObj.getNamedGEN(tableNum) ⇒ Promise.<(string|undefined)>

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

PublicEvents : enum

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.

Csound([params]) ⇒ Promise.<(CsoundObj|undefined)>

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

Package Sidebar

Install

npm i @csound/browser

Weekly Downloads

1,398

Version

6.18.7

License

LGPL-2.1

Unpacked Size

9.02 MB

Total Files

71

Last publish

Collaborators

  • skyne
  • kunstmusik
  • eddyc
  • hlolli