Control Statements
if … else … end if
|
---|
Conditional if statement |
Examples
on controller if (in_range($CC_NUM, 0, 127)) message("CC Number: " & $CC_NUM & " - Value: " & %CC[$CC_NUM]) else if ($CC_NUM = $VCC_PITCH_BEND) message("Pitch Bend - Value: " & %CC[$CC_NUM]) end if if ($CC_NUM = $VCC_MONO_AT) message("Channel Pressure - Value: " & %CC[$CC_NUM]) end if end if end on
Display different text depending on various MIDI controller messages
See Also
select ()
|
---|
Select-case statement |
Remarks
The
select
statement is similar to theif
statement, except that it has an arbitrary number of branches. The expression after theselect
keyword is evaluated and matched against individualcase
branches, the firstcase
branch that matches is executed.The
case
branches may consist of either a single constant number or a number range, expressed by the term "x to y
").While there is no
else
ordefault
case branch in KSP, one can be achieved by usingcase 08000000H to 07FFFFFFFH
, which covers the whole range of 32-bit signed integer values, effectively catching all cases that don't have literally specified branches.
Examples
on controller if ($CC_NUM = $VCC_PITCH_BEND) select (%CC[$VCC_PITCH_BEND]) case -8191 to -1 message("Pitch Bend down") case 0 message("Pitch Bend center") case 1 to 8191 message("Pitch Bend up") case 080000000H to 07FFFFFFH message("We're not sure how you got this Pitch Bend value!") end select end if end on
Query the state of the pitch bend wheel
See Also
while ()
|
---|
While loop |
Examples
on note ignore_event($EVENT_ID) while ($NOTE_HELD = 1) play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, $DURATION_QUARTER / 2) wait($DURATION_QUARTER) end while end on
Repeating held notes at the rate of one quarter note
See Also
Events and MIDI: $NOTE_HELD
Boolean Operators
| Greater than |
| Less than |
| Greater than or equal |
| Less than or equal |
| Equal |
| Not equal |
| True if |
| True if |
| True if |
| True if |
| True only if either |
Remarks
Boolean operators are used in
if
andwhile
statements, since they return if the condition is either true or false. In the list above.x
,y
andz
denote numerals,a
andb
denote Boolean values.