Error: 'MIDI' was not declared in this scope. What am I missing here?!

Arduino: 1.6.13 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Nerdinator\Documents\Arduino\libraries\USBH_MIDI-IOP_ArduinoMIDI\examples\bidrectional_converter\bidrectional_converter.ino: In function 'void setup()':

bidrectional_converter:52: error: 'MIDI' was not declared in this scope

   MIDI.begin(MIDI_CHANNEL_OMNI);

   ^

C:\Users\Nerdinator\Documents\Arduino\libraries\USBH_MIDI-IOP_ArduinoMIDI\examples\bidrectional_converter\bidrectional_converter.ino: In function 'void loop()':

bidrectional_converter:74: error: 'MIDI' was not declared in this scope

     if (MIDI.read()) {

         ^

C:\Users\Nerdinator\Documents\Arduino\libraries\USBH_MIDI-IOP_ArduinoMIDI\examples\bidrectional_converter\bidrectional_converter.ino: In function 'void MIDI_poll()':

bidrectional_converter:34: error: 'MIDI_DEFAULT_SERIAL_PORT' was not declared in this scope

 #define _MIDI_SERIAL_PORT MIDI_DEFAULT_SERIAL_PORT

                           ^

C:\Users\Nerdinator\Documents\Arduino\libraries\USBH_MIDI-IOP_ArduinoMIDI\examples\bidrectional_converter\bidrectional_converter.ino:98:7: note: in expansion of macro '_MIDI_SERIAL_PORT'

       _MIDI_SERIAL_PORT.write(outBuf, size);

       ^

exit status 1
'MIDI' was not declared in this scope

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

trying to make a usb to midi host. heres the sketch:

/*
 *******************************************************************************
 * Legacy Serial MIDI and USB Host bidirectional converter
 * Copyright 2013-2014 Yuuichi Akagawa
 *
 * for use with USB Host Shield 2.0 from Circuitsathome.com
 * https://github.com/felis/USB_Host_Shield_2.0
 * and Arduino MIDI library
 * http://playground.arduino.cc/Main/MIDILibrary
 *******************************************************************************
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *******************************************************************************
 */

#include <MIDI.h>
#include <Usb.h>
#include <usbh_midi.h>

//Workaround for Arduino MIDI library v4.0 compatibility
#ifdef USE_SERIAL_PORT
#define _MIDI_SERIAL_PORT USE_SERIAL_PORT
#else
#define _MIDI_SERIAL_PORT MIDI_DEFAULT_SERIAL_PORT
#endif

//////////////////////////
// MIDI Pin assign
// 2 : GND
// 4 : +5V(Vcc) with 220ohm
// 5 : TX
//////////////////////////

USB  Usb;
USBH_MIDI  Midi(&Usb);

void MIDI_poll();
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime);

void setup()
{
  MIDI.begin(MIDI_CHANNEL_OMNI);

  //Workaround for non UHS2.0 Shield 
  pinMode(7,OUTPUT);
  digitalWrite(7,HIGH);

  if (Usb.Init() == -1) {
    while(1); //halt
  }//if (Usb.Init() == -1...
  delay( 200 );
}

void loop()
{
  unsigned long t1;
  uint8_t msg[4];

  Usb.Task();
  t1 = micros();
  if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
  {
    MIDI_poll();
    if (MIDI.read()) {
       msg[0] = MIDI.getType();
       if( msg[0] == 0xf0 ) { //SysEX
         //TODO
         //SysEx implementation is not yet.
       }else{
         msg[1] = MIDI.getData1();
         msg[2] = MIDI.getData2();
         Midi.SendData(msg, 0);
       }
    }
  }
  //delay(1ms)
  doDelay(t1, micros(), 1000);
}

// Poll USB MIDI Controler and send to serial MIDI
void MIDI_poll()
{
    byte outBuf[ 3 ];
    uint8_t size;

    if( (size=Midi.RcvData(outBuf)) > 0 ){
      //MIDI Output
      _MIDI_SERIAL_PORT.write(outBuf, size);
    }
}

// Delay time (max 16383 us)
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime)
{
    unsigned long t3;

    if( t1 > t2 ){
      t3 = (4294967295 - t1 + t2);
    }else{
      t3 = t2 - t1;
    }

    if( t3 < delayTime ){
      delayMicroseconds(delayTime - t3);
    }
}

C/C++ is case sensitive. You have a variable called Midi, not MIDI.

From looking at the code, I suspect that that is the problem.

You may be using a obsolete version of the USBH_MIDI library. The USBH_MIDI library is now included with USB Host Shield Library 2.0. The bidirectional_converter example is included as well.

From the IDE library manager install or make sure you have installed

  • USB Host Shield Library 2.0 by Oleg Mazurov, et al. version 1.3.1 or newer. This is for MIDI over USB host ports.
  • MIDI Library Built-in by Forty Seven Effects version 4.3.1 or newer. This is for MIDI over UART/serial ports.

The bidirectional_converter example is available in the IDE.

File | Examples | USB Host Shield Library 2.0 | USBH_MIDI | bidirectional_converter

The example should compile without errors. It may fail if you installed other MIDI libraries especially old versions. You may have to remove/uninstall old MIDI libraries to ensure the latest version is used.

Midi and MIDI are two different objects. Midi is for USB Host MIDI and MIDI is for UART/serial MIDI. The goal of the program is to pass MIDI messages between the two interfaces. A Kenton MIDI USB Host box performs a similar function.