annotate decoders/timidity/instrum_dls.c @ 455:cbc2a4ffeeec

* Added support for loading DLS format instruments: Timidity_LoadDLS(), Timidity_FreeDLS(), Timidity_LoadDLSSong() * Added Timidity_Init_NoConfig()
author hercules
date Fri, 26 Sep 2003 20:51:58 +0000
parents
children 69c8ba97f4bd
rev   line source
455
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1 /*
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
2
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
3 TiMidity -- Experimental MIDI to WAVE converter
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
4 Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
5
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
9 (at your option) any later version.
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
10
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
14 GNU General Public License for more details.
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
15
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
17 along with this program; if not, write to the Free Software
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
19
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
20 instrum.h
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
21
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
22 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
23
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
24 #include <stdlib.h>
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
25 #include <string.h>
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
26
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
27 #include "SDL.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
28 #include "SDL_endian.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
29 #include "SDL_rwops.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
30
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
31 #include "SDL_sound.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
32
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
33 #define __SDL_SOUND_INTERNAL__
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
34 #include "SDL_sound_internal.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
35
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
36 #include "timidity.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
37 #include "options.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
38 #include "instrum.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
39 #include "tables.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
40 #include "common.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
41
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
42 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
43 /* * * * * * * * * * * * * * * * * load_riff.h * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
44 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
45 typedef struct _RIFF_Chunk {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
46 Uint32 magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
47 Uint32 length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
48 Uint32 subtype;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
49 Uint8 *data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
50 struct _RIFF_Chunk *child;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
51 struct _RIFF_Chunk *next;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
52 } RIFF_Chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
53
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
54 extern DECLSPEC RIFF_Chunk* SDLCALL LoadRIFF(SDL_RWops *src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
55 extern DECLSPEC void SDLCALL FreeRIFF(RIFF_Chunk *chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
56 extern DECLSPEC void SDLCALL PrintRIFF(RIFF_Chunk *chunk, int level);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
57 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
58
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
59 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
60 /* * * * * * * * * * * * * * * * * load_riff.c * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
61 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
62 #define RIFF 0x46464952 /* "RIFF" */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
63 #define LIST 0x5453494c /* "LIST" */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
64
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
65 static RIFF_Chunk *AllocRIFFChunk()
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
66 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
67 RIFF_Chunk *chunk = (RIFF_Chunk *)malloc(sizeof(*chunk));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
68 if ( !chunk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
69 SDL_Error(SDL_ENOMEM);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
70 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
71 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
72 memset(chunk, 0, sizeof(*chunk));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
73 return chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
74 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
75
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
76 static void FreeRIFFChunk(RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
77 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
78 if ( chunk->child ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
79 FreeRIFFChunk(chunk->child);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
80 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
81 while ( chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
82 RIFF_Chunk *freeable = chunk->next;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
83 chunk->next = freeable->next;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
84 FreeRIFFChunk(freeable);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
85 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
86 free(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
87 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
88
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
89 static int ChunkHasSubType(Uint32 magic)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
90 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
91 static Uint32 chunk_list[] = {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
92 RIFF, LIST
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
93 };
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
94 int i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
95 for ( i = 0; i < SDL_TABLESIZE(chunk_list); ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
96 if ( magic == chunk_list[i] ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
97 return 1;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
98 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
99 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
100 return 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
101 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
102
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
103 static int ChunkHasSubChunks(Uint32 magic)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
104 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
105 static Uint32 chunk_list[] = {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
106 RIFF, LIST
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
107 };
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
108 int i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
109 for ( i = 0; i < SDL_TABLESIZE(chunk_list); ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
110 if ( magic == chunk_list[i] ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
111 return 1;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
112 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
113 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
114 return 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
115 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
116
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
117 static void LoadSubChunks(RIFF_Chunk *chunk, Uint8 *data, Uint32 left)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
118 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
119 Uint8 *subchunkData;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
120 Uint32 subchunkDataLen;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
121
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
122 while ( left > 8 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
123 RIFF_Chunk *child = AllocRIFFChunk();
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
124 RIFF_Chunk *next, *prev = NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
125 for ( next = chunk->child; next; next = next->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
126 prev = next;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
127 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
128 if ( prev ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
129 prev->next = child;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
130 } else {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
131 chunk->child = child;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
132 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
133
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
134 child->magic = (data[0] << 0) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
135 (data[1] << 8) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
136 (data[2] << 16) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
137 (data[3] << 24);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
138 data += 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
139 left -= 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
140 child->length = (data[0] << 0) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
141 (data[1] << 8) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
142 (data[2] << 16) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
143 (data[3] << 24);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
144 data += 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
145 left -= 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
146 child->data = data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
147
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
148 if ( child->length > left ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
149 child->length = left;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
150 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
151
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
152 subchunkData = child->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
153 subchunkDataLen = child->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
154 if ( ChunkHasSubType(child->magic) && subchunkDataLen >= 4 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
155 child->subtype = (subchunkData[0] << 0) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
156 (subchunkData[1] << 8) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
157 (subchunkData[2] << 16) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
158 (subchunkData[3] << 24);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
159 subchunkData += 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
160 subchunkDataLen -= 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
161 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
162 if ( ChunkHasSubChunks(child->magic) ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
163 LoadSubChunks(child, subchunkData, subchunkDataLen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
164 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
165
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
166 data += child->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
167 left -= child->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
168 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
169 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
170
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
171 RIFF_Chunk *LoadRIFF(SDL_RWops *src)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
172 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
173 RIFF_Chunk *chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
174 Uint8 *subchunkData;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
175 Uint32 subchunkDataLen;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
176
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
177 /* Allocate the chunk structure */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
178 chunk = AllocRIFFChunk();
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
179
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
180 /* Make sure the file is in RIFF format */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
181 chunk->magic = SDL_ReadLE32(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
182 chunk->length = SDL_ReadLE32(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
183 if ( chunk->magic != RIFF ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
184 SDL_SetError("Not a RIFF file");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
185 FreeRIFFChunk(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
186 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
187 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
188 chunk->data = (Uint8 *)malloc(chunk->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
189 if ( chunk->data == NULL ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
190 SDL_Error(SDL_ENOMEM);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
191 FreeRIFFChunk(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
192 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
193 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
194 if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
195 SDL_Error(SDL_EFREAD);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
196 FreeRIFF(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
197 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
198 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
199 subchunkData = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
200 subchunkDataLen = chunk->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
201 if ( ChunkHasSubType(chunk->magic) && subchunkDataLen >= 4 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
202 chunk->subtype = (subchunkData[0] << 0) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
203 (subchunkData[1] << 8) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
204 (subchunkData[2] << 16) |
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
205 (subchunkData[3] << 24);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
206 subchunkData += 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
207 subchunkDataLen -= 4;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
208 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
209 if ( ChunkHasSubChunks(chunk->magic) ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
210 LoadSubChunks(chunk, subchunkData, subchunkDataLen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
211 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
212 return chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
213 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
214
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
215 void FreeRIFF(RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
216 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
217 free(chunk->data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
218 FreeRIFFChunk(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
219 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
220
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
221 void PrintRIFF(RIFF_Chunk *chunk, int level)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
222 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
223 static char prefix[128];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
224
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
225 if ( level == sizeof(prefix)-1 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
226 return;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
227 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
228 if ( level > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
229 prefix[(level-1)*2] = ' ';
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
230 prefix[(level-1)*2+1] = ' ';
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
231 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
232 prefix[level*2] = '\0';
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
233 printf("%sChunk: %c%c%c%c (%d bytes)", prefix,
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
234 ((chunk->magic >> 0) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
235 ((chunk->magic >> 8) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
236 ((chunk->magic >> 16) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
237 ((chunk->magic >> 24) & 0xFF), chunk->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
238 if ( chunk->subtype ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
239 printf(" subtype: %c%c%c%c",
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
240 ((chunk->subtype >> 0) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
241 ((chunk->subtype >> 8) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
242 ((chunk->subtype >> 16) & 0xFF),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
243 ((chunk->subtype >> 24) & 0xFF));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
244 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
245 printf("\n");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
246 if ( chunk->child ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
247 printf("%s{\n", prefix);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
248 PrintRIFF(chunk->child, level + 1);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
249 printf("%s}\n", prefix);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
250 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
251 if ( chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
252 PrintRIFF(chunk->next, level);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
253 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
254 if ( level > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
255 prefix[(level-1)*2] = '\0';
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
256 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
257 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
258
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
259 #ifdef TEST_MAIN_RIFF
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
260
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
261 main(int argc, char *argv[])
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
262 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
263 int i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
264 for ( i = 1; i < argc; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
265 RIFF_Chunk *chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
266 SDL_RWops *src = SDL_RWFromFile(argv[i], "rb");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
267 if ( !src ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
268 fprintf(stderr, "Couldn't open %s: %s", argv[i], SDL_GetError());
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
269 continue;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
270 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
271 chunk = LoadRIFF(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
272 if ( chunk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
273 PrintRIFF(chunk, 0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
274 FreeRIFF(chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
275 } else {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
276 fprintf(stderr, "Couldn't load %s: %s\n", argv[i], SDL_GetError());
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
277 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
278 SDL_RWclose(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
279 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
280 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
281
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
282 #endif // TEST_MAIN
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
283 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
284
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
285 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
286 /* * * * * * * * * * * * * * * * * load_dls.h * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
287 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
288 /* This code is based on the DLS spec version 1.1, available at:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
289 http://www.midi.org/about-midi/dls/dlsspec.shtml
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
290 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
291
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
292 /* Some typedefs so the public dls headers don't need to be modified */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
293 #define FAR
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
294 typedef Uint8 BYTE;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
295 typedef Sint16 SHORT;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
296 typedef Uint16 USHORT;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
297 typedef Uint16 WORD;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
298 typedef Sint32 LONG;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
299 typedef Uint32 ULONG;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
300 typedef Uint32 DWORD;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
301 #define mmioFOURCC(A, B, C, D) \
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
302 (((A) << 0) | ((B) << 8) | ((C) << 16) | ((D) << 24))
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
303 #define DEFINE_GUID(A, B, C, E, F, G, H, I, J, K, L, M)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
304
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
305 #include "dls1.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
306 #include "dls2.h"
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
307
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
308 typedef struct _WaveFMT {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
309 WORD wFormatTag;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
310 WORD wChannels;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
311 DWORD dwSamplesPerSec;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
312 DWORD dwAvgBytesPerSec;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
313 WORD wBlockAlign;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
314 WORD wBitsPerSample;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
315 } WaveFMT;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
316
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
317 typedef struct _DLS_Wave {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
318 WaveFMT *format;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
319 Uint8 *data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
320 Uint32 length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
321 WSMPL *wsmp;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
322 WLOOP *wsmp_loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
323 } DLS_Wave;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
324
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
325 typedef struct _DLS_Region {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
326 RGNHEADER *header;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
327 WAVELINK *wlnk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
328 WSMPL *wsmp;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
329 WLOOP *wsmp_loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
330 CONNECTIONLIST *art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
331 CONNECTION *artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
332 } DLS_Region;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
333
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
334 typedef struct _DLS_Instrument {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
335 const char *name;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
336 INSTHEADER *header;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
337 DLS_Region *regions;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
338 CONNECTIONLIST *art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
339 CONNECTION *artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
340 } DLS_Instrument;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
341
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
342 typedef struct _DLS_Data {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
343 struct _RIFF_Chunk *chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
344
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
345 Uint32 cInstruments;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
346 DLS_Instrument *instruments;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
347
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
348 POOLTABLE *ptbl;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
349 POOLCUE *ptblList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
350 DLS_Wave *waveList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
351
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
352 const char *name;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
353 const char *artist;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
354 const char *copyright;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
355 const char *comments;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
356 } DLS_Data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
357
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
358 extern DECLSPEC DLS_Data* SDLCALL LoadDLS(SDL_RWops *src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
359 extern DECLSPEC void SDLCALL FreeDLS(DLS_Data *chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
360 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
361
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
362 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
363 /* * * * * * * * * * * * * * * * * load_dls.c * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
364 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
365
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
366 #define FOURCC_LIST 0x5453494c /* "LIST" */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
367 #define FOURCC_FMT 0x20746D66 /* "fmt " */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
368 #define FOURCC_DATA 0x61746164 /* "data" */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
369 #define FOURCC_INFO mmioFOURCC('I','N','F','O')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
370 #define FOURCC_IARL mmioFOURCC('I','A','R','L')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
371 #define FOURCC_IART mmioFOURCC('I','A','R','T')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
372 #define FOURCC_ICMS mmioFOURCC('I','C','M','S')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
373 #define FOURCC_ICMT mmioFOURCC('I','C','M','T')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
374 #define FOURCC_ICOP mmioFOURCC('I','C','O','P')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
375 #define FOURCC_ICRD mmioFOURCC('I','C','R','D')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
376 #define FOURCC_IENG mmioFOURCC('I','E','N','G')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
377 #define FOURCC_IGNR mmioFOURCC('I','G','N','R')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
378 #define FOURCC_IKEY mmioFOURCC('I','K','E','Y')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
379 #define FOURCC_IMED mmioFOURCC('I','M','E','D')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
380 #define FOURCC_INAM mmioFOURCC('I','N','A','M')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
381 #define FOURCC_IPRD mmioFOURCC('I','P','R','D')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
382 #define FOURCC_ISBJ mmioFOURCC('I','S','B','J')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
383 #define FOURCC_ISFT mmioFOURCC('I','S','F','T')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
384 #define FOURCC_ISRC mmioFOURCC('I','S','R','C')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
385 #define FOURCC_ISRF mmioFOURCC('I','S','R','F')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
386 #define FOURCC_ITCH mmioFOURCC('I','T','C','H')
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
387
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
388
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
389 static void FreeRegions(DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
390 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
391 if ( instrument->regions ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
392 free(instrument->regions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
393 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
394 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
395
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
396 static void AllocRegions(DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
397 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
398 int datalen = (instrument->header->cRegions * sizeof(DLS_Region));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
399 FreeRegions(instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
400 instrument->regions = (DLS_Region *)malloc(datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
401 if ( instrument->regions ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
402 memset(instrument->regions, 0, datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
403 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
404 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
405
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
406 static void FreeInstruments(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
407 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
408 if ( data->instruments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
409 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
410 for ( i = 0; i < data->cInstruments; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
411 FreeRegions(&data->instruments[i]);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
412 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
413 free(data->instruments);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
414 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
415 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
416
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
417 static void AllocInstruments(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
418 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
419 int datalen = (data->cInstruments * sizeof(DLS_Instrument));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
420 FreeInstruments(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
421 data->instruments = (DLS_Instrument *)malloc(datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
422 if ( data->instruments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
423 memset(data->instruments, 0, datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
424 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
425 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
426
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
427 static void FreeWaveList(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
428 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
429 if ( data->waveList ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
430 free(data->waveList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
431 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
432 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
433
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
434 static void AllocWaveList(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
435 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
436 int datalen = (data->ptbl->cCues * sizeof(DLS_Wave));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
437 FreeWaveList(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
438 data->waveList = (DLS_Wave *)malloc(datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
439 if ( data->waveList ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
440 memset(data->waveList, 0, datalen);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
441 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
442 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
443
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
444 static void Parse_colh(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
445 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
446 data->cInstruments = SDL_SwapLE32(*(Uint32 *)chunk->data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
447 AllocInstruments(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
448 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
449
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
450 static void Parse_insh(DLS_Data *data, RIFF_Chunk *chunk, DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
451 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
452 INSTHEADER *header = (INSTHEADER *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
453 header->cRegions = SDL_SwapLE32(header->cRegions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
454 header->Locale.ulBank = SDL_SwapLE32(header->Locale.ulBank);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
455 header->Locale.ulInstrument = SDL_SwapLE32(header->Locale.ulInstrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
456 instrument->header = header;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
457 AllocRegions(instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
458 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
459
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
460 static void Parse_rgnh(DLS_Data *data, RIFF_Chunk *chunk, DLS_Region *region)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
461 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
462 RGNHEADER *header = (RGNHEADER *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
463 header->RangeKey.usLow = SDL_SwapLE16(header->RangeKey.usLow);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
464 header->RangeKey.usHigh = SDL_SwapLE16(header->RangeKey.usHigh);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
465 header->RangeVelocity.usLow = SDL_SwapLE16(header->RangeVelocity.usLow);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
466 header->RangeVelocity.usHigh = SDL_SwapLE16(header->RangeVelocity.usHigh);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
467 header->fusOptions = SDL_SwapLE16(header->fusOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
468 header->usKeyGroup = SDL_SwapLE16(header->usKeyGroup);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
469 region->header = header;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
470 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
471
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
472 static void Parse_wlnk(DLS_Data *data, RIFF_Chunk *chunk, DLS_Region *region)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
473 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
474 WAVELINK *wlnk = (WAVELINK *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
475 wlnk->fusOptions = SDL_SwapLE16(wlnk->fusOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
476 wlnk->usPhaseGroup = SDL_SwapLE16(wlnk->usPhaseGroup);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
477 wlnk->ulChannel = SDL_SwapLE16(wlnk->ulChannel);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
478 wlnk->ulTableIndex = SDL_SwapLE16(wlnk->ulTableIndex);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
479 region->wlnk = wlnk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
480 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
481
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
482 static void Parse_wsmp(DLS_Data *data, RIFF_Chunk *chunk, WSMPL **wsmp_ptr, WLOOP **wsmp_loop_ptr)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
483 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
484 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
485 WSMPL *wsmp = (WSMPL *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
486 WLOOP *loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
487 wsmp->cbSize = SDL_SwapLE32(wsmp->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
488 wsmp->usUnityNote = SDL_SwapLE16(wsmp->usUnityNote);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
489 wsmp->sFineTune = SDL_SwapLE16(wsmp->sFineTune);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
490 wsmp->lAttenuation = SDL_SwapLE32(wsmp->lAttenuation);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
491 wsmp->fulOptions = SDL_SwapLE32(wsmp->fulOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
492 wsmp->cSampleLoops = SDL_SwapLE32(wsmp->cSampleLoops);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
493 loop = (WLOOP *)((Uint8 *)chunk->data + wsmp->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
494 *wsmp_ptr = wsmp;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
495 *wsmp_loop_ptr = loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
496 for ( i = 0; i < wsmp->cSampleLoops; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
497 loop->cbSize = SDL_SwapLE32(loop->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
498 loop->ulType = SDL_SwapLE32(loop->ulType);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
499 loop->ulStart = SDL_SwapLE32(loop->ulStart);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
500 loop->ulLength = SDL_SwapLE32(loop->ulLength);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
501 ++loop;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
502 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
503 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
504
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
505 static void Parse_art(DLS_Data *data, RIFF_Chunk *chunk, CONNECTIONLIST **art_ptr, CONNECTION **artList_ptr)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
506 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
507 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
508 CONNECTIONLIST *art = (CONNECTIONLIST *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
509 CONNECTION *artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
510 art->cbSize = SDL_SwapLE32(art->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
511 art->cConnections = SDL_SwapLE32(art->cConnections);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
512 artList = (CONNECTION *)((Uint8 *)chunk->data + art->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
513 *art_ptr = art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
514 *artList_ptr = artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
515 for ( i = 0; i < art->cConnections; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
516 artList->usSource = SDL_SwapLE16(artList->usSource);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
517 artList->usControl = SDL_SwapLE16(artList->usControl);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
518 artList->usDestination = SDL_SwapLE16(artList->usDestination);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
519 artList->usTransform = SDL_SwapLE16(artList->usTransform);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
520 artList->lScale = SDL_SwapLE32(artList->lScale);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
521 ++artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
522 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
523 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
524
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
525 static void Parse_lart(DLS_Data *data, RIFF_Chunk *chunk, CONNECTIONLIST **conn_ptr, CONNECTION **connList_ptr)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
526 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
527 /* FIXME: This only supports one set of connections */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
528 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
529 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
530 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
531 case FOURCC_ART1:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
532 case FOURCC_ART2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
533 Parse_art(data, chunk, conn_ptr, connList_ptr);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
534 return;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
535 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
536 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
537 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
538
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
539 static void Parse_rgn(DLS_Data *data, RIFF_Chunk *chunk, DLS_Region *region)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
540 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
541 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
542 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
543 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
544 case FOURCC_RGNH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
545 Parse_rgnh(data, chunk, region);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
546 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
547 case FOURCC_WLNK:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
548 Parse_wlnk(data, chunk, region);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
549 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
550 case FOURCC_WSMP:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
551 Parse_wsmp(data, chunk, &region->wsmp, &region->wsmp_loop);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
552 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
553 case FOURCC_LART:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
554 case FOURCC_LAR2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
555 Parse_lart(data, chunk, &region->art, &region->artList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
556 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
557 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
558 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
559 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
560
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
561 static void Parse_lrgn(DLS_Data *data, RIFF_Chunk *chunk, DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
562 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
563 Uint32 region = 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
564 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
565 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
566 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
567 case FOURCC_RGN:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
568 case FOURCC_RGN2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
569 if ( region < instrument->header->cRegions ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
570 Parse_rgn(data, chunk, &instrument->regions[region++]);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
571 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
572 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
573 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
574 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
575 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
576
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
577 static void Parse_INFO_INS(DLS_Data *data, RIFF_Chunk *chunk, DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
578 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
579 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
580 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
581 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
582 case FOURCC_INAM: /* Name */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
583 instrument->name = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
584 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
585 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
586 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
587 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
588
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
589 static void Parse_ins(DLS_Data *data, RIFF_Chunk *chunk, DLS_Instrument *instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
590 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
591 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
592 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
593 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
594 case FOURCC_INSH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
595 Parse_insh(data, chunk, instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
596 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
597 case FOURCC_LRGN:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
598 Parse_lrgn(data, chunk, instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
599 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
600 case FOURCC_LART:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
601 case FOURCC_LAR2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
602 Parse_lart(data, chunk, &instrument->art, &instrument->artList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
603 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
604 case FOURCC_INFO:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
605 Parse_INFO_INS(data, chunk, instrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
606 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
607 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
608 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
609 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
610
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
611 static void Parse_lins(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
612 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
613 Uint32 instrument = 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
614 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
615 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
616 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
617 case FOURCC_INS:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
618 if ( instrument < data->cInstruments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
619 Parse_ins(data, chunk, &data->instruments[instrument++]);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
620 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
621 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
622 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
623 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
624 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
625
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
626 static void Parse_ptbl(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
627 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
628 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
629 POOLTABLE *ptbl = (POOLTABLE *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
630 ptbl->cbSize = SDL_SwapLE32(ptbl->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
631 ptbl->cCues = SDL_SwapLE32(ptbl->cCues);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
632 data->ptbl = ptbl;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
633 data->ptblList = (POOLCUE *)((Uint8 *)chunk->data + ptbl->cbSize);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
634 for ( i = 0; i < ptbl->cCues; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
635 data->ptblList[i].ulOffset = SDL_SwapLE32(data->ptblList[i].ulOffset);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
636 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
637 AllocWaveList(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
638 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
639
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
640 static void Parse_fmt(DLS_Data *data, RIFF_Chunk *chunk, DLS_Wave *wave)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
641 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
642 WaveFMT *fmt = (WaveFMT *)chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
643 fmt->wFormatTag = SDL_SwapLE16(fmt->wFormatTag);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
644 fmt->wChannels = SDL_SwapLE16(fmt->wChannels);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
645 fmt->dwSamplesPerSec = SDL_SwapLE32(fmt->dwSamplesPerSec);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
646 fmt->dwAvgBytesPerSec = SDL_SwapLE32(fmt->dwAvgBytesPerSec);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
647 fmt->wBlockAlign = SDL_SwapLE16(fmt->wBlockAlign);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
648 fmt->wBitsPerSample = SDL_SwapLE16(fmt->wBitsPerSample);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
649 wave->format = fmt;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
650 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
651
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
652 static void Parse_data(DLS_Data *data, RIFF_Chunk *chunk, DLS_Wave *wave)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
653 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
654 wave->data = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
655 wave->length = chunk->length;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
656 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
657
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
658 static void Parse_wave(DLS_Data *data, RIFF_Chunk *chunk, DLS_Wave *wave)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
659 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
660 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
661 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
662 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
663 case FOURCC_FMT:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
664 Parse_fmt(data, chunk, wave);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
665 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
666 case FOURCC_DATA:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
667 Parse_data(data, chunk, wave);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
668 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
669 case FOURCC_WSMP:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
670 Parse_wsmp(data, chunk, &wave->wsmp, &wave->wsmp_loop);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
671 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
672 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
673 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
674 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
675
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
676 static void Parse_wvpl(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
677 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
678 Uint32 wave = 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
679 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
680 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
681 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
682 case FOURCC_wave:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
683 if ( wave < data->ptbl->cCues ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
684 Parse_wave(data, chunk, &data->waveList[wave++]);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
685 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
686 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
687 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
688 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
689 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
690
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
691 static void Parse_INFO_DLS(DLS_Data *data, RIFF_Chunk *chunk)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
692 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
693 for ( chunk = chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
694 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
695 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
696 case FOURCC_IARL: /* Archival Location */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
697 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
698 case FOURCC_IART: /* Artist */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
699 data->artist = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
700 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
701 case FOURCC_ICMS: /* Commisioned */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
702 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
703 case FOURCC_ICMT: /* Comments */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
704 data->comments = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
705 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
706 case FOURCC_ICOP: /* Copyright */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
707 data->copyright = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
708 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
709 case FOURCC_ICRD: /* Creation Date */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
710 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
711 case FOURCC_IENG: /* Engineer */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
712 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
713 case FOURCC_IGNR: /* Genre */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
714 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
715 case FOURCC_IKEY: /* Keywords */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
716 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
717 case FOURCC_IMED: /* Medium */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
718 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
719 case FOURCC_INAM: /* Name */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
720 data->name = chunk->data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
721 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
722 case FOURCC_IPRD: /* Product */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
723 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
724 case FOURCC_ISBJ: /* Subject */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
725 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
726 case FOURCC_ISFT: /* Software */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
727 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
728 case FOURCC_ISRC: /* Source */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
729 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
730 case FOURCC_ISRF: /* Source Form */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
731 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
732 case FOURCC_ITCH: /* Technician */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
733 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
734 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
735 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
736 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
737
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
738 DLS_Data *LoadDLS(SDL_RWops *src)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
739 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
740 RIFF_Chunk *chunk;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
741 DLS_Data *data = (DLS_Data *)malloc(sizeof(*data));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
742 if ( !data ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
743 SDL_Error(SDL_ENOMEM);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
744 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
745 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
746 memset(data, 0, sizeof(*data));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
747
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
748 data->chunk = LoadRIFF(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
749 if ( !data->chunk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
750 FreeDLS(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
751 return NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
752 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
753
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
754 for ( chunk = data->chunk->child; chunk; chunk = chunk->next ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
755 Uint32 magic = (chunk->magic == FOURCC_LIST) ? chunk->subtype : chunk->magic;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
756 switch(magic) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
757 case FOURCC_COLH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
758 Parse_colh(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
759 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
760 case FOURCC_LINS:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
761 Parse_lins(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
762 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
763 case FOURCC_PTBL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
764 Parse_ptbl(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
765 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
766 case FOURCC_WVPL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
767 Parse_wvpl(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
768 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
769 case FOURCC_INFO:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
770 Parse_INFO_DLS(data, chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
771 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
772 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
773 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
774 return data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
775 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
776
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
777 void FreeDLS(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
778 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
779 if ( data->chunk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
780 FreeRIFF(data->chunk);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
781 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
782 FreeInstruments(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
783 FreeWaveList(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
784 free(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
785 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
786
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
787 static const char *SourceToString(USHORT usSource)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
788 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
789 switch(usSource) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
790 case CONN_SRC_NONE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
791 return "NONE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
792 case CONN_SRC_LFO:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
793 return "LFO";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
794 case CONN_SRC_KEYONVELOCITY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
795 return "KEYONVELOCITY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
796 case CONN_SRC_KEYNUMBER:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
797 return "KEYNUMBER";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
798 case CONN_SRC_EG1:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
799 return "EG1";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
800 case CONN_SRC_EG2:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
801 return "EG2";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
802 case CONN_SRC_PITCHWHEEL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
803 return "PITCHWHEEL";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
804 case CONN_SRC_CC1:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
805 return "CC1";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
806 case CONN_SRC_CC7:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
807 return "CC7";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
808 case CONN_SRC_CC10:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
809 return "CC10";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
810 case CONN_SRC_CC11:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
811 return "CC11";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
812 case CONN_SRC_POLYPRESSURE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
813 return "POLYPRESSURE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
814 case CONN_SRC_CHANNELPRESSURE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
815 return "CHANNELPRESSURE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
816 case CONN_SRC_VIBRATO:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
817 return "VIBRATO";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
818 case CONN_SRC_MONOPRESSURE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
819 return "MONOPRESSURE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
820 case CONN_SRC_CC91:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
821 return "CC91";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
822 case CONN_SRC_CC93:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
823 return "CC93";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
824 default:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
825 return "UNKNOWN";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
826 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
827 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
828
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
829 static const char *TransformToString(USHORT usTransform)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
830 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
831 switch (usTransform) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
832 case CONN_TRN_NONE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
833 return "NONE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
834 case CONN_TRN_CONCAVE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
835 return "CONCAVE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
836 case CONN_TRN_CONVEX:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
837 return "CONVEX";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
838 case CONN_TRN_SWITCH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
839 return "SWITCH";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
840 default:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
841 return "UNKNOWN";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
842 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
843 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
844
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
845 static const char *DestinationToString(USHORT usDestination)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
846 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
847 switch (usDestination) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
848 case CONN_DST_NONE:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
849 return "NONE";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
850 case CONN_DST_ATTENUATION:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
851 return "ATTENUATION";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
852 case CONN_DST_PITCH:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
853 return "PITCH";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
854 case CONN_DST_PAN:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
855 return "PAN";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
856 case CONN_DST_LFO_FREQUENCY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
857 return "LFO_FREQUENCY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
858 case CONN_DST_LFO_STARTDELAY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
859 return "LFO_STARTDELAY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
860 case CONN_DST_EG1_ATTACKTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
861 return "EG1_ATTACKTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
862 case CONN_DST_EG1_DECAYTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
863 return "EG1_DECAYTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
864 case CONN_DST_EG1_RELEASETIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
865 return "EG1_RELEASETIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
866 case CONN_DST_EG1_SUSTAINLEVEL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
867 return "EG1_SUSTAINLEVEL";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
868 case CONN_DST_EG2_ATTACKTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
869 return "EG2_ATTACKTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
870 case CONN_DST_EG2_DECAYTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
871 return "EG2_DECAYTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
872 case CONN_DST_EG2_RELEASETIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
873 return "EG2_RELEASETIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
874 case CONN_DST_EG2_SUSTAINLEVEL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
875 return "EG2_SUSTAINLEVEL";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
876 case CONN_DST_KEYNUMBER:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
877 return "KEYNUMBER";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
878 case CONN_DST_LEFT:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
879 return "LEFT";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
880 case CONN_DST_RIGHT:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
881 return "RIGHT";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
882 case CONN_DST_CENTER:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
883 return "CENTER";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
884 case CONN_DST_LEFTREAR:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
885 return "LEFTREAR";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
886 case CONN_DST_RIGHTREAR:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
887 return "RIGHTREAR";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
888 case CONN_DST_LFE_CHANNEL:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
889 return "LFE_CHANNEL";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
890 case CONN_DST_CHORUS:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
891 return "CHORUS";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
892 case CONN_DST_REVERB:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
893 return "REVERB";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
894 case CONN_DST_VIB_FREQUENCY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
895 return "VIB_FREQUENCY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
896 case CONN_DST_VIB_STARTDELAY:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
897 return "VIB_STARTDELAY";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
898 case CONN_DST_EG1_DELAYTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
899 return "EG1_DELAYTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
900 case CONN_DST_EG1_HOLDTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
901 return "EG1_HOLDTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
902 case CONN_DST_EG1_SHUTDOWNTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
903 return "EG1_SHUTDOWNTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
904 case CONN_DST_EG2_DELAYTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
905 return "EG2_DELAYTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
906 case CONN_DST_EG2_HOLDTIME:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
907 return "EG2_HOLDTIME";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
908 case CONN_DST_FILTER_CUTOFF:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
909 return "FILTER_CUTOFF";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
910 case CONN_DST_FILTER_Q:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
911 return "FILTER_Q";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
912 default:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
913 return "UNKOWN";
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
914 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
915 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
916
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
917 static void PrintArt(const char *type, CONNECTIONLIST *art, CONNECTION *artList)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
918 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
919 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
920 printf("%s Connections:\n", type);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
921 for ( i = 0; i < art->cConnections; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
922 printf(" Source: %s, Control: %s, Destination: %s, Transform: %s, Scale: %d\n",
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
923 SourceToString(artList[i].usSource),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
924 SourceToString(artList[i].usControl),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
925 DestinationToString(artList[i].usDestination),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
926 TransformToString(artList[i].usTransform),
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
927 artList[i].lScale);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
928 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
929 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
930
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
931 static void PrintWave(DLS_Wave *wave, Uint32 index)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
932 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
933 WaveFMT *format = wave->format;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
934 if ( format ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
935 printf(" Wave %u: Format: %hu, %hu channels, %u Hz, %hu bits (length = %u)\n", index, format->wFormatTag, format->wChannels, format->dwSamplesPerSec, format->wBitsPerSample, wave->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
936 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
937 if ( wave->wsmp ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
938 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
939 printf(" wsmp->usUnityNote = %hu\n", wave->wsmp->usUnityNote);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
940 printf(" wsmp->sFineTune = %hd\n", wave->wsmp->sFineTune);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
941 printf(" wsmp->lAttenuation = %d\n", wave->wsmp->lAttenuation);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
942 printf(" wsmp->fulOptions = 0x%8.8x\n", wave->wsmp->fulOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
943 printf(" wsmp->cSampleLoops = %u\n", wave->wsmp->cSampleLoops);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
944 for ( i = 0; i < wave->wsmp->cSampleLoops; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
945 WLOOP *loop = &wave->wsmp_loop[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
946 printf(" Loop %u:\n", i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
947 printf(" ulStart = %u\n", loop->ulStart);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
948 printf(" ulLength = %u\n", loop->ulLength);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
949 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
950 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
951 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
952
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
953 static void PrintRegion(DLS_Region *region, Uint32 index)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
954 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
955 printf(" Region %u:\n", index);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
956 if ( region->header ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
957 printf(" RangeKey = { %hu - %hu }\n", region->header->RangeKey.usLow, region->header->RangeKey.usHigh);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
958 printf(" RangeVelocity = { %hu - %hu }\n", region->header->RangeVelocity.usLow, region->header->RangeVelocity.usHigh);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
959 printf(" fusOptions = 0x%4.4hx\n", region->header->fusOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
960 printf(" usKeyGroup = %hu\n", region->header->usKeyGroup);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
961 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
962 if ( region->wlnk ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
963 printf(" wlnk->fusOptions = 0x%4.4hx\n", region->wlnk->fusOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
964 printf(" wlnk->usPhaseGroup = %hu\n", region->wlnk->usPhaseGroup);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
965 printf(" wlnk->ulChannel = %u\n", region->wlnk->ulChannel);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
966 printf(" wlnk->ulTableIndex = %u\n", region->wlnk->ulTableIndex);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
967 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
968 if ( region->wsmp ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
969 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
970 printf(" wsmp->usUnityNote = %hu\n", region->wsmp->usUnityNote);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
971 printf(" wsmp->sFineTune = %hd\n", region->wsmp->sFineTune);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
972 printf(" wsmp->lAttenuation = %d\n", region->wsmp->lAttenuation);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
973 printf(" wsmp->fulOptions = 0x%8.8x\n", region->wsmp->fulOptions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
974 printf(" wsmp->cSampleLoops = %u\n", region->wsmp->cSampleLoops);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
975 for ( i = 0; i < region->wsmp->cSampleLoops; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
976 WLOOP *loop = &region->wsmp_loop[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
977 printf(" Loop %u:\n", i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
978 printf(" ulStart = %u\n", loop->ulStart);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
979 printf(" ulLength = %u\n", loop->ulLength);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
980 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
981 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
982 if ( region->art && region->art->cConnections > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
983 PrintArt("Region", region->art, region->artList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
984 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
985 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
986
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
987 static void PrintInstrument(DLS_Instrument *instrument, Uint32 index)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
988 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
989 printf("Instrument %u:\n", index);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
990 if ( instrument->name ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
991 printf(" Name: %s\n", instrument->name);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
992 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
993 if ( instrument->header ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
994 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
995 printf(" ulBank = 0x%8.8x\n", instrument->header->Locale.ulBank);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
996 printf(" ulInstrument = %u\n", instrument->header->Locale.ulInstrument);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
997 printf(" Regions: %u\n", instrument->header->cRegions);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
998 for ( i = 0; i < instrument->header->cRegions; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
999 PrintRegion(&instrument->regions[i], i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1000 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1001 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1002 if ( instrument->art && instrument->art->cConnections > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1003 PrintArt("Instrument", instrument->art, instrument->artList);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1004 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1005 };
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1006
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1007 void PrintDLS(DLS_Data *data)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1008 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1009 printf("DLS Data:\n");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1010 printf("cInstruments = %u\n", data->cInstruments);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1011 if ( data->instruments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1012 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1013 for ( i = 0; i < data->cInstruments; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1014 PrintInstrument(&data->instruments[i], i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1015 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1016 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1017 if ( data->ptbl && data->ptbl->cCues > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1018 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1019 printf("Cues: ");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1020 for ( i = 0; i < data->ptbl->cCues; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1021 if ( i > 0 ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1022 printf(", ");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1023 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1024 printf("%u", data->ptblList[i].ulOffset);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1025 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1026 printf("\n");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1027 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1028 if ( data->waveList ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1029 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1030 printf("Waves:\n");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1031 for ( i = 0; i < data->ptbl->cCues; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1032 PrintWave(&data->waveList[i], i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1033 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1034 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1035 if ( data->name ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1036 printf("Name: %s\n", data->name);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1037 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1038 if ( data->artist ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1039 printf("Artist: %s\n", data->artist);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1040 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1041 if ( data->copyright ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1042 printf("Copyright: %s\n", data->copyright);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1043 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1044 if ( data->comments ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1045 printf("Comments: %s\n", data->comments);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1046 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1047 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1048
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1049 #ifdef TEST_MAIN_DLS
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1050
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1051 main(int argc, char *argv[])
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1052 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1053 int i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1054 for ( i = 1; i < argc; ++i ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1055 DLS_Data *data;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1056 SDL_RWops *src = SDL_RWFromFile(argv[i], "rb");
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1057 if ( !src ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1058 fprintf(stderr, "Couldn't open %s: %s", argv[i], SDL_GetError());
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1059 continue;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1060 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1061 data = LoadDLS(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1062 if ( data ) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1063 PrintRIFF(data->chunk, 0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1064 PrintDLS(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1065 FreeDLS(data);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1066 } else {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1067 fprintf(stderr, "Couldn't load %s: %s\n", argv[i], SDL_GetError());
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1068 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1069 SDL_RWclose(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1070 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1071 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1072
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1073 #endif // TEST_MAIN
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1074 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1075
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1076 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1077 /* * * * * * * * * * * * * * * * * instrum_dls.c * * * * * * * * * * * * * */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1078 /*-------------------------------------------------------------------------*/
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1079
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1080 DLS_Data *Timidity_LoadDLS(SDL_RWops *src)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1081 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1082 DLS_Data *patches = LoadDLS(src);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1083 if (!patches) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1084 SNDDBG(("%s", SDL_GetError()));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1085 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1086 return patches;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1087 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1088
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1089 void Timidity_FreeDLS(DLS_Data *patches)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1090 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1091 FreeDLS(patches);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1092 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1093
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1094 /* convert timecents to sec */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1095 static double to_msec(int timecent)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1096 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1097 if (timecent == 0x80000000 || timecent == 0)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1098 return 0.0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1099 return 1000.0 * pow(2.0, (double)(timecent / 65536) / 1200.0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1100 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1101
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1102 /* convert decipercent to {0..1} */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1103 static double to_normalized_percent(int decipercent)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1104 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1105 return ((double)(decipercent / 65536)) / 1000.0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1106 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1107
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1108 /* convert from 8bit value to fractional offset (15.15) */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1109 static Sint32 to_offset(int offset)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1110 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1111 return (Sint32)offset << (7+15);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1112 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1113
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1114 /* calculate ramp rate in fractional unit;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1115 * diff = 8bit, time = msec
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1116 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1117 static Sint32 calc_rate(MidiSong *song, int diff, int sample_rate, double msec)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1118 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1119 double rate;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1120
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1121 if(msec < 6)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1122 msec = 6;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1123 if(diff == 0)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1124 diff = 255;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1125 diff <<= (7+15);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1126 rate = ((double)diff / song->rate) * song->control_ratio * 1000.0 / msec;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1127 return (Sint32)rate;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1128 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1129
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1130 static int load_connection(ULONG cConnections, CONNECTION *artList, USHORT destination)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1131 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1132 ULONG i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1133 int value = 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1134 for (i = 0; i < cConnections; ++i) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1135 CONNECTION *conn = &artList[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1136 if(conn->usDestination == destination) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1137 // The formula for the destination is:
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1138 // usDestination = usDestination + usTransform(usSource * (usControl * lScale))
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1139 // Since we are only handling source/control of NONE and identity
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1140 // transform, this simplifies to: usDestination = usDestination + lScale
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1141 if (conn->usSource == CONN_SRC_NONE &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1142 conn->usControl == CONN_SRC_NONE &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1143 conn->usTransform == CONN_TRN_NONE)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1144 value += conn->lScale;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1145 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1146 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1147 return value;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1148 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1149
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1150 static void load_region_dls(MidiSong *song, Sample *sample, DLS_Instrument *ins, Uint32 index)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1151 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1152 DLS_Region *rgn = &ins->regions[index];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1153 DLS_Wave *wave = &song->patches->waveList[rgn->wlnk->ulTableIndex];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1154
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1155 sample->low_freq = freq_table[rgn->header->RangeKey.usLow];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1156 sample->high_freq = freq_table[rgn->header->RangeKey.usHigh];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1157 sample->root_freq = freq_table[rgn->wsmp->usUnityNote];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1158 sample->low_vel = rgn->header->RangeVelocity.usLow;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1159 sample->high_vel = rgn->header->RangeVelocity.usHigh;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1160
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1161 sample->modes = MODES_16BIT;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1162 sample->sample_rate = wave->format->dwSamplesPerSec;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1163 sample->data_length = wave->length / 2;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1164 sample->data = (sample_t *)safe_malloc(wave->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1165 memcpy(sample->data, wave->data, wave->length);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1166 if (rgn->wsmp->cSampleLoops) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1167 sample->modes |= (MODES_LOOPING|MODES_SUSTAIN);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1168 sample->loop_start = rgn->wsmp_loop->ulStart / 2;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1169 sample->loop_end = sample->loop_start + (rgn->wsmp_loop->ulLength / 2);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1170 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1171 sample->volume = 1.0f;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1172
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1173 if (sample->modes & MODES_SUSTAIN) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1174 int value;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1175 double attack, hold, decay, release; int sustain;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1176 CONNECTIONLIST *art = NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1177 CONNECTION *artList = NULL;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1178
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1179 if (ins->art && ins->art->cConnections > 0 && ins->artList) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1180 art = ins->art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1181 artList = ins->artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1182 } else {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1183 art = rgn->art;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1184 artList = rgn->artList;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1185 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1186
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1187 value = load_connection(art->cConnections, artList, CONN_DST_EG1_ATTACKTIME);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1188 attack = to_msec(value);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1189 value = load_connection(art->cConnections, artList, CONN_DST_EG1_HOLDTIME);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1190 hold = to_msec(value);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1191 value = load_connection(art->cConnections, artList, CONN_DST_EG1_DECAYTIME);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1192 decay = to_msec(value);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1193 value = load_connection(art->cConnections, artList, CONN_DST_EG1_RELEASETIME);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1194 release = to_msec(value);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1195 value = load_connection(art->cConnections, artList, CONN_DST_EG1_SUSTAINLEVEL);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1196 sustain = (int)((1.0 - to_normalized_percent(value)) * 250.0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1197 value = load_connection(art->cConnections, artList, CONN_DST_PAN);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1198 sample->panning = (int)((0.5 + to_normalized_percent(value)) * 127.0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1199
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1200 /*
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1201 printf("%d, Rate=%d LV=%d HV=%d Low=%d Hi=%d Root=%d Pan=%d Attack=%f Hold=%f Sustain=%d Decay=%f Release=%f\n", index, sample->sample_rate, rgn->header->RangeVelocity.usLow, rgn->header->RangeVelocity.usHigh, sample->low_freq, sample->high_freq, sample->root_freq, sample->panning, attack, hold, sustain, decay, release);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1202 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1203
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1204 sample->envelope_offset[0] = to_offset(255);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1205 sample->envelope_rate[0] = calc_rate(song, 255, sample->sample_rate, attack);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1206
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1207 sample->envelope_offset[1] = to_offset(250);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1208 sample->envelope_rate[1] = calc_rate(song, 5, sample->sample_rate, hold);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1209
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1210 sample->envelope_offset[2] = to_offset(sustain);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1211 sample->envelope_rate[2] = calc_rate(song, 255 - sustain, sample->sample_rate, decay);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1212
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1213 sample->envelope_offset[3] = to_offset(0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1214 sample->envelope_rate[3] = calc_rate(song, 5 + sustain, sample->sample_rate, release);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1215
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1216 sample->envelope_offset[4] = to_offset(0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1217 sample->envelope_rate[4] = to_offset(1);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1218
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1219 sample->envelope_offset[5] = to_offset(0);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1220 sample->envelope_rate[5] = to_offset(1);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1221
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1222 sample->modes |= MODES_ENVELOPE;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1223 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1224
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1225 sample->data_length <<= FRACTION_BITS;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1226 sample->loop_start <<= FRACTION_BITS;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1227 sample->loop_end <<= FRACTION_BITS;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1228 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1229
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1230 Instrument *load_instrument_dls(MidiSong *song, int drum, int bank, int instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1231 {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1232 Instrument *inst;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1233 Uint32 i;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1234 DLS_Instrument *dls_ins;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1235
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1236 if (!song->patches)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1237 return(NULL);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1238
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1239 drum = drum ? 0x80000000 : 0;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1240 for (i = 0; i < song->patches->cInstruments; ++i) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1241 dls_ins = &song->patches->instruments[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1242 if ((dls_ins->header->Locale.ulBank & 0x80000000) == drum &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1243 ((dls_ins->header->Locale.ulBank >> 8) & 0xFF) == bank &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1244 dls_ins->header->Locale.ulInstrument == instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1245 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1246 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1247 if (i == song->patches->cInstruments && !bank) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1248 for (i = 0; i < song->patches->cInstruments; ++i) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1249 dls_ins = &song->patches->instruments[i];
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1250 if ((dls_ins->header->Locale.ulBank & 0x80000000) == drum &&
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1251 dls_ins->header->Locale.ulInstrument == instrument)
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1252 break;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1253 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1254 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1255 if (i == song->patches->cInstruments) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1256 SNDDBG(("Couldn't find %s instrument %d in bank %d\n", drum ? "drum" : "melodic", instrument, bank));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1257 return(NULL);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1258 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1259
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1260 inst = (Instrument *)safe_malloc(sizeof(*inst));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1261 inst->samples = dls_ins->header->cRegions;
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1262 inst->sample = (Sample *)safe_malloc(inst->samples * sizeof(*inst->sample));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1263 memset(inst->sample, 0, inst->samples * sizeof(*inst->sample));
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1264 /*
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1265 printf("Found %s instrument %d in bank %d named %s with %d regions\n", drum ? "drum" : "melodic", instrument, bank, dls_ins->name, inst->samples);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1266 */
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1267 for (i = 0; i < dls_ins->header->cRegions; ++i) {
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1268 load_region_dls(song, &inst->sample[i], dls_ins, i);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1269 }
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1270 return(inst);
cbc2a4ffeeec * Added support for loading DLS format instruments:
hercules
parents:
diff changeset
1271 }