| 1 | /* |
| 2 | * |
| 3 | * File: elements.h |
| 4 | * |
| 5 | * Copyright (C) 1999 Steve Ratcliffe |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * |
| 17 | * |
| 18 | * |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #define MD_CONTAINER_BEGIN 50 /* Begining of container types */ |
| 23 | |
| 24 | /* |
| 25 | * The basic element type. All elements have a time associated with |
| 26 | * them and most use the device and channel field. |
| 27 | */ |
| 28 | struct element { |
| 29 | short type; /* Element type */ |
| 30 | guint32 element_time; /* Time for this element */ |
| 31 | short device_channel; /* Device/channel for this element */ |
| 32 | }; |
| 33 | #define MD_ELEMENT(e) \ |
| 34 | ((struct element *)md_check_cast((struct element *)(e), MD_TYPE_ELEMENT)) |
| 35 | |
| 36 | |
| 37 | struct containerElement { |
| 38 | struct element parent; |
| 39 | GPtrArray *elements; /* List of elements */ |
| 40 | }; |
| 41 | #define MD_CONTAINER(e) \ |
| 42 | ((struct containerElement *)md_check_cast((struct element *)(e), MD_TYPE_CONTAINER)) |
| 43 | |
| 44 | |
| 45 | struct rootElement { |
| 46 | struct containerElement parent; |
| 47 | short format; /* Midi format */ |
| 48 | short tracks; /* Number of tracks */ |
| 49 | short time_base; /* Time base value */ |
| 50 | }; |
| 51 | #define MD_ROOT(e) \ |
| 52 | ((struct rootElement *)md_check_cast((struct element *)(e), MD_TYPE_ROOT)) |
| 53 | |
| 54 | |
| 55 | struct trackElement { |
| 56 | struct containerElement parent; |
| 57 | guint32 final_time; |
| 58 | }; |
| 59 | #define MD_TRACK(e) \ |
| 60 | ((struct trackElement *)md_check_cast((struct element *)(e), MD_TYPE_TRACK)) |
| 61 | |
| 62 | |
| 63 | struct tempomapElement { |
| 64 | struct containerElement parent; |
| 65 | }; |
| 66 | #define MD_TEMPOMAP(e) \ |
| 67 | ((struct tempomapElement *)md_check_cast((struct element *)(e), MD_TYPE_TEMPOMAP)) |
| 68 | |
| 69 | |
| 70 | struct noteElement { |
| 71 | struct element parent; |
| 72 | short note; |
| 73 | short vel; |
| 74 | int length; |
| 75 | short offvel; /* Note Off velocity */ |
| 76 | }; |
| 77 | #define MD_NOTE(e) \ |
| 78 | ((struct noteElement *)md_check_cast((struct element *)(e), MD_TYPE_NOTE)) |
| 79 | |
| 80 | |
| 81 | struct partElement { |
| 82 | struct containerElement parent; |
| 83 | guint32 final_time; |
| 84 | }; |
| 85 | #define MD_PART(e) \ |
| 86 | ((struct partElement *)md_check_cast((struct element *)(e), MD_TYPE_PART)) |
| 87 | |
| 88 | |
| 89 | struct controlElement { |
| 90 | struct element parent; |
| 91 | short control; /* Controller number */ |
| 92 | short value; /* Controller value */ |
| 93 | }; |
| 94 | #define MD_CONTROL(e) \ |
| 95 | ((struct controlElement *)md_check_cast((struct element *)(e), MD_TYPE_CONTROL)) |
| 96 | |
| 97 | |
| 98 | struct programElement { |
| 99 | struct element parent; |
| 100 | int program; /* Program number */ |
| 101 | }; |
| 102 | #define MD_PROGRAM(e) \ |
| 103 | ((struct programElement *)md_check_cast((struct element *)(e), MD_TYPE_PROGRAM)) |
| 104 | |
| 105 | |
| 106 | struct keytouchElement { |
| 107 | struct element parent; |
| 108 | int note; |
| 109 | int velocity; |
| 110 | }; |
| 111 | #define MD_KEYTOUCH(e) \ |
| 112 | ((struct keytouchElement *)md_check_cast((struct element *)(e), MD_TYPE_KEYTOUCH)) |
| 113 | |
| 114 | |
| 115 | struct pressureElement { |
| 116 | struct element parent; |
| 117 | int velocity; |
| 118 | }; |
| 119 | #define MD_PRESSURE(e) \ |
| 120 | ((struct pressureElement *)md_check_cast((struct element *)(e), MD_TYPE_PRESSURE)) |
| 121 | |
| 122 | |
| 123 | struct pitchElement { |
| 124 | struct element parent; |
| 125 | int pitch; |
| 126 | }; |
| 127 | #define MD_PITCH(e) \ |
| 128 | ((struct pitchElement *)md_check_cast((struct element *)(e), MD_TYPE_PITCH)) |
| 129 | |
| 130 | |
| 131 | struct sysexElement { |
| 132 | struct element parent; |
| 133 | int status; |
| 134 | unsigned char *data; |
| 135 | int length; |
| 136 | }; |
| 137 | #define MD_SYSEX(e) \ |
| 138 | ((struct sysexElement *)md_check_cast((struct element *)(e), MD_TYPE_SYSEX)) |
| 139 | |
| 140 | |
| 141 | struct metaElement { |
| 142 | struct element parent; |
| 143 | }; |
| 144 | #define MD_META(e) \ |
| 145 | ((struct metaElement *)md_check_cast((struct element *)(e), MD_TYPE_META)) |
| 146 | |
| 147 | |
| 148 | struct mapElement { |
| 149 | struct metaElement parent; |
| 150 | }; |
| 151 | #define MD_MAP(e) \ |
| 152 | ((struct mapElement *)md_check_cast((struct element *)(e), MD_TYPE_MAP)) |
| 153 | |
| 154 | |
| 155 | struct keysigElement { |
| 156 | struct mapElement parent; |
| 157 | char key; /* Key signature */ |
| 158 | char minor; /* Is this a minor key or not */ |
| 159 | }; |
| 160 | #define MD_KEYSIG(e) \ |
| 161 | ((struct keysigElement *)md_check_cast((struct element *)(e), MD_TYPE_KEYSIG)) |
| 162 | |
| 163 | |
| 164 | struct timesigElement { |
| 165 | struct mapElement parent; |
| 166 | short top; /* 'top' of timesignature */ |
| 167 | short bottom; /* 'bottom' of timesignature */ |
| 168 | short clocks; /* Can't remember what this is */ |
| 169 | short n32pq; /* Thirtysecond notes per quarter */ |
| 170 | }; |
| 171 | #define MD_TIMESIG(e) \ |
| 172 | ((struct timesigElement *)md_check_cast((struct element *)(e), MD_TYPE_TIMESIG)) |
| 173 | |
| 174 | |
| 175 | struct tempoElement { |
| 176 | struct mapElement parent; |
| 177 | int micro_tempo; /* The tempo in microsec per quarter note */ |
| 178 | }; |
| 179 | #define MD_TEMPO(e) \ |
| 180 | ((struct tempoElement *)md_check_cast((struct element *)(e), MD_TYPE_TEMPO)) |
| 181 | |
| 182 | |
| 183 | struct textElement { |
| 184 | struct element parent; |
| 185 | int type; /* Type of text (lyric, copyright etc) */ |
| 186 | char *name; /* Type as text */ |
| 187 | char *text; /* actual text */ |
| 188 | int length; /* length of the text (including a null?) */ |
| 189 | }; |
| 190 | #define MD_TEXT(e) \ |
| 191 | ((struct textElement *)md_check_cast((struct element *)(e), MD_TYPE_TEXT)) |
| 192 | |
| 193 | |
| 194 | struct smpteoffsetElement { |
| 195 | struct element parent; |
| 196 | short hours; |
| 197 | short minutes; |
| 198 | short seconds; |
| 199 | short frames; |
| 200 | short subframes; |
| 201 | }; |
| 202 | #define MD_SMPTEOFFSET(e) \ |
| 203 | ((struct smpteoffsetElement *)md_check_cast((struct element *)(e), MD_TYPE_SMPTEOFFSET)) |
| 204 | |
| 205 | |
| 206 | struct element *md_element_new(); |
| 207 | struct containerElement *md_container_new(); |
| 208 | struct rootElement *md_root_new(void); |
| 209 | struct trackElement *md_track_new(void); |
| 210 | struct tempomapElement *md_tempomap_new(); |
| 211 | struct noteElement *md_note_new(short note, short vel, int length); |
| 212 | struct partElement *md_part_new(void); |
| 213 | struct controlElement *md_control_new(short control, short value); |
| 214 | struct programElement *md_program_new(int program); |
| 215 | struct keytouchElement *md_keytouch_new(int note, int vel); |
| 216 | struct pressureElement *md_pressure_new(int vel); |
| 217 | struct pitchElement *md_pitch_new(int val); |
| 218 | struct sysexElement *md_sysex_new(int status, unsigned char *data, int len); |
| 219 | struct metaElement *md_meta_new(); |
| 220 | struct mapElement *md_map_new(); |
| 221 | struct keysigElement *md_keysig_new(short key, short minor); |
| 222 | struct timesigElement *md_timesig_new(short top, short bottom, short clocks, |
| 223 | short n32pq); |
| 224 | struct tempoElement *md_tempo_new(int m); |
| 225 | struct textElement *md_text_new(int type, char *text); |
| 226 | struct smpteoffsetElement *md_smpteoffset_new(short hours, short minutes, |
| 227 | short seconds, short frames, short subframes); |
| 228 | void md_add(struct containerElement *c, struct element *e); |
| 229 | void md_free(struct element *el); |
| 230 | struct element *md_check_cast(struct element *el, int type); |
| 231 | |
| 232 | |
| 233 | /* Defines for types */ |
| 234 | #define MD_TYPE_PART (0 + MD_CONTAINER_BEGIN) |
| 235 | #define MD_TYPE_ROOT (1 + MD_CONTAINER_BEGIN) |
| 236 | #define MD_TYPE_KEYTOUCH 2 |
| 237 | #define MD_TYPE_TEXT 3 |
| 238 | #define MD_TYPE_PITCH 4 |
| 239 | #define MD_TYPE_PROGRAM 5 |
| 240 | #define MD_TYPE_META 6 |
| 241 | #define MD_TYPE_PRESSURE 7 |
| 242 | #define MD_TYPE_NOTE 8 |
| 243 | #define MD_TYPE_ELEMENT 9 |
| 244 | #define MD_TYPE_SMPTEOFFSET 10 |
| 245 | #define MD_TYPE_TEMPO 11 |
| 246 | #define MD_TYPE_TEMPOMAP (12 + MD_CONTAINER_BEGIN) |
| 247 | #define MD_TYPE_SYSEX 13 |
| 248 | #define MD_TYPE_TRACK (14 + MD_CONTAINER_BEGIN) |
| 249 | #define MD_TYPE_KEYSIG 15 |
| 250 | #define MD_TYPE_TIMESIG 16 |
| 251 | #define MD_TYPE_CONTAINER 17 |
| 252 | #define MD_TYPE_MAP 18 |
| 253 | #define MD_TYPE_CONTROL 19 |