Pdelta : FilterPattern


As input, Pdelta takes a pattern that returns time points within a measure and outputs the difference between successive values (suitable for use as the delta stream of a Pbind).


*new(pattern, cycle = 4)


pattern: The time point pattern. The return values must be numeric.


cycle: Length of a measure, for wrapping the deltas if needed. If the time point values are always increasing, cycle is not used. If the next value of the input pattern is less than the previous value, however, the previous value is adjusted downward by a multiple of cycle. See the "cyclical time points" example below.


This cyclical behavior distinguishes Pdelta from Pdiff.


// always increasing time points

p = Pseq(#[0, 2, 3, 6, 7, 9, 10, 11, 15], 1);

q = Pdelta(p).asStream;

q.nextN(10);

[ 2, 1, 3, 1, 2, 1, 1, 4, nil, nil ]




// cyclical time points

// the time point pattern puts 4 notes in random places in the bar

p = Pn(Plazy({ Pseq(({ 4.0.rand } ! 4).round(0.125).sort, 1) }), inf);


// trace lets us see the time points first

q = Pdelta(p.trace).asStream;

q.nextN(6);


0.25

1.625

3

3.25

1.25

1.625

2.5

[ 1.375, 1.375, 0.25, 2, 0.375, 0.875 ]


In the second example, 3.25 is followed by 1.25. Assuming a four beat cycle, we would expect two beats between the two time points, and this is what returns.