Using a pattern as argument for another list pattern

Hi guys,

I’ve a question related to patterns and lists. Maybe the solution relays in the knowledge of some kind of list pattern I ignore.
I would try to explain what I want to achieve.

Let’s say I have a list of lists like this:

a = [[1,2,3], [4,5,6], [7,8,9]];

I would like to create an Event pattern which should generate random values taken from the first list ( [1,2,3] ) then, let’s say after 3 times, will continue generating random values but, this time, from the second list, and then from the third, and repeat the process again.

The straight way to implement this that comes to my mind is the following:

(
Pbindef(\score1,
	\instrument, \default,
	\degree, Prand( Pdup(3, Pseq(a, inf)), inf),
	\dur, 0.5
).play
);

but, obviously, this approach doesn’t work. The error I see in the post window is this one which makes perfectly sense to me

The preceding error dump is for ERROR: ListPattern (Prand) requires a non-empty collection; received a Pdup.

But the question still remains, I do I achieve the wnated result?
Is there any useful pattern out-of-the-box for doing this?
Thank you so much
n

Why not using this simple solution? There is a manual part to it (the indexing) but it gets to the result you seem to describe.

(
a = [[1,2,3], [4,5,6], [7,8,9]];
Pbindef(\score1,
	\instrument, \default,
	\degree, Pseq([
      Prand(a[0], 3),
      Prand(a[1], 3),
      Prand(a[2], 3),
    ], inf),
	\dur, 0.5
).play
);

EDIT: there is also this solution that seems to work on the paper for lists of size n but it freezes in a real pattern.

(
~test = {
  Pseq(a.size.collect({
    arg elem;
    Prand(a[elem], 3)
  }), inf)
};
)
~test.().asStream.nextN(9); // Seems to work

And getting stuck here:

(
a = [[1,2,3], [4,5,6], [7,8,9]];
Pbindef(\score1,
	\instrument, \default,
	\degree, Pfunc({
    Pseq(a.size.collect({
      arg elem;
      Prand(a[elem], 3)
    }), inf)
  }),
	\dur, 0.5
).play
);
1 Like

It works if you remove the Pfunc wrapping:

(
a = [[1,2,3], [4,5,6], [7,8,9]];
Pbindef(\score1,
    \instrument, \default,
    \degree, Pseq(a.collect(Prand(_, 3)), inf),
    \dur, 0.5
).play
);

@moscardo I don’t know if there’s an out-of-the-box pattern for this, but I hope this is a simple enough solution.

1 Like

Thank you @Bubo and @PitchTrebler for your support.