Is it possible to select a property from an object containing a class like this below?
//Object
const voices = {
fmsynth: Tone.FMSynth,
amsynth: Tone.AMSynth,
synth: Tone.Synth
}
//my function to select the above synths
switch_synth(synth_id) {
const synth = new Tone.PolySynth(voices[synth_id], 6).toDestination();
console.log(voices[synth_id]);
}
Yes, as long as you call it with the appropriate key
In your code, call
voices["fmsynth"]or evenvoices.fmsynth, to getTone.FMSynth.So your code seems to be doing the right thing, as long as you are calling
switch_synthwith an appropriatesynth_id, e.g.Are you getting an error, and if so, what error?