34 static int nbytesPerChnMsg[7] =
39 unsigned short format,ntrcks;
41 if (chnkType!=
"MThd")
throw Error(
"Expected a header chunk\n");
45 throw Error(
"Unexpected header chunk length\n");
48 if (format!=0 && format!=1)
49 throw Error(
"Unsupported MIDI file format\n");
55 for (
int i=0;i<ntrcks;i++)
58 if (chnkType!=
"MTrk")
throw Error(
"Expected a track chunk\n");
62 Byte runningStatus = 0;
69 while (mCnt!=chnkLength)
76 int type = ((b&0xF0)>>4)-8;
89 for (
unsigned int i=0;i<length;i++)
98 else if (b == 0xF0 || b==0xF7)
108 throw Error(
"SysEx message did not terminate with 0xF7");
113 throw Error(
"Encountered a message that I don't know how to handle");
117 if (nbytesPerChnMsg[type]==2)
131 int type = ((runningStatus&0xF0)>>4)-8;
132 if (nbytesPerChnMsg[type]==2)