Hi all,
finally got some time to do some colliding, but have been colliding my head against the wall in this particular case. Typing this up I’ve finally found a workaround but I’m still not sure why Patterns behave that way, so would be thankful for explanations.
I am trying to get a \phrase-type Pdef to pass an array (of pitches) to a subordinate Pdef, and the subordinate pattern should then play these pitches sequentially (in a Pshuf or whatever). The superordinate pdef sends it new arrays periodically; it gets these arrays from a bigger, preexisting list of pitch material; the arrays are not themselves generated by supercollider patterns. I suspect that’s where the problem is.
Trying to mock this up really quickly it should work something like this:
(
var testarray = Array.fill([5,3], {10.rand});
var a, b, c;
a = Prand(testarray);
5.do({ b = Pshuf(a.asStream.next.postln);
c = b.asStream;
3.do({ c.next.postln; })
});
)
which works as expected, as its essentially just two nested loops.
But doing the same thing with full flegded Pbinds etc. doesn’t:
(
var testarray = Array.fill([5,3], {10.rand});
Pdef(\subord, {|wontwork| wontwork.postln; //a dimension is chewed off the array somehow
Pbind(\note, Pshuf(wontwork), //and Pshuf gets an int, with which it won't know what to do.
// etc.
}
);
Pdef(\superord, {
Pbind(\instrument, \subord,
\type, \phrase,
\wontwork, Prand(testarray),
// etc.
)}
);
Pdef(\superord).play //error
)
Now I’ve tried enclosing the testarray variable in another pair of brackets, but that just plays all the subord patterns at once (which is expected behavior I think). Substituting the variable with a literal array #[[1,2],[3,4]]
gets the exact same problems, so that’s not it either.
What finally did help is moving the inner arrays one level deeper, i.e. from [[1,2],[3,4]]
to [[[1,2],[3,4]]]
. Now I guess I’ve found a solution but I still don’t understand why this is happening - why does one dimension of the array get “chewed off” as it is passed to the subordinate pattern?