MDmidi.h modify

there must be a way to change the h file to work with esp32 chips, seems the MDmidi library uses the SDfat library and this library conflicts with the esp32 . i just upload the simple MDmidi play sketch and get the error does not support this board. is there a work around for this ? all im looking to do is read a midi file from a sd card as in parse form and pick out the individual notes...any help would be really appreciated. or just point me in the right direction

First search in Library Manager, then in github. Specify the board you want to use as well as MDmidi in the search.

thank you but i have already done that.. seems the MDmidi library uses the Fat sd library only. thats were the problem is. esp32 will not work with that .

I checked the library properties and it says all architectures. I then compiled the SDInfo sketch for an esp32 do it and it worked. I have not tried to execute the code, but usually if they compile they work. I would question the 'doesn't work' until you are 100% sure.

I can compile it, but it fails using Boards 3, Roll back to 2.0.17 and it compiles clean.


ok thank you i will check it tomorrow and post results

ok i just uploaded a sketch from the examples im using IDE 2.3.4 nodeMCU 32S and here is code

// Test playing a succession of MIDI files from the SD card.
// Example program to demonstrate the use of the MIDFile library
// Just for fun light up a LED in time to the music.
//
// Hardware required:
//  SD card interface - change SD_SELECT for SPI comms
//  3 LEDs (optional) - to display current status and beat. 
//  Change pin definitions for specific hardware setup - defined below.

#include <SdFat.h>
#include <MD_MIDIFile.h>

#define USE_MIDI  1   // set to 1 to enable MIDI output, otherwise debug output

#if USE_MIDI // set up for direct MIDI serial output

#define DEBUG(s, x)
#define DEBUGX(s, x)
#define DEBUGS(s)
#define SERIAL_RATE 31250

#else // don't use MIDI to allow printing debug statements

#define DEBUG(s, x)  do { Serial.print(F(s)); Serial.print(x); } while(false)
#define DEBUGX(s, x) do { Serial.print(F(s)); Serial.print(F("0x")); Serial.print(x, HEX); } while(false)
#define DEBUGS(s)    do { Serial.print(F(s)); } while (false)
#define SERIAL_RATE 57600

#endif // USE_MIDI


// SD chip select pin for SPI comms.
// Default SD chip select is the SPI SS pin (10 on Uno, 53 on Mega).
const uint8_t SD_SELECT = SS;

// LED definitions for status and user indicators
const uint8_t READY_LED = 7;      // when finished
const uint8_t SMF_ERROR_LED = 6;  // SMF error
const uint8_t SD_ERROR_LED = 5;   // SD error
const uint8_t BEAT_LED = 4;       // toggles to the 'beat'

const uint16_t WAIT_DELAY = 2000; // ms

#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))

// The files in the tune list should be located on the SD card 
// or an error will occur opening the file and the next in the 
// list will be opened (skips errors).
const char *tuneList[] = 
{
  "LOOPDEMO.MID",  // simplest and shortest file
  "BANDIT.MID",
  "ELISE.MID",
  "TWINKLE.MID",
  "GANGNAM.MID",
  "FUGUEGM.MID",
  "POPCORN.MID",
  "AIR.MID",
  "PRDANCER.MID",
  "MINUET.MID",
  "FIRERAIN.MID",
  "MOZART.MID",
  "FERNANDO.MID",
  "SONATAC.MID",
  "SKYFALL.MID",
  "XMAS.MID",
  "GBROWN.MID",
  "PROWLER.MID",
  "IPANEMA.MID",
  "JZBUMBLE.MID",
};

// These don't play as they need more than 16 tracks but will run if MIDIFile.h is changed
//#define MIDI_FILE  "SYMPH9.MID"     // 29 tracks
//#define MIDI_FILE  "CHATCHOO.MID"   // 17 tracks
//#define MIDI_FILE  "STRIPPER.MID"   // 25 tracks

SDFAT	SD;
MD_MIDIFile SMF;

void midiCallback(midi_event *pev)
// Called by the MIDIFile library when a file event needs to be processed
// thru the midi communications interface.
// This callback is set up in the setup() function.
{
#if USE_MIDI
  if ((pev->data[0] >= 0x80) && (pev->data[0] <= 0xe0))
  {
    Serial.write(pev->data[0] | pev->channel);
    Serial.write(&pev->data[1], pev->size-1);
  }
  else
    Serial.write(pev->data, pev->size);
#endif
  DEBUG("\n", millis());
  DEBUG("\tM T", pev->track);
  DEBUG(":  Ch ", pev->channel+1);
  DEBUGS(" Data");
  for (uint8_t i=0; i<pev->size; i++)
    DEBUGX(" ", pev->data[i]);
}

