APC40 Cue Level Knob - Need help with rules

Dewey

2016-11-16 01:48:24

Hi All, I've been using MTP for a couple years to control MA2 OnPC with an APC40 using a project file I got from someone else. Recently I got in and started poking around with the code to try to customize some things and make a few tweaks.

I have a couple more ambitious long term things I'd like to do with the backlit buttons which I'm finding a lot of good references in other threads to get me going down that path, so I'd like to first thank the forum for all the great info that is already out there!

The first little thing I'm trying to do is get the "Cue Level" knob to control an executor fader, but the knob is set up as an endless encoder (proper term?) only sending one midi command each for clockwise and ccw turns (B0 2F 01 and B0 2F 7F respectively).

So I got the basic functionality down with this simple code

Code: Select all

[x] Translator 3.23: Cue Level
Options: swallow
Incoming: MIDI B0 2F ga
Rules:
  if ga<5 then gb=gb+1
  if ga>5 then gb=gb-1
Outgoing: MIDI 90 14 gb
The encoder is a little jittery and sometimes sends 02 or 7E as stray velocities so the <5 >5 is just to clean that up.

So as you probably can guess, the problem I have now is that the encoder doesn't stop at the "top" (velocity 174?) or the bottom. If I overshoot going up, the executor jumps back down to the bottom and the encoder and executor get out of syncc.

I've tried adding rule: if gb>174 then gb=174 thinking that should stop the when it reaches the top which does not work.

Any suggestions would be greatly appreciated! Thanks

florian

2016-11-16 10:39:11

Hi Dewey,
welcome! MIDI is a 7-bit protocol, which means that all data values go from 0...127. So your boundaries need to be 0 and 127:

Code: Select all

if gb<0 then gb=0
if gb>127 then gb=127
Note that most encoders send incremental MIDI data in a way that when turned faster, it makes up for "skipped" values. Most likely, the APC40 works like that, too: when turning cw faster, it sends a control change with value 2, etc. For best feel, you should consider that when converting to an absolute control change message. The middle value is the (theoretical) dividing point from cw vs. ccw. For ccw turns, slowly turning sends value 127, faster 126, and so on, so we need a 2-step calculation for calculating the updated gb value: gb=gb+ga-128, hence two lines for that in the Rules:

Code: Select all

if ga<64 then gb=gb+ga
  if ga>=64 then gb=gb+ga
  if ga>=64 then gb=gb-128
Last, but not least, using the global variable ga is not needed here, because it's only used inside the translator. To not accidentally mess with other translators using ga, I recommend using a local variable, e.g. pp (which can be used in multiple translators without affecting other translators using pp).

Here's the resulting translator for converting the relative encoder to a Note On message with velocity converted from the current encoder value:

Code: Select all

[x] Translator 3.23: Cue Level
Options: swallow
Incoming: MIDI Control Change, Channel 1, CC#47, any value, set pp to value
Rules:
  if pp<64 then gb=gb+pp
  if pp>=64 then gb=gb+pp
  if pp>=64 then gb=gb-128
  if gb<0 then gb=0
  if gb>127 then gb=127
Outgoing: MIDI Note On, Channel 1, Note 20, set velocity to gb
Note that I've also used the "simple" MIDI types for incoming and outgoing.

Dewey

2016-11-16 13:37:58

Ahhhh! That works perfectly. Thank you for the super fast reply!!

I understand what you did there, but I feel l like I should go back to study some midi basics. Can you suggest a good "midi for dummies" resource?

Thanks again

florian

2016-11-16 14:20:52

great to hear! Have you tried The MIDI Association?