defaultxr / cl-patterns

Library for writing patterns to generate or process (a)musical sequences of mathematically (un)related (non-)compound values in Lisp.
https://w.struct.ws/cl-patterns
MIT License
76 stars 10 forks source link

:tempo key #30

Open ntrocado opened 2 years ago

ntrocado commented 2 years ago

From the documentation on special keys I got the impression that the following should work, but it doesn't:

(pb :foo
  :midinote 60
  :tempo 140/60)

The tempo is unchanged... Having each pb in its own tempo would be great, is it possible?

defaultxr commented 2 years ago

Hmm, it looks like you're right, the :tempo key doesn't actually change the tempo of the clock, despite what the documentation says. I'm currently planning and in the process of reworking the backend and clock parts of the library, and I will probably fix this bug as part of those changes once they're ready. For now I've added a test to the suite to test for this behavior so I don't forget, and I'll also leave this issue open until then.

As for having each pattern in its own tempo, I don't think that would be directly possible, since tempo is a property of the clock, not a property of the pattern. The :tempo key is basically just meant as a possibly-more-convenient way to adjust the tempo from within a pattern, not to specify a per-pattern tempo.

That said, it should be possible to achieve basically the same effect by adjusting the :dur of each pattern. For example, if you want one pattern to play as if it were at 140BPM, regardless of the tempo of the *clock*, you can specify a :dur like the following for its last key:

(pb :foo
  :midinote 60
  :dur (pf (* (freq-dur 140/60)
              (e :dur))))

As long as that :dur is the last duration key in the pb, any previous duration information will be multiplied by the correct amount to "tempo shift" the pattern to the desired tempo, even though the tempo of the clock is not actually changing. It should also remain correct even if you do actually change the tempo of the clock.