void sysexCallback(sysex_event *pev)
// Called by the MIDIFile library when a system Exclusive (sysex) file event needs 
// to be processed through the midi communications interface. Most sysex events cannot 
// really be processed, so we just ignore it here.
// This callback is set up in the setup() function.
{
  DEBUG("\nS T", pev->track);
  DEBUGS(": Data");
  for (uint8_t i=0; i<pev->size; i++)
    DEBUGX(" ", pev->data[i]);
}

void midiSilence(void)
// Turn everything off on every channel.
// Some midi files are badly behaved and leave notes hanging, so between songs turn
// off all the notes and sound
{
  midi_event ev;

  // All sound off
  // When All Sound Off is received all oscillators will turn off, and their volume
  // envelopes are set to zero as soon as possible.
  ev.size = 0;
  ev.data[ev.size++] = 0xb0;
  ev.data[ev.size++] = 120;
  ev.data[ev.size++] = 0;

  for (ev.channel = 0; ev.channel < 16; ev.channel++)
    midiCallback(&ev);
}

void setup(void)
{
  // Set up LED pins
  pinMode(READY_LED, OUTPUT);
  pinMode(SD_ERROR_LED, OUTPUT);
  pinMode(SMF_ERROR_LED, OUTPUT);
  pinMode(BEAT_LED, OUTPUT);

  // reset LEDs
  digitalWrite(READY_LED, LOW);
  digitalWrite(SD_ERROR_LED, LOW);
  digitalWrite(SMF_ERROR_LED, LOW);
  digitalWrite(BEAT_LED, LOW);
  
  Serial.begin(SERIAL_RATE);

  DEBUGS("\n[MidiFile Play List]");

  // Initialize SD
  if (!SD.begin(SD_SELECT, SPI_FULL_SPEED))
  {
    DEBUGS("\nSD init fail!");
    digitalWrite(SD_ERROR_LED, HIGH);
    while (true) ;
  }

  // Initialize MIDIFile
  SMF.begin(&SD);
  SMF.setMidiHandler(midiCallback);
  SMF.setSysexHandler(sysexCallback);

  digitalWrite(READY_LED, HIGH);
}

void tickMetronome(void)
// flash a LED to the beat
{
  static uint32_t lastBeatTime = 0;
  static boolean  inBeat = false;
  uint16_t  beatTime;

  beatTime = 60000/SMF.getTempo();    // msec/beat = ((60sec/min)*(1000 ms/sec))/(beats/min)
  if (!inBeat)
  {
    if ((millis() - lastBeatTime) >= beatTime)
    {
      lastBeatTime = millis();
      digitalWrite(BEAT_LED, HIGH);
      inBeat = true;
    }
  }
  else
  {
    if ((millis() - lastBeatTime) >= 100)	// keep the flash on for 100ms only
    {
      digitalWrite(BEAT_LED, LOW);
      inBeat = false;
    }
  }
}

void loop(void)
{
  static enum { S_IDLE, S_PLAYING, S_END, S_WAIT_BETWEEN } state = S_IDLE;
  static uint16_t currTune = ARRAY_SIZE(tuneList);
  static uint32_t timeStart;

  switch (state)
  {
  case S_IDLE:    // now idle, set up the next tune
    {
      int err;

      DEBUGS("\nS_IDLE");

      digitalWrite(READY_LED, LOW);
      digitalWrite(SMF_ERROR_LED, LOW);

      currTune++;
      if (currTune >= ARRAY_SIZE(tuneList))
        currTune = 0;

      // use the next file name and play it
      DEBUG("\nFile: ", tuneList[currTune]);
      err = SMF.load(tuneList[currTune]);
      if (err != MD_MIDIFile::E_OK)
      {
        DEBUG(" - SMF load Error ", err);
        digitalWrite(SMF_ERROR_LED, HIGH);
        timeStart = millis();
        state = S_WAIT_BETWEEN;
        DEBUGS("\nWAIT_BETWEEN");
      }
      else
      {
        DEBUGS("\nS_PLAYING");
        state = S_PLAYING;
      }
    }
    break;

  case S_PLAYING: // play the file
    DEBUGS("\nS_PLAYING");
    if (!SMF.isEOF())
    {
      if (SMF.getNextEvent())
        tickMetronome();
    }
    else
      state = S_END;
    break;

  case S_END:   // done with this one
    DEBUGS("\nS_END");
    SMF.close();
    midiSilence();
    timeStart = millis();
    state = S_WAIT_BETWEEN;
    DEBUGS("\nWAIT_BETWEEN");
    break;

  case S_WAIT_BETWEEN:    // signal finished with a dignified pause
    digitalWrite(READY_LED, HIGH);
    if (millis() - timeStart >= WAIT_DELAY)
      state = S_IDLE;
    break;

  default:
    state = S_IDLE;
    break;
  }
}

