I've been trying to create script that adds touch functionality to a fader. So if you touch it without dragging, it goes immediately to the position of the touch. Eventually, I'd like to have it move to the value at a specific rate, but that comes later.
It works fine so far, but then I realized that I needed my fader to be log taper. And I can't figure out what math to do on the mouse-position-based VAL (normalized to 0..1) to get log taper out.
VAL := log(VAL) gives negative numbers, and VAL := exp(VAL) gives numbers above 1. Neither is what I expected...
THANKS!
=e
edit: you can ignore the bit about negative and over-values--I was doing my range adjusting before the conversion. But I still don't know what usine's log taper is. Some research on audio taper makes it seem like this is not a universal standard... so I guess I need to know the math behind usine's implementation....
log vs exp question
-
woodslanding
- Member
- Posts: 1327
- Contact:
log vs exp question
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
-
woodslanding
- Member
- Posts: 1327
- Contact:
well, some more experimenting. I tried mouse * mouse, and that was better. mouse^4 seems about right. Guess that will do!
cheers,
-e
cheers,
-e
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
-
woodslanding
- Member
- Posts: 1327
- Contact:
Here's the script, if it's useful to anybody....
Code: Select all
///////////////////////////////////////////////////////////
// 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 value
procedure 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;
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
yes the power car replace the log/exp scale.
Olivier Sens
www.brainmodular.com
www.brainmodular.com
Who is online
Users browsing this forum: No registered users and 13 guests
