forked from sacchy777/mid2wav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidievent.c
82 lines (75 loc) · 2.69 KB
/
midievent.c
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
#include "midievent.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*---------------------------------------------------
*---------------------------------------------------*/
midievent_t *midievent_create_short(unsigned int absolute_time, int channel, int type, int param0, int param1, int param2, int param3){
midievent_t *e;
e = (midievent_t *)malloc(sizeof(midievent_t));
memset(e, 0, sizeof(midievent_t));
e->is_meta = 0;
e->absolute_time = absolute_time;
e->channel = channel;
e->type = type;
e->shortparam[0] = param0;
e->shortparam[1] = param1;
e->shortparam[2] = param2;
e->shortparam[3] = param3;
return e;
}
/*---------------------------------------------------
*---------------------------------------------------*/
midievent_t *midievent_create_meta_string(unsigned int absolute_time, char *name, int length, int event){
midievent_t *e;
e = (midievent_t *)malloc(sizeof(midievent_t));
memset(e, 0, sizeof(midievent_t));
e->absolute_time = absolute_time;
e->is_meta = 1;
e->channel = 0;
e->type = event;
e->longparam_char = (char *)malloc(sizeof(char) * MIDIEVENT_STRING_CHAR_MAX);
memset(e->longparam_char, 0, sizeof(char) * MIDIEVENT_STRING_CHAR_MAX);
strncpy(name, e->longparam_char, length);
return e;
}
/*---------------------------------------------------
*---------------------------------------------------*/
midievent_t *midievent_create_meta_int(unsigned int absolute_time, int param, int event){
midievent_t *e;
e = (midievent_t *)malloc(sizeof(midievent_t));
memset(e, 0, sizeof(midievent_t));
e->absolute_time = absolute_time;
e->is_meta = 1;
e->channel = 0;
e->type = event;
e->longparam_int = param;
return e;
}
/*---------------------------------------------------
*---------------------------------------------------*/
void midievent_destroy(midievent_t *e){
if(e->longparam_char != NULL){
free(e->longparam_char);
}
free(e);
}
/*---------------------------------------------------
*---------------------------------------------------*/
void midievent_dump(midievent_t *e){
if(e->is_meta == 0){
printf(" Ticks[%010d] Ch[%02d]: Type[%02x] Param[%d %d %d %d]\n",
e->absolute_time, e->channel, e->type,
e->shortparam[0], e->shortparam[1], e->shortparam[2], e->shortparam[3]);
}else{
printf(" %010d %010d [%02d]: Long %02x %d\n",
e->absolute_time, e->ticks, e->channel, e->type, e->longparam_int);
}
}
/*---------------------------------------------------
*---------------------------------------------------*/
int midievent_compare(const void *p, const void *q){
midievent_t **_p = (midievent_t **)p;
midievent_t **_q = (midievent_t **)q;
return (*_p)->absolute_time - (*_q)->absolute_time;
}