A python library for controlling the flow of musical time.
Project description
clockblocks
clockblocks is a python library for controlling the flow of time, designed with musical applications in mind. In particular, it is a central component of scamp, a Suite for Computer-Assisted Music in Python. It is described in detail in this paper.
A Clock
acts like thread, but with the advantage that when multiple clocks are coordinated under the same master clock they remain precisely coordinated and do not experience drift. Furthermore, processing time is taken into account when "wait" is called in a given Clock. For example, the following program:
import clockblocks import time import math clock = clockblocks.Clock() start = time.time() while True: print("Current time: {}".format(round(time.time() - start, 4))) # do some pointless and time-consuming calculations for i in range(1000000): math.log((i+1)**0.7) clock.wait(2)
... generates the output:
Current time: 0.0 Current time: 2.0001 Current time: 4.0001 Current time: 6.0 Current time: 8.0001 Current time: 10.0
Whereas a traditional thread:
import time import math start = time.time() while True: print("Current time: {}".format(round(time.time() - start, 4))) # do some pointless and time-consuming calculations for i in range(1000000): math.log((i+1)**0.7) time.sleep(2)
...will gradually drift because of the intensive calculations, outputting:
Current time: 0.0 Current time: 2.3772 Current time: 4.7623 Current time: 7.1397 Current time: 9.5151 Current time: 11.893
In addition, clockblocks offers useful musical functionality, like sudden and gradual changes of tempo. Perhaps the most exciting feature of clockblocks is that clocks moving at different tempos can be nested within each other. In this case, each clock distorts time for those underneath it: a clock whose tempo is oscillating between slow and fast, nested within a clock that is accelerating, will generate a time stream whose tempo oscillates faster and faster.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size clockblocks-0.6-py3-none-any.whl (62.9 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Hashes for clockblocks-0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 675841b7fece4d2d999ef2cc37cd7ddba3869b56dc23e7d17698ea9359530ae6 |
|
MD5 | fee2e0a44aeab57a2104a48ce30606b3 |
|
BLAKE2-256 | 7426b1ccc5207e049ba2a32a0eee06014cb777f22829c74bf70084954c35f21a |