usbMIDI.sendControlChange() breaking DAW

Status
Not open for further replies.

steve_o

New member
Hey all,

I was just making a MIDI controller to control Ableton Live with a Teensy 3.5. I had some buttons sending MIDI notes and all was good. I then added some pretty simple code to send a CC message every time a potentiometer's position moves. For some reason, as soon as Ableton received a few CCs, it completely stopped reading them and any other USB MIDI messages in from Teensy. I Googled around for a while until I found a random post about USB MIDI controllers I think on this very forum (sorry can't find the link) with someone adding "usbMIDI.read();" in the loop and commenting that this, for some reason, is necessary.

I followed this person's advice and added usbMIDI.read(); to my loop and all of the sudden MIDI CCs now work perfectly in Ableton.

Can anyone help me understand what exactly is going on behind the scenes here and why exactly this seemingly unintuitive step (which I never would have guessed) of reading in MIDI messages *into* the MIDI controller is necessary just to make a MIDI controller with MIDI CCs? Is the DAW sending MIDI messages back to the DAW and the buffer overflows if I don't read them in?

Any thoughts are appreciated. Thanks so much.

Code:
int lastPotVal = 0;
int potVal = 0;
int ccVal = 0;
unsigned long lastCCTime = 0;

void setup() {
}

void loop() {

  usbMIDI.read();

  lastPotVal = potVal;
  potVal = analogRead(A14);

  ccVal = map(potVal, 0, 1023, 0, 127);

  if (potVal != lastPotVal && millis() > lastCCTime + 10) {
    lastCCTime = millis();
    usbMIDI.sendControlChange(1, ccVal, 1);
  }
}
 
If there is no .read the host can freeze as its data buffer overflows.

If it gets a .read it clears the cached data... otherwise it's just waiting to overload.

What is sending it midi is a separate mystery.
 
Status
Not open for further replies.
Back
Top