-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,44 @@ | ||
# Action events | ||
|
||
Action events trigger Python functions. | ||
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: | ||
|
||
```python | ||
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](note.md) 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: | ||
|
||
```python | ||
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](/patterns/#globals) variables: | ||
|
||
```python | ||
def set_key(k): | ||
iso.Globals.set("key", iso.Key(key)) | ||
|
||
timeline.schedule({ | ||
"action": set_key, | ||
"args": { | ||
"k": iso.PWhite(8) | ||
}, | ||
"duration": 4 | ||
}) | ||
timeline.schedule({ | ||
"degree": 0, | ||
"key": iso.PGlobals("key"), | ||
"octave": 4 | ||
}) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters