Error compiling MIDI input test code.

Hey all,

This, unfortunately, is my first post and it happens to be a code issue. I'm getting 4 errors when trying to compile. Since I'm completely new here and to the Arduino platform, I need a little n00b guidance to get me off the ground. First the code:

char foo;

#include "MIDI.h"

void setup() {
  MIDI.begin(MIDI_CHANNEL_OMNI);
  Serial.begin(57600);
  Serial.println("MIDI Input Test");
}

unsigned long t=0;

void loop() {
  int type, note, velocity, channel, d1, d2;
  if (MIDI.read()) {                    // Is there a MIDI message incoming ?
    byte type = MIDI.getType();
    switch (type) {
    case NoteOn:
      note = MIDI.getData1();
      velocity = MIDI.getData2();
      channel = MIDI.getChannel();
      if (velocity > 0) {
        Serial.println(String("Note On:  ch=") + channel + ", note=" + note + ", velocity=" + velocity);
      } 
      else {
        Serial.println(String("Note Off: ch=") + channel + ", note=" + note);
      }
      break;
    case NoteOff:
      note = MIDI.getData1();
      velocity = MIDI.getData2();
      channel = MIDI.getChannel();
      Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
      break;
    default:
      d1 = MIDI.getData1();
      d2 = MIDI.getData2();
      Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2);
    }
    t = millis();
  }
  if (millis() - t > 10000) {
    t += 10000;
    Serial.println("(inactivity)");
  }
}

Next, the errors.

In file included from MIDI_IN_Test.ino:3:
/Applications/Arduino.app/Contents/Resources/Java/libraries/MIDI/MIDI.h:67: error: expected identifier before numeric constant
/Applications/Arduino.app/Contents/Resources/Java/libraries/MIDI/MIDI.h:67: error: expected `}' before numeric constant
/Applications/Arduino.app/Contents/Resources/Java/libraries/MIDI/MIDI.h:67: error: expected unqualified-id before numeric constant
/Applications/Arduino.app/Contents/Resources/Java/libraries/MIDI/MIDI.h:86: error: expected declaration before '}' token

I've searched for answers but haven't found anything that really helped me out. Thanks for your time!

The error is in Midi.h. Something is probably not defined, especially if midi.h was written for an earlier IDE. Can you post midi.h?

Thanks for your reply!

I’ve attached MIDI.h

MIDI.h.zip (3.7 KB)

If you downloaded that library it should not be inside the Arduino.app file. Read this:

http://arduino.cc/en/Guide/Libraries

Hey Nick, thanks for the reminder! Unfortunately, that has already been cleared as a possible problem on my end... I installed the library as per your link but still no joy. Same error messages. This code is just reused from the teensy midi-in example here: http://www.pjrc.com/teensy/td_libs_MIDI.html I would think they made sure their code worked before posting it! Maybe it was written with an earlier version of the MIDI library...?

Which of their libraries did you download (file name)? I downloaded the top one and got:

In file included from sketch_mar29a.ino:3:
/Users/nick/Documents/Arduino/libraries/MIDI/MIDI.h:131: error: ISO C++ forbids declaration of 'w' with no type
/Users/nick/Documents/Arduino/libraries/MIDI/MIDI.h:139: error: expected ';' before 'public'

So, not the same error.

At the start of MIDI.cpp, change:

#include "MIDI.h"
#include <stdlib.h>
#include "WConstants.h" 
#include "HardwareSerial.h"

to:

#include "MIDI.h"
#include "Arduino.h

Then it should compile OK.

Thanks Nick! That solved it! I owe you one!