Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: usbMIDI.sendControlChange() breaking DAW

  1. #1
    Junior Member
    Join Date
    Jan 2017
    Posts
    4

    usbMIDI.sendControlChange() breaking DAW

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

  2. #2
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,378
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •