hey, this is a succesor to Subdivide phase by Demand sequence - #6 by dietcv
i have succesfully came up with way to subdivide a measure phase by an arbitrary demand sequence of divisions per measure and to get a continuous event phase.
(
var rampFromBPM = { |bpm, beatsPerMeasure, reset|
var beatsPerSec = bpm / 60;
var measureRate = beatsPerSec / beatsPerMeasure;
var measurePhase = Phasor.ar(reset, measureRate * SampleDur.ir);
(measurePhase - SampleDur.ir).wrap(0, 1);
};
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 rampToSwing = { |measurePhase, stepsPerMeasure, swing|
var swingCount = stepsPerMeasure / 2;
var swingPhase = (measurePhase * swingCount).wrap(0, 1);
var swingIndex = (measurePhase * swingCount).floor;
var swingPhaseShaped = swingPhase.linlin(0, 1, swing.neg, 1 - swing).bilin(0, swing.neg, 1 - swing, 0.5, 0, 1);
swingIndex + swingPhaseShaped / swingCount;
};
var rampToSlope = { |phase|
var history = Delay1.ar(phase);
var delta = (phase - history);
delta.wrap(-0.5, 0.5);
};
var accum = { |trig|
Duty.ar(SampleDur.ir, trig, Dseries(0, 1));
};
{
var measurePhase, measurePhaseSwing, stepPhase, stepTrigger, stepSlope;
var stepIndex, eventTrigger, eventPhase, eventDuration, stepDuration;
var plotScale = 100;
var stepsPerMeasure = 12;
// measure phase
measurePhase = rampFromBPM.(\bpm.kr(160) * plotScale, \beatsPerMeasure.kr(4), \reset.tr(0));
measurePhaseSwing = rampToSwing.(measurePhase, stepsPerMeasure, \swing.ar(0.5));
// step phase, slope, trigger and duration
stepPhase = (measurePhaseSwing * stepsPerMeasure).wrap(0, 1);
stepSlope = rampToSlope.(stepPhase);
stepTrigger = rampToTrig.(stepPhase);
stepDuration = rampToSlope.(measurePhase) / rampToSlope.(measurePhaseSwing);
eventDuration = Ddup(2, Dseq([2, 6, 1, 2, 1], inf));
eventDuration = Demand.ar(stepTrigger, 0, Ddup(eventDuration, eventDuration));
stepIndex = Demand.ar(stepTrigger, 0, Dseq([Dseries(0, 1, eventDuration)], inf));
eventTrigger = stepTrigger * Demand.ar(stepTrigger, 0, Dswitch1([1] ++ (0 ! (stepsPerMeasure - 1)), stepIndex));
eventPhase = stepSlope * stepDuration / eventDuration * accum.(eventTrigger);
[measurePhase, stepPhase, eventPhase];
}.plot(0.021);
)
now i would like to add my rampToSwing function, its swinging every other step and adjust the event phase accordingly:
here swing is set to 0.75:
you can calculate the swung step duration by the slope of the measure phase divided by the slope of the swung measure phase. when setting swing to 0.75 you get a sequence for the step duration of 1.5, 0.5, 1.5, 0.5, etc.
I have tried to use the stepDuration to scale the step slope to get a continous event phase between 0 and 1:
the event phase is continuous but as you can see in the plot, the problem arises for odd durations. for a sequence of event durations of [2, 6, 1, 2, 1] only the odd numbers, in this case the duration of 1 causes the event slope to be either outside of the range of 0 to 1 or not reach 1 at all, depending on its index in the sequence of durations.
I know that this is tricky but maybe someone is interested helping me out