refactor: replace .cpm with setcpm calls

+ doc setcpm
This commit is contained in:
Felix Roos 2025-06-19 09:09:45 +02:00
parent a8f2537e31
commit 6c4aa12c60
No known key found for this signature in database
12 changed files with 169 additions and 109 deletions

View file

@ -43,21 +43,33 @@ This is why the same CPS can produce different perceived tempos.
## Setting CPM
If you're familiar with BPM, you can use the `cpm` method to set the tempo in cycles per minute:
If you're familiar with BPM, you can use the `setcpm` method to set the global tempo in cycles per minute:
<MiniRepl client:visible tune={`s("bd hh").cpm(110)`} />
<MiniRepl
client:visible
tune={`setcpm(110)
s("bd hh")`}
/>
If you want to add more beats per cycle, you might want to divide the cpm:
<MiniRepl client:visible tune={`s("bd sd bd rim, hh*8").cpm(110/4)`} />
<MiniRepl
client:visible
tune={`setcpm(110/4)
s("bd sd bd rim, hh*8")`}
/>
Or using 2 beats per cycle:
<MiniRepl client:visible tune={`s("bd sd, hh*4").cpm(110/2)`} />
<MiniRepl
client:visible
tune={`setcpm(110/2)
s("bd sd, hh*4")`}
/>
<Box>
To set a specific bpm, use `.cpm(bpm/bpc)`
To set a specific bpm, use `setcpm(bpm/bpc)`
- bpm: the target beats per minute
- bpc: the number of perceived beats per cycle
@ -74,22 +86,31 @@ Many music programs use it as a default.
Strudel does not a have concept of bars or measures, there are only cycles.
How you use them is up to you. Above, we've had this example:
<MiniRepl client:visible tune={`s("bd sd bd rim, hh*8").cpm(110/4)`} />
<MiniRepl
client:visible
tune={`setcpm(110/4)
s("bd sd bd rim, hh*8")`}
/>
This could be interpreted as 4/4 time with a tempo of 110bpm.
We could write out multiple bars like this:
<MiniRepl
client:visible
tune={`s(\`<
tune={`setcpm(110/4)
s(\`<
[bd sd bd rim, hh*8]
[bd sd bd rim*2, hh*8]
>\`).cpm(110/4)`}
>\`)`}
/>
Instead of writing out each bar separately, we could express this much shorter:
<MiniRepl client:visible tune={`s("bd <sd rim*<1 2>>,hh*4").cpm(110/2)`} />
<MiniRepl
client:visible
tune={`setcpm(110/2)
s("bd <sd rim*<1 2>>,hh*4")`}
/>
Here we can see that thinking in cycles rather than bars simplifies things a lot!
These types of simplifications work because of the repetitive nature of rhythm.
@ -109,10 +130,11 @@ We could also write multiple bars with different time signatures:
<MiniRepl
client:visible
tune={`s(\`<
tune={`setcpm(110*2)
s(\`<
[bd hh rim]@3
[bd hh rim sd]@4
>\`).cpm(110*2)`}
>\`)`}
/>
Here we switch between 3/4 and 4/4, keeping the same tempo.
@ -121,10 +143,11 @@ If we don't specify the length, we get what's called a metric modulation:
<MiniRepl
client:visible
tune={`s(\`<
tune={`setcpm(110/2)
s(\`<
[bd hh rim]
[bd hh rim sd]
>\`).cpm(110/2)`}
>\`)`}
/>
Now the 3 elements get the same time as the 4 elements, which is why the tempo changes.