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.
44 Maps and constrains a strong::value:: between 0 and 1 to the range between minval and maxval.
47 Maps and constrains a strong::value:: between minval and maxval to the range between 0 and 1.
49 g = ControlSpec(0.01, 2000, \exp, 0.1, 220, "Hz");
50 g.map(0.5); // convert from [0..1] to [0.01..2000]
51 g.unmap(1000); // convert from [0.01..2000] to [0..1]
53 // fore and back translation should be close to identical:
58 The lower of maxval and minval.
61 The higher of maxval and minval.
64 Returns code::value.asFloat.clip(clipLo, clipHi).round(step)::.
67 Returns code::maxval - minval::.
69 method::guessNumberStep
70 Used for EZ GUI classes for guessing a sensible strong::step:: if none is specified.
75 g = ControlSpec(0.01, 2000, \exp, 0.1, 220, "Hz");
79 [0.001, 2000, \exp, 0.1, 220, "hz"].asSpec;
81 // or add it to the ControlSpec.specs IdentityDictionary:
83 ControlSpec.specs[\myFreq] = ControlSpec(0.01, 2000, \exp, 0.01, 440, units: "Hz");
87 // array is used as arguments to ControlSpec.new(minval, maxval, warp, step, default)
88 [300,3000,\exponential,100].asSpec.dump
89 Instance of ControlSpec { (0313FC08, gc=00, fmt=00, flg=00, set=03)
90 instance variables [6]
93 warp : Symbol 'exponential'
98 // partially specified ...
100 Instance of ControlSpec { (0313FF18, gc=00, fmt=00, flg=00, set=03)
101 instance variables [6]
104 warp : Symbol 'linear'
106 default : Integer -48
111 Instance of ControlSpec { (180F4910, gc=3C, fmt=00, flg=00, set=03)
112 instance variables [8]
114 maxval : Integer 20000
115 warp : instance of ExponentialWarp (17FEDB30, size=1, set=1)
117 default : Integer 440
120 clipHi : Integer 20000
124 // nil becomes a default ControlSpec
126 Instance of ControlSpec { (0313FF18, gc=00, fmt=00, flg=00, set=03)
127 instance variables [6]
130 warp : Symbol 'linear'
137 // make a frequency spec with an exponential range from 20 to 20000,
138 // give it a rounding of 30 (Hz)
143 a = [20, 20000, 'exp', 100, 440].asSpec;
146 a.constrain(800); // make sure it is in range and round it.
147 a.constrain(803); // make sure it is in range and round it.
150 a.map(0.0); // returns min
151 a.map(1.5); // exceeds the area: clip, returns max
158 // like in envelopes, a CurveWarp is created by a number:
160 a = [0, 1, -4].asSpec;
163 a.map((0..10).normalize).plot;
165 // look at different distributions:
167 var invals = (0..10).normalize;
169 var a = [0, 1, curve].asSpec;
176 // using spec for sliders:
179 w = Window.new("control", Rect(128, 64, 340, 160));
181 c = Slider.new(w, Rect(10, 10, 300, 30));
182 d = StaticText.new(w, Rect(10, 40, 300, 30));
184 d.string = "unmapped value"
185 + c.value.round(0.01)
194 // ControlSpec-map can also be used to map ugens
197 spec = [ 100, 18000, \exp].asSpec;
200 osc = SinOsc.kr(0.1).range(0,1);
201 freq = spec.map( osc );
203 freq.dump;// BinaryOpUGen