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