User-defined Functions
|
|---|
Declares a function. |
|
|---|
Calls a previously declared function |
Remarks
The function has to be declared before it is called.
Empty parentheses can be optionally used when declaring and calling the function.
Function arguments and return values are not supported. However, any variable assignments prior to function call can be used to emulate function arguments, and any variable used within a function can of course be used later as if it were a return value. In this case it is advised to add comments to the code to explain the intent.
Examples
on init
declare $root_note := 60
declare ui_button $button_1
declare ui_button $button_2
declare ui_button $button_3
set_text($button_1, "Play C Major")
set_text($button_2, "Play F# Major")
set_text($button_3, "Play C7 (b9, #11)")
end on
function func_play_triad()
play_note($root_note, 100, 0, 300000)
play_note($root_note + 4, 100, 0, 300000)
play_note($root_note + 7, 100, 0, 300000)
end function
on ui_control ($button_1)
$root_note := 60
call func_play_triad()
$button_1 := 0
end on
on ui_control ($button_2)
$root_note := 66
call func_play_triad()
$button_2 := 0
end on
on ui_control ($button_3)
$root_note := 60
call func_play_triad()
$root_note := 66
call func_play_triad()
$button_3 := 0
end on
Jazz Harmony 101.