comparison minijss/jloadjss.c @ 1314:4670907412e7

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 20 Aug 2017 01:47:45 +0300
parents 4eb394c9e682
children 817a4d0c70b5
comparison
equal deleted inserted replaced
1313:eb3f883f4acb 1314:4670907412e7
262 #ifdef JM_SUP_EXT_INSTR 262 #ifdef JM_SUP_EXT_INSTR
263 static int jssMODLoadEnvelope(DMResource *inFile, 263 static int jssMODLoadEnvelope(DMResource *inFile,
264 JSSEnvelope *env, const char *name, const int ninst) 264 JSSEnvelope *env, const char *name, const int ninst)
265 { 265 {
266 JSSMODEnvelope jssEnv; 266 JSSMODEnvelope jssEnv;
267 int i;
268 267
269 // Read envelope data 268 // Read envelope data
270 if (!dmf_read_byte(inFile, &jssEnv.flags) || 269 if (!dmf_read_byte(inFile, &jssEnv.flags) ||
271 !dmf_read_byte(inFile, &jssEnv.npoints) || 270 !dmf_read_byte(inFile, &jssEnv.npoints) ||
272 !dmf_read_byte(inFile, &jssEnv.sustain) || 271 !dmf_read_byte(inFile, &jssEnv.sustain) ||
273 !dmf_read_byte(inFile, &jssEnv.loopS) || 272 !dmf_read_byte(inFile, &jssEnv.loopS) ||
274 !dmf_read_byte(inFile, &jssEnv.loopE)) 273 !dmf_read_byte(inFile, &jssEnv.loopE))
274 {
275 JSSERROR(DMERR_FREAD, DMERR_FREAD, 275 JSSERROR(DMERR_FREAD, DMERR_FREAD,
276 "Failed to read %s-envelope data for instrument #%d.\n", 276 "Failed to read %s-envelope data for instrument #%d.\n",
277 name, ninst); 277 name, ninst);
278 }
278 279
279 // Do some sanity checking 280 // Do some sanity checking
280 if (jssEnv.npoints > jsetMaxEnvPoints || 281 if (jssEnv.npoints > jsetMaxEnvPoints ||
281 jssEnv.loopS < jssEnv.loopE || 282 jssEnv.loopS < jssEnv.loopE ||
282 jssEnv.loopS > jssEnv.npoints || 283 jssEnv.loopS > jssEnv.npoints ||
283 jssEnv.loopE > jssEnv.npoints) 284 jssEnv.loopE > jssEnv.npoints)
285 {
284 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, 286 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
285 "Invalid values in %s-envelope for instrument #%d.\n", 287 "Invalid values in %s-envelope for instrument #%d.\n",
286 name, ninst); 288 name, ninst);
289 }
287 290
288 // Copy data 291 // Copy data
289 env->flags = jssEnv.flags; 292 env->flags = jssEnv.flags;
290 env->npoints = jssEnv.npoints; 293 env->npoints = jssEnv.npoints;
291 env->sustain = jssEnv.sustain; 294 env->sustain = jssEnv.sustain;
292 env->loopS = jssEnv.loopS; 295 env->loopS = jssEnv.loopS;
293 env->loopE = jssEnv.loopE; 296 env->loopE = jssEnv.loopE;
294 297
295 for (i = 0; i < jssEnv.npoints; i++) 298 for (int i = 0; i < jssEnv.npoints; i++)
296 { 299 {
297 Uint16 frame, value; 300 Uint16 frame, value;
298 if (!dmf_read_le16(inFile, &frame) || 301 if (!dmf_read_le16(inFile, &frame) ||
299 !dmf_read_le16(inFile, &value)) 302 !dmf_read_le16(inFile, &value))
303 {
300 JSSERROR(DMERR_FREAD, DMERR_FREAD, 304 JSSERROR(DMERR_FREAD, DMERR_FREAD,
301 "Failed to read %s-envelope values (%d) for instrument #%d.\n", 305 "Failed to read %s-envelope values (%d) for instrument #%d.\n",
302 name, i, ninst); 306 name, i, ninst);
307 }
303 308
304 env->points[i].frame = frame; 309 env->points[i].frame = frame;
305 env->points[i].value = value; 310 env->points[i].value = value;
306 } 311 }
307 312