annotate src/midifile.c @ 29:4df6d9714314

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