Emulating encoder acceleration

metastatik

2008-08-20 02:30:46

I have an encoder that just sends a decimal value of 1 when turned to the right and 127 when turned to the left. I’d like to emulate acceleration so that turning the encoder quickly in either direction sends different values (like 5 and 122 for example).

I kind of have this working by using a short frequency timer, but it’s unreliable…it causes MT to crash intermittently. Here’s how I have it set up…these are just the translators for the right turn…the left turn is basically identical.

Code: Select all

Translator 1: RightSetGlobal
Options: stop=false
Incoming: MIDI F0 42 40 6E 08 43 00 01 F7 
Rules: 
  ga=ga+1
Outgoing: (none)

Translator 2: RightSetTimer
Options: stop=false
Incoming: MIDI F0 42 40 6E 08 43 00 01 F7 
Outgoing: One-shot timer "t1": 25 ms delay

Translator 3: RightResetGlobal
Options: stop=false
Incoming: On timer "t1"
Rules: 
  ga=0
Outgoing: (none)

Translator 4: RightMIDIOut
Options: stop=false
Incoming: MIDI F0 42 40 6E 08 43 00 01 F7 
Rules: 
  if ga<=3 then qq=1
  if ga>=4 then qq=5
Outgoing: MIDI b0 3c qq
So turning the encoder increases a global variable and triggers a timer. If the encoder is spun quickly, the timer will never get a chance to execute and the global variable will just keep increasing. If it’s turned slowly, the timer will execute and reset the global back to 0. The value of the global determines which value gets sent out…either 1 or 5.

It does what I want it to just not reliably. I’m assuming the timer is the issue and I tried increasing the delay, but that causes the acceleration to not work properly.

Any ideas on how to solve the reliability issue or handle this in a different way?

Thanks in advance.

miguel

2008-09-11 22:02:09

Hi metastatik,
Are you sure your controller only outputs 1 or 127?
I have an iControl that works similarly to yours but it sends from 1 up to 63 when rotated clockwise depending on the speed I turn the knob. And from 127 to 64 for counter-clockwise rotation.

If it doen't I'll try to think something, although I wouldn't call myself an expert by any means.

Good luck,
miguel

florian

2008-09-14 15:28:49

Hi metastatik,

we'll see that we'll fix these crashes (still have to evaluate and try to reproduce, though).

Regards,
Florian

metastatik

2008-09-16 03:54:30

Thanks for looking into it Florian.

Thanks for the response, Miguel. What you describe is the behavior I’m trying to emulate. Unfortunately, my encoder only sends 1 and 127 regardless of how fast it’s turned.