MinBox a minimal gui
Inherits from: UserView
MinBox is a custom GUI widget that attempts to emulate slider, knob, numberbox, button, and the "EZ" container classes, all in a minimal amount of space. You may also specify a ControlSpec, as well as step and round values.
You may change the value using the mouse, programmatically, using the arrow keys, or using the number keys to set the value directly. The Ctrl and Alt keys change the step value when changing the value via mouse.
Creation / Class Methods
*new (parent, bounds)
parent - The parent view.
bounds - An instance of Rect, or a Point indicating width@height.
(
w = Window.new("",Rect(300,300,90,90)).front;
m = MinBox(w,Rect(10,10,70,70));
m.value = 0.4;
m.action = { arg q;
q.postln
};
)
Use this widget factory to explore the various customization options of MinBox:
(
~win = FlowView.new;
~minbox = MinBox.new(~win, 150@150).label_("a minbox").resize_(5);
~flow = FlowView.new(~win, 150@150);
StaticText(~flow, 60@20).align_(\right).string_("mode");
~mode = PopUpMenu.new(~flow, 60@20)
.items_(MinBox.modes)
.value_(0)
.action_({|v| ~minbox.mode = v.item; ~minbox.refresh });
StaticText(~flow, 60@20).align_(\right).string_("textMode");
~textMode = PopUpMenu.new(~flow, 60@20)
.items_(MinBox.textModes)
.value_(1)
.action_({|v| ~minbox.textMode = v.item; ~minbox.refresh });
StaticText(~flow, 60@20).align_(\right).string_("align");
~align = PopUpMenu.new(~flow, 60@20)
.items_(MinBox.aligns)
.value_(2)
.action_({|v| ~minbox.align = v.item; ~minbox.refresh });
StaticText(~flow, 60@20).align_(\right).string_("spec");
~spec = PopUpMenu.new(~flow, 60@20)
.items_(Spec.specs.select({|x| x.isKindOf(ControlSpec)}).keys.asArray.sort)
.action_({|v| ~minbox.spec = Spec.specs.at(v.item).postln; ~minbox.refresh });
~spec.valueAction = ~spec.items.indexOf(\unipolar);
StaticText(~flow, 60@20).align_(\right).string_("step");
~step = NumberBox(~flow, 60@20)
.value_(~minbox.step)
.action_({|v| ~minbox.step = v.value });
StaticText(~flow, 60@20).align_(\right).string_("round");
~round = NumberBox(~flow, 60@20)
.value_(~minbox.round)
.action_({|v| ~minbox.round = v.value });
StaticText(~flow, 60@20).align_(\right).string_("label");
~label = TextField(~flow, 60@20)
.value_(~minbox.label)
.action_({|v| ~minbox.label = v.value.asString });
~win.startRow;
~result = Button.new(~win, 100@40).states_([["Compile String"]]);
~result.action_({|view|
var str = "MinBox.new(parent, bounds)";
str = str++"\n\t.label_(%)\n\t.spec_(%)"
.format(~minbox.label.asCompileString,~minbox.spec.asCompileString);
str = str++"\n\t.mode_(%).textMode_(%).align_(%)"
.format(~minbox.mode.asCompileString,~minbox.textMode.asCompileString,~minbox.align.asCompileString);
str = str++"\n\t.step_(%).round_(%)".format(~minbox.step, ~minbox.round);
str.postln
})
)
Accessing Instance and Class Variables
defaultMode
classvar. the default mode for MinBox may be changed.
Default value is \vert
modes
lists the possible display modes
textModes
lists the possible textModes
aligns
lists the possible values for align
round
when a value is set it is rounded using this value. This rounds the spec-mapped value. See step for rounding the unmapped value
Default is 0.01
mode
this sets the display mode. See example above for what the options look like.
Default is \vert
spec
A ControlSpec. When this is set the value of this view is mapped to the spec.
Default value is \unipolar
Note: changing the step value of the ControlSpec does not change the round or step of the MinBox
value
The value of the view mapped to the view's current spec.
Default value is 0.0;
align_(arg1)
align
Sets the align of the text within the view
Default value is \center
textMode
Changes the mode for the text display
Default value is nil.
label
A String. Default value is ""
hiColor_(arg1)
hiColor
A Color. Sets the color for the max value
loColor_(arg1)
loColor
A Color. Sets the color for the min value
lineColor_(arg1)
lineColor
A Color. Sets the color for the min value
font_(arg1)
font
A Font. Sets the font
typingColor_(arg1)
typingColor
A Color. See [NumberBox]
normalColor_(arg1)
normalColor
A Color. See [NumberBox]
editable_(arg1)
editable
Sets the view editable or not.
skin
Use this to change the view's display settings all at once. Here are some examples:
// NOTE: use with widget factory code above
// grayscale
~minbox.skin = (
hi: Color.gray(0.85),
lo: Color.gray(0.5),
text: Color.gray(0.1,0.8),
type: Color.red(0.8,0.8),
line: Color.gray(0.98),
font: Font("Verdana-Bold", 12.0),
defaultMode: 'blend'
)
~minbox.font = Font("Verdana-Bold", 12); ~minbox.refresh
// 70's
~minbox.skin = (
hi: Color(0.8, 0.4, 0.0, 1.0),
lo: Color(0.74, 0.72, 0.42, 1.0),
line: Color(0.15, 0.25, 0.55, 0.7),
text: Color(0.1, 0.1, 0.1, 1.0),
type: Color(1.0, 1.0, 1.0, 1.0),
font: Font("Verdana-Bold", 12.0),
defaultMode: 'blend'
)
// iXi-inspired
~minbox.skin = (
hi: Color(1.0, 0.4, 0.0, 0.63),
lo: Color(0.4, 0.58, 0.4, 1.0),
line: Color(0.61, 0.8, 0.61, 1.0),
text: Color(0.88, 0.94, 0.88, 1.0),
type: Color(0.5, 0.2, 0.0, 0.81),
//Color(1.0, 0.82, 0.7, 0.89),
font: Font("Helvetica", 15.0),
defaultMode: 'horiz'
)
~minbox.skin = GUI.skins.default.minbox
step_(arg1)
step
Sets the step size for changing the value. This is mapped to the 0-1 range, not the ControlSpec value
Default value is 0.001.
input_ (in)
input
returns or sets the unmapped value (0-1 range) of the view
Examples
// start server before running example
s.boot
(
// a gui for Gendy
~ex = ();
// list of specs
~ex[\specs] = (
ampdist: [0,6,\lin,1].asSpec, durdist: [0,6,\lin,1].asSpec,
adparam: \unipolar.asSpec, ddparam: \unipolar.asSpec,
ampscale: \unipolar.asSpec, durscale: \unipolar.asSpec,
minfreq: \midfreq.asSpec, maxfreq: \midfreq.asSpec,
amp: \unipolar.asSpec, knum: [1,24,\lin,1].asSpec,
start: [0,1,\lin,1].asSpec, close: [0,1,\lin,1].asSpec
);
// inital values
~ex[\defaults] = [1,1,1,1,0.5,0.5,20,1000,0.5,12,0,0];
// synth that will be controlled by GUI
~ex[\synth] = NodeProxy.audio(s,2);
~ex[\synth].source = {|ampdist=1, durdist=1, adparam=1, ddparam=1, ampscale=1, durscale=1, minfreq=25, maxfreq=4000, amp=1.0, knum=12, gate=1.0|
var sig = Gendy1.ar(ampdist, durdist, adparam, ddparam, minfreq, maxfreq, ampscale, durscale, 24, knum);
var env = Linen.kr(gate,doneAction:2);
Pan2.ar(sig*env, 0, amp*env)
};
// gui setup
~ex[\win] = Window.new("synth",Rect(300,200, 160, 200)).front;
~ex[\win].onClose = { { ~ex[\synth].clear }.defer };
~ex[\boxes] = List[];
~ex[\guilayout] = [[\ampdist, \durdist],[\adparam,\ddparam],[\ampscale,\durscale],[\minfreq,\maxfreq],[\amp,\knum],[\start,\close]];
~ex[\rowmode] = [\clear,\blend,\vert,\horiz,\round,\button];
~ex[\guilayout].do {|pair,row|
var rect = Rect(0,0,80,32);
pair.do {|name,col|
rect = rect.moveTo(col*rect.width,row*rect.height);
// create grid of MinBoxes
~ex[\boxes] = ~ex[\boxes].add(
MinBox.new(~ex[\win], rect.insetBy(1,1))
.label_(name)
.spec_(~ex[\specs][name]).mode_(~ex[\rowmode][row])
.textMode_('switch').align_('center')
.value_(~ex[\defaults][(row*2)+col])
.action_({|me| ~ex[\synth].set(me.label.asSymbol, me.value) })
)
}
};
// start button
~ex[\boxes][10].action = {|me|
if(~ex[\boxes][10].input==0)
{ ~ex[\synth].stop }
{ ~ex[\synth].play }
};
// close button
~ex[\boxes][11].action = {|me| { ~ex[\win].close }.defer(0.3) }
)