Skip to main content

User-defined Functions

function <function-name>()

    <statements>

end function

Declares a function.

call <function-name>

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.

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.