Midi Mapping from Leonardo to Ableton

hi.

I am using a leonardo to send midi messages to ableton live.

It works well when I use it as a midi note generator using 3 potentiometers to generate 3 x (0-127) midi notes into three channels that are mapped to 'lanes' in ableton.

But when I try to 'midi map' to the volume sliders it only seems to use one channel?
Making one pot control all three - which I don't want.

Am I missing something - perhaps the way the midi message is being formulated?


#include "MIDIUSB.h"

#define POT_PIN_0 A0
#define POT_PIN_1 A1
#define POT_PIN_2 A2

int lastNote_0 = 0;
int lastNote_1 = 0;
int lastNote_2 = 0;

//USING MIDI MAPPING IN ABLETON
//
void setup() {
  Serial.begin(115200);

}

void loop() {
  //read analogue pin

    int fader_0 = analogRead(POT_PIN_0);
    int note_0 = map(fader_0, 0, 1023, 0, 127);

    int fader_1 = analogRead(POT_PIN_1);
    int note_1 = map(fader_1, 0, 1023, 0, 127);

    int fader_2 = analogRead(POT_PIN_2);
    int note_2 = map(fader_2, 0, 1023, 0, 127);

    int channel_0 = 1;
    int channel_1 = 2;
    if(lastNote_0 != note_0){
      noteOn1(channel_0, note_0, 64);   // Channel 0, middle C, normal velocity
      lastNote_0 = note_0;
    }
    
     if(lastNote_1 != note_1){
      noteOn2(channel_1, note_1, 64);   // Channel 0, middle C = 60, normal velocity
     }
    
}
//midi
void noteOn1(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}
void noteOn2(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}

void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
}

i worked it out..

midi needs one note at a time?

so rather than sending 2/3 notes on/off on different channels. I just use the 'noteOn()' call once per loop - but change the values depending on whether i am using the faders.

This is just for mapping - if using as instrument maybe different?

:slight_smile:

void loop() {
  //read analogue pin

    int fader_0 = analogRead(POT_PIN_0);
    int note_0 = map(fader_0, 0, 1023, 0, 127);
//    Serial.println(note_0);//0 ok
    
    int fader_1 = analogRead(POT_PIN_1);
    int note_1 = map(fader_1, 0, 1023, 0, 127);
//    Serial.println(note_1);//0 ok

    int fader_2 = analogRead(POT_PIN_2);
    int note_2 = map(fader_2, 0, 1023, 0, 127);
//    Serial.println(note_2);//0 ok

  if(note_0 != lastNote_0){
      //theres a change on 0
      note = note_0;
      ch = 0;
      lastNote_0 = note_0;
        //neo
      int color_0 = map(fader_0, 0, 1023, 0, 16);
      colorGrade(strip.Color(0, 200, 215),50,color_0);
      
    }else if(note_1 != lastNote_1){
      //theres a change on 1
      note = note_1;
      ch = 1;
      lastNote_1 = note_1;
    }else if(note_2 != lastNote_2){
      //theres a change on 1
      note = note_2;
      ch = 2;
      lastNote_2 = note_2;
    }
    //one message every blit
    noteOn(ch, note, 64);   // Channel 0, middle C, normal velocity 
     
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.