polymorphism: better names for .binaryValue and .booleanValue are .asInteger and...
[supercollider.git] / Help / Libraries / JITLib / GUI / softSet.html
blob0c273072e22373cd9af3d8934ddf6505543f4dae
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="1038.29">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #782727; min-height: 12.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0000ee}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0909}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000; min-height: 12.0px}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0000bf}
21 span.s1 {font: 18.0px Helvetica}
22 span.s2 {color: #000000}
23 span.s3 {color: #2b30fa}
24 span.s4 {color: #0000bf}
25 span.s5 {color: #007300}
26 span.s6 {color: #1e22bf}
27 span.s7 {color: #007313}
28 span.s8 {color: #bf0000}
29 span.s9 {color: #bf0909}
30 span.s10 {color: #606060}
31 span.Apple-tab-span {white-space:pre}
32 </style>
33 </head>
34 <body>
35 <p class="p1"><span class="s1"><b>softSet <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>set a proxy param value conditionally</b></p>
36 <p class="p2"><br></p>
37 <p class="p3"><span class="s2"><b>See also </b><a href="softVol_.html"><b>softVol_</b></a></span><span class="s3"><b>,</b></span><span class="s2"><b> </b><a href="softPut.html"><b>softPut</b></a><b>.</b></span></p>
38 <p class="p2"><br></p>
39 <p class="p1"><b>NodeProxy.softSet, Ndef.softSet<span class="Apple-converted-space"> </span></b></p>
40 <p class="p1"><span class="Apple-tab-span"> </span>sets a nodeproxy param value only<span class="Apple-converted-space">  </span>in two conditions:<span class="Apple-converted-space"> </span></p>
41 <p class="p1"><span class="Apple-tab-span"> </span>* if the new value is close enough to the current param value;</p>
42 <p class="p1"><span class="Apple-tab-span"> </span>*or<span class="Apple-converted-space">  </span>if the setting controller knows the previous value and sends it<span class="Apple-converted-space"> </span></p>
43 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>along. the idea here is that if the controller knows it did the last<span class="Apple-converted-space"> </span></p>
44 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>value change, it has authority to jump now.</p>
45 <p class="p4"><span class="Apple-tab-span"> </span></p>
46 <p class="p1"><b><span class="Apple-tab-span"> </span>softSet(param, val, within = 0.025, mapped=false, lastVal, spec)</b></p>
47 <p class="p1"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>param - <span class="Apple-tab-span"> </span></b>the name of the parameter to set</p>
48 <p class="p1"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>val - <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>the value to set the param to (can be mapped or unmapped)</p>
49 <p class="p1"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>within<span class="Apple-converted-space">  <span class="Apple-tab-span"> </span></span></b>the normalized range within which the set is accepted - default is 0.025</p>
50 <p class="p1"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>lastVal<span class="Apple-tab-span"> </span></b>the previous value that a control has set - see last examples.</p>
51 <p class="p1"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>mapped<span class="Apple-tab-span"> </span></b>a flag whether <b>val</b> is mapped (within the range of param.asSpec) or unmapped (0.0-1.0)</p>
52 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>spec</b><span class="Apple-tab-span"> </span>a ControlSpec can be passed in. if nil, param.asSpec is used.</p>
53 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>NOTE: if no spec is given, softSet simply allows setting.</b></p>
54 <p class="p4"><br></p>
55 <p class="p1">Typical uses would be switching to a preset, then using a faderbox,<span class="Apple-converted-space"> </span></p>
56 <p class="p1">and avoiding sudden controller jumps that could occur (soft takeover).</p>
57 <p class="p4"><br></p>
58 <p class="p5"><br></p>
59 <p class="p6"><span class="s4">Ndef</span>(<span class="s5">\test</span>, { <span class="s4">|freq=200|</span> Splay.ar(<span class="s4">SinOsc</span>.ar(freq * Array.rand(12, 0.95, 1.05))) });</p>
60 <p class="p6"><span class="s4">Ndef</span>(<span class="s5">\test</span>).play(vol: 0.1);</p>
61 <p class="p5"><br></p>
62 <p class="p6"><span class="s6">Ndef</span>(<span class="s7">\test</span>).gui(4)</p>
63 <p class="p5"><br></p>
64 <p class="p6"><span class="s4">Ndef</span>(<span class="s5">\test</span>).set(<span class="s5">\freq</span>, 300);</p>
65 <p class="p5"><br></p>
66 <p class="p7"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// 3 midi steps == 0.02362;</p>
67 <p class="p6"><span class="s4">Ndef</span>(<span class="s5">\test</span>).softSet(<span class="s5">\freq</span>, 320, 0.03); <span class="s8">// ok</span></p>
68 <p class="p6"><span class="s4">Ndef</span>(<span class="s5">\test</span>).softSet(<span class="s5">\freq</span>, 280, 0.03); <span class="s8">// ok</span></p>
69 <p class="p7"><span class="s4">Ndef</span><span class="s2">(</span><span class="s5">\test</span><span class="s2">).softSet(</span><span class="s5">\freq</span><span class="s2">, 200, 0.03); </span>// returns false if too big jump</p>
70 <p class="p5"><br></p>
71 <p class="p8"><span class="s4">Ndef</span><span class="s2">(</span>\test<span class="s2">).set(</span>\freq<span class="s2">, </span>600<span class="s2">);<span class="Apple-converted-space"> </span></span></p>
72 <p class="p5"><br></p>
73 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span></span>// softSet can be risky - one can lose a parameter when moving a controller</p>
74 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span></span>// too quickly. So, if we know the last value (e.g. because the same controller<span class="Apple-converted-space"> </span></p>
75 <p class="p9"><span class="s2"><span class="Apple-tab-span"> </span></span>// knows it has set to that value),<span class="Apple-converted-space">  </span>it is OK to jump:</p>
76 <p class="p6"><span class="s6">Ndef</span>(<span class="s7">\test</span>).softSet(<span class="s7">\freq</span>, 330, 0.03, lastVal: 630);<span class="Apple-tab-span"> </span></p>
77 <p class="p5"><br></p>
78 <p class="p6"><span class="s6">Ndef</span>(<span class="s7">\test</span>).softSet(<span class="s7">\freq</span>, rrand(300, 350), 0.01);<span class="Apple-tab-span"> </span>// sometimes yes, sometimes no</p>
79 <p class="p5"><br></p>
80 <p class="p5"><br></p>
81 <p class="p7"><span class="s2"><span class="Apple-tab-span"> </span></span>// use unmapped, i.e. normalized values to set:</p>
82 <p class="p10"><br></p>
83 <p class="p6"><span class="s6">Ndef</span>(<span class="s7">\test</span>).set(<span class="s7">\freq</span>, 600);<span class="Apple-tab-span"> </span><span class="s9">// ok</span></p>
84 <p class="p6"><span class="s4">Ndef</span>(<span class="s5">\test</span>).softSet(<span class="s5">\freq</span>, 0.5, 0.05, mapped: false);<span class="Apple-tab-span"> </span><span class="s8">// ok</span></p>
85 <p class="p6"><span class="s4">Ndef</span>(<span class="s5">\test</span>).softSet(<span class="s5">\freq</span>, 0.45, 0.03, mapped: false);<span class="Apple-tab-span"> </span><span class="s8">// no, too big</span></p>
86 <p class="p6"><span class="s6">Ndef</span>(<span class="s7">\test</span>).softSet(<span class="s7">\freq</span>, 0.3, 0.03, mapped: false, lastVal: 0.5);<span class="Apple-tab-span"> </span><span class="s9">// but ok if lastVal is close</span></p>
87 <p class="p5"><br></p>
88 <p class="p5"><br></p>
89 <p class="p7"><span class="s2"><span class="Apple-tab-span"> </span></span>// example of softSet, softSet which knows lastVal,</p>
90 <p class="p7"><span class="s2"><span class="Apple-tab-span"> </span></span>// softVol_ and softVol_ which knows lastVol:</p>
91 <p class="p6">(</p>
92 <p class="p6">w = <span class="s4">Window</span>(<span class="s10">"softSet, softVol"</span>, <span class="s4">Rect</span>(500, 200, 400, 240)).front;</p>
93 <p class="p6">w.view.addFlowLayout;</p>
94 <p class="p11">NdefGui<span class="s2">(</span>Ndef<span class="s2">(</span><span class="s5">\test</span><span class="s2">), 2, w);</span></p>
95 <p class="p5"><br></p>
96 <p class="p7"><span class="s2"><span class="Apple-tab-span"> </span></span>// can lose control if wiggled too fast</p>
97 <p class="p6"><span class="s4">EZSlider</span>(w, 340@30, <span class="s5">\softSet</span>, <span class="s4">\freq</span>, { <span class="s4">|sl|</span><span class="Apple-converted-space"> </span></p>
98 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">Ndef</span>(<span class="s5">\test</span>).softSet(<span class="s5">\freq</span>, sl.value, 0.05)</p>
99 <p class="p6">});</p>
100 <p class="p5"><br></p>
101 <p class="p7"><span class="s2"><span class="Apple-tab-span"> </span></span>// knows it was in control</p>
102 <p class="p11">EZSlider<span class="s2">(w, 340@30, </span><span class="s5">\knowsLast</span><span class="s2">, </span>\freq<span class="s2">, </span>Routine<span class="s2"> { </span>|sl|<span class="s2"><span class="Apple-converted-space"> </span></span></p>
103 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">var</span> newVal, lastVal;<span class="Apple-converted-space"> </span></p>
104 <p class="p6"><span class="Apple-tab-span"> </span>loop {<span class="Apple-converted-space"> </span></p>
105 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>newVal = sl.value;</p>
106 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Ndef</span>(<span class="s5">\test</span>).softSet(<span class="s5">\freq</span>, newVal, 0.05, lastVal: lastVal);</p>
107 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>lastVal = newVal;</p>
108 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">\dummy</span>.yield;</p>
109 <p class="p6"><span class="Apple-tab-span"> </span>}</p>
110 <p class="p6">});</p>
111 <p class="p5"><br></p>
112 <p class="p7"><span class="s2"><span class="Apple-tab-span"> </span></span>// same for volume - not too safe</p>
113 <p class="p6"><span class="s4">EZSlider</span>(w, 340@30, <span class="s5">\softVol</span>, <span class="s5">\amp</span>, { <span class="s4">|sl|</span><span class="Apple-converted-space"> </span></p>
114 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">Ndef</span>(<span class="s5">\test</span>).softVol_(sl.value, 0.05)</p>
115 <p class="p6">});</p>
116 <p class="p7"><span class="s2"><span class="Apple-tab-span"> </span></span>// safer</p>
117 <p class="p6"><span class="s4">EZSlider</span>(w, 340@30, <span class="s5">\knowLastV</span>, <span class="s5">\amp</span>, <span class="s4">Routine</span> { <span class="s4">|sl|</span><span class="Apple-converted-space"> </span></p>
118 <p class="p6"><span class="Apple-tab-span"> </span><span class="s4">var</span> newVal, lastVal;<span class="Apple-converted-space"> </span></p>
119 <p class="p6"><span class="Apple-tab-span"> </span>loop {<span class="Apple-converted-space"> </span></p>
120 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>newVal = sl.value;</p>
121 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Ndef</span>(<span class="s5">\test</span>).softVol_(sl.value, 0.05, lastVal: lastVal);</p>
122 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>lastVal = newVal;</p>
123 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">\dummy</span>.yield;</p>
124 <p class="p6"><span class="Apple-tab-span"> </span>}</p>
125 <p class="p6">});</p>
126 <p class="p6">)</p>
127 <p class="p5"><br></p>
128 </body>
129 </html>