b = 2.781 is the duration of the portion to be played. It isn’t the endpoint of the sample. I’m not quite sure where the idea got stubbornly stuck in your head that 2.781 is the endpoint (in fact, the help file gives the endpoint as 3.185917 in the first paragraph).
Pretty much all of your confusion derives from this.
When I wrote this help file originally, I took too many shortcuts in the logic. So, basically, forget the entire discussion in the help file and let’s start completely over from the beginning. 0.3595368 – forget it – even though it’s a valid number, we can arrive at the destination by a clearer path.
So, from the beginning:
We want to play a portion beginning at 0.404561 and ending at 3.185917. Why do we want to play this portion and not some other portion? Because it makes musical sense. There’s nothing special about these numbers – you choose them carefully to get the rhythm you want.
The duration of this section is end - start = 3.185917 - 0.404561 = 2.781356 seconds.
We want to use this section for a complete bar of 4/4 time. Therefore the 2.78xx seconds = 4 beats. Therefore 1 beat = 2.78xx seconds / 4 beats = 0.695339 seconds/beat.
TempoClock expects tempo to be expressed as beats/second. We have seconds/beat. So we need to take the reciprocal. 1 / 0.695339 = 1.438147. (At this point, you might note that 0.3595368 * 4 = 1.438147 – like I said, we end up at the same place, but maybe this route is clearer. 0.359xx is actually 1 / 2.78xx, i.e., 1 / duration.)
The above gets us to:
1 / ((end - start) / beats)
Using a bit of algebraic reduction:
(1 / (end - start)) * beats
<<-- (this is 0.35953685899971 * 4)
beats / (end - start)
4 / 2.78xx = 1.438xx
It might be useful to explain the \time
key.
It’s a little clearer in the rewrite (maybe).
Step A: You want the loop segment to span the entire bar – i.e. 4 beats. We can get 4 beats from the dur
key.
Step B: The server operates in seconds, not beats. So we have to convert by dividing by the tempo.
\time, Pkey(\dur) / Pfunc { thisThread.clock.tempo },
Admittedly I didn’t explain that in the text, but at least there are no more magic numbers in that part and it’s possible to reason it through: beats divided by beats/sec = beats * secs/beat, beats cancel out leaving seconds.
hjh