Skip to content

My MIDI controller freezes up my Roland synth. #28

@romandesign

Description

@romandesign

Something in the way this library works freezes my Rolang Go:Keys 5 synth after a minute or 2 of using Arduino Pro Micro MIDI controller. Using my Alesis Vorex 2 keytar as MIDI controller doesn't do this. I measured power draw and Alesis takes 0.13A, while Arduino Pro Micro doesn't even registers (0A) so it's not the power draw. Must be something in the MIDI. I tried adding 20ms delay after sending each MIDI message, which made the controller almost unusable, but it didn't help.

Any idea? Is it a USBMIDI bug or am I doing something wrong? Here's the part of my code that's sending MIDI messages:

// --- JOYSTICK HANDLING BLOCK ---
  const int DEADZONE = 50;
  int rawXValue = analogRead(X_PIN);
  int rawYValue = analogRead(Y_PIN);
  int xVal = filterAnalog(rawXValue, xVal, 0.4); // adjust alpha as needed
  int yVal = filterAnalog(rawYValue, yVal, 0.4); // adjust alpha as needed
  //int xVal = analogRead(X_PIN);
  //int yVal = analogRead(Y_PIN);
  int bend = map(xVal, 0, 406, 16383, 0); // X axis: pitch bend
  // Reverse Y axis so up = higher value
  int mod = map(yVal, 203, 406, 0, 127);                 // Y axis: modulation
  int expr = map(yVal, 0, 203, minExpression, 127);    // Y axis: expression

  // Only send/display if joystick values change by more than threshold
  
  if (abs(bend - lastBend) > JOY_THRESHOLD) {
      if (abs(xVal - 203) > DEADZONE) {
        MIDI.sendPitchBend(bend, 4);
        delay(throttlingDelay);
      } else {
        MIDI.sendPitchBend(8192, 4);
        delay(throttlingDelay);
      }
      int bendPercent = map(bend, 16383, 0, 100, -100);
      //displaySetting("Pitch Bend", bendPercent);
      displaySetting("Pitch Bend", xVal);
      lastValueChangeTime = millis();
      lastBend = bend;
  }
 
  
  if ((abs(mod - lastMod) > JOY_THRESHOLD) && (yVal > 203)) {
      if (abs(yVal - 203) > DEADZONE) {
        MIDI.sendControlChange(1, mod, 4); // Modulation
        delay(throttlingDelay);
      } else {  
        MIDI.sendControlChange(1, 0, 4); // Modulation
        delay(throttlingDelay);
      }
      displaySetting("Modulation", mod);
      lastValueChangeTime = millis();
      lastMod = mod;
  }
  if ((abs(expr - lastExpr) > JOY_THRESHOLD) && (yVal <= 203)) {
      MIDI.sendControlChange(11, expr, 4); // Expression
      delay(throttlingDelay);
      displaySetting("Expression", yVal);
      lastValueChangeTime = millis();
      lastExpr = expr;
  }
  // --- END JOYSTICK HANDLING BLOCK ---

  // READ POTS 
  static int filteredPot[6] = {0,0,0,0,0,0}; // store last filtered values  
  
  for (int i = 0; i < 6; i++) {
    int rawValue = analogRead(Pot[i]);
    filteredPot[i] = filterAnalog(rawValue, filteredPot[i], 0.5); // adjust alpha as needed
    int mapped = map(filteredPot[i], 0, 1023, 0, 127);
    if (abs(mapped - lastPotState[i]) > 0) {
      MIDI.sendControlChange(page0CC[i], mapped, 4);
      delay(throttlingDelay);
      lastPotState[i] = mapped;
      displaySetting(pageName[0][i], mapped);
      lastValueChangeTime = millis();
      inputDetected = true;
    }
  }
  
  //Reverb Encoder
  long reverbPos = reverbEncoder.read() / 4;
  if (reverbPos != lastReverbPos) {
    int delta = reverbPos - lastReverbPos;
    initialReverb = constrain(initialReverb + delta, 0, 127);
    MIDI.sendControlChange(reverbCC, initialReverb, 4);
    delay(throttlingDelay);
    displaySetting(pageName[0][6], initialReverb);
    lastReverbPos = reverbPos;
    lastValueChangeTime = millis();
    inputDetected = true;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions