Mercurial > hg > forks > bilotrip-mj12
annotate src/midifile.c @ 54:7fd43d272c93 good64bit
Ahh .. yup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 06 Aug 2013 15:57:30 +0300 |
parents | a2f736d06b70 |
children | 79977d487182 |
rev | line source |
---|---|
0 | 1 /* |
2 * midiFile.c - A general purpose midi file handling library. This code | |
3 * can read and write MIDI files in formats 0 and 1. | |
4 * Version 1.4 | |
5 * | |
6 * AUTHOR: Steven Goodwin (StevenGoodwin@gmail.com) | |
7 * Copyright 1998-2010, Steven Goodwin | |
8 * | |
9 * This program is free software; you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation; either version 2 of | |
12 * the License,or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 */ | |
23 | |
45
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
24 #include "midifile.h" |
0 | 25 #include <stdio.h> |
26 #include <string.h> | |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
27 #include <stdarg.h> |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
28 |
0 | 29 |
30 /* | |
31 ** Internal Data Structures | |
32 */ | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
33 typedef struct |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
34 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
35 Uint8 note, chn; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
36 Uint8 valid, p2; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
37 Uint32 end_pos; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
38 } MIDI_LAST_NOTE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
39 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
40 typedef struct |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
41 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
42 Uint8 *ptr; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
43 Uint8 *pBase; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
44 Uint8 *pEnd; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
45 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
46 Uint32 pos; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
47 Uint32 dt; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 /* For Reading MIDI Files */ |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
49 Uint32 sz; /* size of whole iTrack */ |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 /* For Writing MIDI Files */ |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
51 Uint32 iBlockSize; /* max size of track */ |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
52 Uint8 iDefaultChannel; /* use for write only */ |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
53 Uint8 last_status; /* used for running status */ |
0 | 54 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
55 MIDI_LAST_NOTE LastNote[MAX_TRACK_POLYPHONY]; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
56 } MIDI_FILE_TRACK; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
57 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
58 typedef struct |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
59 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
60 Uint32 iHeaderSize; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
61 /**/ Uint16 iVersion; /* 0, 1 or 2 */ |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
62 Uint16 iNumTracks; /* number of tracks... (will be 1 for MIDI type 0) */ |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
63 Uint16 PPQN; /* pulses per quarter note */ |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
64 } MIDI_HEADER; |
0 | 65 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
66 typedef struct |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
67 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
68 FILE *pFile; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
69 BOOL bOpenForWriting; |
0 | 70 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
71 MIDI_HEADER Header; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
72 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
73 Uint8 *ptr, *curr, *end; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
74 size_t file_size; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
75 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
76 MIDI_FILE_TRACK Track[MAX_MIDI_TRACKS]; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
77 } _MIDI_FILE; |
0 | 78 |
79 | |
80 /* | |
81 ** Internal Functions | |
82 */ | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
83 #define DT_DEF 32 /* assume maximum delta-time + msg is no more than 32 bytes */ |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
84 #define _VAR_CAST _MIDI_FILE *pMF = (_MIDI_FILE *)_pMF |
0 | 85 #define IsFilePtrValid(pMF) (pMF) |
86 #define IsTrackValid(_x) (_midiValidateTrack(pMF, _x)) | |
87 #define IsChannelValid(_x) ((_x)>=1 && (_x)<=16) | |
88 #define IsNoteValid(_x) ((_x)>=0 && (_x)<128) | |
89 #define IsMessageValid(_x) ((_x)>=msgNoteOff && (_x)<=msgMetaEvent) | |
90 | |
91 | |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
92 static void midiErrorV(_MIDI_FILE *pMF, const char *fmt, va_list ap) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
93 { |
40 | 94 (void) pMF; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
95 printf("MIDI: "); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
96 vprintf(fmt, ap); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
97 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
98 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
99 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
100 static void midiError(_MIDI_FILE *pMF, const char *fmt, ...) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
101 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
102 va_list ap; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
103 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
104 va_start(ap, fmt); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
105 midiErrorV(pMF, fmt, ap); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
106 va_end(ap); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
107 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
108 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
109 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
110 static int midiStrNCmp(_MIDI_FILE *pMF, const char *str, const size_t n) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
111 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
112 if (pMF->curr + n < pMF->end) |
53 | 113 return memcmp(pMF->curr, str, n); |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
114 else |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
115 return 1; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
116 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
117 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
118 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
119 static BOOL midiSkip(_MIDI_FILE *pMF, const size_t n) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
120 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
121 pMF->curr += n; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
122 return (pMF->curr < pMF->end); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
123 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
124 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
125 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
126 static BOOL midiGetBE32(_MIDI_FILE *pMF, Uint32 *val) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
127 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
128 if (pMF->curr + sizeof(Uint32) < pMF->end) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
129 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
130 Uint32 tmp; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
131 memcpy(&tmp, pMF->curr, sizeof(Uint32)); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
132 *val = DM_BE32_TO_NATIVE(tmp); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
133 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
134 pMF->curr += sizeof(Uint32); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
135 return TRUE; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
136 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
137 else |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
138 return FALSE; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
139 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
140 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
141 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
142 static BOOL midiGetBE16(_MIDI_FILE *pMF, Uint16 *val) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
143 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
144 if (pMF->curr + sizeof(Uint16) < pMF->end) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
145 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
146 Uint16 tmp; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
147 memcpy(&tmp, pMF->curr, sizeof(Uint16)); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
148 *val = DM_BE16_TO_NATIVE(tmp); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
149 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
150 pMF->curr += sizeof(Uint16); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
151 return TRUE; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
152 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
153 else |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
154 return FALSE; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
155 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
156 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
157 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
158 static BOOL midiGetByte(_MIDI_FILE *pMF, Uint8 *val) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
159 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
160 if (pMF->curr + sizeof(Uint8) < pMF->end) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
161 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
162 memcpy(val, pMF->curr, sizeof(Uint8)); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
163 pMF->curr += sizeof(Uint8); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
164 return TRUE; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
165 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
166 else |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
167 return FALSE; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
168 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
169 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
170 |
30
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
171 static void midiFree(void *ptr) |
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
172 { |
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
173 if (ptr != NULL) |
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
174 free(ptr); |
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
175 } |
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
176 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
177 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
178 static BOOL midiWriteBE32(FILE *fp, const Uint32 val) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
179 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
180 Uint32 result = DM_NATIVE_TO_BE32(val); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
181 return (fwrite(&result, sizeof(result), 1, fp) == 1); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
182 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
183 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
184 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
185 static BOOL midiWriteBE16(FILE *fp, const Uint16 val) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
186 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
187 Uint16 result = DM_NATIVE_TO_BE16(val); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
188 return (fwrite(&result, sizeof(result), 1, fp) == 1); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
189 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
190 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
191 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
192 static BOOL midiWriteByte(FILE *fp, const Uint8 val) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
193 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
194 return fputc(val, fp) == val; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
195 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
196 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
197 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
198 static BOOL midiWriteData(FILE *fp, const Uint8 *data, const size_t n) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
199 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
200 return fwrite(data, sizeof(Uint8), n, fp) == n; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
201 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
202 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
203 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
204 static BOOL midiWriteStr(FILE *fp, const char *str) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
205 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
206 size_t len = strlen(str); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
207 return fwrite(str, sizeof(char), strlen(str), fp) == len; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
208 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
209 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
210 |
0 | 211 static BOOL _midiValidateTrack(const _MIDI_FILE *pMF, int iTrack) |
212 { | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
213 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
214 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
215 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
216 if (pMF->bOpenForWriting) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
217 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
218 if (iTrack < 0 || iTrack >= MAX_MIDI_TRACKS) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
219 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
220 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
221 else /* open for reading */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
222 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
223 if (!pMF->ptr) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
224 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
225 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
226 if (iTrack < 0 || iTrack >= pMF->Header.iNumTracks) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
227 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
228 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
229 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
230 return TRUE; |
0 | 231 } |
232 | |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
233 static Uint8 *_midiWriteVarLen(Uint8 * ptr, int n) |
0 | 234 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
235 register long buffer; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
236 register long value = n; |
0 | 237 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
238 buffer = value & 0x7f; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
239 while ((value >>= 7) > 0) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
240 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
241 buffer <<= 8; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
242 buffer |= 0x80; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
243 buffer += (value & 0x7f); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
244 } |
0 | 245 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
246 while (TRUE) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
247 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
248 *ptr++ = (Uint8) buffer; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
249 if (buffer & 0x80) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
250 buffer >>= 8; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
251 else |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
252 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
253 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
254 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
255 return (ptr); |
0 | 256 } |
257 | |
258 /* Return a ptr to valid block of memory to store a message | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
259 ** of up to sz_reqd bytes |
0 | 260 */ |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
261 static Uint8 *_midiGetPtr(_MIDI_FILE *pMF, int iTrack, int sz_reqd) |
0 | 262 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
263 const Uint32 mem_sz_inc = 8092; /* arbitary */ |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
264 Uint8 *ptr; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
265 int curr_offset; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
266 MIDI_FILE_TRACK *pTrack = &pMF->Track[iTrack]; |
0 | 267 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
268 ptr = pTrack->ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
269 if (ptr == NULL || ptr + sz_reqd > pTrack->pEnd) /* need more RAM! */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
270 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
271 curr_offset = ptr - pTrack->pBase; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
272 if ((ptr = |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
273 (Uint8 *) realloc(pTrack->pBase, |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
274 mem_sz_inc + pTrack->iBlockSize))) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
275 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
276 pTrack->pBase = ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
277 pTrack->iBlockSize += mem_sz_inc; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
278 pTrack->pEnd = ptr + pTrack->iBlockSize; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
279 /* Move new ptr to continue data entry: */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
280 pTrack->ptr = ptr + curr_offset; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
281 ptr += curr_offset; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
282 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
283 else |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
284 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
285 /* NO MEMORY LEFT */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
286 return NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
287 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
288 } |
0 | 289 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
290 return ptr; |
0 | 291 } |
292 | |
293 | |
294 static int _midiGetLength(int ppqn, int iNoteLen, BOOL bOverride) | |
295 { | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
296 int length = ppqn; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
297 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
298 if (bOverride) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
299 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
300 length = iNoteLen; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
301 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
302 else |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
303 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
304 switch (iNoteLen) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
305 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
306 case MIDI_NOTE_DOTTED_MINIM: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
307 length *= 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
308 break; |
0 | 309 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
310 case MIDI_NOTE_DOTTED_CROCHET: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
311 length *= 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
312 length /= 2; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
313 break; |
0 | 314 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
315 case MIDI_NOTE_DOTTED_QUAVER: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
316 length *= 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
317 length /= 4; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
318 break; |
0 | 319 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
320 case MIDI_NOTE_DOTTED_SEMIQUAVER: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
321 length *= 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
322 length /= 8; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
323 break; |
0 | 324 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
325 case MIDI_NOTE_DOTTED_SEMIDEMIQUAVER: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
326 length *= 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
327 length /= 16; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
328 break; |
0 | 329 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
330 case MIDI_NOTE_BREVE: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
331 length *= 4; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
332 break; |
0 | 333 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
334 case MIDI_NOTE_MINIM: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
335 length *= 2; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
336 break; |
0 | 337 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
338 case MIDI_NOTE_QUAVER: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
339 length /= 2; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
340 break; |
0 | 341 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
342 case MIDI_NOTE_SEMIQUAVER: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
343 length /= 4; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
344 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
345 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
346 case MIDI_NOTE_SEMIDEMIQUAVER: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
347 length /= 8; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
348 break; |
0 | 349 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
350 case MIDI_NOTE_TRIPLE_CROCHET: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
351 length *= 2; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
352 length /= 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
353 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
354 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
355 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
356 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
357 return length; |
0 | 358 } |
359 | |
360 /* | |
361 ** midiFile* Functions | |
362 */ | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
363 MIDI_FILE *midiFileCreate(const char *pFilename, BOOL bOverwriteIfExists) |
0 | 364 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
365 _MIDI_FILE *pMF = (_MIDI_FILE *) malloc(sizeof(_MIDI_FILE)); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
366 int i; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
367 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
368 if (pMF == NULL) |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
369 return NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
370 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
371 if (!bOverwriteIfExists && (pMF->pFile = fopen(pFilename, "r")) != NULL) |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
372 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
373 fclose(pMF->pFile); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
374 midiFree(pMF); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
375 return NULL; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
376 } |
0 | 377 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
378 if ((pMF->pFile = fopen(pFilename, "wb+")) == NULL) |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
379 { |
30
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
380 midiFree(pMF); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
381 return NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
382 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
383 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
384 pMF->bOpenForWriting = TRUE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
385 pMF->Header.PPQN = MIDI_PPQN_DEFAULT; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
386 pMF->Header.iVersion = MIDI_VERSION_DEFAULT; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
387 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
388 for (i = 0; i < MAX_MIDI_TRACKS; ++i) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
389 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
390 pMF->Track[i].pos = 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
391 pMF->Track[i].ptr = NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
392 pMF->Track[i].pBase = NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
393 pMF->Track[i].pEnd = NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
394 pMF->Track[i].iBlockSize = 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
395 pMF->Track[i].dt = 0; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
396 pMF->Track[i].iDefaultChannel = (Uint8) (i & 0xf); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
397 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
398 memset(pMF->Track[i].LastNote, 0, sizeof(pMF->Track[i].LastNote)); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
399 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
400 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
401 return (MIDI_FILE *) pMF; |
0 | 402 } |
403 | |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
404 int midiFileSetTracksDefaultChannel(MIDI_FILE *_pMF, int iTrack, int iChannel) |
0 | 405 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
406 int prev; |
0 | 407 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
408 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
409 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
410 return 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
411 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
412 return 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
413 if (!IsChannelValid(iChannel)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
414 return 0; |
0 | 415 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
416 /* For programmer each, iChannel is between 1 & 16 - but MIDI uses |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
417 ** 0-15. Thus, the fudge factor of 1 :) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
418 */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
419 prev = pMF->Track[iTrack].iDefaultChannel + 1; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
420 pMF->Track[iTrack].iDefaultChannel = (Uint8) (iChannel - 1); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
421 return prev; |
0 | 422 } |
423 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
424 int midiFileGetTracksDefaultChannel(const MIDI_FILE *_pMF, int iTrack) |
0 | 425 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
426 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
427 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
428 return 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
429 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
430 return 0; |
0 | 431 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
432 return pMF->Track[iTrack].iDefaultChannel + 1; |
0 | 433 } |
434 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
435 int midiFileSetPPQN(MIDI_FILE *_pMF, int PPQN) |
0 | 436 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
437 int prev; |
0 | 438 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
439 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
440 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
441 return MIDI_PPQN_DEFAULT; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
442 prev = pMF->Header.PPQN; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
443 pMF->Header.PPQN = (Uint16) PPQN; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
444 return prev; |
0 | 445 } |
446 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
447 int midiFileGetPPQN(const MIDI_FILE *_pMF) |
0 | 448 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
449 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
450 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
451 return MIDI_PPQN_DEFAULT; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
452 return (int) pMF->Header.PPQN; |
0 | 453 } |
454 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
455 int midiFileSetVersion(MIDI_FILE *_pMF, int iVersion) |
0 | 456 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
457 int prev; |
0 | 458 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
459 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
460 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
461 return MIDI_VERSION_DEFAULT; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
462 if (iVersion < 0 || iVersion > 2) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
463 return MIDI_VERSION_DEFAULT; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
464 prev = pMF->Header.iVersion; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
465 pMF->Header.iVersion = (Uint16) iVersion; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
466 return prev; |
0 | 467 } |
468 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
469 int midiFileGetVersion(const MIDI_FILE *_pMF) |
0 | 470 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
471 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
472 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
473 return MIDI_VERSION_DEFAULT; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
474 return pMF->Header.iVersion; |
0 | 475 } |
476 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
477 MIDI_FILE *midiFileOpen(const char *pFilename) |
0 | 478 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
479 _MIDI_FILE *pMF = NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
480 BOOL bValidFile = FALSE; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
481 FILE *fp; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
482 int i; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
483 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
484 if ((fp = fopen(pFilename, "rb")) == NULL) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
485 goto error; |
0 | 486 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
487 if ((pMF = (_MIDI_FILE *) malloc(sizeof(_MIDI_FILE))) == NULL) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
488 goto error; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
489 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
490 fseek(fp, 0L, SEEK_END); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
491 pMF->file_size = ftell(fp); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
492 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
493 if ((pMF->curr = pMF->ptr = (Uint8 *) malloc(pMF->file_size)) == NULL) |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
494 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
495 midiError(pMF, "Could not allocate %d bytes for MIDI file.\n", pMF->file_size); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
496 goto error; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
497 } |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
498 |
49
1efee62c0f96
Possibly fix MIDI loading(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
499 pMF->end = pMF->ptr + pMF->file_size; |
1efee62c0f96
Possibly fix MIDI loading(?)
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
500 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
501 fseek(fp, 0L, SEEK_SET); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
502 if (fread(pMF->ptr, sizeof(Uint8), pMF->file_size, fp) != pMF->file_size) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
503 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
504 midiError(pMF, "Error reading file data.\n"); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
505 goto error; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
506 } |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
507 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
508 /* Is this a valid MIDI file ? */ |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
509 if (midiStrNCmp(pMF, "MThd", 4) != 0) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
510 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
511 midiError(pMF, "Not a MIDI file.\n"); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
512 goto error; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
513 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
514 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
515 midiSkip(pMF, 4); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
516 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
517 if (!midiGetBE32(pMF, &pMF->Header.iHeaderSize) || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
518 !midiGetBE16(pMF, &pMF->Header.iVersion) || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
519 !midiGetBE16(pMF, &pMF->Header.iNumTracks) || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
520 !midiGetBE16(pMF, &pMF->Header.PPQN)) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
521 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
522 midiError(pMF, "Error reading MIDI file header.\n"); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
523 goto error; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
524 } |
0 | 525 |
52 | 526 midiSkip(pMF, pMF->Header.iHeaderSize - 3 * sizeof(Uint16)); |
0 | 527 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
528 /* |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
529 ** Get all tracks |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
530 */ |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
531 for (i = 0; i < MAX_MIDI_TRACKS; ++i) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
532 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
533 pMF->Track[i].pos = 0; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
534 pMF->Track[i].last_status = 0; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
535 } |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
536 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
537 for (i = 0; i < pMF->Header.iNumTracks; ++i) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
538 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
539 if (midiStrNCmp(pMF, "MTrk", 4) != 0) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
540 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
541 midiError(pMF, "Expected track %d data, not found.\n", i); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
542 goto error; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
543 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
544 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
545 pMF->Track[i].pBase = pMF->curr; |
54 | 546 |
547 if (!midiSkip(pMF, 4) || | |
548 !midiGetBE32(pMF, &pMF->Track[i].sz)) | |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
549 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
550 midiError(pMF, "Could not read MTrk size.\n"); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
551 goto error; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
552 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
553 |
54 | 554 pMF->Track[i].ptr = pMF->curr; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
555 pMF->Track[i].pEnd = pMF->curr + pMF->Track[i].sz; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
556 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
557 midiSkip(pMF, pMF->Track[i].sz); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
558 } |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
559 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
560 pMF->bOpenForWriting = FALSE; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
561 pMF->pFile = NULL; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
562 bValidFile = TRUE; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
563 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
564 |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
565 error: |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
566 // Cleanup |
31 | 567 if (fp != NULL) |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
568 fclose(fp); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
569 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
570 if (!bValidFile) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
571 { |
30
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
572 midiFree(pMF); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
573 return NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
574 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
575 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
576 return (MIDI_FILE *) pMF; |
0 | 577 } |
578 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
579 typedef struct |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
580 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
581 int iIdx; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
582 int iEndPos; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
583 } MIDI_END_POINT; |
0 | 584 |
585 static int qs_cmp_pEndPoints(const void *e1, const void *e2) | |
586 { | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
587 MIDI_END_POINT *p1 = (MIDI_END_POINT *) e1; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
588 MIDI_END_POINT *p2 = (MIDI_END_POINT *) e2; |
0 | 589 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
590 return p1->iEndPos - p2->iEndPos; |
0 | 591 } |
592 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
593 BOOL midiFileFlushTrack(MIDI_FILE *_pMF, int iTrack, BOOL bFlushToEnd, |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
594 Uint32 dwEndTimePos) |
0 | 595 { |
40 | 596 size_t sz, index; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
597 Uint8 *ptr; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
598 MIDI_END_POINT *pEndPoints; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
599 int num, mx_pts; |
40 | 600 //BOOL bNoChanges = TRUE; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
601 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
602 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
603 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
604 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
605 if (!_midiValidateTrack(pMF, iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
606 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
607 sz = sizeof(pMF->Track[0].LastNote) / sizeof(pMF->Track[0].LastNote[0]); |
0 | 608 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
609 /* |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
610 ** Flush all |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
611 */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
612 pEndPoints = (MIDI_END_POINT *) malloc(sz * sizeof(MIDI_END_POINT)); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
613 mx_pts = 0; |
40 | 614 for (index = 0; index < sz; index++) |
615 { | |
616 if (pMF->Track[iTrack].LastNote[index].valid) | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
617 { |
40 | 618 pEndPoints[mx_pts].iIdx = index; |
619 pEndPoints[mx_pts].iEndPos = pMF->Track[iTrack].LastNote[index].end_pos; | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
620 mx_pts++; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
621 } |
40 | 622 } |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
623 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
624 if (bFlushToEnd) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
625 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
626 if (mx_pts) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
627 dwEndTimePos = pEndPoints[mx_pts - 1].iEndPos; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
628 else |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
629 dwEndTimePos = pMF->Track[iTrack].pos; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
630 } |
0 | 631 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
632 if (mx_pts) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
633 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
634 /* Sort, smallest first, and add the note off msgs */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
635 qsort(pEndPoints, mx_pts, sizeof(MIDI_END_POINT), qs_cmp_pEndPoints); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
636 |
40 | 637 int n = 0; |
638 while ((dwEndTimePos >= (Uint32) pEndPoints[n].iEndPos || bFlushToEnd) && n < mx_pts) | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
639 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
640 ptr = _midiGetPtr(pMF, iTrack, DT_DEF); |
40 | 641 if (ptr == NULL) |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
642 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
643 |
40 | 644 num = pEndPoints[n].iIdx; /* get 'LastNote' index */ |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
645 |
40 | 646 ptr = _midiWriteVarLen(ptr, |
647 pMF->Track[iTrack].LastNote[num].end_pos - | |
648 pMF->Track[iTrack].pos); | |
649 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
650 /* msgNoteOn msgNoteOff */ |
40 | 651 *ptr++ = (Uint8) (msgNoteOff | pMF->Track[iTrack].LastNote[num].chn); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
652 *ptr++ = pMF->Track[iTrack].LastNote[num].note; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
653 *ptr++ = 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
654 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
655 pMF->Track[iTrack].LastNote[num].valid = FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
656 pMF->Track[iTrack].pos = pMF->Track[iTrack].LastNote[num].end_pos; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
657 pMF->Track[iTrack].ptr = ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
658 |
40 | 659 //bNoChanges = FALSE; |
660 n++; | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
661 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
662 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
663 |
30
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
664 midiFree(pEndPoints); |
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
665 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
666 /* |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
667 ** Re-calc current position |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
668 */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
669 pMF->Track[iTrack].dt = dwEndTimePos - pMF->Track[iTrack].pos; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
670 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
671 return TRUE; |
0 | 672 } |
673 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
674 BOOL midiFileSyncTracks(MIDI_FILE *_pMF, int iTrack1, int iTrack2) |
0 | 675 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
676 int p1, p2; |
0 | 677 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
678 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
679 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
680 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
681 if (!IsTrackValid(iTrack1)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
682 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
683 if (!IsTrackValid(iTrack2)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
684 return FALSE; |
0 | 685 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
686 p1 = pMF->Track[iTrack1].pos + pMF->Track[iTrack1].dt; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
687 p2 = pMF->Track[iTrack2].pos + pMF->Track[iTrack2].dt; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
688 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
689 if (p1 < p2) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
690 midiTrackIncTime(pMF, iTrack1, p2 - p1, TRUE); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
691 else if (p2 < p1) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
692 midiTrackIncTime(pMF, iTrack2, p1 - p2, TRUE); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
693 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
694 return TRUE; |
0 | 695 } |
696 | |
697 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
698 BOOL midiFileClose(MIDI_FILE *_pMF) |
0 | 699 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
700 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
701 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
702 return FALSE; |
0 | 703 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
704 if (pMF->bOpenForWriting) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
705 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
706 Uint16 iNumTracks = 0; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
707 int i; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
708 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
709 /* Flush our buffers */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
710 for (i = 0; i < MAX_MIDI_TRACKS; ++i) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
711 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
712 if (pMF->Track[i].ptr) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
713 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
714 midiSongAddEndSequence(pMF, i); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
715 midiFileFlushTrack(pMF, i, TRUE, 0); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
716 iNumTracks++; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
717 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
718 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
719 /* |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
720 ** Header |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
721 */ |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
722 if (!midiWriteStr(pMF->pFile, "MThd") || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
723 !midiWriteBE32(pMF->pFile, 6) || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
724 !midiWriteBE16(pMF->pFile, iNumTracks == 1 ? pMF->Header.iVersion : 1) || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
725 !midiWriteBE16(pMF->pFile, iNumTracks) || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
726 !midiWriteBE16(pMF->pFile, pMF->Header.PPQN)) |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
727 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
728 midiError(pMF, "Could not write MThd header.\n"); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
729 goto error; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
730 } |
0 | 731 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
732 /* |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
733 ** Track data |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
734 */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
735 for (i = 0; i < MAX_MIDI_TRACKS; ++i) |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
736 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
737 if (pMF->Track[i].ptr) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
738 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
739 size_t sz = pMF->Track[i].ptr - pMF->Track[i].pBase; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
740 if (!midiWriteStr(pMF->pFile, "MTrk") || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
741 !midiWriteBE32(pMF->pFile, sz) || |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
742 !midiWriteData(pMF->pFile, pMF->Track[i].pBase, sz)) |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
743 { |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
744 midiError(pMF, "Could not write track #%d data.\n", i); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
745 goto error; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
746 } |
0 | 747 |
30
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
748 midiFree(pMF->Track[i].pBase); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
749 } |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
750 } |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
751 } |
0 | 752 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
753 error: |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
754 if (pMF->pFile != NULL) |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
755 return fclose(pMF->pFile) ? FALSE : TRUE; |
30
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
756 |
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
757 midiFree(pMF); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
758 return TRUE; |
0 | 759 } |
760 | |
761 | |
762 /* | |
763 ** midiSong* Functions | |
764 */ | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
765 BOOL midiSongAddSMPTEOffset(MIDI_FILE *_pMF, int iTrack, int iHours, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
766 int iMins, int iSecs, int iFrames, int iFFrames) |
0 | 767 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
768 static Uint8 tmp[] = |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
769 { msgMetaEvent, metaSMPTEOffset, 0x05, 0, 0, 0, 0, 0 }; |
0 | 770 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
771 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
772 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
773 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
774 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
775 return FALSE; |
0 | 776 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
777 if (iMins < 0 || iMins > 59) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
778 iMins = 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
779 if (iSecs < 0 || iSecs > 59) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
780 iSecs = 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
781 if (iFrames < 0 || iFrames > 24) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
782 iFrames = 0; |
0 | 783 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
784 tmp[3] = (Uint8) iHours; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
785 tmp[4] = (Uint8) iMins; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
786 tmp[5] = (Uint8) iSecs; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
787 tmp[6] = (Uint8) iFrames; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
788 tmp[7] = (Uint8) iFFrames; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
789 return midiTrackAddRaw(pMF, iTrack, sizeof(tmp), tmp, FALSE, 0); |
0 | 790 } |
791 | |
792 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
793 BOOL midiSongAddSimpleTimeSig(MIDI_FILE *_pMF, int iTrack, int iNom, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
794 int iDenom) |
0 | 795 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
796 return midiSongAddTimeSig(_pMF, iTrack, iNom, iDenom, 24, 8); |
0 | 797 } |
798 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
799 BOOL midiSongAddTimeSig(MIDI_FILE *_pMF, int iTrack, int iNom, int iDenom, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
800 int iClockInMetroTick, int iNotated32nds) |
0 | 801 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
802 static Uint8 tmp[] = { msgMetaEvent, metaTimeSig, 0x04, 0, 0, 0, 0 }; |
0 | 803 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
804 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
805 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
806 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
807 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
808 return FALSE; |
0 | 809 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
810 tmp[3] = (Uint8) iNom; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
811 tmp[4] = (Uint8) (MIDI_NOTE_MINIM / iDenom); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
812 tmp[5] = (Uint8) iClockInMetroTick; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
813 tmp[6] = (Uint8) iNotated32nds; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
814 return midiTrackAddRaw(pMF, iTrack, sizeof(tmp), tmp, FALSE, 0); |
0 | 815 } |
816 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
817 BOOL midiSongAddKeySig(MIDI_FILE *_pMF, int iTrack, tMIDI_KEYSIG iKey) |
0 | 818 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
819 static Uint8 tmp[] = { msgMetaEvent, metaKeySig, 0x02, 0, 0 }; |
0 | 820 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
821 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
822 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
823 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
824 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
825 return FALSE; |
0 | 826 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
827 tmp[3] = (Uint8) ((iKey & keyMaskKey) * ((iKey & keyMaskNeg) ? -1 : 1)); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
828 tmp[4] = (Uint8) ((iKey & keyMaskMin) ? 1 : 0); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
829 return midiTrackAddRaw(pMF, iTrack, sizeof(tmp), tmp, FALSE, 0); |
0 | 830 } |
831 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
832 BOOL midiSongAddTempo(MIDI_FILE *_pMF, int iTrack, int iTempo) |
0 | 833 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
834 static Uint8 tmp[] = { msgMetaEvent, metaSetTempo, 0x03, 0, 0, 0 }; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
835 int us; /* micro-seconds per qn */ |
0 | 836 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
837 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
838 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
839 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
840 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
841 return FALSE; |
0 | 842 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
843 us = 60000000L / iTempo; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
844 tmp[3] = (Uint8) ((us >> 16) & 0xff); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
845 tmp[4] = (Uint8) ((us >> 8) & 0xff); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
846 tmp[5] = (Uint8) ((us >> 0) & 0xff); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
847 return midiTrackAddRaw(pMF, iTrack, sizeof(tmp), tmp, FALSE, 0); |
0 | 848 } |
849 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
850 BOOL midiSongAddMIDIPort(MIDI_FILE *_pMF, int iTrack, int iPort) |
0 | 851 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
852 static Uint8 tmp[] = { msgMetaEvent, metaMIDIPort, 1, 0 }; |
0 | 853 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
854 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
855 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
856 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
857 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
858 return FALSE; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
859 tmp[3] = (Uint8) iPort; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
860 return midiTrackAddRaw(pMF, iTrack, sizeof(tmp), tmp, FALSE, 0); |
0 | 861 } |
862 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
863 BOOL midiSongAddEndSequence(MIDI_FILE *_pMF, int iTrack) |
0 | 864 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
865 static Uint8 tmp[] = { msgMetaEvent, metaEndSequence, 0 }; |
0 | 866 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
867 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
868 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
869 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
870 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
871 return FALSE; |
0 | 872 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
873 return midiTrackAddRaw(pMF, iTrack, sizeof(tmp), tmp, FALSE, 0); |
0 | 874 } |
875 | |
876 | |
877 /* | |
878 ** midiTrack* Functions | |
879 */ | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
880 BOOL midiTrackAddRaw(MIDI_FILE *_pMF, int iTrack, int data_sz, |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
881 const Uint8 * pData, BOOL bMovePtr, int dt) |
0 | 882 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
883 MIDI_FILE_TRACK *pTrk; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
884 Uint8 *ptr; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
885 int dtime; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
886 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
887 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
888 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
889 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
890 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
891 return FALSE; |
0 | 892 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
893 pTrk = &pMF->Track[iTrack]; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
894 ptr = _midiGetPtr(pMF, iTrack, data_sz + DT_DEF); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
895 if (!ptr) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
896 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
897 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
898 dtime = pTrk->dt; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
899 if (bMovePtr) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
900 dtime += dt; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
901 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
902 ptr = _midiWriteVarLen(ptr, dtime); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
903 memcpy(ptr, pData, data_sz); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
904 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
905 pTrk->pos += dtime; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
906 pTrk->dt = 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
907 pTrk->ptr = ptr + data_sz; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
908 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
909 return TRUE; |
0 | 910 } |
911 | |
912 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
913 BOOL midiTrackIncTime(MIDI_FILE *_pMF, int iTrack, int iDeltaTime, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
914 BOOL bOverridePPQN) |
0 | 915 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
916 Uint32 will_end_at; |
0 | 917 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
918 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
919 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
920 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
921 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
922 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
923 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
924 will_end_at = _midiGetLength(pMF->Header.PPQN, iDeltaTime, bOverridePPQN); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
925 will_end_at += pMF->Track[iTrack].pos + pMF->Track[iTrack].dt; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
926 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
927 midiFileFlushTrack(pMF, iTrack, FALSE, will_end_at); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
928 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
929 return TRUE; |
0 | 930 } |
931 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
932 BOOL midiTrackAddText(MIDI_FILE *_pMF, int iTrack, tMIDI_TEXT iType, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
933 const char *pTxt) |
0 | 934 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
935 Uint8 *ptr; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
936 int sz; |
0 | 937 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
938 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
939 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
940 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
941 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
942 return FALSE; |
0 | 943 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
944 sz = strlen(pTxt); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
945 if ((ptr = _midiGetPtr(pMF, iTrack, sz + DT_DEF))) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
946 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
947 *ptr++ = 0; /* delta-time=0 */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
948 *ptr++ = msgMetaEvent; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
949 *ptr++ = (Uint8) iType; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
950 ptr = _midiWriteVarLen((Uint8 *) ptr, sz); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
951 strcpy((char *) ptr, pTxt); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
952 pMF->Track[iTrack].ptr = ptr + sz; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
953 return TRUE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
954 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
955 else |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
956 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
957 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
958 } |
0 | 959 } |
960 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
961 BOOL midiTrackSetKeyPressure(MIDI_FILE *pMF, int iTrack, int iNote, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
962 int iAftertouch) |
0 | 963 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
964 return midiTrackAddMsg(pMF, iTrack, msgNoteKeyPressure, iNote, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
965 iAftertouch); |
0 | 966 } |
967 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
968 BOOL midiTrackAddControlChange(MIDI_FILE *pMF, int iTrack, tMIDI_CC iCCType, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
969 int iParam) |
0 | 970 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
971 return midiTrackAddMsg(pMF, iTrack, msgControlChange, iCCType, iParam); |
0 | 972 } |
973 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
974 BOOL midiTrackAddProgramChange(MIDI_FILE *pMF, int iTrack, int iInstrPatch) |
0 | 975 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
976 return midiTrackAddMsg(pMF, iTrack, msgSetProgram, iInstrPatch, 0); |
0 | 977 } |
978 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
979 BOOL midiTrackChangeKeyPressure(MIDI_FILE *pMF, int iTrack, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
980 int iDeltaPressure) |
0 | 981 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
982 return midiTrackAddMsg(pMF, iTrack, msgChangePressure, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
983 iDeltaPressure & 0x7f, 0); |
0 | 984 } |
985 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
986 BOOL midiTrackSetPitchWheel(MIDI_FILE *pMF, int iTrack, int iWheelPos) |
0 | 987 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
988 Uint16 wheel = (Uint16) iWheelPos; |
0 | 989 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
990 /* bitshift 7 instead of eight because we're dealing with 7 bit numbers */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
991 wheel += MIDI_WHEEL_CENTRE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
992 return midiTrackAddMsg(pMF, iTrack, msgSetPitchWheel, wheel & 0x7f, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
993 (wheel >> 7) & 0x7f); |
0 | 994 } |
995 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
996 BOOL midiTrackAddMsg(MIDI_FILE *_pMF, int iTrack, tMIDI_MSG iMsg, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
997 int iParam1, int iParam2) |
0 | 998 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
999 Uint8 *ptr; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1000 Uint8 data[3]; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1001 int sz; |
0 | 1002 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1003 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1004 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1005 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1006 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1007 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1008 if (!IsMessageValid(iMsg)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1009 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1010 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1011 ptr = _midiGetPtr(pMF, iTrack, DT_DEF); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1012 if (!ptr) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1013 return FALSE; |
0 | 1014 |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1015 data[0] = (Uint8) (iMsg | pMF->Track[iTrack].iDefaultChannel); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1016 data[1] = (Uint8) (iParam1 & 0x7f); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1017 data[2] = (Uint8) (iParam2 & 0x7f); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1018 /* |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1019 ** Is this msg a single, or double Uint8, prm? |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1020 */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1021 switch (iMsg) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1022 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1023 case msgSetProgram: /* only one byte required for these msgs */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1024 case msgChangePressure: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1025 sz = 2; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1026 break; |
0 | 1027 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1028 default: /* double byte messages */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1029 sz = 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1030 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1031 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1032 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1033 return midiTrackAddRaw(pMF, iTrack, sz, data, FALSE, 0); |
0 | 1034 |
1035 } | |
1036 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1037 BOOL midiTrackAddNote(MIDI_FILE *_pMF, int iTrack, int iNote, int iLength, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1038 int iVol, BOOL bAutoInc, BOOL bOverrideLength) |
0 | 1039 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1040 MIDI_FILE_TRACK *pTrk; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1041 Uint8 *ptr; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1042 BOOL bSuccess = FALSE; |
40 | 1043 int chn; |
1044 size_t i; | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1045 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1046 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1047 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1048 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1049 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1050 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1051 if (!IsNoteValid(iNote)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1052 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1053 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1054 pTrk = &pMF->Track[iTrack]; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1055 ptr = _midiGetPtr(pMF, iTrack, DT_DEF); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1056 if (!ptr) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1057 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1058 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1059 chn = pTrk->iDefaultChannel; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1060 iLength = _midiGetLength(pMF->Header.PPQN, iLength, bOverrideLength); |
0 | 1061 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1062 for (i = 0; i < sizeof(pTrk->LastNote) / sizeof(pTrk->LastNote[0]); ++i) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1063 if (pTrk->LastNote[i].valid == FALSE) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1064 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1065 pTrk->LastNote[i].note = (Uint8) iNote; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1066 pTrk->LastNote[i].chn = (Uint8) chn; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1067 pTrk->LastNote[i].end_pos = pTrk->pos + pTrk->dt + iLength; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1068 pTrk->LastNote[i].valid = TRUE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1069 bSuccess = TRUE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1070 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1071 ptr = _midiWriteVarLen(ptr, pTrk->dt); /* delta-time */ |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1072 *ptr++ = (Uint8) (msgNoteOn | chn); |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1073 *ptr++ = (Uint8) iNote; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1074 *ptr++ = (Uint8) iVol; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1075 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1076 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1077 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1078 if (!bSuccess) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1079 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1080 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1081 pTrk->ptr = ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1082 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1083 pTrk->pos += pTrk->dt; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1084 pTrk->dt = 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1085 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1086 if (bAutoInc) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1087 return midiTrackIncTime(pMF, iTrack, iLength, bOverrideLength); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1088 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1089 return TRUE; |
0 | 1090 } |
1091 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1092 BOOL midiTrackAddRest(MIDI_FILE *_pMF, int iTrack, int iLength, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1093 BOOL bOverridePPQN) |
0 | 1094 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1095 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1096 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1097 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1098 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1099 return FALSE; |
0 | 1100 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1101 iLength = _midiGetLength(pMF->Header.PPQN, iLength, bOverridePPQN); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1102 return midiTrackIncTime(pMF, iTrack, iLength, bOverridePPQN); |
0 | 1103 } |
1104 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1105 int midiTrackGetEndPos(MIDI_FILE *_pMF, int iTrack) |
0 | 1106 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1107 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1108 if (!IsFilePtrValid(pMF)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1109 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1110 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1111 return FALSE; |
0 | 1112 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1113 return pMF->Track[iTrack].pos; |
0 | 1114 } |
1115 | |
1116 /* | |
1117 ** midiRead* Functions | |
1118 */ | |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1119 static Uint8 *_midiReadVarLen(Uint8 * ptr, Uint32 * num) |
0 | 1120 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1121 register Uint32 value; |
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1122 register Uint8 c; |
0 | 1123 |
1124 if ((value = *ptr++) & 0x80) | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1125 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1126 value &= 0x7f; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1127 do |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1128 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1129 value = (value << 7) + ((c = *ptr++) & 0x7f); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1130 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1131 while (c & 0x80); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1132 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1133 *num = value; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1134 return (ptr); |
0 | 1135 } |
1136 | |
1137 | |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1138 static BOOL _midiReadTrackCopyData(MIDI_MSG * pMsg, Uint8 * ptr, Uint32 sz, |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1139 BOOL bCopyPtrData) |
0 | 1140 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1141 if (sz > pMsg->data_sz) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1142 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1143 pMsg->data = (Uint8 *) realloc(pMsg->data, sz); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1144 pMsg->data_sz = sz; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1145 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1146 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1147 if (!pMsg->data) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1148 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1149 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1150 if (bCopyPtrData && ptr) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1151 memcpy(pMsg->data, ptr, sz); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1152 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1153 return TRUE; |
0 | 1154 } |
1155 | |
1156 int midiReadGetNumTracks(const MIDI_FILE *_pMF) | |
1157 { | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1158 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1159 return pMF->Header.iNumTracks; |
0 | 1160 } |
1161 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1162 BOOL midiReadGetNextMessage(const MIDI_FILE *_pMF, int iTrack, |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1163 MIDI_MSG * pMsg) |
0 | 1164 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1165 MIDI_FILE_TRACK *pTrack; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1166 Uint8 *bptr, *pMsgDataPtr; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1167 int sz; |
0 | 1168 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1169 _VAR_CAST; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1170 if (!IsTrackValid(iTrack)) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1171 return FALSE; |
0 | 1172 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1173 pTrack = &pMF->Track[iTrack]; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1174 /* FIXME: Check if there is data on this track first!!! */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1175 if (pTrack->ptr >= pTrack->pEnd) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1176 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1177 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1178 pTrack->ptr = _midiReadVarLen(pTrack->ptr, &pMsg->dt); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1179 pTrack->pos += pMsg->dt; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1180 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1181 pMsg->dwAbsPos = pTrack->pos; |
0 | 1182 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1183 if (*pTrack->ptr & 0x80) /* Is this is sys message */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1184 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1185 pMsg->iType = (tMIDI_MSG) ((*pTrack->ptr) & 0xf0); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1186 pMsgDataPtr = pTrack->ptr + 1; |
0 | 1187 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1188 /* SysEx & Meta events don't carry channel info, but something |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1189 ** important in their lower bits that we must keep */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1190 if (pMsg->iType == 0xf0) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1191 pMsg->iType = (tMIDI_MSG) (*pTrack->ptr); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1192 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1193 else /* just data - so use the last msg type */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1194 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1195 pMsg->iType = pMsg->iLastMsgType; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1196 pMsgDataPtr = pTrack->ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1197 } |
0 | 1198 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1199 pMsg->iLastMsgType = (tMIDI_MSG) pMsg->iType; |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1200 pMsg->iLastMsgChnl = (Uint8) ((*pTrack->ptr) & 0x0f) + 1; |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1201 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1202 switch (pMsg->iType) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1203 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1204 case msgNoteOn: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1205 pMsg->MsgData.NoteOn.iChannel = pMsg->iLastMsgChnl; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1206 pMsg->MsgData.NoteOn.iNote = *(pMsgDataPtr); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1207 pMsg->MsgData.NoteOn.iVolume = *(pMsgDataPtr + 1); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1208 pMsg->iMsgSize = 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1209 break; |
0 | 1210 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1211 case msgNoteOff: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1212 pMsg->MsgData.NoteOff.iChannel = pMsg->iLastMsgChnl; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1213 pMsg->MsgData.NoteOff.iNote = *(pMsgDataPtr); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1214 pMsg->iMsgSize = 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1215 break; |
0 | 1216 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1217 case msgNoteKeyPressure: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1218 pMsg->MsgData.NoteKeyPressure.iChannel = pMsg->iLastMsgChnl; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1219 pMsg->MsgData.NoteKeyPressure.iNote = *(pMsgDataPtr); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1220 pMsg->MsgData.NoteKeyPressure.iPressure = *(pMsgDataPtr + 1); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1221 pMsg->iMsgSize = 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1222 break; |
0 | 1223 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1224 case msgSetParameter: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1225 pMsg->MsgData.NoteParameter.iChannel = pMsg->iLastMsgChnl; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1226 pMsg->MsgData.NoteParameter.iControl = (tMIDI_CC) * (pMsgDataPtr); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1227 pMsg->MsgData.NoteParameter.iParam = *(pMsgDataPtr + 1); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1228 pMsg->iMsgSize = 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1229 break; |
0 | 1230 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1231 case msgSetProgram: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1232 pMsg->MsgData.ChangeProgram.iChannel = pMsg->iLastMsgChnl; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1233 pMsg->MsgData.ChangeProgram.iProgram = *(pMsgDataPtr); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1234 pMsg->iMsgSize = 2; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1235 break; |
0 | 1236 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1237 case msgChangePressure: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1238 pMsg->MsgData.ChangePressure.iChannel = pMsg->iLastMsgChnl; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1239 pMsg->MsgData.ChangePressure.iPressure = *(pMsgDataPtr); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1240 pMsg->iMsgSize = 2; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1241 break; |
0 | 1242 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1243 case msgSetPitchWheel: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1244 pMsg->MsgData.PitchWheel.iChannel = pMsg->iLastMsgChnl; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1245 pMsg->MsgData.PitchWheel.iPitch = |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1246 *(pMsgDataPtr) | (*(pMsgDataPtr + 1) << 7); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1247 pMsg->MsgData.PitchWheel.iPitch -= MIDI_WHEEL_CENTRE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1248 pMsg->iMsgSize = 3; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1249 break; |
0 | 1250 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1251 case msgMetaEvent: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1252 /* We can use 'pTrack->ptr' from now on, since meta events |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1253 ** always have bit 7 set */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1254 bptr = pTrack->ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1255 pMsg->MsgData.MetaEvent.iType = (tMIDI_META) * (pTrack->ptr + 1); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1256 pTrack->ptr = _midiReadVarLen(pTrack->ptr + 2, &pMsg->iMsgSize); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1257 sz = (pTrack->ptr - bptr) + pMsg->iMsgSize; |
0 | 1258 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1259 if (_midiReadTrackCopyData(pMsg, pTrack->ptr, sz, FALSE) == FALSE) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1260 return FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1261 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1262 /* Now copy the data... */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1263 memcpy(pMsg->data, bptr, sz); |
0 | 1264 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1265 /* Now place it in a neat structure */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1266 switch (pMsg->MsgData.MetaEvent.iType) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1267 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1268 case metaMIDIPort: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1269 pMsg->MsgData.MetaEvent.Data.iMIDIPort = *(pTrack->ptr + 0); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1270 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1271 case metaSequenceNumber: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1272 pMsg->MsgData.MetaEvent.Data.iSequenceNumber = *(pTrack->ptr + 0); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1273 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1274 case metaTextEvent: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1275 case metaCopyright: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1276 case metaTrackName: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1277 case metaInstrument: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1278 case metaLyric: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1279 case metaMarker: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1280 case metaCuePoint: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1281 /* TODO - Add NULL terminator ??? */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1282 pMsg->MsgData.MetaEvent.Data.Text.pData = pTrack->ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1283 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1284 case metaEndSequence: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1285 /* NO DATA */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1286 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1287 case metaSetTempo: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1288 { |
34
a14cc6c5d7ef
Possibly fix 64-bit issues. Probably not.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
1289 Uint32 us = |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1290 ((*(pTrack->ptr + 0)) << 16) | ((*(pTrack->ptr + 1)) << 8) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1291 | (*(pTrack->ptr + 2)); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1292 pMsg->MsgData.MetaEvent.Data.Tempo.iBPM = 60000000L / us; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1293 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1294 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1295 case metaSMPTEOffset: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1296 pMsg->MsgData.MetaEvent.Data.SMPTE.iHours = *(pTrack->ptr + 0); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1297 pMsg->MsgData.MetaEvent.Data.SMPTE.iMins = *(pTrack->ptr + 1); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1298 pMsg->MsgData.MetaEvent.Data.SMPTE.iSecs = *(pTrack->ptr + 2); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1299 pMsg->MsgData.MetaEvent.Data.SMPTE.iFrames = *(pTrack->ptr + 3); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1300 pMsg->MsgData.MetaEvent.Data.SMPTE.iFF = *(pTrack->ptr + 4); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1301 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1302 case metaTimeSig: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1303 pMsg->MsgData.MetaEvent.Data.TimeSig.iNom = *(pTrack->ptr + 0); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1304 pMsg->MsgData.MetaEvent.Data.TimeSig.iDenom = |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1305 *(pTrack->ptr + 1) * MIDI_NOTE_MINIM; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1306 /* TODO: Variations without 24 & 8 */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1307 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1308 case metaKeySig: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1309 if (*pTrack->ptr & 0x80) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1310 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1311 /* Do some trendy sign extending in reverse :) */ |
48 | 1312 pMsg->MsgData.MetaEvent.Data.KeySig.iKey = (tMIDI_KEYSIG) (((256 - *pTrack->ptr) & keyMaskKey) | keyMaskNeg); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1313 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1314 else |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1315 { |
48 | 1316 pMsg->MsgData.MetaEvent.Data.KeySig.iKey = (tMIDI_KEYSIG) (*pTrack->ptr & keyMaskKey); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1317 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1318 if (*(pTrack->ptr + 1)) |
48 | 1319 pMsg->MsgData.MetaEvent.Data.KeySig.iKey = (tMIDI_KEYSIG) (pMsg->MsgData.MetaEvent.Data.KeySig.iKey | keyMaskMin); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1320 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1321 case metaSequencerSpecific: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1322 pMsg->MsgData.MetaEvent.Data.Sequencer.iSize = pMsg->iMsgSize; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1323 pMsg->MsgData.MetaEvent.Data.Sequencer.pData = pTrack->ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1324 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1325 } |
0 | 1326 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1327 pTrack->ptr += pMsg->iMsgSize; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1328 pMsg->iMsgSize = sz; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1329 break; |
0 | 1330 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1331 case msgSysEx1: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1332 case msgSysEx2: |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1333 bptr = pTrack->ptr; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1334 pTrack->ptr = _midiReadVarLen(pTrack->ptr + 1, &pMsg->iMsgSize); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1335 sz = (pTrack->ptr - bptr) + pMsg->iMsgSize; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1336 |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1337 if (_midiReadTrackCopyData(pMsg, pTrack->ptr, sz, FALSE) == FALSE) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1338 return FALSE; |
0 | 1339 |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1340 /* Now copy the data... */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1341 memcpy(pMsg->data, bptr, sz); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1342 pTrack->ptr += pMsg->iMsgSize; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1343 pMsg->iMsgSize = sz; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1344 pMsg->MsgData.SysEx.pData = pMsg->data; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1345 pMsg->MsgData.SysEx.iSize = sz; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1346 break; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1347 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1348 /* |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1349 ** Standard MIDI messages use a common copy routine |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1350 */ |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1351 pMsg->bImpliedMsg = FALSE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1352 if ((pMsg->iType & 0xf0) != 0xf0) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1353 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1354 if (*pTrack->ptr & 0x80) |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1355 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1356 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1357 else |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1358 { |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1359 pMsg->bImpliedMsg = TRUE; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1360 pMsg->iImpliedMsg = pMsg->iLastMsgType; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1361 pMsg->iMsgSize--; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1362 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1363 _midiReadTrackCopyData(pMsg, pTrack->ptr, pMsg->iMsgSize, TRUE); |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1364 pTrack->ptr += pMsg->iMsgSize; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1365 } |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1366 return TRUE; |
0 | 1367 } |
1368 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1369 void midiReadInitMessage(MIDI_MSG * pMsg) |
0 | 1370 { |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1371 pMsg->data = NULL; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1372 pMsg->data_sz = 0; |
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1373 pMsg->bImpliedMsg = FALSE; |
0 | 1374 } |
1375 | |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1376 void midiReadFreeMessage(MIDI_MSG * pMsg) |
0 | 1377 { |
30
26741527f3b7
Add midiFree() utility function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
1378 midiFree(pMsg->data); |
29
4df6d9714314
Automatic reindent/cleanup pass on the midi code.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1379 pMsg->data = NULL; |
0 | 1380 } |