forked from sacchy777/mid2wav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidievent.h
118 lines (101 loc) · 4.1 KB
/
midievent.h
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
/*
* Midievent
*
* midievent.h
*
*
* Copyright (c) 2013 sada.gussy (sada dot gussy at gmail dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
/* ----------------------------------------------------------------------
*
* This library assmes:
* (unsigned) int as 32 bit integer,
* (unsigned) short as 16 bit integer
*
* ----------------------------------------------------------------------*/
#ifndef MIDIEVENT_H
#define MIDIEVENT_H
#ifdef __cplusplus
extern "C" {
#endif
#define MIDIEVENT_TYPE_NONE 0
#define MIDIEVENT_TYPE_NOTEOFF 0x80
#define MIDIEVENT_TYPE_NOTEON 0x90
#define MIDIEVENT_TYPE_KEYPRESSURE 0xa0
#define MIDIEVENT_TYPE_CONTROLCHANGE 0xb0
#define MIDIEVENT_TYPE_PROGRAMCHANGE 0xc0
#define MIDIEVENT_TYPE_CHANNELPRESSURE 0xd0
#define MIDIEVENT_TYPE_PITCHBENDCHANGE 0xe0
#define MIDIEVENT_TYPE_SYSEX 0xf0
#define MIDIEVENT_MAX_ABSOLUTETIME 999999999
#define MIDIEVENT_META_TEMPOCHANGE 0x51
#define MIDIEVENT_META_TITLECHANGE 0x02
#define MIDIEVENT_META_AUTHORCHANGE 0x03
#define MIDIEVENT_STRING_CHAR_MAX 129
#define MIDIEVENT_CC_MODULATION 1
#define MIDIEVENT_CC_VOLUME 7
#define MIDIEVENT_CC_PANPOT 10
#define MIDIEVENT_CC_EXPRESSION 11
/*---------------------------------------------------
* main structure
*---------------------------------------------------*/
typedef struct {
unsigned int absolute_time; /* MIDI delta time */
unsigned int ticks; /* in samples */
int is_meta;
int channel;
int type;
int shortparam[4];
int longparam_size;
char *longparam_char;
int longparam_int;
} midievent_t;
/*---------------------------------------------------
* create a midievent with midi short message
*---------------------------------------------------*/
midievent_t *midievent_create_short(unsigned int absolute_time, int channel, int type, int param0, int param1, int param2, int param3);
/*---------------------------------------------------
* compare time of the event
*---------------------------------------------------*/
int midievent_compare(const void *p, const void *q);
/*---------------------------------------------------
* destructor
*---------------------------------------------------*/
void midievent_destroy(midievent_t *e);
/*---------------------------------------------------
* for debug
*---------------------------------------------------*/
void midievent_dump(midievent_t *e);
/*---------------------------------------------------
* create a midievent with midi long message
*---------------------------------------------------*/
midievent_t *midievent_create_meta_string(unsigned int absolute_time, char *name, int length, int event);
#define midievent_create_meta_author(a, n) midievent_create_meta_string(a, n, MIDIEVENT_META_AUTHORCHANGE)
#define midievent_create_meta_title(a, n) midievent_create_meta_string(a, n, MIDIEVENT_META_TITLECHANGE)
/*---------------------------------------------------
* create a midievent having int with midi long message, especially for TEMPO
*---------------------------------------------------*/
midievent_t *midievent_create_meta_int(unsigned int absolute_time, int param, int event);
#ifdef __cplusplus
}
#endif
#endif