i think a sequence of divisions does not work together with wrap. I dont know why, but in the meantime i came up with this solution. The downside here is that you cant fully use the potential of ramp division which is using non-integers values. The following attempt just works for a sequence of integers which are masking the step triggers to get the event triggers which are resetting the accumulator. You still can curve the phase of the measure ramp to create bpm synced swing or ratchets (i will make another post on this when ready), which is an advantage over a trigger based approach and if you add the subsample offset calculation for the accumulator you get a sequence of subsample accurate event phases ready for granulation.
(
var rampToSlope = { |phase|
var history = Delay1.ar(phase);
var delta = (phase - history);
delta.wrap(-0.5, 0.5);
};
var rampToTrig = { |phase|
var history = Delay1.ar(phase);
var delta = (phase - history);
var sum = (phase + history);
var trig = (delta / sum).abs > 0.5;
Trig1.ar(trig, SampleDur.ir);
};
var accum = { |trig|
Duty.ar(SampleDur.ir, trig, Dseries(0, 1));
};
{
var measurePhase, measureTrigger, stepPhase, stepTrigger, stepIndex, stepSlope;
var durations, eventTrigger, eventPhase;
var plotScale = 100;
var bpm = 160 * plotScale;
var beatsPerSec = bpm / 60;
var beatsPerMeasure = 4;
var measureRate = beatsPerSec / beatsPerMeasure;
var stepsPerMeasure = 12;
// measure phase & trigger
measurePhase = (Phasor.ar(DC.ar(0), measureRate * SampleDur.ir) - SampleDur.ir).wrap(0, 1);
measureTrigger = rampToTrig.(measurePhase);
// step phase, slope & trigger
stepPhase = (measurePhase * stepsPerMeasure).wrap(0, 1);
stepSlope = rampToSlope.(stepPhase);
stepTrigger = rampToTrig.(stepPhase);
durations = Ddup(2, Dseq([2, 6, 1, 2, 1], inf));
durations = Demand.ar(stepTrigger, 0, Ddup(durations, durations));
stepIndex = Demand.ar(stepTrigger, 0, Dseq([Dseries(0, 1, durations)], inf));
eventTrigger = stepTrigger * Demand.ar(stepTrigger, 0, Dswitch1([1] ++ (0 ! (stepsPerMeasure - 1)), stepIndex));
eventPhase = stepSlope / max(1, durations) * accum.(eventTrigger);
[measurePhase, stepPhase, eventPhase];
}.plot(0.03);
)
