I am creating a library (called MIDIFile) that implements a class that can be used to read a MIDI file from an SD card and stream it to a MIDI device. I am using the SDFat library to read the SD card, so this is referenced in the library.
When I try and compile a test program, I get definition errors for items that are defined in the SDFat library. It just seems like the compiler cannot find the header file and no matter what combinations I try (order of includes, bracket types, relative paths) they don't seem to make any difference.
MIDI_FileRead2.ino:1:19: warning: SDFat.h: No such file or directory
SDFile and my new library are in the Sketchbook/libraries folder. I am running windows and I have the IDE 1.0.3.
Clearly I am not adding stuff in the header files in the right order, so here are the start of the files with the include sequence, and the erroe message I get. I am sure someone will have solved this before...
Midifile.h - the library header file
#ifndef _MIDIFILE_H
#define _MIDIFILE_H
// Arduino MIDI File library
//
// A class which can read Standard MIDI files.
//
#include <Arduino.h>
#include <SdFat.h>
class MidiFile
{
public:
MidiFile(void);
MidiFile(uint8_t ss);
MidiFile(const char* aFile);
MidiFile(uint8_t ss, const char* aFile);
~MidiFile(void);
MidiFile.cpp - library code file implementing the class
// Arduino MIDI File library
//
// A class which can read Standard MIDI files.
//
#include <string.h>
#include "MidiFile.h"
My test program
#include <SDFat.h>
#include <MidiFile.h>
/*
* SD chip select pin. Common values are:
* Arduino Ethernet shield, pin 4.
*/
#define SD_SELECT 4
#define MIDI_FILE "LOOPDEMO.MID"
MidiFile SMF(SD_SELECT, MIDI_FILE);
/*
void dumpBuffer(SdFile *f, int len)
{
for (int i=0; i<len; i++)
{
uint8_t c = f->read();
if ((i!=0) && ((i%8) == 0)) Serial.println();
Serial.print(' ');
if (c<=0xf) Serial.print('0');
Serial.print(c, HEX);
}
}
*/
void DumpSMF(void)
{
Serial.println(SMF.getFilename());
Serial.print("File Version:\t");
Serial.println(SMF.getFormat());
Serial.print("Tracks:\t\t");
Serial.println(SMF.getTrackCount());
Serial.print("Speed:\t\t");
Serial.println(SMF.getTicksPerQuarterNote());
}
void setup(void)
{
Serial.begin(57600);
Serial.println("[MIDI file reader]");
SMF.load();
DumpSMF();
// close the file:
SMF.close();
}
void loop(void)
{
}
Error messages (compiler verbose turned on):
F:\arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=103 -IF:\arduino\hardware\arduino\cores\arduino -IF:\arduino\hardware\arduino\variants\standard -IF:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile C:\Users\Marco\AppData\Local\Temp\build6922185689476771770.tmp\MIDI_FileRead2.cpp -o C:\Users\Marco\AppData\Local\Temp\build6922185689476771770.tmp\MIDI_FileRead2.cpp.o
MIDI_FileRead2.ino:1:19: warning: SDFat.h: No such file or directory
In file included from MIDI_FileRead2.ino:2:
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:33:19: warning: SdFat.h: No such file or directory
In file included from MIDI_FileRead2.ino:2:
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:132: error: 'SdFat' does not name a type
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:133: error: 'SdFile' does not name a type
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:136: error: 'SdFile' has not been declared
F:\Marco\Documents\Programming\Arduino\Sketchbook\libraries\MIDIFile/MidiFile.h:137: error: 'SdFile' has not been declared