Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

61 The if...else statement

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

The if...else statement accommodates handling code to execute when a condition is either true or false. The syntax is very similar:

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

In the above example:

if...else workflow.

To expand upon the example in HandleMIDI(), because there are many types of events:

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

In the above example, the following is happening:

if...else workflow.

For a simple track with one note, the following is output to the console:

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

Evaluating MIDI-processing script...
Script evaluated successfully!
NoteOn
[NoteOff channel:1 pitch:61 [C#3] velocity:64]
[ControlChange channel:1 number:120 [All Sound Off] value:0]
>

In the output, note the following: