2 summary:: set a (number) parameter in an environment conditionally
3 categories:: Libraries>JITLib>GUI
4 related:: Reference/softSet, Reference/softVol_
7 code::softPut:: is an extension method to link::Classes/Dictionary:: that changes an existing numerical value for key in a dictionary only in two conditions:
9 ## if the new value is close enough to the current value at that key;
10 ## or if the setting controller knows the previous value and sends it along. the idea here is that if the controller knows it did the last value change, it has authority to jump now.
12 Typical uses would be switching to a new preset, then using a faderbox, and avoiding sudden controller jumps that could occur (soft takeover).
14 method:: softPut (param, val, within = 0.025, lastVal, mapped = true, spec)
16 the name of the parameter (key) to set
18 the value to set the param to (can be mapped or unmapped)
20 the normalized range within which the set is accepted - default is 0.025
22 a flag whether strong::val:: is mapped (within the range of param.asSpec) or unmapped (0.0-1.0)
24 the previous value that a control has set - see last examples.
26 a link::Classes/ControlSpec:: can be passed in. if nil, param.asSpec is used.
28 if no spec is given, or no value exists yet, softSet simply allows setting.
34 e = (amp: 0.1, dur: 0.2);
39 (amp: e.amp, dur: dur, degree: 7.rand).play;
45 e.put(\amp, 0.03); // just set it
47 e.softPut(\amp, 0.11); // small change, OK to set
49 e.softPut(\amp, 0.15); // no bigger change
50 e.softPut(\amp, 0.15, 0.1); // bigger change is OK with larger within value
52 e.softPut(\amp, 0.01); // no
53 e.softPut(\amp, 0.01, lastVal: 0.15); // can make big jumps when lastVal is close to current.
55 // no spec for dur exists by default:
58 e.softPut(\dur, 0.05); // so this always really sets.
63 // PatternProxies ( e.g. Tdefs, Pdefs) have a softSet method, which
64 // forwards softPut to their envirs:
66 Pdef(\test, Pbind(\degree, Pseq((0..7), inf))).play;
68 Pdef(\test).set(\amp, 0.03)
69 Pdef(\test).envir.softPut(\amp, 0.06); // no, too big
70 Pdef(\test).envir.softPut(\amp, 0.06, 0.1); // ok with wider range
73 Pdef(\test).set(\amp, 0.03)
74 Pdef(\test).softSet(\amp, 0.1); // no, too big
75 Pdef(\test).softSet(\amp, 0.06, 0.1); // ok with wider "within"
78 Pdef(\test).softSet(\amp, 0.5); // no!
79 Pdef(\test).softSet(\amp, 0.5, lastVal: 0.06); // ok!
80 Pdef(\test).softSet(\amp, 0.05, lastVal: 0.5); // ok
82 Pdef(\test).softSet(\dur, 0.05); // alsways ok, no spec for dur.
83 Pdef(\test).softSet(\dur, 0.1); // ok
85 Pdef(\test).softSet(\dur, 0.05, spec: [0.03, 3, \exp]); // not OK with that spec
90 // softPut and softSet can be risky - one can lose a parameter when moving a controller
91 // too quickly. So, if we know the last value (e.g. because the same controller
92 // knows it has set to that value), it is OK to jump:
94 // example of softSet, softSet which knows lastVal,
95 // softVol_ and softVol_ which knows lastVol:
97 w = Window("softSet, softVol", Rect(500, 200, 400, 240)).front;
99 PdefGui(Pdef(\test), 2, w, 340@80);
101 // can lose control if wiggled too fast
102 EZSlider(w, 340@30, \softSetDur, [0.03, 3, \exp], { |sl|
103 Pdef(\test).softSet(\dur, sl.value, 0.05)
106 // knows it was in control
107 EZSlider(w, 340@30, \knowsLast, [0.03, 3, \exp], Routine { |sl|
111 Pdef(\test).softSet(\dur, newVal, 0.05, lastVal: lastVal);