Vargui slider: choose from array elements?

dear list,

how can a vargui slider just choose between array elements instead of being continuous from minval to maxval? couldn’t seem to find that case in the miscellaneous examples.

a= [1.0, 1.4444, 1.777, 1.5, 2]

(

v = VarGui([

dur: [0, 1, \lin, 0, 0.1],

array: [1,2,\lin,0,0.1],   /how to set it to choose between the fixed values of array a?

],

stream:p,

).gui(tryColumnNum: 1);

)

thanks,

jan

Hello Jan,

discrete steps can be achieved via the control specification array, how to use these (as array indices) is outside the scope of VarGui itself. It could e.g. be done like this

(
p = Pbind(
	\dur, Pfunc { ~dur },
	\note, Pfunc { a[~index] }
);

a = [1.0, 1.4444, 1.777, 1.5, 2] * 5;
	
v = VarGui([
		dur: [0.1, 1, \lin, 0, 0.1],
		index: [0, 4, \lin, 1, 0],  
	], 
	stream: p
).gui;
)

This is a flexible approach, as arrays can be exchanged on the fly.

But note that VarGui plays in newly generated envirs, above you used an interpreter variable for the array, with an envir variable it would fail:

(
p = Pbind(
	\dur, Pfunc { ~dur },
	\note, Pfunc { ~array[~index] }
);

~array = [1.0, 1.4444, 1.777, 1.5, 2] * 5;
	
v = VarGui([
		dur: [0.1, 1, \lin, 0, 0.1],
		index: [0, 4, \lin, 1, 0],  
	], 
	stream: p
).gui;
)

If you want to use speaking variable names, you can define in a dedicated envir, e.g. the topEnvironment.

(
t = topEnvironment;

p = Pbind(
	\dur, Pfunc { ~dur },
	\note, Pfunc { t[\array][~index] }
);

t[\array] = [1.0, 1.4444, 1.777, 1.5, 2] * 5;
	
v = VarGui([
		dur: [0.1, 1, \lin, 0, 0.1],
		index: [0, 4, \lin, 1, 0],  
	], 
	stream: p
).gui;
)

hi daniel,
great, this seems to me lika a good solution for what im after.
many thanks!
jan