I am building a script that takes initial values and allows the user to overwrite them during a performance. I want to be able to capture the values the user has contributed and allow them to become the new initial values. I have one possible solution, but if someone has something else that might work, I’m all ears!
My possible solution is to use environmental variables for both the initial values and the “live” values and then to post the value of the “live” variables so they can be copy/pasted over the initial values. The problem is that when I post the environmental variable, it contains the name of a ugen (MostChange), not the actual values
Here is some simple code that replicates the problem:
~someInitialValues = [399, 402];
SynthDef(\postMeSomeArrayGuts, {
var signal;
~freqs = MostChange.kr(~someInitialValues, LFNoise0.kr(freq:[1,1]).linexp(-1,1,100,1000)); //my real code has something more interesting happening where user input is the second argument to MostChange.kr()
signal = SinOsc.ar(~freqs, mul:0.05);
Out.ar(0, signal);
}).add; Synth.new(\postMeSomeArrayGuts);
//THE LINE BELOW IS WHAT I REALLY CARE ABOUT. I want to be able to print the value of ~freqs so I can copy/paste over ~someInitialValues up above with the live values
"~someInitialValues = ".post; ~freqs.postln; //this will only output "~someInitialValues = [ a MostChange, a MostChange ]". I want "~someInitialValues = [433, 658]" or whatever the values of ~freqs happen to be at that time
Thanks in advance for any solutions or ideas about how I might get to a solution!! (I really don’t understand why the output is [a MostChange, a MostChange])
-Ray
if you use an environmental variable in a SynthDef - the value of that variably is fixed when the synthDef is compiled - so your example Synth will always have the same two values initially even if you change ~someInitialValues later so that’s probably not what you want!
…and likewise you are setting ~freqs at compile time - when you compile the SynthDef ~freqs is being set to the array of MostChanges…
Synths run on the Server - environmental variables live in the language - so ordinarily Synths don’t change values in the language (you need to explicitly send stuff back and forth via OSC)
If you are hoping to see the current value of MostChange.kr(freq, LFNoise0.kr(freq:[1,1]).linexp(-1,1,100,1000)); I would suggest writing it to a bus so
var getMe = MostChange.kr(freq, LFNoise0.kr(freq:[1,1]).linexp(-1,1,100,1000);
Out.kr(10, getMe);
then: Bus(index: 10).get will get the current value.
–
If you just want the user to create the Synth and you want to keep a record of the initial values you just need to add initialFreqs as an arg (tip: you can use NamedControl to conveniently create an arrayed control). then its: Synth(\mySynth, [\initialFreqs, ~someInitialValues])
This sounds super helpful, thank you!! I’m going to take a minute to absorb this and understand it and then have another go at getting the output I want, probably with a bus.
One thing, though, that might spark another useful insight from you or someone else:
I actually would be happy to recompile the SynthDef after updating ~someInitialValues. The idea is that I’ve got a live sound generation thing that starts with some initial values and then I mess with them to come up with something else - I want to be able to save that “something else” and I’m happy to command-period, get the existing values (my original issue), copy/paste them over the intial values, and then compile again and have more fun. It would be easy to keep a record of a bunch of cool initial values just by saving different scripts or different object names. Long story short, if I’m willing to recompile the SynthDef, are there any easier solutions to my question?