hey, would someone know, how the following example can be rewritten without using % or wrap.
I would like to sequence different wrapping boundaries with another demand sequence per measure trigger. Using % or wrap together with a sequence of different wrapping boundaries seems not work.
(
{
var trig = Impulse.kr(1);
(0..7).collect{ |i|
Demand.kr(trig, 0, Dswitch1((1..8), Dseries(0, 1) + i % 8)).poll(trig, \demand);
};
}.play;
)
The context is this: I would like to translate this piece of code to Demand Ugens, to get the sum of a sequence of different rotated rows of the flattened 2d matrix per multichannel event trigger:
(
var numChannels = 5;
var array = [
[ 12 ],
[ 6, 6 ],
[ 6, 3, 3 ],
[ 3, 3, 3, 3 ],
[ 3, 3, 2, 1, 3 ],
[ 3, 1, 2, 2, 1, 3 ],
[ 3, 1, 2, 2, 1, 2, 1 ],
[ 2, 1, 1, 2, 2, 1, 2, 1 ],
[ 2, 1, 1, 2, 2, 1, 1, 1, 1 ],
[ 2, 1, 1, 2, 1, 1, 1, 1, 1, 1 ],
[ 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
].flat;
var measureIndex = [5, 6];
var eventsPerMeasure = measureIndex + 1;
var stepOffset = measureIndex * eventsPerMeasure / 2;
numChannels.collect{ |chan|
var count = eventsPerMeasure.collect{ |x| Array.series(x, 0, 1) };
var index = count + chan % eventsPerMeasure + stepOffset;
index.collect{ |x| array[x] };
}.sum;
)
I have a Demand example which does this already, but only for a fixed row and not for a sequence of different rows. Here are the main parts (i left out alot to isolate the problem), unfortunately the problem cant be isolated further. I hope the problem is the sequence of different mod or wrap values and someone would know how to rewrite the example from above, which would help me to fix it.
arrayOfValues = [
[ 12 ],
[ 6, 6 ],
[ 6, 3, 3 ],
[ 3, 3, 3, 3 ],
[ 3, 3, 2, 1, 3 ],
[ 3, 1, 2, 2, 1, 3 ],
[ 3, 1, 2, 2, 1, 2, 1 ],
[ 2, 1, 1, 2, 2, 1, 2, 1 ],
[ 2, 1, 1, 2, 2, 1, 1, 1, 1 ],
[ 2, 1, 1, 2, 1, 1, 1, 1, 1, 1 ],
[ 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
].flat;
// the calculation of maxOverlap works if seqOfRows is a single value but not if it is a sequence
seqOfRows = [5, 6];
// create sequence of measure indices
measureIndex = Demand.ar(measureTrigger, reset, Dseq(seqOfRows, inf));
eventsPerMeasure = measureIndex + 1;
// calculate stepOffset of each event for flattened 2d matrix
stepOffset = measureIndex * eventsPerMeasure / 2;
// calculate stepIndex (each measure has measureIndex + 1 items)
stepIndex = Dseq([Dseries(0, 1, eventsPerMeasure)], inf);
[.....]
// create stepTrigger, eventTrigger, calculate legato values and distribute multichannel trigger round robin across the channels
[.....]
// calculate maximum overlap per multichannel trigger
maxOverlap = numChannels.collect{ |chan|
//Demand.ar(triggers, reset, Dswitch1(arrayOfValues, chan + stepIndex + stepOffset));
Demand.ar(triggers, reset, Dswitch1(arrayOfValues, Dseries(0, 1) + chan % eventsPerMeasure + stepOffset));
}.sum;
My implementation gives me the correct calculation for row 5:
[3, 1, 2, 2, 1, 3] -> row 5
index: [15, 16, 17, 18, 19] -> durations: [3, 1, 2, 2, 1] -> sum: 9
index: [16, 17, 18, 19, 20] -> durations: [1, 2, 2, 1, 3] -> sum: 9
index: [17, 18, 19, 20, 15] -> durations: [2, 2, 1, 3, 3] -> sum: 11
index: [18, 19, 20, 15, 16] -> durations: [2, 1, 3, 3, 1] -> sum: 10
index: [19, 20, 15, 16, 17] -> durations: [1, 3, 3, 1, 2] -> sum: 10
index: [20, 15, 16, 17, 18] -> durations: [3, 3, 1, 2, 2] -> sum: 11
and the correct calculation for row 6:
[3, 1, 2, 2, 1, 2, 1] -> row 6
index: [21, 22, 23, 24, 25] -> durations: [3, 1, 2, 2, 1] -> sum: 9
index: [22, 23, 24, 25, 26] -> durations: [1, 2, 2, 1, 2] -> sum: 8
index: [23, 24, 25, 26, 27] -> durations: [2, 2, 1, 2, 1] -> sum: 8
index: [24, 25, 26, 27, 21] -> durations: [2, 1, 2, 1, 3] -> sum: 9
index: [25, 26, 27, 21, 22] -> durations: [1, 2, 1, 3, 1] -> sum: 8
index: [26, 27, 21, 22, 23] -> durations: [2, 1, 3, 1, 2] -> sum: 9
index: [27, 21, 22, 23, 24] -> durations: [1, 3, 1, 2, 2] -> sum: 9
But not for the sequence of row 5 and 6:
// sequence of rows [5, 6] gives:
[15, 16, 17, 18, 19] -> [3, 1, 2, 2, 1] -> 9 -> OK!
[16, 17, 18, 19, 20] -> [1, 2, 2, 1, 3] -> 9 -> OK!
[17, 18, 19, 20, 15] -> [2, 2, 1, 3, 3] -> 11 -> OK!
[18, 19, 20, 15, 16] -> [2, 1, 3, 3, 1] -> 10 -> OK!
[19, 20, 15, 16, 17] -> [1, 3, 3, 1, 2] -> 10 -> OK!
[20, 15, 16, 17, 18] -> [3, 3, 1, 2, 2] -> 11 -> OK!
[27, 21, 22, 23, 24] -> FALSE!
[21, 22, 23, 24, 25] -> [3, 1, 2, 2, 1] -> 9 -> OK!
[22, 23, 24, 25, 26] -> [1, 2, 2, 1, 2] -> 8 -> OK!
[23, 24, 25, 26, 27] -> [2, 2, 1, 2, 1] -> 8 -> OK!
[24, 25, 26, 27, 21] -> [2, 1, 2, 1, 3] -> 9 -> OK!
[25, 26, 27, 21, 22] -> [1, 2, 1, 3, 1] -> 8 -> OK!
[26, 27, 21, 22, 23] -> [2, 1, 3, 1, 2] -> 9 -> OK!
[16, 17, 18, 19, 20] -> FALSE!