Pages: [1]   Go Down
Author Topic: midi effects pot help  (Read 326 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 1
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:

/* 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));
}

Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1260
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Offline Offline
Jr. Member
**
Karma: 1
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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:
 
/* 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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
Logged

Pages: [1]   Go Up
Jump to: