dotherightthing / control-traktor

A collection of settings and Max4Live devices for improved control over Traktor Pro.
4 stars 0 forks source link

Move knob #15

Closed dotherightthing closed 1 year ago

dotherightthing commented 1 year ago

Inspecting the MIDI output of the Kontrol Z1 Mk2 left encoder, it seems that it generates a value of 127 when moving left and 1 when moving right.

I'm not 100% sure if that's true as I then put in some code that forced that, so not sure if I was seeing the natural or forced behaviour:

Screen Shot 2022-10-02 at 10 41 58 PM

Screen Shot 2022-10-02 at 10 44 03 PM

// TraktorPro3.js

// globals
inlets = 1
outlets = 2
var oldTime;

function getResetValue(val) {
  var midPoint = 64;
  var centerPull = 10;
  var resetValue;

  // val 60
  // 60 < 64
  // 60 >= 64-10 = 54
  // 60 >= 64-9  = 55
  // 60 >= 64-8  = 56
  // 60 >= 64-7  = 57
  // 60 >= 64-6  = 58
  // 60 >= 64-5  = 59
  // 60 >= 64-4  = 60
  // 60 <  64-3  = 61
  // centerPull = 3
  // resetValue = 60 + 3 = 63

  // val 70
  // 70 >= 64
  // 70 <= 64+10 = 74
  // 70 <= 64+9 = 73
  // 70 <= 64+8 = 72
  // 70 <= 64+7 = 71
  // 70 <= 64+6 = 70
  // 70 >  64+5 = 69
  // centerPull = 5
  // resetValue = 70 - 5 = 65

  if (val < midPoint) {
    // control moving left
    while (val >= (midPoint - centerPull)) {
      centerPull -= 1;
    }

    resetValue = val + centerPull;
  } else {
    // control moving right
    while (val <= (midPoint + centerPull)) {
      centerPull -= 1;
    }

    resetValue = val - centerPull;
  }

  return resetValue;
}

function controlStillMoving(arg) {
  var timeDifference = 0;
  var newTime = new Date().getMilliseconds();
  var knobNewValue = arg;

  if (typeof oldTime === 'number') {
    timeDifference = (newTime - oldTime);
  }

  if (timeDifference < 1000) {
    knobNewValue = getResetValue(arg); 
  }

  oldTime = newTime;

  outlet(0, arg);
  outlet(1, knobNewValue);
}

Anyway. With the forced behaviour, the dial needs to jogged back-and-forth within the value range 0-63 to move left, or 64-127 to move right. They key thing is that this process needs to be made to repeat so that the change message is registered so the logic can run. Mapping the X1 touchstrip also works, in that case swiping right to left on the left portion moves back, and swiping left to right on the right portion moves forward.

Max4Live does not have an endless encoder object, only a fixed 0-127 dial (or slider). So I put in a JS fix to pull the knob back towards the center. While the user is still turning the knob, this will feed a reset value back into the knob so that it never reaches its limits.

Even with this fix the behaviour of the live.dial is not great. So, while I'd love to have everything managed from Live, so that any controller could be used for scrubbing, I'll have to let my Kontrol X1 Mk2 manage this natively for now.

dotherightthing commented 1 year ago

Kontrol X1 Mk2 replaced with Kontrol S8