The Cabbage JavaScript API provides the communication layer between webview UIs and the Cabbage backend. This API enables bidirectional communication for plugin development.
Use Cabbage.sendControlData() to send widget value changes to the backend. The backend automatically determines routing based on channel automatable status.
The backend sends messages via window.hostMessageCallback(). Implement this global function to handle incoming messages.
Cabbage.sendControlData(data, vscode)Send widget value changes to the Cabbage backend. This is the primary API for user interactions.
Parameters:
data (Object): Control data object
channel (string): The channel namevalue (number |
string): Value in natural range (e.g., 20-20000 Hz for frequency) |
gesture (string, optional): Gesture type - "begin", "value", "end", "complete" (default: "complete")vscode (Object |
null): VS Code API instance (null for plugin mode) |
Behavior:
Examples:
// Basic usage
Cabbage.sendControlData({ channel: "frequency", value: 1000 }, this.vscode);
// With gesture for DAW automation
Cabbage.sendControlData({ channel: "volume", value: 0.8, gesture: "begin" }, this.vscode);
Cabbage.sendControlData({ channel: "volume", value: 0.9, gesture: "value" }, this.vscode);
Cabbage.sendControlData({ channel: "volume", value: 0.9, gesture: "end" }, this.vscode);
Cabbage.sendChannelData(channel, data, vscode)Send channel data directly to Csound without DAW automation - bypasses all widget routing and validation.
Parameters:
channel (string): Csound channel namedata (number |
string): Data to send |
vscode (Object |
null): VS Code API instance |
Notes:
sendControlData() instead for most cases as it will determine the best route for this dataCabbage.sendMidiMessageFromUI(statusByte, dataByte1, dataByte2, vscode)Send MIDI messages from the UI to the backend.
Parameters:
statusByte (number): MIDI status bytedataByte1 (number): First data bytedataByte2 (number): Second data bytevscode (Object |
null): VS Code API instance |
Example:
Cabbage.sendMidiMessageFromUI(144, 60, 100, this.vscode); // Note on
Cabbage.MidiMessageFromHost(statusByte, dataByte1, dataByte2)Handle incoming MIDI messages from the backend (callback function).
Parameters:
statusByte (number): MIDI status bytedataByte1 (number): First data bytedataByte2 (number): Second data byteCabbage.isReadyToLoad(vscode, additionalData)Signal that the UI is ready to load and initialize.
Parameters:
vscode (Object |
null): VS Code API instance |
additionalData (Object, optional): Additional initialization dataCabbage.triggerFileOpenDialog(vscode, channel, options)Trigger a file open dialog for file selection widgets.
Parameters:
vscode (Object |
null): VS Code API instance |
channel (string): Associated channel nameoptions (Object, optional): Dialog options
directory (string): Starting directoryfilters (string): File filtersopenAtLastKnownLocation (boolean): Use last known locationExample:
Cabbage.triggerFileOpenDialog(this.vscode, "audioFile", {
filters: "*.wav;*.aiff",
openAtLastKnownLocation: true
});
Cabbage.openUrl(vscode, url, file)Open a URL or file in the system default application.
Parameters:
vscode (Object |
null): VS Code API instance |
url (string): URL to openfile (string): File path to openCabbage.requestResize(width, height, vscode)Request a resize of the plugin GUI window (plugin mode only).
Parameters:
width (number): Requested width in pixelsheight (number): Requested height in pixelsvscode (Object |
null): VS Code API instance |
Notes:
resizeResponse message indicating acceptance and final dimensionsThese functions are used internally and are not for general use.
Cabbage.sendCustomCommand(command, vscode, additionalData)Send custom commands to the backend for specialized operations.
Parameters:
command (string): Command namevscode (Object |
null): VS Code API instance |
additionalData (Object, optional): Additional data to sendExample:
Cabbage.sendCustomCommand('cabbageIsReadyToLoad', null);
Cabbage.sendWidgetUpdate(widget, vscode)Update widget state in the backend (used by property panel).
Parameters:
widget (Object): Widget configuration objectvscode (Object |
null): VS Code API instance |
Implement window.hostMessageCallback to handle messages from the backend:
window.hostMessageCallback = function(data) {
switch(data.command) {
case "parameterChange":
// DAW automation or backend parameter update
// Update display only - NEVER send back to backend
// updateWidgetDisplay(data.channel, data.value);
break;
case "updateWidget":
// Widget property update from Csound (cabbageSetValue, cabbageSet)
// updateWidget(data.widgetJson);
break;
case "csoundOutputUpdate":
// Csound console output for debugging
console.log("Csound output:", data.text);
break;
case "resizeResponse":
// Response to GUI resize request
if (data.accepted) {
// updateGuiDimensions(data.width, data.height);
} else {
// handleResizeRejected(data.width, data.height);
}
break;
}
};
parameterChangechannel, value, gestureupdateWidgetid, widgetJson, value (optional)csoundOutputUpdatetextresizeResponseaccepted (boolean), width (number), height (number)Use appropriate gestures for proper DAW automation recording:
"begin": Start of user interaction (e.g., mouse down on slider)"value": Continuous updates during interaction (e.g., mouse drag)"end": End of continuous interaction (e.g., mouse up)"complete": Discrete actions (e.g., button clicks, default)When receiving parameterChange messages, only update the visual display. Never send sendControlData() in response, as this creates feedback loops that interfere with DAW automation.
All outgoing functions are asynchronous and thread-safe. They queue messages without blocking the audio thread.
Send values in their natural/meaningful ranges (e.g., 20-20000 Hz for frequency). The backend handles all DAW normalization automatically.
this.vscode as the vscode parameternull for vscode parameter