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

Thread: Help with MIDI Controller: Trying to send pitch bend over 8 separate channels

Threaded View

  1. #1

    Help with MIDI Controller: Trying to send pitch bend over 8 separate channels

    I'm running into an issue in a MIDI controller project I'm working on. I'm trying to make an MPE controller that will send pitch bend data over 8 channels of MIDI. But for some reason, I can only send 2 channels at a time. Every time I introduce a third channel, the program completely crashes.

    Is there something I'm missing about the MIDI library that I need to address to be able to do this?

    Here's a condensed version of the code. I'm using a serial output on the Teensy 4.1.

    Any help would be greatly appreciated.

    Code:
    #include <MIDI.h>
    
    // DIN MIDI
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI);
    
    void setup() {
      MIDI.begin();
      delay(100);
    }
    
    void loop() {
      updateSlider(1, analogRead(A0));
      updateSlider(2, analogRead(A1));
      updateSlider(3, analogRead(A2));
      updateSlider(4, analogRead(A3));
      updateSlider(5, analogRead(A4));
      updateSlider(6, analogRead(A5));
      updateSlider(7, analogRead(A6));
      updateSlider(8, analogRead(A7));
    }
    
    void updateSlider(byte sliderNumber, int value) {
      int osc1Bend,
          osc2Bend,
          osc3Bend,
          osc4Bend,
          osc5Bend,
          osc6Bend,
          osc7Bend,
          osc8Bend;
    
      // Pitch bend goes from -8192 to +8192.
      // The MPE standard is 48 semitones for a full pitch up/down.
      int pitchBendMultiplier = 8192 / 48;
    
      switch (sliderNumber) {
        case 1:
          osc1Bend = map(value, 0, 1023, 0, 3 * pitchBendMultiplier);
          MIDI.sendPitchBend(osc1Bend, sliderNumber);
          break;
        case 2:
          osc2Bend = map(value, 0, 1023, 0, 3 * pitchBendMultiplier);
          MIDI.sendPitchBend(osc2Bend, sliderNumber);
          break;
        case 3:
          osc3Bend = map(value, 0, 1023, 0, 3 * pitchBendMultiplier);
          MIDI.sendPitchBend(osc3Bend, sliderNumber);
          break;
        case 4:
          osc4Bend = map(value, 0, 1023, 0, 3 * pitchBendMultiplier);
          MIDI.sendPitchBend(osc4Bend, sliderNumber);
          break;
        case 5:
          osc5Bend = map(value, 0, 1023, 0, 3 * pitchBendMultiplier);
          MIDI.sendPitchBend(osc5Bend, sliderNumber);
          break;
        case 6:
          osc6Bend = map(value, 0, 1023, 0, 3 * pitchBendMultiplier);
          MIDI.sendPitchBend(osc6Bend, sliderNumber);
          break;
        case 7:
          osc7Bend = map(value, 0, 1023, 0, 3 * pitchBendMultiplier);
          MIDI.sendPitchBend(osc7Bend, sliderNumber);
          break;
        case 8:
          osc8Bend = map(value, 0, 1023, 0, 3 * pitchBendMultiplier);
          MIDI.sendPitchBend(osc8Bend, sliderNumber);
          break;
      }
    
    
    }
    Last edited by toutant; 07-28-2021 at 02:56 AM. Reason: typo in the code

Posting Permissions

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