2 summary:: numerical input specification
4 categories:: Control, Spec
8 The original, and most common spec (see link::Classes/Spec::). A ControlSpec is used by GUI sliders and knobs to specify the range and curve of the controls. ControlSpec may be used in many ways to map from linear 0..1 range to your desired range and back.
10 The most common way to create a ControlSpec is by
12 anObject.asSpec // the object may be an array or a symbol
22 The minimum value of the range.
25 The maximium value of the range.
28 a link::Classes/Warp::, a symbol (e.g. \lin or \exponential: Default value is \lin), or something else that returns a Warp when sent the message .asWarp. A CurveWarp is defined by a number.
31 The smallest possible increment.
37 The units, e.g. "hz". Used by some gui's as a unit label.
42 Maps and constrains a strong::value:: between 0 and 1 to the range between minval and maxval.
45 Maps and constrains a strong::value:: between minval and maxval to the range between 0 and 1.
47 g = ControlSpec(0.01, 2000, \exp, 0.1, 220, "Hz");
48 g.map(0.5); // convert from [0..1] to [0.01..2000]
49 g.unmap(1000); // convert from [0.01..2000] to [0..1]
51 // fore and back translation should be close to identical:
56 The lower of maxval and minval.
59 The higher of maxval and minval.
62 Returns code::value.asFloat.clip(clipLo, clipHi).round(step)::.
65 Returns code::maxval - minval::.
67 method::guessNumberStep
68 Used for EZ GUI classes for guessing a sensible strong::step:: if none is specified.
73 g = ControlSpec(0.01, 2000, \exp, 0.1, 220, "Hz");
77 [0.001, 2000, \exp, 0.1, 220, "hz"].asSpec;
79 // or add it to the ControlSpec.specs IdentityDictionary:
81 ControlSpec.specs[\myFreq] = ControlSpec(0.01, 2000, \exp, 0.01, 440, units: "Hz");
85 // array is used as arguments to ControlSpec.new(minval, maxval, warp, step, default)
86 [300,3000,\exponential,100].asSpec.dump
87 Instance of ControlSpec { (0313FC08, gc=00, fmt=00, flg=00, set=03)
88 instance variables [6]
91 warp : Symbol 'exponential'
96 // partially specified ...
98 Instance of ControlSpec { (0313FF18, gc=00, fmt=00, flg=00, set=03)
99 instance variables [6]
102 warp : Symbol 'linear'
104 default : Integer -48
109 Instance of ControlSpec { (180F4910, gc=3C, fmt=00, flg=00, set=03)
110 instance variables [8]
112 maxval : Integer 20000
113 warp : instance of ExponentialWarp (17FEDB30, size=1, set=1)
115 default : Integer 440
118 clipHi : Integer 20000
122 // nil becomes a default ControlSpec
124 Instance of ControlSpec { (0313FF18, gc=00, fmt=00, flg=00, set=03)
125 instance variables [6]
128 warp : Symbol 'linear'
135 // make a frequency spec with an exponential range from 20 to 20000,
136 // give it a rounding of 30 (Hz)
141 a = [20, 20000, 'exp', 100, 440].asSpec;
144 a.constrain(800); // make sure it is in range and round it.
145 a.constrain(803); // make sure it is in range and round it.
148 a.map(0.0); // returns min
149 a.map(1.5); // exceeds the area: clip, returns max
156 // like in envelopes, a CurveWarp is created by a number:
158 a = [0, 1, -4].asSpec;
161 a.map((0..10).normalize).plot;
163 // look at different distributions:
165 var invals = (0..10).normalize;
167 var a = [0, 1, curve].asSpec;
174 // using spec for sliders:
177 w = Window.new("control", Rect(128, 64, 340, 160));
179 c = Slider.new(w, Rect(10, 10, 300, 30));
180 d = StaticText.new(w, Rect(10, 40, 300, 30));
182 d.string = "unmapped value"
183 + c.value.round(0.01)
192 // ControlSpec-map can also be used to map ugens
195 spec = [ 100, 18000, \exp].asSpec;
198 osc = SinOsc.kr(0.1).range(0,1);
199 freq = spec.map( osc );
201 freq.dump;// BinaryOpUGen