Skip to content

simple c++ smf midi file reader for linux and teensy

License

Notifications You must be signed in to change notification settings

newdigate/midi-smf-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

  • download gcc-arm-none-eabi
  • clone src dependencies into a directory (in this case /Users/me/git)
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
  • update COMPILERPATH, DEPSPATH in cmake/toolchains/teensy41.toolchain.cmake:
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 
  • run these commands in a terminal from the root repository directory
mkdir cmake-build-debug
cd cmake-build-debug
cmake .. -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/teensy41.toolchain.cmake"
make 

compile and install on linux

  • clone:
    git clone https://github.com/newdigate/midi-smf-reader.git
    cd midi-smf-reader
  • compile src, tests
    mkdir cmake-build-debug
    cd cmake-build-debug
    cmake .. 
    make
  • run tests
    test/midi_smf_reader_test
  • install library for linux:
    sudo make install
  • uninstall library for linux:
    sudo make uninstall

todo:

  • read tempo / key changes done

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.

About

simple c++ smf midi file reader for linux and teensy

Topics

Resources

License

Stars

Watchers

Forks

Languages