Variables in a dictionary

Often i like to structure different patterns/parts of a longer piece in a dictionary like this:

(
part1: Pbind(...),
part2: Pbind(...),
etc
)

Now, if i want to have a shared variable/key, local to this dictionary’s environment; how do i do that?
This doesn’t work obviously:

(
sharedVar: [0, 3, 5, 7],
part1: Pbind(\degree, ~sharedVar),
part2: Pbind(\degree, ~sharedVar)
);

I tried some of the examples in the Environment helpfile but today (and possibly tomorrow as well) i’m to stupid to understand how to do this.

no doubt there are better, more idiomatic ways, but here is one

(
~pieceDict = (
	sharedVar: [0, 3, 5, 7],
	part1: Pbind(\degree, Pfunc{~pieceDict[\sharedVar]}),
	part2: Pbind(\degree, Pfunc{~pieceDict[\sharedVar]})
)
)


p = ~pieceDict[\part1].play


~pieceDict[\sharedVar] = (7..11)
~pieceDict[\sharedVar] = [0, 2, 5, 7]
~pieceDict[\sharedVar] = [0, 3, 4, 8]
~pieceDict[\sharedVar] = [0, 3, 5, 7]

p.pause

cheers,
eddi

1 Like

Yes, thanks! The problem here is that it is accesible from outside of the event/dict. Might not be a problem in most cases, but it’s not completely safe i guess.

I usually do something like this:

().make({
	~sharedVar = [0, 3, 5, 7];
	~part1 = Pbind(\degree, ~sharedVar);
	~part2 = Pbind(\degree, ~sharedVar)
});
1 Like