cl-patterns icon indicating copy to clipboard operation
cl-patterns copied to clipboard

:tempo key

Open ntrocado opened this issue 2 years ago • 1 comments

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?

ntrocado avatar Mar 12 '22 12:03 ntrocado

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.

defaultxr avatar Mar 12 '22 21:03 defaultxr