version 1.6 breaks MIDI library. I think.

Either that or there is some new weirdness in SoftwareSerial.

I have a very simple sketch: just uses event handlers to change PWM lights in response to MIDI input via a SoftwareSerial input.

Works perfectly when built with 1.0.6

Misses almost all the MIDI events when built with 1.6

Works perfectly when compiled with 1.0.6 again.

No compiler errors or warnings.

It looks like something in the interrupt handling has changed, but since this is the "official" MIDI library I would expect any such big changes to be documented somewhere.

Is this a problem with the new version of gcc? Any good ideas on how to fix it?

Can you share the whole sketch so we may try to reproduce the issue?

Sure. Here is the entire sketch:

#include <SoftwareSerial.h>

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

extern void handleNoteOn(byte channel, byte pitch, byte velocity);
extern void handleNoteOff(byte channel, byte pitch, byte velocity);
extern void handleStop();

#define N_NOTES  12
const int pins[][3] = {{10, 9, 11}, {5, 3, 6}};
volatile int currentNote[] = {0, 0};
int brightness[] = {0, 0, 0};
const int black[] = {0, 0, 0};
const int red[] = {255, 0, 0};
const int yellow[] = {128, 50, 0};
const int green[] = {0, 200, 0};
const int aqua[] = {0, 100, 128};
const int blue[] = {0, 0, 255};
const int violet[] = {128, 0, 128};
const int gain[] = {100, 170, 150};
int notecolor[N_NOTES][3];

SoftwareSerial softSerial(7,8);
MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiA);

void setup()  { 
  // declare pwm pins to be output:
  for (int i=0; i<3; i++) {
    pinMode(pins[0][i], OUTPUT);
    pinMode(pins[1][i], OUTPUT);
  }
  
  for (int i=0; i<N_NOTES; i++) {
    calcBrightness((i * 768) / N_NOTES);
    copyColor(notecolor[i], brightness);
  }
  midiA.setHandleNoteOn(handleNoteOn);
  midiA.setHandleNoteOff(handleNoteOff);
  midiA.setHandleStop(handleStop);
  midiA.begin(MIDI_CHANNEL_OMNI);
} 

void loop()  { 
  midiA.read();
}

void copyColor(int target[], const int source[]) {
  for (int i=0; i<3; i++) {
    target[i] = source[i];
  }
}

void displayColor(const int pin[], const int color[]) {
  analogWrite(pin[0], (color[0] * 100) / gain[0]);
  analogWrite(pin[1], (color[1] * 100) / gain[1]);
  analogWrite(pin[2], (color[2] * 100) / gain[2]);
}

void calcBrightness(int i)
{
  if (i < 128) {
    interpolate(red, yellow, 128-i);
  } else if (i < 256) {
    interpolate(yellow, green, 256-i);
  } else if (i < 384) {
    interpolate(green, aqua, 384-i);
  } else if (i < 512) {
    interpolate(aqua, blue, 512-i);
  } else if (i < 640) {
    interpolate(blue, violet, 640-i);
  } else if (i < 768) {
    interpolate(violet, red, 768-i);
  }
}

void interpolate(const int *c1, const int *c2, int i)
{
  int c;
  for (c = 0; c<3; c++) {
    brightness[c] = (c1[c] * i + c2[c] * (128 - i)) / 128;
  }
}

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
  int p, ch;
  if (channel <= 2) {
    ch = channel - 1;
    if (ch >= 0) {
      p = pitch % N_NOTES;
      currentNote[ch] = pitch;
      displayColor(pins[ch], notecolor[p]);
    }
  }
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
  int ch;
  if (channel <= 2) {
    ch = channel - 1;
    if (ch >= 0) {
      if (currentNote[ch] == pitch) {
        displayColor(pins[ch], black);
      }
    }
  }
}

void handleStop()
{
  for (int i=0; i<2; i++) {
    displayColor(pins[i], black);
    currentNote[i] = 0;
  }
}

Your sketch compiles fine: using MIDI 4.2 Release Arduino MIDI Library v4.2 · FortySevenEffects/arduino_midi_library · GitHub

That's the right version.

I'm sorry I was not clear: The sketch compiles fine. There are no error messages at any time.

The error is a runtime problem. It misses almost all the MIDI events. Compiling with v1.0.6 results in the sketch working perfectly. As I said, it looks like there is something weird happening with the interrupts.

It's looking like a problem with SoftwareSerial. Anybody else have troubles with it and the new avr-gcc?