Module clock
clock coroutines
Functions
| create (f) | create a coroutine to run but do not immediately run it; |
| run (f) | create a coroutine from the given function and immediately run it; the function parameter is a task that will suspend when clock.sleep and clock.sync are called inside it and will wake up again after specified time. |
| cancel (coro_id) | stop execution of a coroutine started using clock.run. |
| sleep (s) | yield and schedule waking up the coroutine in s seconds; must be called from within a coroutine started with clock.run. |
| sync (beats) | yield and schedule waking up the coroutine at beats beat; the coroutine will suspend for the time required to reach the given fraction of a beat; must be called from within a coroutine started with clock.run. |
| suspend () | yield and do not schedule wake up, clock must be explicitly resumed must be called from within a coroutine started with clock.run. |
| set_source (source) | select the sync source |
| get_beats () | get current time in beats |
| get_tempo () | get current tempo |
| get_beat_sec (x) | get current beat time in seconds |
Functions
- create (f)
-
create a coroutine to run but do not immediately run it;
Parameters:
- f function
Returns:
-
integer
: coroutine ID that can be used to resume/stop it later
- run (f)
-
create a coroutine from the given function and immediately run it;
the function parameter is a task that will suspend when clock.sleep and clock.sync are called inside it and will wake up again after specified time.
Parameters:
- f function
Returns:
-
integer
: coroutine ID that can be used to stop it later
- cancel (coro_id)
-
stop execution of a coroutine started using clock.run.
Parameters:
- coro_id integer : coroutine ID
- sleep (s)
-
yield and schedule waking up the coroutine in s seconds;
must be called from within a coroutine started with clock.run.
Parameters:
- s float : seconds
- sync (beats)
-
yield and schedule waking up the coroutine at beats beat;
the coroutine will suspend for the time required to reach the given fraction of a beat;
must be called from within a coroutine started with clock.run.
Parameters:
- beats float : next fraction of a beat at which the coroutine will be resumed. may be larger than 1.
- suspend ()
- yield and do not schedule wake up, clock must be explicitly resumed must be called from within a coroutine started with clock.run.
- set_source (source)
-
select the sync source
Parameters:
- source string : "internal", "midi", or "link"
- get_beats ()
- get current time in beats
- get_tempo ()
- get current tempo
- get_beat_sec (x)
-
get current beat time in seconds
Parameters:
- x