ddiakopoulos/hiduino

'Midi' was not declared in this scope

s00500 opened this issue · 8 comments

When i try to run the examples the compiler says: 'Midi' was not declared in this scope
What`s the problem??

It's likely that you don't have the the Arduino MIDI lib in your libraries folder. Download this: https://github.com/FortySevenEffects/arduino_midi_library and be sure to restart Arduino before trying to recompile the HIDUINO example.

Thank you ! I thought i had to use the hiduno lib in the src folder
Thanks for the quick response and the great project =D

Hello,

Sorry I'm new to this. I'm getting a similar error. I placed the arduino_midi_library into my arduino/libraries folder. Still getting the same error. "midi was not declared in scope"

also #include <midi.h> "midi" is in red, not sure what that means.

Here is my code:

#include <MIDI.h>
#include "LPD8806.h"
#include "SPI.h"

int LED = 13;       // on-board LED
int nLEDs = 32;         //LED strip num LEDs
int dataPin  = 2;       //LED strip data
int clockPin = 3;

LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);

void setup() {
  pinMode(LED, OUTPUT);
  MIDI.begin(MIDI_CHANNEL_OMNI);                // Launch MIDI with default options         
  strip.begin();
  strip.show();
}

void loop() {

  int i;

  for(i=0; i< strip.numPixels() ; i++) strip.setPixelColor(i, 0);  strip.show();              // Refresh LED states

  int type, note, velocity, channel, d1, d2;

  digitalWrite(LED,LOW);                  // Is there a MIDI message incoming ?

    if(MIDI.read() && MIDI.getType() == NoteOn){       // Is it a Note ON?

    digitalWrite(LED,HIGH);  // Blink on-board LED for debugging purposes
         note = MIDI.getData1();
         velocity = MIDI.getData2();
         channel = MIDI.getChannel();

         if (velocity > 1) {
           colorExplode(
              RandomColor(),   //color 
              30,              //speed of explosion
              note,            //note
              5                //max spread
           );   
         }
    }   
}

void colorExplode(uint32_t c, uint8_t wait,int note,int maxSpread) {
  // Start by turning all pixels off:
  int i = 0;
  int start = note - 60;
  for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);

  unsigned long startTime = millis();
  unsigned long currTime;

  // first hold the note for 1000 miliseconds

  do{
    currTime = millis();
    strip.setPixelColor(start, c); // Set new pixel 'on'
    strip.setPixelColor(start, c); // Set new pixel 'on'
    strip.show();              // Refresh LED states   
    if(MIDI.read()){
      if(MIDI.getType() == NoteOn ){
        for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);
        strip.show();
        return; 
      }
    }

  }while(currTime - startTime < 400);

  //then explode out

  int direction = 1;

  for(i=0;i <= maxSpread; i = i + direction){
    // 1 is "out", -1 is "in"; 
    uint32_t color;
    if (direction == 1) color = c;
   else  color = 0;

    strip.setPixelColor(start + i, color); // Set new pixel 'on'
    strip.setPixelColor(start - i, color); // Set new pixel 'on'
    strip.show();              // Refresh LED states
    delay(wait);

    if( i == maxSpread  ){
       direction = direction * -1;
       strip.setPixelColor(start + maxSpread, 0);
       strip.setPixelColor(start - maxSpread, 0);
    }

    if(MIDI.read()){
      if(MIDI.getType() == NoteOn){
        for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);
        strip.show();
        return; 
      }
    }
  }
}
/* Helper functions */
uint32_t RandomColor(){
 return Wheel( rand() % 384);
}
uint32_t Wheel(uint16_t WheelPos)
{
  byte r, g, b;
  switch(WheelPos / 128)

  {
    case 0:
      r = 127 - WheelPos % 128;   //Red down
      g = WheelPos % 128;      // Green up
      b = 0;                  //blue off
      break; 

    case 1:
      g = 127 - WheelPos % 128;  //green down
      b = WheelPos % 128;      //blue up
      r = 0;                  //red off
      break; 

    case 2:
      b = 127 - WheelPos % 128;  //blue down 
      r = WheelPos % 128;      //red up
      g = 0;                  //green off
      break; 
  }

  return(strip.Color(r,g,b));

}

Here is the compile Error:

Arduino: 1.6.4 (Mac OS X), Board: "Arduino Uno"

KeyboardRainbowBlast.ino: In function 'void setup()':
KeyboardRainbowBlast:35: error: 'MIDI' was not declared in this scope
KeyboardRainbowBlast.ino: In function 'void loop()':
KeyboardRainbowBlast:71: error: 'MIDI' was not declared in this scope
KeyboardRainbowBlast:71: error: 'NoteOn' was not declared in this scope
KeyboardRainbowBlast.ino:71:41: note: suggested alternative:
In file included from /Users/gschwarz82/Documents/Arduino/libraries/MIDI/MIDI.h:26:0,
                 from KeyboardRainbowBlast.ino:1:
/Users/gschwarz82/Documents/Arduino/libraries/MIDI/midi_Defs.h:60:5: note:   'NoteOn'
     NoteOn                = 0x90,    ///< Note On
     ^
KeyboardRainbowBlast.ino: In function 'void colorExplode(uint32_t, uint8_t, int, int)':
KeyboardRainbowBlast:135: error: 'MIDI' was not declared in this scope
KeyboardRainbowBlast:137: error: 'NoteOn' was not declared in this scope
KeyboardRainbowBlast.ino:137:28: note: suggested alternative:
In file included from /Users/gschwarz82/Documents/Arduino/libraries/MIDI/MIDI.h:26:0,
                 from KeyboardRainbowBlast.ino:1:
/Users/gschwarz82/Documents/Arduino/libraries/MIDI/midi_Defs.h:60:5: note:   'NoteOn'
     NoteOn                = 0x90,    ///< Note On
     ^
KeyboardRainbowBlast:197: error: 'MIDI' was not declared in this scope
KeyboardRainbowBlast:199: error: 'NoteOn' was not declared in this scope
KeyboardRainbowBlast.ino:199:28: note: suggested alternative:
In file included from /Users/gschwarz82/Documents/Arduino/libraries/MIDI/MIDI.h:26:0,
                 from KeyboardRainbowBlast.ino:1:
/Users/gschwarz82/Documents/Arduino/libraries/MIDI/midi_Defs.h:60:5: note:   'NoteOn'
     NoteOn                = 0x90,    ///< Note On
     ^
'MIDI' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

@gschwarz82 The red midi.h means the IDE can't find the midi library in your arduino libraries folder

So I changed the midi.h from being into quotes to brackets and it's no longer red. Still having an issue with the midi not being declared in scope. Do you have to tell the Arduino what specific folder it is in? For instance the midi.h file is in my MIDI folder.

I see that it finds the midi.h file. It looks like you may have grabbed some of the midi commands from really old code... Getting data via a midi.read() is all done by callback for the past few major versions of the MIDI library. Check out the example apps in this repo.

SoI added MIDI_CREATE_DEFAULT_INSTANCE();

and it cleared that error!

Now I'm getting noteon was not declared in scope.

This is the section throwing the error. I tried to contact the person who wrote the code for help, but he didn't respond back. The code is very old.

if(MIDI.read()){

  if(MIDI.getType() == NoteOn ){                    <------- Error here

    for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);

    strip.show();

    return; 

  }