# Can one use VarGui as a simple Environment GUI?

I’m trying to use VarGui as a simple Environment display (no synth of ESP controls). Is this possible? If I just try VarGui(envir: (foo: 3)) it barfs “Bad definition: unused explicitly given envirs”.

What I’m ultimately trying to do is a bit more sophisticated, i.e. a mulit-envir display, see GUI for multiple Environments. VarGui looks quite promising for this because it can color-group sliders, but I can’t seem to make it show an envir without a player… So is this possible with VarGui as-is, or should I try to hack/subclass it?

Yep, but you have to pass the variables with specs, that you want to control:

~d = (foo: 3);
v = VarGui([\foo, [0, 10, \lin, 1, 1]], envir: ~d).gui;


That’s possible

~d = { (x: 1, y: 1, z: 1) } ! 3;
~s = [0, 10, \lin, 1, 1];

v = VarGui([\x, ~s, \y, ~s, \z, ~s] ! 3, envir: ~d).gui;

// play around with sliders and check
~d


I never thought about controlling Event hierarchies as you asked in the other thread. But that’s also possible:

~d1 = (x: 1, y: 1, z: 1);
~d2 = (x: 2).parent_(~d1);
~d3 = (y: 3).parent_(~d2);

~s = [0, 10, \lin, 1, 1];

v = VarGui([
[\x, ~s, \y, ~s, \z, ~s],
[\x, ~s],
[\y, ~s]
],
envir: [~d1, ~d2, ~d3]
).gui;

// play around with sliders and check
~d1
~d2
~d2.parent
~d3.parent


VarGui’s help file has admittedly grown too long and is hiding basic stuff. For a short introduction better go to the help file “Introduction to miSCellaneous” Tour 1-3.

1 Like

Thank you, very much appreciated.

As a minor point, I see that VarGui can do also global Spec lookup, but the syntax to make it do that is slightly surprising, i.e. the key needs to be duplicated as in:

Spec.add(\foo, [0, 10, \lin, 1, 1])
Spec.add(\bar, [20, 30, \lin, 2, 22])
// one 'foo' and one 'bar' slider
v = VarGui([\foo, \foo, \bar, \bar], envir: ~d).gui;


I.e., the first \foo in that parameter array is a lookup in ~d, whereas the second is a lookup in Spec.specs.

I do have one more basic question though: in all the examples you gave the initial value displayed in the GUI is the spec-default, not what was in the environment (EnvirGui makes the opposite choice). Is there a way change this initialization behavior (i.e. to be like EnvirGui’s), short of passing in modified specs with an environment lookup-up value? I.e. I can obviously do something like

(
Spec.add(\foo, [0, 10, \lin, 1, 1]);
Spec.add(\bar, [20, 30, \lin, 2, 22]);

~hackspecs = { |d ... xa| flatten ( xa collect: { |x|
[x, Spec.specs[x].copy.default_(d[x])] } ) };

~d = (foo: 3, bar: 27);
v = VarGui(~hackspecs.(~d, \foo, \bar), envir: ~d).gui;
~d // -> ( 'foo': 3.0, 'bar': 28.0 ) because it applied spec's rounding
)


But this seems a bit complicated… especially for the dict array use

[\x, \y, \z] do: Spec.add(_, [0, 30, \lin, 1, 22])
~da = [0, 10, 20] collect: { |i| (x: i+1, y: i+2, z: i+3) };
~va = ~da collect: ~hackspecs.(_, \x, \y, \z)
v = VarGui(~va, envir: ~da).gui;


The feature of EnvirGui that I don’t know how to replicate in VarGui is the auto-update with new controls/sliders, i.e.

~d = (foo: 3, bar: 27);
EnvirGui(~d)
~d[\zap] = 66 // gui updates automatically with new slider


I haven’t even discovered how manually/explicitly add sliders after a VarGui is instantiated…

(By the way, that one can double-click on the ctrl name in VarGui to edit the spec in the GUI itself is quite cool, although the feature seems not mentioned in documentation.)

It looks strange but imo it makes sense, you have chosen a special case. There might well be a variable with a different name, e.g. for a pattern key ‘modFreq’ which you want to control with a

global Spec of name ‘freq’. Glad that you found it at all, I have almost forgotten that feature

IIRC no. You’ve found the best way I think. Note, using VarGui with an envir passed is a special feature, the “normal” use case for which I’ve written it (as described in the introduction help file), is RT pattern control via dynamic scope. For this usage newly generated envirs are taken to encapsulate control in case of multiple patterns/players.
I’m not sure about your intended use case, but it might be that things become easier if - when using VarGui - you would choose this approach (if it’d be possible at all).

Not supported, sorry. Again this is related to my personal intended usage, control of chosen setups. I can well see the point that if you want to play a live setup you might want to sponataneously add further controls. I’m not playing live sets, so I didn’t focus on this (however students of mine have often used VarGui for such). The best you can do is open further VarGuis – and close them on occasion.

This is probably an EZSlider feature, or of one of the gui classes it uses.

1 Like