Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clockblocks-0.6.10.tar.gz (52.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clockblocks-0.6.10-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

File details

Details for the file clockblocks-0.6.10.tar.gz.

File metadata

  • Download URL: clockblocks-0.6.10.tar.gz
  • Upload date:
  • Size: 52.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for clockblocks-0.6.10.tar.gz
Algorithm Hash digest
SHA256 7baec009d10b144f30576bd725c77a860908c310bf1c394d5afd928fe74fdcd2
MD5 df1f875eddace78174dc0efab6356daf
BLAKE2b-256 76d363fb16225d3a2b45236739b4fd7a0798af8c57e0a554b842158b93edf8ca

See more details on using hashes here.

File details

Details for the file clockblocks-0.6.10-py3-none-any.whl.

File metadata

  • Download URL: clockblocks-0.6.10-py3-none-any.whl
  • Upload date:
  • Size: 54.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for clockblocks-0.6.10-py3-none-any.whl
Algorithm Hash digest
SHA256 44e8588335ca7638a9f113c34da86e7785e07dd89d091a7b8e32db9be5a90856
MD5 f17986d24af1b816ab75bdb82aabd39f
BLAKE2b-256 c332211c3604a436241deb2c4bc73f5491524000d27ba41ac788786c362eb2b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page