here is the error

In file included from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Stream.h:25,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:193,
                 from C:\Users\johnb\AppData\Local\arduino\sketches\830034CD80A938851387F12C19330A38\sketch\MD_MIDIFile_Play.ino.cpp:1:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h: In instantiation of 'class PrintFile<FsBaseFile>':
c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:468:23:   required from here
C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Print.h:64:18: warning: 'virtual size_t Print::write(const uint8_t*, size_t)' was hidden [-Woverloaded-virtual=]
   64 |   virtual size_t write(const uint8_t *buffer, size_t size);
      |                  ^~~~~
In file included from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatFile.h:883,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatVolume.h:27,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatLib.h:28,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:31,
                 from C:\Users\johnb\AppData\Local\Temp\.arduinoIDE-unsaved20241131-8304-1lticun.l7qx\MD_MIDIFile_Play\MD_MIDIFile_Play.ino:10:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h:53:10: note:   by 'PrintFile<FsBaseFile>::write'
   53 |   size_t write(uint8_t b) { return BaseFile::write(&b, 1); }
      |          ^~~~~
In file included from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Stream.h:25,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:193,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.h:385,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp:23:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h: In instantiation of 'class PrintFile<FsBaseFile>':
c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:468:23:   required from here
C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Print.h:64:18: warning: 'virtual size_t Print::write(const uint8_t*, size_t)' was hidden [-Woverloaded-virtual=]
   64 |   virtual size_t write(const uint8_t *buffer, size_t size);
      |                  ^~~~~
In file included from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatFile.h:883,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatVolume.h:27,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatLib.h:28,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:31,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.h:386:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h:53:10: note:   by 'PrintFile<FsBaseFile>::write'
   53 |   size_t write(uint8_t b) { return BaseFile::write(&b, 1); }
      |          ^~~~~
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp: In member function 'bool MD_MFTrack::getNextEvent(MD_MIDIFile*, uint16_t)':
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp:119:44: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
  119 |   if (_endOfTrack) DUMPS(" - OUT OF TRACK");
      |                                            ^
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp: In member function 'void MD_MFTrack::parseEvent(MD_MIDIFile*)':
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp:418:29: error: no matching function for call to 'min(unsigned int, uint32_t&)'
  418 |         uint8_t minLen = min(ARRAY_SIZE(mev.data), mLen);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/algorithm:61,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:188:
C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algo.h:5785:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5785 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algo.h:5785:5: note:   template argument deduction/substitution failed:
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp:418:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
  418 |         uint8_t minLen = min(ARRAY_SIZE(mev.data), mLen);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algo.h:5775:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5775 |     min(initializer_list<_Tp> __l)
      |     ^~~
C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algo.h:5775:5: note:   template argument deduction/substitution failed:
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp:418:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
  418 |         uint8_t minLen = min(ARRAY_SIZE(mev.data), mLen);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/specfun.h:43,
                 from C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/cmath:3699,
                 from C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/math.h:36,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/esp32-hal.h:30,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:36:
C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algobase.h:281:5: note:   template argument deduction/substitution failed:
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp:418:29: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'uint32_t' {aka 'long unsigned int'})
  418 |         uint8_t minLen = min(ARRAY_SIZE(mev.data), mLen);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
C:/Users/johnb/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2405/xtensa-esp-elf/include/c++/13.2.0/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDITrack.cpp:418:29: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'uint32_t' {aka 'long unsigned int'})
  418 |         uint8_t minLen = min(ARRAY_SIZE(mev.data), mLen);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Stream.h:25,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:193,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src/MD_MIDIFile.h:385,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIHelper.cpp:23:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h: In instantiation of 'class PrintFile<FsBaseFile>':
c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:468:23:   required from here
C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Print.h:64:18: warning: 'virtual size_t Print::write(const uint8_t*, size_t)' was hidden [-Woverloaded-virtual=]
   64 |   virtual size_t write(const uint8_t *buffer, size_t size);
      |                  ^~~~~
In file included from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatFile.h:883,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatVolume.h:27,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatLib.h:28,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:31,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src/MD_MIDIFile.h:386:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h:53:10: note:   by 'PrintFile<FsBaseFile>::write'
   53 |   size_t write(uint8_t b) { return BaseFile::write(&b, 1); }
      |          ^~~~~
