#include #include int main() { int i, v, c, c1, c2, low, hi; char id[5]; int div4, delta_sum; double sec; int tempo, tempo_delta_sum; double tempo_sec; printf("header\n"); for(i=0; i<4; i++) id[i] = getchar(); id[i] = '\0'; printf("id='%s'\n", id); v = 0; for(i=0; i<4; i++) v = (v << 8) | getchar(); printf("size=%d\n", v); v = 0; for(i=0; i<2; i++) v = (v << 8) | getchar(); printf("format type=%d\n", v); v = 0; for(i=0; i<2; i++) v = (v << 8) | getchar(); printf("track num=%d\n", v); v = 0; for(i=0; i<2; i++) v = (v << 8) | getchar(); printf("time division=%d (0x%x)\n\n", v, v); div4 = v; printf("track\n"); for(i=0; i<4; i++) id[i] = getchar(); id[i] = '\0'; printf("id='%s'\n", id); v = 0; for(i=0; i<4; i++) v = (v << 8) | getchar(); printf("size=%d\n", v); tempo = 500000; tempo_delta_sum = 0; tempo_sec = 0; delta_sum = 0; while(1){ v = 0; do{ if((c = getchar()) == EOF) break; v = (v << 7) | (c & 0x7f); }while(c & 0x80); if(c == EOF) break; delta_sum += v; sec = tempo_sec + (double)(delta_sum - tempo_delta_sum) / div4 * tempo * 0.000001; printf("sec=%.3f ", sec); c = getchar(); if(c & 0x80){ c1 = c; hi = (c1 >> 4) & 0xf; low = c1 & 0xf; if(c == 0xf8){ printf("midi clock\n"); continue; } c2 = getchar(); }else{ c2 = c; } if(hi == 9 || hi == 8){ printf("%s ch=%d ", hi == 9 ? "on" : "off", low); printf("note=%d ", c2); printf("velo=%d\n", getchar()); continue; } if(c1 == 0xff){ printf("meta event type=%d ", c2); v = getchar(); printf("len=%d ", v); if(c2 == 0x51){ /* set tempo */ tempo = 0; } for(i=0; i