28
Example 5 : using conditional commands
// 'Conditional commands' are another common concept in traditional programming languages:
// 'if...then...else...' statements allow an application to make decisions.
// The examples below show how your setup can behave differently depending on the value
// of any variable.
PRESET Sample =
{
// here $solo is a boolean variable, it can be true or false :
if($solo)
{
// send a set of MIDI messages...
}
else if($currentBank > 1)
{
// send another set of messages...
}
// a 'switch' statement checks the value of a variable
// and specifies the code to be executed for each value :
switch($currentSong)
{
case “No one knows”:
SendMidi MyGear CtrlChange 112 127
break
case “Go with the flow”:
SendMidi MyGear CtrlChange 12 0
SendMidi MyGear CtrlChange 113 127
break
// and so on...
default:
SendMidi MyGear CtrlChange 12 127
break
}
// By using a ‘while’ statement it is even possible to create loops, for instance
// in order to do an effect fade-in/fade-out
$fadeout = 100
$fadein = 0
while($fadeout > 0)
{
SendMidi MyGear CtrlChange 07 $fadeout
SendMidi MyOtherGear CtrlChange 07 $fadein
Wait 1
$fadeout -= 5
$= 5
}
}