// Reads the entire content of a fileletdata=Util.readFile("/path/to/file.txt");// Layouts a text so that it fits a rect of a given width by // adding line breaks. Naive algorithm.// Arguments are: // - text to lay out// - font to use// - font size// - maximum width in pixelslettext=Util.layoutTextLines("some long text","Monospace",24,100);
Undo-redo and general helpers
// Find an object by nameletobj=Score.find("Interval.foobar");// Get a reference to the object first selected in the scoreletobj=Score.selectedObject();// Get a reference to all the objects currently selected in the scoreletobjs=Score.selectedObjects();// Get a reference to the current root document objectletdoc=Score.document();// Undo-redo:Score.undo();Score.redo();// Undo-redo macros: // this is so that commands that do multiple // changes to the score, e.g. by adding multiple processes,// only show up as one single action in the undo-redo panel.// Every action that changes the score must be between these two calls.Score.startMacro();Score.endMacro();
UI
// This function allows to show a prompt to the user.// The object passed in argument allows to configure the UI to show. // They will be shown as a UI form.// The return value will be the list of values that the user has set on every widget if the prompt was accepted, and 'undefined' otherwise.constres=Score.prompt({title:"Input JSON",widgets:[{name:"Name",type:"lineedit",init:"Hello"},{name:"JSON",type:"textfield"},{name:"Foo",type:"spinbox",min:0,max:100,init:10},{name:"Bar",type:"slider",min:0.5,max:10.2,init:1.0},{name:"Baz",type:"checkbox",init:false}]});// Res could look like: // ["text", "long text", 30, 4.6, true]
Transport
// Plays the scoreScore.play();// Plays a specific objectletan_interval=Score.find("my_interval");Score.play(an_interval);// Stops playbackScore.stop();
Functions operating on devices
// Converts a device tree to JSON. // Useful for e.g. preset snapshotting, sending over the internet...letjson=Score.deviceToJson("deviceName");// Create a WebSocket device from QML code.// See the QML code examples in the library.Score.createQMLWebSocketDevice("name","QML Code");// Create a Serial device from QML code.// See the QML code examples in the library.Score.createQMLSerialDevice("name","/dev/ttyUSB1","QML Code");
Functions operating on the score
// Create a new process in an interval.// The process names are those in the library.// Third argument is reserved for future use.letnew_process=Score.createProcess(an_interval,"Automation (float)",null);// Change the name of an objectScore.setName(an_interval,"Foo");// Create a new free-floating interval // Arguments: // - parent scenario// - At which time the interval is created (e.g. "00:01:15.345" for 1 minute 15 seconds 345 millis)// - How long it lasts (same format)// - Which vertical position (between [0;1] (top;bottom))letnew_itv=Score.createBox(scenar,"00:00:10.000","00:01:15.000",0.2);// Create a new interval after a stateletnew_itv=Score.createIntervalAfter(state,duration,y);// Get a port by name given a processletport=Score.port(my_lfo,"Frequency");// Get an inlet / outlet by index given a process.// Here "port1" would be the "Offset" port of a LFO processletport1=Score.inlet(my_lfo,2);// Here "port2" would be the "Outlet" port of a LFO processletport2=Score.outlet(my_lfo,0);// Returns how many inlets / outlets there are in a given processletcount=Score.inlets(my_lfo);letcount=Score.outlets(my_lfo);// Set the address of a portScore.setAddress(port1,"midi:/1/control/34");// Set the value of a port (only relevant for ports with UI controls)Score.setValue(port1,0.34);Score.setValue(portA,"foo");Score.setValue(portB,true);// etc...// Get the type of a port as a string. Float, Int, String, etc.lettype=Score.valueType(port1);// Get the min/max range of a port if it has oneletmin=Score.min(port1);letmax=Score.max(port1);// Get the list of values if the port is an enum / combo box / chooser ...letvals=Score.enumValues(port1);// Access the metadata object of an object. Allows to see the label, comments, etcletmeta=Score.metadata(scenario);console.log(meta.name,meta.label,meta.comment)// Access the start / end elements of an intervalletst=Score.startState(itv);letst=Score.endState(itv);letev=Score.startEvent(itv);letev=Score.endEvent(itv);letts=Score.startSync(itv);letts=Score.endSync(itv);// Remove an object from the scoreScore.remove(itv);// Create an automation on the given interval from an addressScore.automate(itv,"foo:/bar");// Create an automation on the given interval from a port objectScore.automate(itv,port1);
Functions operating on curves
// Set a curve from a list of points:// [ [ x1, y1 ], [ x2, y2 ], ... ]letpoints=[[0,0.5],[0.2,1.],[0.5,0.9],[1.0,0.0],];Score.setCurvePoints(an_automation_process,points);
Functions operating on step sequencer
// Sets the step on a Step SequencerScore.setSteps(a_step_sequencer_process,[0.1,0,1.,0.4,0.5]);