2 summary:: set a proxy param value conditionally
3 categories:: Libraries>JITLib>GUI
4 related:: Reference/softVol_, Reference/softPut
7 code::softSet:: is an extension method to link::Classes/NodeProxy:: and link::Classes/Ndef:: that sets a nodeproxy param value only in two conditions:
9 ## if the new value is close enough to the current param value;
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 preset, then using a faderbox, and avoiding sudden controller jumps that could occur (soft takeover).
14 method:: softSet (param, val, within = 0.025, mapped=false, lastVal, spec)
16 the name of the parameter 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 the previous value that a control has set - see last examples.
24 a flag whether strong::val:: is mapped (within the range of param.asSpec) or unmapped (0.0-1.0)
26 a link::Classes/ControlSpec:: can be passed in. if nil, param.asSpec is used.
28 if no spec is given, softSet simply allows setting.
33 Ndef(\test, { |freq=200| Splay.ar(SinOsc.ar(freq * Array.rand(12, 0.95, 1.05))) });
34 Ndef(\test).play(vol: 0.1);
38 Ndef(\test).set(\freq, 300);
40 // 3 midi steps == 0.02362;
41 Ndef(\test).softSet(\freq, 320, 0.03); // ok
42 Ndef(\test).softSet(\freq, 280, 0.03); // ok
43 Ndef(\test).softSet(\freq, 200, 0.03); // returns false if too big jump
45 Ndef(\test).set(\freq, 600);
47 // softSet can be risky - one can lose a parameter when moving a controller
48 // too quickly. So, if we know the last value (e.g. because the same controller
49 // knows it has set to that value), it is OK to jump:
50 Ndef(\test).softSet(\freq, 330, 0.03, lastVal: 630);
52 Ndef(\test).softSet(\freq, rrand(300, 350), 0.01); // sometimes yes, sometimes no
55 // use unmapped, i.e. normalized values to set:
57 Ndef(\test).set(\freq, 600); // ok
58 Ndef(\test).softSet(\freq, 0.5, 0.05, mapped: false); // ok
59 Ndef(\test).softSet(\freq, 0.45, 0.03, mapped: false); // no, too big
60 Ndef(\test).softSet(\freq, 0.3, 0.03, mapped: false, lastVal: 0.5); // but ok if lastVal is close
63 // example of softSet, softSet which knows lastVal,
64 // softVol_ and softVol_ which knows lastVol:
66 w = Window("softSet, softVol", Rect(500, 200, 400, 240)).front;
68 NdefGui(Ndef(\test), 2, w);
70 // can lose control if wiggled too fast
71 EZSlider(w, 340@30, \softSet, \freq, { |sl|
72 Ndef(\test).softSet(\freq, sl.value, 0.05)
75 // knows it was in control
76 EZSlider(w, 340@30, \knowsLast, \freq, Routine { |sl|
80 Ndef(\test).softSet(\freq, newVal, 0.05, lastVal: lastVal);
86 // same for volume - not too safe
87 EZSlider(w, 340@30, \softVol, \amp, { |sl|
88 Ndef(\test).softVol_(sl.value, 0.05)
91 EZSlider(w, 340@30, \knowLastV, \amp, Routine { |sl|
95 Ndef(\test).softVol_(sl.value, 0.05, lastVal: lastVal);