Skip to content

Action events

Action events trigger Python functions. Set the action property to a function or lambda, and it will be executed at the time of the event:

timeline.schedule({
    "action": lambda: print("Hello world")
})

Observe that, when you run the above, it will print Hello world indefinitely, once per beat. Why is this?

Just as for notes and other event types, the duration parameter of the event template defaults to an infinitely-repeating pattern generated by PConstant. To limit the number of repeats that an action performs, use the count argument:

timeline.schedule({
    "action": lambda: print(round(timeline.current_time))
}, count=4)

Action arguments

For more complex functions, custom named keyword arguments can be passed to the function using the args property

This executes an action every 4 beats to change the global key of the piece, using the Globals variables:

def set_key(k):
    iso.Globals.set("key", iso.Key(k))

timeline.schedule({
    "action": set_key,
    "args": {
        "k": iso.PWhite(8)
    },
    "duration": 4
})
timeline.schedule({
    "degree": 0,
    "key": iso.PGlobals("key"),
    "octave": 4
})