basic MIDI js request: when moving cc, ignore initial position +/- 1 (flicker-killer)
hey guys.
this is something i figured out how to code in arduino, where potentiometers give an incoming signal of 0-1023.
when you map this value down to 0-127, you often get a "flicker," ie cc data jumping between 45, 44, 45, 44 for example as the higher-resolution data of the sensor fluctuates on a scale that the lower resolution cc data cannot handle.
the trick in arduino is to convert the large resolution data from 0-1023 down to 0-255, do some math against a threshold of 2, and then divide the result before sending it off as cc data. here's an example, the bold part is the important thing:
transval = analogRead(transpin);
mappedtransval = map(transval, 0, 1023, 0, 16);
if(mappedtransval != lasttransval){
if(abs(mappedtransval - prevtransval) >= THRESHOLD){
prevtransval = mappedtransval;
applytrans = mappedtransval/2*12-48;
//Serial.println(transpose);
lasttransval = mappedtransval;}}
i'd like to achieve something similar in js, but i can't because the values are already in 0-127. for this reason, i need something that ignores a cc data change if it is + or - 1 of the initial position.
does this make any sense? any takers? it's undoubtedly dirt simple and i'd learn a lot from looking at it...tried to hack one out of "cc rider" but didn't get very far.
thanks
nym
|