Traktor MIDI Controller

Status
Not open for further replies.

CocoNat

Member
Hi guys,

I'm trying to map an encoder, for start. I've been following this instructable https://www.instructables.com/id/A-Framework-For-Making-Affordable-Stylish-Modula/
and modified it, using this code:
Code:
int pressed1 = 0;
int p1_state = 0;
int encoder_pin_a = 0;
int encoder_pin_b = 1;
boolean enableDebug = 0;

int8_t enc_states[] = 
{
  0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0 //16
};

int read_encoder(){
  p1_state <<= 2;
  p1_state |= (digitalRead(encoder_pin_a)<< 1 | digitalRead(encoder_pin_b));
  p1_state &= 0x0f;
  return enc_states[p1_state];
  }

void intFunc1(void){
  pressed1=1;
  }

void setup() {
  if(enableDebug==1){
  Serial.begin(9600);//open serail port @ debug speed
  }
  else{
  Serial.begin(31250);//open serail port @ midi speed
  }
  pinMode(encoder_pin_a, INPUT);
  digitalWrite(encoder_pin_a,HIGH);
  pinMode(encoder_pin_b, INPUT);
  digitalWrite(encoder_pin_b, HIGH);
  attachInterrupt(0, intFunc1, CHANGE);
  attachInterrupt(1, intFunc1, CHANGE);
}

void loop() 
{
  if(pressed1){ //encoder has been touched
    pressed1=0; //reset flag
    switch(read_encoder()){ //call out encoder function
    case -1:
    if (enableDebug==1){
     Serial.println("encoder +"); 
    }
    else {
      usbMIDI.sendNoteOn(1,127,127); 
    }
      break;
    case 0:
      break;
    case 1:
    if(enableDebug==1){
     Serial.println("encoder -"); 
    }
    else {
      usbMIDI.sendNoteOn(1,127,126);
    }
      break;
    }
  }
}

Is this the kind of MIDI message you would use to map to Traktor? When I try to map it, what I get is jog turn only in one direction, regardless in which direction I turn the encoder.

Any kind of help is deeply appreciated.

Best regards,
Natasha
 
Hi guys,

I'm trying to map an encoder, for start. I've been following this instructable https://www.instructables.com/id/A-Framework-For-Making-Affordable-Stylish-Modula/
and modified it, using this code:
Code:
int pressed1 = 0;
int p1_state = 0;
int encoder_pin_a = 0;
int encoder_pin_b = 1;
boolean enableDebug = 0;

int8_t enc_states[] = 
{
  0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0 //16
};

int read_encoder(){
  p1_state <<= 2;
  p1_state |= (digitalRead(encoder_pin_a)<< 1 | digitalRead(encoder_pin_b));
  p1_state &= 0x0f;
  return enc_states[p1_state];
  }

void intFunc1(void){
  pressed1=1;
  }

void setup() {
  if(enableDebug==1){
  Serial.begin(9600);//open serail port @ debug speed
  }
  else{
  Serial.begin(31250);//open serail port @ midi speed
  }
  pinMode(encoder_pin_a, INPUT);
  digitalWrite(encoder_pin_a,HIGH);
  pinMode(encoder_pin_b, INPUT);
  digitalWrite(encoder_pin_b, HIGH);
  attachInterrupt(0, intFunc1, CHANGE);
  attachInterrupt(1, intFunc1, CHANGE);
}

void loop() 
{
  if(pressed1){ //encoder has been touched
    pressed1=0; //reset flag
    switch(read_encoder()){ //call out encoder function
    case -1:
    if (enableDebug==1){
     Serial.println("encoder +"); 
    }
    else {
      usbMIDI.sendNoteOn(1,127,127); 
    }
      break;
    case 0:
      break;
    case 1:
    if(enableDebug==1){
     Serial.println("encoder -"); 
    }
    else {
      usbMIDI.sendNoteOn(1,127,126);
    }
      break;
    }
  }
}

Is this the kind of MIDI message you would use to map to Traktor? When I try to map it, what I get is jog turn only in one direction, regardless in which direction I turn the encoder.

Any kind of help is deeply appreciated.

Best regards,
Natasha

The official way to send encoder messages is using control change numbers 96 & 97, they are named “data increment” and “data decrement” respectively. However even though this is the official way in the midi documentation not every DAW will actually use it, it’s also important to note that it can be used as part of rpn or nrpn commands though I don’t believe it’s required in order to use it. So your typical midi message and will look like ‘b0 60 ff’ to increase controller number 127 and ‘b0 61 ff’ to decrease controller number 127, based on that you can discern that the third byte is the controller number you want to edit whereas for normal control change messages it’s the second byte.

So try using this to increment
Code:
usbMIDI.sendControlChange(1, 96, encoderNumber);

And this to decrement
Code:
usbMIDI.sendControlChange(1, 97, encoderNumber);

I can confirm that this works in FL Studio but you will have to test your DAW, some use it and some don’t.
 
As far as I remember I believe Native Instruments does implement NRPNs, if that is the case the Teensy usbMIDI library has built in functions to send them.

This is the list of functions it has for NRPN messages
Code:
beginNrpn(number, channel, cable);
sendNrpnValue(value, channel, cable);
sendNrpnIncrement(amount, channel, cable);
sendNrpnDecrement(amount, channel, cable);
endNrpn(channel, cable);

So to send a full NRPN message the structure looks like this for both increment and decrement
Code:
uint16_t controlNumber = 12 //0-16382       16383 is used as null to end NRPNs
uint8_t channelNumber = 1 //1-16
uint8_t incrementAmount = 1 //0-127 typically 1 and sometimes ignored in DAWs
usbMIDI.beginNrpn(controlNumber, channelNumber);
usbMIDI.sendNrpnIncrement(incrementAmount, channelNumber); //Any amount of changes can be sent before ending a NRPN
usbMIDI.endNrpn(channelNumber); //NRPNs also don’t have to be ended, but it’s best practice to end after your values are sent so a stray message doesn’t interfere with anything down the line
 
Status
Not open for further replies.
Back
Top