comparison minijss/jssmod.c @ 1222:823f8e06ff6a

Rename some variables.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Mar 2015 09:53:39 +0200
parents 848a88ce7a57
children e667710aee8e
comparison
equal deleted inserted replaced
1221:e0aa979e7188 1222:823f8e06ff6a
372 /* Allocates and initializes a internal pattern structure. 372 /* Allocates and initializes a internal pattern structure.
373 */ 373 */
374 JSSPattern *jssAllocatePattern(const int nrows, const int nchannels) 374 JSSPattern *jssAllocatePattern(const int nrows, const int nchannels)
375 { 375 {
376 int row, chn; 376 int row, chn;
377 JSSPattern *res; 377 JSSPattern *pattern;
378 JSSNote *pnote; 378 JSSNote *pnote;
379 379
380 // Check arguments 380 // Check arguments
381 if (nrows <= 0 || nchannels <= 0) 381 if (nrows <= 0 || nchannels <= 0)
382 JSSERROR(DMERR_INVALID_ARGS, NULL, "Invalid nrows=%i or nchannels=%i.\n", nrows, nchannels); 382 JSSERROR(DMERR_INVALID_ARGS, NULL, "Invalid nrows=%i or nchannels=%i.\n", nrows, nchannels);
383 383
384 // Allocate a pattern structure 384 // Allocate a pattern structure
385 res = dmMalloc0(sizeof(JSSPattern)); 385 if ((pattern = dmMalloc0(sizeof(JSSPattern))) == NULL)
386 if (res == NULL)
387 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern structure.\n"); 386 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern structure.\n");
388 387
389 // Allocate notedata 388 // Allocate notedata
390 res->data = dmCalloc(nrows * nchannels, sizeof(JSSNote)); 389 pattern->data = dmCalloc(nrows * nchannels, sizeof(JSSNote));
391 if (res->data == NULL) 390 if (pattern->data == NULL)
392 { 391 {
393 dmFree(res); 392 dmFree(pattern);
394 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern data (nrows=%i, nchannels=%i).\n", nrows, 393 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern data (nrows=%i, nchannels=%i).\n", nrows,
395 nchannels); 394 nchannels);
396 } 395 }
397 396
398 // Initialize 397 // Initialize
399 res->nrows = nrows; 398 pattern->nrows = nrows;
400 res->nchannels = nchannels; 399 pattern->nchannels = nchannels;
401 400
402 pnote = res->data; 401 pnote = pattern->data;
403 for (row = 0; row < nrows; row++) 402 for (row = 0; row < nrows; row++)
404 { 403 {
405 for (chn = 0; chn < nchannels; chn++) 404 for (chn = 0; chn < nchannels; chn++)
406 { 405 {
407 pnote->note = pnote->instrument = pnote->volume = 406 pnote->note = pnote->instrument = pnote->volume =
410 pnote++; 409 pnote++;
411 } 410 }
412 } 411 }
413 412
414 // OK, return pointer to struct 413 // OK, return pointer to struct
415 return res; 414 return pattern;
415 }
416 } 416 }
417 417
418 418
419 /* Allocates and initializes internal "normal" instrument structure. 419 /* Allocates and initializes internal "normal" instrument structure.
420 */ 420 */
421 JSSInstrument *jssAllocateInstrument(void) 421 JSSInstrument *jssAllocateInstrument(void)
422 { 422 {
423 JSSInstrument *res; 423 JSSInstrument *inst;
424 424
425 // Allocate a instrument structure 425 // Allocate a instrument structure
426 res = dmMalloc0(sizeof(JSSInstrument)); 426 if ((inst = dmMalloc0(sizeof(JSSInstrument))) == NULL)
427 if (res == NULL)
428 return NULL; 427 return NULL;
429 428
430 return res; 429 return inst;
431 } 430 }
432 431
433 432
434 /* Allocates and initializes "extended" instrument structure. 433 /* Allocates and initializes "extended" instrument structure.
435 */ 434 */
436 JSSExtInstrument *jssAllocateExtInstrument(void) 435 JSSExtInstrument *jssAllocateExtInstrument(void)
437 { 436 {
438 int i; 437 int i;
439 JSSExtInstrument *res; 438 JSSExtInstrument *inst;
440 439
441 // Allocate a instrument structure 440 // Allocate a instrument structure
442 res = dmMalloc0(sizeof(JSSExtInstrument)); 441 if ((inst = dmMalloc0(sizeof(JSSExtInstrument))) == NULL)
443 if (res == NULL)
444 return NULL; 442 return NULL;
445 443
444 // Initialize the requisite fields
446 for (i = 0; i < jsetNNotes; i++) 445 for (i = 0; i < jsetNNotes; i++)
447 { 446 {
448 res->sNumForNotes[i] = jsetNotSet; 447 inst->sNumForNotes[i] = jsetNotSet;
449 } 448 inst->instConvTable[i] = jsetNotSet;
450 449 }
451 return res; 450
452 } 451 return inst;
452 }