How to use strings in a do block as argument names in Synth?

How do I do this? I want to pass in a name to use as an argument during Synth creation?

(["\freq"]).do{
 | a i |
 Synth(\sinesynth,[ a[0]: 220] );
};

Hi,
This seems to work:

["freq"].do{
 | a, i |
	Synth(\default, [a.asSymbol, 50] );
};
1 Like

you can also pass symbols in directly

 [\freq].do{|i| Synth(\default, [i, 300])} 

This is going to make a new synth instance for each symbol you provide.
e.g:

[\freq, \freq2, \freq3].do{|a|
	Synth(\t, [a, 220])
}

This code creates three synths for the three arguments.
A better way to achieve this is with collect.

[\freq, \freq2, \freq3].collect{|a|
	Synth(\t, [a, 220])
}

This now returns an array of three synth instances.
However, I have a suspicion this isn’t actually what you wanted.

The other issue is the a[0].
a is not the array.
When you do ([...]).do, the outer brackets disappear, meaning you are calling do on an array.

Could you describe what you actually would like to happen. It isn’t clear from the code what this refers to.
e.g…
Why the array, why not just Synth(\default, [\freq, 200])?
How many synths would you like?
What interface do you want to use to describe your code?

Why doesn’t Synth(\default, [\freq, 200]) work in your situation?
Why do you want to separate the argument and its value, the \freq and the value?

Is an interface like this what you are looking for?

~mk_default = { |...args| Synth(\default, args) };
~mk_default.(\freq, 200);
1 Like

When I initially posed the question, I’d gone through using \name to send as part of a do loop to initalize a bunch of synths, but for some reason it wasn’t working, which I thought was rather weird, hence the question.

just to be super clear you want to distinguish between Strings and Symbols. Symbols are fast to work with, are stored in a table are written either 'aSymbol' or \aSymbol. Method names and parameters are Symbols. Strings are arrays of Chars so you can write “what”[2] but not \what[2]. Strings can be concatenated and mutated so its a common practice to assemble a name by concatenating strings or whatever and then use .asSymbol before using as a method or parameter etc.