ArrayArrayArrayArray
CODE:
///////////////////////////////////////////////////////////// TOUCH FADER// eric moon 2024// Wire this up to a fader to get a feature where you can touch the fader at a // spot, and it will go to that value.// dragging works as usual.// set logIN on, if your fader is set to logarithmic taper// if your fader goes from 0 to 1, you shouldn't have to wire in min and max// slop is how much mouse movement is needed to be considered 'dragging'/////////////////////////////////////////////////////////////// Globally enable/disable logging const DTAG = 'TextButton: ';const DBUG_ON = TRUE;procedure debug(s: string); begin if DBUG_ON then strace(DTAG + s); end;procedure iDebug(s: string; num : integer); begin debug(s + '= ' + intToStr(num)); end;procedure fDebug(s: string; num : single); begin debug(s + '= ' + floatToStr(num)); end;// Always log, whether debug is on or not.procedure Error(s: string); begin strace('ERROR-' + DTAG + s); end;procedure fError(s: string; num : single); begin strace('ERROR-' + DTAG + s + '= ' + floatToStr(num)); end;procedure iError(s: string; num : integer); begin strace('ERROR-' + DTAG + s + '= ' + intToStr(num)); end;const LOG_TAPER = 1;const LINEAR_TAPER = 0;var mouseValIN, mouseDownIN, minIN, maxIN, slopIN, logIN, valueOUT: tParameter;var gMouseVal: float;var doneMousing, mouseDown: boolean;// when we see the mouseDown, we note the mouseValue. If it is the same (within slop) when the mouse is released// just set the fader to that valueprocedure init;var i : integer; begin SetModuleColor($804080+600000); minIN := CreateParam('fader min', ptDatafield, pioInput); minIN.DefaultValue(0); maxIN := CreateParam('fader max', ptDatafield, pioInput); maxIN.DefaultValue(1); logIN := CreateParam('log taper', ptSwitch, pioInput); mouseDownIN := CreateParam('mouse down', ptSwitch, pioInput); mouseValIN := CreateParam('mouse X', ptDatafield, pioInput); slopIN := CreateParam('slop in', ptDatafield, pioInput); slopIN.DefaultValue(0.05); valueOUT := CreateParam('val to fader', ptDatafield, pioOutput); doneMousing := FALSE;END;//todo: could track mouse movement more continuously.procedure mouse(down: boolean);var current, travel, range, val: float;begin if down then begin mouseDown := TRUE; gMouseVal := mouseValIN.asFloat; //store the mouse value fDebug('mouse val ',gMouseVal); end else begin mouseDown := FALSE; current := mouseValIN.asFloat; travel := abs(gMouseVal - current); fDebug('travel ', travel); range := maxIN.asFloat - minIN.asFloat; //compute mouse movement if travel < slopIN.asFloat then // set value of control begin if logIN.asInteger = LOG_TAPER then current := current * current * current * current; val := minIn.asFloat + (current * range); fDebug('val ', val); valueOUT.asFloat(val); end; end;end;procedure callback(n: integer);begin if n = mouseDownIN then mouse(mouseDownIN.asInteger = 1);end;procedure processIdle();begin if not mouseDown then begin //doneMousing := FALSE; valueOUT.length(-1); end;end;Statistics: Posted by woodslanding — 12 Dec 2024, 08:26
Statistics: Posted by woodslanding — 12 Dec 2024, 06:42
Statistics: Posted by woodslanding — 11 Dec 2024, 23:30
CODE:
///////////////////////////////////////////////////////////// TOUCH FADER// eric moon 2024// Wire this up to a fader to get a feature where you can touch the fader at a // spot, and it will go to that value.// dragging works as usual.// set logIN on, if your fader is set to logarithmic taper// if your fader goes from 0 to 1, you shouldn't have to wire in min and max// slop is how much mouse movement is needed to be considered 'dragging'/////////////////////////////////////////////////////////////// Globally enable/disable logging const DTAG = 'TextButton: ';const DBUG_ON = TRUE;procedure debug(s: string); begin if DBUG_ON then strace(DTAG + s); end;procedure iDebug(s: string; num : integer); begin debug(s + '= ' + intToStr(num)); end;procedure fDebug(s: string; num : single); begin debug(s + '= ' + floatToStr(num)); end;// Always log, whether debug is on or not.procedure Error(s: string); begin strace('ERROR-' + DTAG + s); end;procedure fError(s: string; num : single); begin strace('ERROR-' + DTAG + s + '= ' + floatToStr(num)); end;procedure iError(s: string; num : integer); begin strace('ERROR-' + DTAG + s + '= ' + intToStr(num)); end;const LOG_TAPER = 1;const LINEAR_TAPER = 0;var mouseValIN, mouseDownIN, minIN, maxIN, slopIN, logIN, valueOUT: tParameter;var gMouseVal: float;var doneMousing, mouseDown: boolean;// when we see the mouseDown, we note the mouseValue. If it is the same (within slop) when the mouse is released// just set the fader to that valueprocedure init;var i : integer; begin SetModuleColor($804080+600000); minIN := CreateParam('fader min', ptDatafield, pioInput); minIN.DefaultValue(0); maxIN := CreateParam('fader max', ptDatafield, pioInput); maxIN.DefaultValue(1); logIN := CreateParam('log taper', ptSwitch, pioInput); mouseDownIN := CreateParam('mouse down', ptSwitch, pioInput); mouseValIN := CreateParam('mouse X', ptDatafield, pioInput); slopIN := CreateParam('slop in', ptDatafield, pioInput); slopIN.DefaultValue(0.05); valueOUT := CreateParam('val to fader', ptDatafield, pioOutput); doneMousing := FALSE;END;//todo: could track mouse movement more continuously.procedure mouse(down: boolean);var current, travel, range, val: float;begin if down then begin mouseDown := TRUE; gMouseVal := mouseValIN.asFloat; //store the mouse value fDebug('mouse val ',gMouseVal); end else begin mouseDown := FALSE; current := mouseValIN.asFloat; travel := abs(gMouseVal - current); fDebug('travel ', travel); range := maxIN.asFloat - minIN.asFloat; //compute mouse movement if travel < slopIN.asFloat then // set value of control begin if logIN.asInteger = LOG_TAPER then current := current * current * current * current; val := minIn.asFloat + (current * range); fDebug('val ', val); valueOUT.asFloat(val); end; end;end;procedure callback(n: integer);begin if n = mouseDownIN then mouse(mouseDownIN.asInteger = 1);end;procedure processIdle();begin if not mouseDown then begin //doneMousing := FALSE; valueOUT.length(-1); end;end;Statistics: Posted by woodslanding — 12 Dec 2024, 08:26
Statistics: Posted by woodslanding — 12 Dec 2024, 06:42
Statistics: Posted by woodslanding — 11 Dec 2024, 23:30