Pdef started with .fork: can I query the key of the Pdef?

Hi,

I’m using .fork with Pdef instead of .play, to create multiple layers.

Is there a way to query the value of the ‘key’ of a Pdef instantiated in this way?

If we do a=Pdef(\myPattern).play, then a.key returns the key, ‘myPattern’. But if I do a=Pdef(\myPattern).fork, a.key returns ‘an EventStreamPlayer’.

I’m sure I’m misunderstanding the relation between Pdef and EventStreamPlayer and what is actually going on here, but if anyone has a solution that’d be great!

Thanks -

you can always access your Pdef directly:

just write Pdef(\myPattern).key(\foo)

Pdef, like Synthdef, keeps a registry of pattern proxies accessible by key!

no need to access Pdefs via variable

if you must though
(a = Pdef(\foo)).fork
will work for your case (a will still point to your Pdef after it is forked)

thanks!

Yeah I knew that about Pdef, but wanted to use .fork to kind of spawn multiple instances.

It works, but I can’t now stop that forked Pdef with a.stop.

Maybe I need to find a different way. I was wanting to have an array of instances of Pdefs randomly allocated, then query which ones were which in the array. Maybe I need to use Pspawn.

how about:

a=List[]
a.add(Pdef(\ttt).fork) // do a bunch of times
a.do(_.stop) //stops them all

FWIW this works:

a=Pdef(\ttt).fork // a points to an EventStreamPlayer
a.stop // call stop on EventStreamPlayer to stop it

when you evaluate that first line a bunch of times though you lose any reference to the earlier EventStreamPlayers - which is why I suggested storing them in a List

Thanks, that’s super helpful!