In file included from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Stream.h:25,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:193,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.h:385,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.cpp:24:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h: In instantiation of 'class PrintFile<FsBaseFile>':
c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:468:23:   required from here
C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Print.h:64:18: warning: 'virtual size_t Print::write(const uint8_t*, size_t)' was hidden [-Woverloaded-virtual=]
   64 |   virtual size_t write(const uint8_t *buffer, size_t size);
      |                  ^~~~~
In file included from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatFile.h:883,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatVolume.h:27,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatLib.h:28,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:31,
                 from c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.h:386:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h:53:10: note:   by 'PrintFile<FsBaseFile>::write'
   53 |   size_t write(uint8_t b) { return BaseFile::write(&b, 1); }
      |          ^~~~~
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.cpp: In member function 'bool MD_MIDIFile::isEOF()':
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.cpp:155:29: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
  155 |   if (bEof) DUMPS("\n! EOF");
      |                             ^
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.cpp: In member function 'void MD_MIDIFile::processEvents(uint16_t)':
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.cpp:243:35: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
  243 |     if (_format != 0) DUMPX("", i);
      |                                   ^
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0\src\MD_MIDIFile.cpp:254:25: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
  254 |       DUMPS("\n-- TRK ");
      |                         ^

exit status 1

Compilation error: exit status 1

thank you so much..i did reinstalled to 2.0.17 and it compiled fine..:slightly_smiling_face:

The incompatibility of the "MD_MIDIFile" with the recent versions of the "esp32" boards platform has already been fixed:

There hasn't been a new release of the library since that time, which is why you still encounter the problem when using version 2.6.0 of the library, but at least the future releases of the library will be compatible.

In case you would like to use the modern version of the "esp32" boards platform, you can manually install the latest version of the "MD_MIDIFile" library:

  1. Remove the installation of the release version of the library by deleting the folder at the following path on your hard drive:
    c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile-2.6.0
    
    :warning: Please be careful when deleting things from your computer. When in doubt, back up!
  2. Click the following link to open the library's GitHub repository homepage in your web browser:
    https://github.com/MajicDesigns/MD_MIDIFile
  3. Click the "Code ▾" button you see on that page.
  4. Select Download ZIP from the menu.
    A download of the ZIP file of the library will start.
  5. Wait for the download to finish.
  6. Select Sketch > Include library > Add .ZIP Library from the Arduino IDE menus.
    The "Select the zip file containing the library you'd like to add" dialog will open.
  7. Select the downloaded file from the dialog.
  8. Click the "Open" button.
    The dialog will close.
  9. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully installed library from ...

sorry to inform you but i did have the latest version of the MDmidi.h but did not work with the latest esp32 version.. like i said it did work with the 2.0.17

What do you mean by "latest version"? If you mean the 2.6.0 release version, then that is expected. When I said "latest version" in my previous reply, I meant the latest development version of the library. You will get that version if you follow the instructions I provided.

will that version work with the latest version of esp32 ?

Give it a try.

ok I did the changes and it did compile but what puzzles me is why all of these warnings ?

C:\Users\johnb\AppData\Local\Temp\.arduinoIDE-unsaved202503-916-ztgs8d.epgp\MD_MIDIFile_Play\MD_MIDIFile_Play.ino:44: warning: "ARRAY_SIZE" redefined
   44 | #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
      | 
In file included from C:\Users\johnb\AppData\Local\Temp\.arduinoIDE-unsaved202503-916-ztgs8d.epgp\MD_MIDIFile_Play\MD_MIDIFile_Play.ino:11:
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile\src/MD_MIDIFile.h:455: note: this is the location of the previous definition
  455 | #define ARRAY_SIZE(a) (uint32_t)(sizeof(a)/sizeof((a)[0]))
      | 
In file included from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Stream.h:25,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:193,
                 from C:\Users\johnb\AppData\Local\arduino\sketches\0D76DCA4A39E37DB7224C072D29C5D5C\sketch\MD_MIDIFile_Play.ino.cpp:1:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h: In instantiation of 'class PrintFile<FsBaseFile>':
c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:468:23:   required from here
C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Print.h:64:18: warning: 'virtual size_t Print::write(const uint8_t*, size_t)' was hidden [-Woverloaded-virtual=]
   64 |   virtual size_t write(const uint8_t *buffer, size_t size);
      |                  ^~~~~
In file included from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatFile.h:883,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatVolume.h:27,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatLib.h:28,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:31,
                 from C:\Users\johnb\AppData\Local\Temp\.arduinoIDE-unsaved202503-916-ztgs8d.epgp\MD_MIDIFile_Play\MD_MIDIFile_Play.ino:10:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h:53:10: note:   by 'PrintFile<FsBaseFile>::write'
   53 |   size_t write(uint8_t b) { return BaseFile::write(&b, 1); }
      |          ^~~~~
