Storing a reference to a parameter

Hello forum! I was wondering if there’s an easy way to create pointers to parameters. So for example, I define an array of parameter references stored at the top of a chop execute, but fetch, modify, and update them within the valuechange function. So basically I want to pass by reference instead of by value.


Hey B,

Have you looked into using python storage?

You can place all sorts of goodies into storage and retrieve them based on a the key they’re stored as. Here’s a quick overview:

While we’re here you might look at this example:
base_storage.tox (1.29 KB)

Here we create a variable outside of our function that points to our dictionary in storage, then in the execution of the function we clear the table, update the values, then change the seed parameter for the noise CHOP. This means that our table values are one seed behind the vals in the noise CHOP.

Is this the kind of thing you’re looking for?

Thank you Matt! This definitely helps clear some things up; I still need to play around with these concepts to fully understand how it works.

With respect to using ‘local’ as a base that stores everything - do you move the default ‘local’ base to be inside of your overall project container?

I don’t normally use local variables these days - though they’re still a functioning feature of Touch.

Here’s an example of how to set this up.
base_variables_example.tox (758 Bytes)

Local variables will inherit - from the parent object. You can see here in base_variable_example that ‘test’ evaluates to the results in local. The same is true for base1.

base1, however, has it’s own set of variables that are retrieved instead of the parent’s.

So the idea would be that you’d create a set of local variables at the levels of your project where you need them. Storage is similar, though more pythonic in nature, and a little easier to wrangle IMO, though both work well.

Hope that helps!

Thanks again Matt! Follow up question for anyone:

Let’s say I have a chop execute, and I have several functions defined within it that alter a given parameter. Instead of constantly referencing the parameter in its entirety, I decide to store the parameter.

So, what’s the best practice for storing the parameter? IE do I just run a script once to store the relevant param? And then when I want to retrieve the reference from storage, where in my chop execute should I do that? I notice that if I try fetching something from storage and assigning it to a variable at the beginning of my script, I run into problems where the assignment isn’t occurring.

I think I understand where you’re going with this. A note about storing a parameter - this is great for reading vals, but not ideal for setting vals. Instead I’ll do something like store the operator. In an execute DAT you might assign your variable outside of your methods (assuming that your reference here isn’t changing every execution), then do the assignment in the method. That would look like this in a very simple form:

[code]noise = parent().fetch(‘noise_TOP’)

def onValueChange(channel, sampleIndex, val, prev):

noise.par.seed = val


Here’s a tox as well:
base_store_and_set.tox (878 Bytes)

Does that make sense?

Thanks Matt, yes it does. I was just hoping that there’d be a nicer way of setting values without have to go “op.par.val” all over the place, but if that’s the best practice, I’ll stick with it. Thanks again.

I looked at this one more time, and I think you can do something like this:

[code]noise = parent().fetch(‘noise_TOP’)
seed_par = parent().fetch(‘seed_par’)

def onValueChange(channel, sampleIndex, val, prev):

seed_par.val = val

That .val call should let you set the value of the parameter. Here’s an example tox:
base_store_and_set_val.tox (1.13 KB)

Thanks Matt. As a follow up question; when you have a chop execute (or any execute), and there’s a definition outside of a function, when does that get evaluated? It seems like in some cases, definitions outside of functions can fail to be evaluated if they aren’t there when first ‘activated’.

I’m pretty sure what’s outside of the function is only called when you edit and then click away from the execute code.

It’s worth pointing out that this will not work as expected:

[code]msg = parent().fetch(‘my_val’)

def onOffToOn(channel, sampleIndex, val, prev):



This will only ever print the value fetched from storage during the last edit of the execute code. If your value in storage will change, you’ll need to do something like this:

def onOffToOn(channel, sampleIndex, val, prev):
msg = parent().fetch(‘my_val’)