Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

60 The if statement

MDN: Control Flow and Error Handling: if...else statement

The if statement is the simplest of all branching. If a specified condition is true, then do something. The if statement has a very simple syntax:

if ( <condition is true> ) {
	<do something>
}

In the above example:

if statement workflow.

A common example is capturing events passed to HandleMIDI():

function HandleMIDI(event) {
	if (event instanceof NoteOn) {
		Trace(event);
	}
}

In the above example:

if statement HandleMIDI() workflow.

This outputs exactly what would be expected with any MIDI data in the track:

***Creating a new MIDI engine with script***

Evaluating MIDI-processing script...
Script evaluated successfully!
[NoteOn channel:1 pitch:61 [C#3] velocity:100]
>