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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

clockblocks-0.5.3-py3-none-any.whl (58.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clockblocks-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 58.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.2

File hashes

Hashes for clockblocks-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c1d3a63e43b56c58448ff56757298431f60189d8dc0405f47f1d3dcf86d96160
MD5 85f7333e2b7ff5a4191058da49aa0155
BLAKE2b-256 1101d11baa6e9bf4feb2c7a7e0b2e52026970bf6dda29f782edc754d20829771

See more details on using hashes here.

Supported by

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