midiDemo.m
/*------------------------------------------------------------------------------- This file demonstrates how to use MKMIDIFile to read a .mid file saved on disk and iterate over its events. This program just reads files passed into it, looks for note on and note off messages on channel 1, and prints a line to stdout if it finds one. MKMIDIFile guarentees that every event will have a status byte (no running status), and all note off messages will have a status byte of 0x80 | channel. MKMIDIFile always uses track numbers starting at index 1. The code contained in this file is available free of charge, lisence, or restriction of any kind. Anyone may use it for anything, although it will probably crash your computer irreparably. Written by Michael Krzyzaniak krzyzani@uga.edu -------------------------------------------------------------------------------*/ #import//<stdio.h> #import "MKMIDIFile.h" #define CHANNEL CHANNEL_1 int main(int argc, char* argv[]) { if(argc<2) { printf("invoke with midi files\n"); return; } unsigned int currentTrack; MKMIDIEvent* event; unsigned char statusByte; while(--argc) { argv++; MKMIDIFile* midiFile = [MKMIDIFile midiFileFromFile: *argv]; if(midiFile == nil){ printf("\n%s is not a valid MIDI file\n", *argv); continue; } printf("\n%s OK\n", *argv); for(currentTrack=1; currentTrack<=[midiFile numTracks]; currentTrack++) { printf("\nBegin data for track %u\n", currentTrack); if([midiFile resetIteratorOnTrack: currentTrack]) { do{ event = [midiFile currentEventOnTrack: currentTrack]; statusByte = [event statusByte]; if(statusByte == (NOTE_ON | CHANNEL)) printf("Note %hhu turned ON\n", [event argumentAtIndex: 0]); else if(statusByte == (NOTE_OFF | CHANNEL)) printf("Note %hhu turned OFF\n", [event argumentAtIndex: 0]); }while([midiFile advanceIteratorOnTrack: currentTrack]); } } [midiFile free]; } return 0; }
:/ root#