11 mFile = fopen(filename,
"wb");
22 static int nbytesPerChnMsg[7] = { 3,3,3,3,2,3,3 };
25 mFormat = (mTracks > 1) ? 1 : 0;
30 unsigned long trkhdr=
MTrk;
33 for(
int i=0; i < mTracks; i++)
38 offset = ftell(mFile);
44 for(;it != track->
End(); it++)
46 const Event &ev = **it;
48 int type = ((ev[0]&0xF0)>>4)-8;
51 if(ev[0]==0xFF && ev[1]==0x51)
59 for(
int k=0; k < 3; k++)
68 int msglen = nbytesPerChnMsg[type];
69 for(
int j=0; j < msglen; j++)
79 WriteCh((
unsigned)0xFF);
80 WriteCh((
unsigned)0x2f);
83 fseek(mFile,offset,0);
85 Write32Bit(mBytesWritten);
92 void Writer::WriteHeader()
94 unsigned long id=
MThd;
100 Write16Bit(mDivision);
103 void Writer::WriteVarLen(
register unsigned long value)
105 register unsigned long buffer;
106 buffer = value & 0x7F;
108 while( (value >>= 7) )
111 buffer |= ((value & 0x7F) | 0x80);
124 void Writer::Write32Bit(
unsigned long data)
126 WriteCh((
unsigned)((data >> 24) & 0xff));
127 WriteCh((
unsigned)((data >> 16) & 0xff));
128 WriteCh((
unsigned)((data >> 8 ) & 0xff));
129 WriteCh((
unsigned)(data & 0xff));
132 void Writer::Write16Bit(
int data)
134 WriteCh((
unsigned)((data & 0xff00) >> 8));
135 WriteCh((
unsigned)(data & 0xff));
138 void Writer::WriteCh(
char c)