event.c++
5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//====================================================================
// event.c++
//
// Synopsis:
//
// Author(s)
// Steve Shepard
//
// Copyright 1993, Silicon Graphics, Inc.
// All Rights Reserved.
//
// This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
// the contents of this file may not be disclosed to third parties, copied or
// duplicated in any form, in whole or in part, without the prior written
// permission of Silicon Graphics, Inc.
//
// RESTRICTED RIGHTS LEGEND:
// Use, duplication or disclosure by the Government is subject to restrictions
// as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
// and Computer Software clause at DFARS 252.227-7013, and/or in similar or
// successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
// rights reserved under the Copyright Laws of the United States.
//====================================================================
#include "event.h"
#include <math.h>
void Event::GetTime(Time& t)
{
t = eventTime;
}
void Event::SetTime(const Time& t)
{
eventTime = t;
}
MetaEvent::MetaEvent()
{
type = 0xff;
subtype = -1;
}
MetaEvent::MetaEvent(char stype)
{
type = 0xff;
subtype = stype;
}
int MetaEvent::Init(FILE *file)
{
int bytes = 0;
int i;
bytes += parseVarLen(&len, file);
for (i = 0; i < len; i++) {
char tmp = getc(file);
bytes++;
}
return bytes;
}
void MetaEvent::Print()
{
eventTime.Print();
printf("meta\t");
switch (subtype) {
case (0x0):
printf("Sequence Number\n");
break;
case (0x2f):
printf("End of track\n");
break;
case (0x54):
printf("SMPTE offset\n");
break;
case (0x58):
printf("Time Signature\n");
break;
case (0x59):
printf("Key Signature\n");
break;
default:
printf("unknown type = %x\n", type);
break;
}
}
char MetaEvent::GetType()
{
return type;
}
char MetaEvent::GetSubtype()
{
return subtype;
}
void MetaEvent::SetSubtype(char c)
{
subtype = c;
}
MTextEvent::MTextEvent()
{
ptr = 0;
len = 0;
}
MTextEvent::~MTextEvent()
{
if (ptr)
delete ptr;
}
int MTextEvent::Init(FILE *file)
{
int bytes = 0;
bytes += parseVarLen(&len, file);
ptr = new char[len];
assert(ptr);
fread (ptr, sizeof(char), (int) len, file);
bytes += (int)len;
return bytes;
}
void MTextEvent::Print()
{
eventTime.Print();
printf("meta\t");
char str[256];
switch (subtype) {
case (0x1):
strcpy(str, "Text Event:");
break;
case (0x2):
strcpy (str, "Copyright Notice:");
break;
case (0x3):
strcpy(str, "Sequence/Track: ");
break;
case (0x4):
strcpy(str, "Instrument: ");
break;
case (0x5):
strcpy(str, "Lyric:");
break;
case (0x6):
strcpy(str, "Marker:");
break;
case (0x7):
strcpy(str, "Cue Point:");
break;
default:
printf("MTextEvent:: unknown type = %x\n", type);
break;
}
strncat(str, ptr, (int)len);
printf("%s\n", str);
}
int MSetTempo::Init(FILE *file)
{
int bytes = 0;
bytes += parseVarLen(&len, file);
tempo = getc(file);
tempo = (tempo << 8) | getc(file);
tempo = (tempo << 8) | getc(file);
bytes += 3;
return bytes;
}
long MSetTempo::GetTempo()
{
return tempo;
}
void MSetTempo::Print()
{
eventTime.Print();
float bpm = 60.0*1000000.0/(tempo);
printf("meta\t");
printf("Tempo: %.2f\n", bpm);
}
int MTimeSig::Init(FILE *file)
{
int bytes = 0;
bytes += parseVarLen(&len, file);
nn = getc(file);
dd = getc(file);
cc = getc(file);
bb = getc(file);
bytes += 4;
return bytes;
}
void MTimeSig::Print()
{
eventTime.Print();
int denom = (int)pow(2,dd);
printf("meta\t");
printf("Time Sig: %d/%d\n", nn, denom);
}
MIDIEvent::MIDIEvent()
{
status.byte = 0;
}
MIDIEvent::MIDIEvent(char statusByte)
{
status.byte = statusByte;
}
int MIDIEvent::Init(FILE *file)
{
int bytes = 0;
if (status.byte == 0) {
status.byte = getc(file);
bytes++;
}
if ((status.type == 0xc) || (status.type == 0xd)) {
byte1 = getc(file);
byte2 = 0;
bytes++;
} else {
byte1 = getc(file);
byte2 = getc(file);
bytes += 2;
}
return bytes;
}
void MIDIEvent::Print()
{
int chan = status.byte & 0xf;
int type = (status.byte >> 4) & 0xf;
eventTime.Print();
printf("midi\t");
switch (type) {
case (0x8):
printf("Note Off\n");
break;
case (0x9):
printf("Note On: c: %d k: %d, v: %d\n", chan, byte1, byte2);
break;
case (0xa):
printf("Key Pressure\n");
break;
case (0xb):
printf("Control Change c: %d ctrl: %d val: %d\n", chan, byte1,
byte2);
break;
case (0xc):
printf("Program Change: c: %d p: %d\n", chan, byte1);
break;
case (0xd):
printf("Channel Pressure\n");
break;
case (0xe):
printf("Pitch Bend\n");
break;
default:
printf("unknown midi event: %x\n", status.type);
break;
}
}
char MIDIEvent::GetType()
{
return status.byte;
}
char MIDIEvent::GetSubtype()
{
return 0;
}