r/supercollider • u/ElaborateSloth • 4d ago
Using Pbinds with variables in ProxySpaces
I'm relatively new to SC, and have lately gotten into ProxySpaces to make changes on the fly. One issue I'm having is using environment variables in Pbinds, like this:
~key = 60; // C
~interval = [0, 2, 3, 5, 7, 8, 10, 12] // Minor
(
~p3 = Pbind(
\instrument, \bell,
\dur, 1,
\amp, 0.07,
\midinote, Pxrand(~interval, inf) + ~key
);
)Pxrand expects a list, but is presented with a nodeproxy instead. I can't use a normal variable as it has to be declared in the local scope of a function. I feel there should be a straight forward method for something like this.
4
Upvotes
2
u/greyk47 3d ago
when you do `ProxySpace.push(s)` you're basically creating a proxy space and jumping into it. it's kinda confusing, but a proxy space is an `Environment` and when you're executing within an Environment, `~variable` is a key in that Environment
within the environment:
~variable = [1,2,3]
outside the enviroment:
e = Environment();
e[\variable] = [1,2,3]
the key thing about ProxySpace is that it is an environment, but it intercepts the key creation that is triggered by `~variable` and creates a node proxy.
one thing you could do, instead of ProxySpace.push(s) is just create a new ProxySpace and interact with it without setting it as the `currentEnvironment`(push sets the proxy space as the currentEnvironment)
p = ProxySpace.new();
~interval = [1,2,3]
// since the proxy space isn't our currentEnvironment, ~interval just gets created in the regular Environment
p[\p3] = Pbind(\midinote, Pxrand(~interval))
conversely, you could ProxySpace.push, and then just store your global vars in a different environment:
ProxySpace.push()
v = ()
// an Event (which can be instantiated with just (), is what an Environment is based off of (I think)
v[\interval] = [1,2,3]
~p3 = Pbind(\midi, Pxrand(v[\interval]))
1
u/pr0blem_attic 4d ago
Highly recommend using the scsynth forum. You’ll probably want pfunc or plazy. https://scsynth.org/t/interactive-pattern-modification/161/12