Pages: [1]   Go Down
Author Topic: MIDI cc problems with Midi Library, Hairless MIDI and Ableton Live  (Read 96 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm creating my own MIDI Controller using the Arduino MIDI library.
I succeed sending notes into Ableton Live, but I have some problems sending MIDI controls.
I want to trigger a loop with a button but there is lag and Ableton Live just starts to go crazy and I have to close it. Maybe should I use another CC number? or another Arduino input?
I selected cc 16 because it's for general purpose (i read it here: http://nickfever.com/402/production-tips-and-resources/midi-cc-list/)

Here is my code:
Code:
#include <MIDI.h>

//Starting MIDI
MIDI_CREATE_DEFAULT_INSTANCE();

//VARIABLES

//the Led will shine while the button is pressed
int led = 13;

//button1 sends note, button2 sends Control Change
int button1 = 2;
int button2 = 4;

//last button state counter
int lastB1State = 0;
int lastB2State = 0;

//curent button state counter
int currentB1State = 0;
int currentB2State = 0;

//Note 60 = C
int note = 60;

//Control 16 = general purpose
int cc = 16;

//Setup:
void setup(){
 
  //Start midi connection
  MIDI.begin();
 
  //Serial connection 115200 for Hairless MIDI
  Serial.begin(115200);
 
  //input button, output led
  pinMode(led, OUTPUT);
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
}

//Loop:
void loop(){
 
  //FIRST PART WORKING PERFECT
 
  //BUTTON1 = B1 = piano key
  currentB1State = digitalRead(button1);
 
  if( currentB1State == 1){
   
    if (lastB1State == 0) {
      MIDI.sendNoteOn(note,127,1);
      digitalWrite(led, HIGH);
    }
   
    lastB1State = 1;

  }else{
   
    if(currentB1State == 0){
     
      if (lastB1State == 1) {
        MIDI.sendNoteOff(note,0,1);
        digitalWrite(led, LOW);
      }
     
      lastB1State = 0;
    }
  }
 
  //HERE I HAVE PROBLEMS
 
  //BUTTON2 = B2 = CC
  currentB2State = digitalRead(button2);
 
  if( currentB2State == 1){
   
    if (lastB2State == 0) {
      MIDI.sendControlChange(cc,127,1); //HERE IS WHERE I WANT TO SEND THE CONTROL CHANGE
      digitalWrite(led, HIGH);
    }
   
    lastB2State = 1;

  }else{
   
    if(currentB2State == 0){
     
      if (lastB2State == 1) {
        MIDI.sendControlChange(cc,0,1);
        digitalWrite(led, LOW);
      }
     
      lastB2State = 0;
    }
  }
 
 
 
  //50ms space
  delay(50);
}

Thank you for your help
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34220
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this:-

Code:
//BUTTON2 = B2 = CC
  currentB2State = digitalRead(button2);
 
  if( currentB2State == 1 && lastB2State == 0){
      MIDI.sendControlChange(cc,127,1);
      digitalWrite(led, HIGH);
  } 
  if (currentB2State == 0 && lastB2State == 1) {
        MIDI.sendControlChange(cc,0,1);
        digitalWrite(led, LOW);
      }
     
      lastB2State = currentB2State;

 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much, now it works with controls like stop tracks, solo, rec, etc... but when I trigger a loop it overflows.
Maybe there are some controls that are better than others? I don't really understand how Midi CC works in Ableton Live.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34220
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but when I trigger a loop it overflows
Not sure I know what you mean by that?

That code is just sending the value 0 or 127 to a controller. Some control inputs need a value between those two value, for example a volume control.
Logged

Pages: [1]   Go Up
Jump to: