Home

Awesome

standard midi file reader for teensy

MIT license CMake Ubuntu-x64 teensy40

c++ standard midi file type-0 reader built for teensy (32 bit arm cortex m7 thumb arch)

contents:

usage:

midireader reader;
reader.open("1234.mid");
double microsPerTick = reader.get_microseconds_per_tick();
int totalNumNotesRead = 0;
for (int t = 0; t < reader.getNumTracks(); t++) {
    reader.setTrackNumber(t);
    int i = 0;
    long totalTicks = 0, microseconds = 0;
    smfmidimessage *message;
    while ((message = reader.read()) != nullptr) {
        totalTicks += message->delta_ticks;
        microseconds += microsPerTick * message->delta_ticks;
        switch(message->getMessageType()) {
            case smftype_channelvoicemessage : {
                smfchannelvoicemessage *channelvoicemessage = (smfchannelvoicemessage *)message;
                printf("%5d: [%2d,%4d]: %6d: delta: %3d\tstatus: 0x%2x\tdata1: %3d\tdata2: %3d\tdata3: %2d\t\n",
                    microseconds/1000,
                    t,
                    i,
                    totalTicks,
                    channelvoicemessage->delta_ticks,
                    channelvoicemessage->status,
                    channelvoicemessage->data1,
                    channelvoicemessage->data2,
                    channelvoicemessage->data3);
                break; 
            }

            case smftype_settempomessage : {
                printf("tempo change: %f\n", ((smfsettempomessage *)message)->getTempo());
                break;
            }

            default: 
                break;
        }

        delete message;
        i++;
    }
    totalNumNotesRead += i;
}

dependencies:

compile example for teensy:

mkdir /Users/me/git
cd /Users/me/git
git clone https://github.com/PaulStoffregen/cores
git clone https://github.com/greiman/SdFat
git clone -b Juse_Use_SdFat https://github.com/PaulStoffregen/SD
git clone https://github.com/PaulStoffregen/SPI
set(COMPILERPATH "/Applications/ARM/bin/")   # should point to folder with GCC-ARM-NONE-EABI executables
set(DEPSPATH "/Users/me/git")                # path with 4 x src dependencies 
mkdir cmake-build-debug
cd cmake-build-debug
cmake .. -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/teensy41.toolchain.cmake"
make 

compile and install on linux

todo:

credits

Don't Run Unit Tests on the Arduino Device or Emulator
cmake uninstaller

license

Unless specified in source code file, all code is MIT license.