Go Down

Topic: midi effects pot help (Read 373 times) previous topic - next topic

michael040990

hey can anyone help me my code is making the values jump around when i try to map them in traktor pro


an example output when trying to map them is like
Code: [Select]

ch16.note.B8
ch16.note.63+ch8.CC.00
ch8.note.D#4
ch16.note.63+ch8.CC.12

its being used as a midi effects pot
it seems to be jumping channels and from note to control chainge any help would be great

Code: [Select]


/* The format of the message to send via serial */
typedef struct {
 uint8_t command;
 uint8_t channel;
 uint8_t data2;
 uint8_t data3;
}
t_midiMsg;

int potPin[] = {
 0};                 //choose the input pin for a potentometer
int potVal[] = {
 0};                 //variable for reading potentiometer value
int mappedPotVal[] = {
 0};           //variable for holding remapped pot value
int prevPotVal[] = {
 0};             //variable for storing our prev pot value
int THRESHOLD = 2;    
int MAX_POT = sizeof(potPin);
int channel = 1;

void setup() {
 // set up serial port
 Serial.begin(31250);
}

void loop() {

 for (int mypots = 0; mypots < MAX_POT /2; mypots++){

   potVal[mypots] = analogRead(potPin[mypots]);                       //read input from potentiometer
   mappedPotVal[mypots] = map(potVal[mypots], 0, 1023, 0, 127);       //map value to 0-127
   if(abs(mappedPotVal[mypots] - prevPotVal[mypots]) >= THRESHOLD){
     sendmidi(0xB0, mypots, mappedPotVal[mypots]);                    //Control Change (Ch 1), Controller 7 - default control for volume.
     prevPotVal[mypots] = mappedPotVal[mypots];
   }
   else{
   }
   // end pot code  
 }

}


void sendmidi(int command,int data2, int data3){
 t_midiMsg msg;
 int ind;
 /* Send the notes */

 msg.command = command;   //noteon
 msg.channel = channel;
 msg.data2   = data2;     //note
 msg.data3   = data3;     /* Velocity */
 Serial.write((uint8_t *)&msg, sizeof(msg));
}


marco_c

Is the pot connected to the same port that you are reading? If it is, is the wiring correct?

Lots of examples to look at if you need to know how.
Arduino libraries http://arduinocode.codeplex.com<br />Parola for Arduino http://parola.codeplex.com

michael040990

sorry for the late responce i found out from trial and error that the midi message needed to be send using 4 parts
and ended up using Serial.write()\s insted of

Code: [Select]

  msg.command = command;   //noteon
  msg.channel = channel;
  msg.data2   = data2;     //note
  msg.data3   = data3;     /* Velocity */
  Serial.write((uint8_t *)&msg, sizeof(msg));


in the end this is what worked
Code: [Select]
 
/* The format of the message to send via serial */
typedef struct {
  uint8_t command;
  uint8_t channel;
  uint8_t data2;
  uint8_t data3;
}
t_midiMsg;

int potPin[] = {
  0};                 //choose the input pin for a potentometer
int potVal[] = {
  0};                 //variable for reading potentiometer value
int mappedPotVal[] = {
  0};           //variable for holding remapped pot value
int prevPotVal[] = {
  0};             //variable for storing our prev pot value
int THRESHOLD = 2;     
int MAX_POT = sizeof(potPin)/2;
int channel = 1;

void setup() {
  // set up serial port
  Serial.begin(115200);
}

void loop() {

  for (int mypots = 0; mypots < MAX_POT; mypots++){

    potVal[mypots] = analogRead(potPin[mypots]);                       //read input from potentiometer
    mappedPotVal[mypots] = map(potVal[mypots], 0, 1023, 0, 127);       //map value to 0-127
    if(abs(mappedPotVal[mypots] - prevPotVal[mypots]) >= THRESHOLD){
    //controlChange(channel, 0xB0, mappedPotVal[mypots]);
   
   
controlChange(0xB0,1,0x01,mappedPotVal[mypots]);


//Serial.println("---------------------");
//Serial.println(mypots);
//Serial.println(mappedPotVal[mypots]);
//Serial.println("---------------------");
//delay(100);
      prevPotVal[mypots] = mappedPotVal[mypots];
    }
    // end pot code 
  }
}
void controlChange(byte statusbit,byte channel, byte control, byte value)
{
      Serial.write(statusbit);
      Serial.write(control);
      Serial.write(channel);
      Serial.write(value);
}

thanks

PaulS

Code: [Select]
int potPin[] = {
  0};                 //choose the input pin for a potentometer
int potVal[] = {
  0};                 //variable for reading potentiometer value
int mappedPotVal[] = {
  0};           //variable for holding remapped pot value
int prevPotVal[] = {
  0};             //variable for storing our prev pot value

One element arrays have absolutely no advantage over scalar variables.

Go Up