How to create a popup menu whose menu options are dynamic

Yes there ought to be some more advanced tutorials, or techniques really, particularly around Function which is secretly rather complex and nuanced.

Just one of my favourites relating to valueWithEnvir

var voice_processing = { |atk, dec, amp, freq, freqWobble, pan, panRange|
	var sig = SomeUgen.ar(atk...)
	... some audio code that uses the arguments ...
}

// keys match args above.
var default_voice = (\atk: 0.2, \dec: 1.2, \amp: -10.dbamp, \freq: 200, \freqWobble: 2.1, \pan: LFNoise2.kr(0.2), \panRange: [-1, 1]);

// each entry (voice) will become an audio channel (or multiple depending on voice_processing)
var voices_spec = [ 
	(\atk: 0.8, \freq: 143),
	(\atk: 0.04, \dec: 0.2),
	(\pan: 0, \freq: LFNoise2.kr(2).range(220, 440))
];

var arr_of_voices = voices_spec.collect{ |spec|
	voice_processing.valueWithEnvir( default_voice ++ spec )
};
var mixed_voices = Mix.ar(arr_of_voices);

Here each new Event in voices_spec becomes a new voice, replacing the default_voice with any specified arguments. Its a nice alternative to multichannel expansion, where only the differences between the voices are specified - which I think is often more musical.

2 Likes