Scripter Javascript Tutorial
javascriptmusiclogicscripterbookexcerpttutorial55 JSON
A very useful technique for debugging is to use JSON (JavaScript
Object Notation), which is a text-based format to represent an object’s
contents. This is particularly useful for interrogating events passed
into the HandleMIDI()
function:
function HandleMIDI(event) {
var json = JSON.stringify(event);
Trace(json);
}
In the above example:
Line 1: An event is passed to the
HandleMIDI()
function, in this example the event will beNoteOn
.Line 2: To get the JSON representation of the object,
JSON.stringify()
is called with the event passed to it. This function returns a string containing the complete JSON.Line 3: The string is output to the console, resulting in the following:
"detune":0,"pitch":61,"velocity":100,"status":144,"isRealtime":false,"data1":61,"data3":0,"data2":100,"channel":1,"port":1,"articulationID":0,"beatPos":0} {