ckv blog: Clock, and huge documentation update

Posted February 15, 2010

A beat isn't really a unit of time. Although beat = second / 2 is good enough for lots of electronic music, for any music where the tempo will change over time, yield(beat) is insufficient because threads will get out of sync if beat ever changes unless great care is taken.

This was the motivation for introducing Clock objects to ckv. Clocks allow you to use musically meaningful units when yielding time, and won't let threads get out of sync when you change a beat's duration. Here's an example:

clock = Clock(300)

fork(function()
  while sync(1, clock) do
    local n = Noise()
    c(n, speaker)
    yield(100 * ms)
    disconnect(n, speaker)
  end
end)

clock_mod = SinOsc(0.1)
c(clock_mod, blackhole)

while true do
  clock.bpm = clock_mod.last * 90 + 100
  print("bpm:", clock.bpm)
  yield(100 * ms)
end

now, yield, and sync have been updated to work with clocks by taking one as the last argument.

… which you would know if you had checked out the just-updated Language Reference page (formerly "ugen Reference"), which now documents ugens, events, clocks, forking, the global namespace, and more. Check it out, it's so long.

You can e-mail comments to tom@alltom.com


Home