Slider value snapping please
-
@Christoph-Hart Can we add value snapping feature to the slider please?
For example: There is a knob with a value range between 75 and 15000.
The user should be able to choose whether these values are continuous or snapped with a switch.
So if the user selects snapped values, the slider will jump to the previously defined snap values (for example: 75, 150, 500, 1040, 3600, 15000).
If the user selects continuous mode, then the slider will be like we all know.
-
@orange you should be able to do that with a broadcaster attached to the slider mouse callback and then round the values in the drag callback.
-
@Christoph-Hart I didin't know that. Is there any reference or snippet for this?
-
@orange Here's an example snippet using a broadcaster as @Christoph-Hart suggested and a hidden knob (otherwise it's glitchy). But since my solution can also be done from within the knob's CB I don't understand why a broadcaster should be used here... Or maybe it has advantages I can't see and I use it wrongly?
- Broadcaster solution
HiseSnippet 1373.3ocyW8nSabCF+NfisbaqZUZO.VQSUGBHjPg1oArERfrgJPiHzpIUg5btyIwMN1Q9bBMCgzdf1qvj1d.16xdC19r8kbWf.kFoIsHQD96u+99i+7WpKEgj3XgzwM24i5Sbb+buFi3pNU6fobmiNvw8QdmfiUDIxRpxn933XRjiq6h+flfatkbLe96uuBlg4gjTRNNuVPCIGS6QUoTqW9ETFqFNhbNsWFo2p7QgBdUASL.vyhdEc5iC6haSNEqEaAOG2kOLhpDxFJrhD63tTEQznFcDWxsx+ZZLsIinOTxoAXHK4ZBVjFwZpNU6PYQ0GG2wNfUpmlEVzlE9JuSnQzIzSyFeogAJUir4C2ElFdKNE7JcWvaFPxMCjVxBoG60HTR6qR4nwym4cDGJNsvPZOKTrx5rvWurWUAHAWUnGtKolDNLQifmUr3ZH3qU1wGjJVvHEBYDrL.H3C0hXEZHVhh439UTbzdnw1pMQUUzqufCGBxmvOOnUpRufKZV5NUwv81Jr48pvl4mFWCAoeyy2dMTosg3XacvTp3Vv2O0DX.0hEu.z3lwRehrRUP2C4sobHjkDndUQJvQglV8fq7Qn7zn7eKx3WTCqR4WSSGKaGCbdS9vwnK+Zn7jg5+4B+q0PbhSJfUJbXmyEShjSDChIGpENNvjD.c2mwPUwLVSncOVarD+gLBiNlBfhC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08E3aufKwhgsBfiQr9licRmtah3seWwObmxDiCnO3.RMdBcy9jKVcNWRdMyQGUruyFceQc5LUYowg.hXphUWXHlGPG1fv1DQ9bhRQnK5jslW8w0Z1KINmSQN6DFU95HR554e2hQZhBZoubJCguI0MzWKsgdRRvfBF4yrzECFZxCWLt5SVK8dzGMX2wfStU82+iZyD7gCjRNSCtfUZys6AGtU23GO4HrDqtUJ0a.OLhHjTUfz7HxMvU7I2QUv5HRbeIOR6toue.a+Qc32O9.q8tZCyVvqAc+7CHM4wTUhdrDzuUCJpiZQ+EvvVVtkJaDlaXj+7hZg3Lid5eUCZnhGDjzJIuZFeB7z8+I7z5QjFyL5u1OGS+4N0jj2C1XUqVmePSXXrGLnALhC2eP.VN4bOpg8REnbv7CanFnfAN9v7kMeBCCUdtCC8Xo3SsZRkd8lNGWZJbDpn+ufioiP9UVG2oCwSlQvUrZ7SK57heji+B9.ILLvYXofBYdqyGD1Blh1i.mNiAWoB6YtjpORx5xp0pHPKByWu3efOoBcUqMSE5NRnQH1SveqWRuD0PpetdGfSL874Efen.rFMtCjkUYc4tO8sddJ2eKnE4zwTYAv77E.yNK.lcW.LuXAv7xE.y2LWLpepxACj7vjWGfMZdrtUto4wLLTYoqBM9W.7ws0HA
-
I don't understand why a broadcaster should be used here...
You don't need to write a callback if you just connect it to a module parameter. Also it's a bit weird setting the value in a callback that reacts on a value (it will happen in automation too).
The broadcaster just adds that functionality without messing with the original function so it's more modular and reusable.
-
@Christoph-Hart said in Slider value snapping please:
Also it's a bit weird setting the value in a callback that reacts on a value (it will happen in automation too).
Yeah I agree but doing so in a broadcaster also creates glitches
I wanted to force the knob's value by snapping it but it's glitchy in both solutions, hence the reason I used a hidden knob.Of course the broadcaster spares a callback, but just using a callback is easier and less verbose than the broadcaster alone in this case
-
Another simple solution:
HiseSnippet 1042.3ocsV91aaSDF.+bRcY1.SLI9.bJuxAZScXsaHpPKKosPzncQ3RAoopwU6KIG47cF6KgFPSZe13SDugWCO2YmXGHMqD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BGudFqsFF0e38+.iE269g1mNbHMTUB3N1m8Ca6kruik+akSULwnyIpTFbxaewz3.3WOBovpKDvbbPmUMcOWtruVVWABnhHiveAOEFaqksJL1dgQTLILU95v7lM8M6OvnAXRX9oFG3uq.Y7xVTaaXPp9SZ1qCC0a+8gw.qOlOaKh4waQLGtEwbzVDyS1hXd5VDymuwXz+e2ympjw4sCfhAmZl0YYcpf.eYY9JD82ok7Df.
-
@ustk Yeah that might be the best one. I would suggest to interpolate between the array indexes if snap is off like this:
local freq; local idx = parseInt(Math.floor(value)); if (snapBtn.getValue()) freq = v[idx]; else { local lo = v[idx]; local hi = v[idx+1]; local alpha = Math.fmod(value, 1.0); local interpolated = lo * (1.0-alpha) + hi * (alpha); freq = interpolated; }
This will retain the position to the snap one.
-
@ustk All three solutions are great, I will choose the latest one. Thank you!
-
@Christoph-Hart Great example! Thank you