Sketch uses 325448 bytes (24%) of program storage space. Maximum is 1310720 bytes.
Global variables use 21576 bytes (6%) of dynamic memory, leaving 306104 bytes for local variables. Maximum is 327680 bytes.

There are two warnings. The first one is fairly self-explanatory:

C:\Users\johnb\AppData\Local\Temp\.arduinoIDE-unsaved202503-916-ztgs8d.epgp\MD_MIDIFile_Play\MD_MIDIFile_Play.ino:44: warning: "ARRAY_SIZE" redefined
   44 | #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
      | 
In file included from C:\Users\johnb\AppData\Local\Temp\.arduinoIDE-unsaved202503-916-ztgs8d.epgp\MD_MIDIFile_Play\MD_MIDIFile_Play.ino:11:
c:\Users\johnb\Documents\Arduino\libraries\MD_MIDIFile\src/MD_MIDIFile.h:455: note: this is the location of the previous definition
  455 | #define ARRAY_SIZE(a) (uint32_t)(sizeof(a)/sizeof((a)[0]))
      | 

A macro function named ARRAY_SIZE was defined at line 44 of the MD_MIDIFile_Play.ino sketch file:

#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))

This definition is overriding the definition of another macro function of the same name at line 455 in the MD_MIDIFile.h file of the library:

#define ARRAY_SIZE(a) (uint32_t)(sizeof(a)/sizeof((a)[0]))

The compiler is warning that the macro function was redefined in case you might be expecting that the first definition will be used. In this case the two macros are probably functionally identical so it should not cause any problems.

The library developer should have avoided polluting the global namespace with such a generic macro name. It would have been best practices to name it MD_MIDIFILE_ARRAY_SIZE to avoid collisions, or better to avoid exposing it to the sketch at all.

The library developer also should have noticed the collision between the macro from the library and the one in the example sketch. Unfortunately it seems like many of the developers in the Arduino community either don't have compiler warnings enabled, or ignore them as it is very common to see easily corrected warnings like this. That is disturbing because warnings provide very useful information to developers, and it is best practices to fix the code that produces a warning even in cases like this where it doesn't indicate a real problem.

However, we must also keep in mind that projects like the "MD_MIDIFile" library are given freely to the entire world under an open source license, and are often undertaken as a hobby in the developer's free time. So we can be grateful for the incredible wealth of these projects we have access to, even if they are not always perfect.


As for the other warning:

In file included from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Stream.h:25,
                 from C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:193,
                 from C:\Users\johnb\AppData\Local\arduino\sketches\0D76DCA4A39E37DB7224C072D29C5D5C\sketch\MD_MIDIFile_Play.ino.cpp:1:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h: In instantiation of 'class PrintFile<FsBaseFile>':
c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:468:23:   required from here
C:\Users\johnb\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Print.h:64:18: warning: 'virtual size_t Print::write(const uint8_t*, size_t)' was hidden [-Woverloaded-virtual=]
   64 |   virtual size_t write(const uint8_t *buffer, size_t size);
      |                  ^~~~~
In file included from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatFile.h:883,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatVolume.h:27,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/ExFatLib/ExFatLib.h:28,
                 from c:\Users\johnb\Documents\Arduino\libraries\SdFat\src/SdFat.h:31,
                 from C:\Users\johnb\AppData\Local\Temp\.arduinoIDE-unsaved202503-916-ztgs8d.epgp\MD_MIDIFile_Play\MD_MIDIFile_Play.ino:10:
c:/Users/johnb/Documents/Arduino/libraries/SdFat/src/common/ArduinoFiles.h:53:10: note:   by 'PrintFile<FsBaseFile>::write'
   53 |   size_t write(uint8_t b) { return BaseFile::write(&b, 1); }
      |          ^~~~~

This is more complex and I'm not qualified to comment on it. Hopefully one of the other forum helpers will be able to provide an analysis.

thank you for all your help in this ptillisch...:+1:

1 Like

ok now i keep getting a reboot message , constantly reboots every 1 sec. any ideas ?

 rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
14:23:25.580 -> configsip: 0, SPIWP:0xee
14:23:25.580 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
14:23:25.580 -> mode:DIO, clock div:1
14:23:25.613 -> load:0x3fff0030,len:1344
14:23:25.613 -> load:0x40078000,len:13924
14:23:25.613 -> ho 0 tail 12 room 4
14:23:25.613 -> load:0x40080400,len:3600

MDfile_Dump sketch does the same,

but the MDfile_Dump_RAW sketch works perfect

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.