Javascript support
For language syntax, imports and the different scripting contexts, see JavaScript and QML under Reference → Languages. The complete JavaScript Process API documents ports, callbacks, timing, persistent state and example programs.
Scripting in Javascript / QML.
score allows to write scripts using the JavaScript language. These scripts can be used to write specific processes such as value mappers, audio generators.
score executes JavaScript through Qt’s QML engine. Language and Qt module availability follow the Qt version bundled with the application; this is not a browser or Node.js environment. See the JavaScript reference for language concepts.
QML is Qt’s declarative object language with embedded JavaScript expressions and functions. Its object declarations and properties (property real, etc.) are not ordinary JavaScript syntax. See the language overview for the distinction and upstream language references.
Enter QML code or a source-file path in the Javascript code editor. File-backed scripts keep their source location so that relative imports, images and companion UIs resolve correctly.
JS can be used as a process both for intervals, and in states.
- To add a JS process to an interval, simply drag’n’drop it from the Process Library to the interval.
- To add a JS process to a state, right-click on the state in the Object Explorer, and choose “Add Process”.
JS can also be used for generative graphics with Qt Quick. See the graphics examples; connect the texture outlet to a graphical output before playing.
Editing code
The editor validates QML before applying it to the process. Resolve reported compilation errors before expecting the new program or its ports to be used; keep substantial code in an external source file as well as in the document.
Files, relative resources and presets
The source location (rootPath internally) supplies a QML base URL, not a new JavaScript filesystem global. Use Qt.resolvedUrl("image.png") and relative imports next to the source file. The companion name.ui.qml supplies a ScriptUI for name.qml; see the custom UI API.
Source files are watched. If a saved/edited program differs from its external source, the inspector can offer an Update action rather than silently discarding the document’s copy. An unreadable source does not replace the saved program with empty text. See source update notices. When moving projects, retain the source’s neighboring assets and imported modules.
JavaScript presets include program code, companion UI and persisted script state. Plain temporary QML properties are not automatically saved as document state: see the persistent state callbacks.
Execution and build limitations
Declare the ports and controls required by the process, then apply the code and connect its inlets and outlets to other processes or device addresses. The port reference covers messages, audio, MIDI, controls and textures.
GPU scripts use the graphics execution path; CPU scripts run with execution, not on the GUI thread. Do not open native dialogs or directly edit the document from tick. GPU ports need GPU JavaScript support, and the current WebAssembly build does not insert Javascript processes into the execution graph. See the canonical execution and build limitations.
Language and API reference
The detailed language and API reference is under Reference → Languages. Go directly to a relocated section:
-
General syntax:
import Score, theScriptobject and execution callbacks. -
Available functions:
Device.readandDevice.write. - Token object: model, physical and musical timing.
- Token properties.
- Token methods.
- State object: execution environment and audio-buffer timing.
- Execution state properties.
- Example of a value mapper.
- Example of an audio generator.
- Example of a MIDI transposer.
- Port types.
- Properties common to all ports.
- Audio ports.
- Example of fetching various timings.
- MIDI ports.
- Message ports.
- Controls.
- Generative graphics: texture output, reactive bindings and interactive widgets.
- Canvas2D.
- Texture input and render size.