Mercurial > hg > dmlib
comparison minijss/jloadxm.c @ 1259:8e854dfee26d
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 10 Mar 2015 11:49:22 +0200 |
parents | 60dc14a2e4c5 |
children | 94e9444b0fa7 |
comparison
equal
deleted
inserted
replaced
1258:13c274d22a29 | 1259:8e854dfee26d |
---|---|
323 Uint32 headSize; | 323 Uint32 headSize; |
324 | 324 |
325 // Get the pattern header size and packing | 325 // Get the pattern header size and packing |
326 if (!dmf_read_le32(inFile, &xmP.headSize) || | 326 if (!dmf_read_le32(inFile, &xmP.headSize) || |
327 !dmf_read_byte(inFile, &xmP.packing)) | 327 !dmf_read_byte(inFile, &xmP.packing)) |
328 { | |
328 JSSERROR(DMERR_FREAD, DMERR_FREAD, | 329 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
329 "Could not read pattern header #%d.\n", | 330 "Could not read pattern header #%d.\n", |
330 index); | 331 index); |
332 } | |
331 | 333 |
332 // Different format versions have slightly different headers | 334 // Different format versions have slightly different headers |
333 if (module->intVersion == 0x0102) | 335 if (module->intVersion == 0x0102) |
334 { | 336 { |
335 Uint8 tmp; | 337 Uint8 tmp; |
361 index); | 363 index); |
362 } | 364 } |
363 | 365 |
364 // Sanity-check rest of the header data | 366 // Sanity-check rest of the header data |
365 if (xmP.packing != 0) | 367 if (xmP.packing != 0) |
368 { | |
366 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | 369 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
367 "Pattern #%d packing type unsupported (%d)\n", | 370 "Pattern #%d packing type unsupported (%d)\n", |
368 index, xmP.packing); | 371 index, xmP.packing); |
372 } | |
369 | 373 |
370 if (xmP.nrows == 0) | 374 if (xmP.nrows == 0) |
375 { | |
371 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | 376 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
372 "Pattern #%d has %d rows, invalid data.\n", | 377 "Pattern #%d has %d rows, invalid data.\n", |
373 index, xmP.nrows); | 378 index, xmP.nrows); |
379 } | |
374 | 380 |
375 if (xmP.size > 0) | 381 if (xmP.size > 0) |
376 { | 382 { |
377 // Allocate and unpack pattern | 383 // Allocate and unpack pattern |
378 module->patterns[index] = jssAllocatePattern(xmP.nrows, module->nchannels); | 384 module->patterns[index] = jssAllocatePattern(xmP.nrows, module->nchannels); |
578 JSFSET(inst->flags, jsf16bit); | 584 JSFSET(inst->flags, jsf16bit); |
579 inst->size = xmS.size / sizeof(Uint16); | 585 inst->size = xmS.size / sizeof(Uint16); |
580 inst->loopS = xmS.loopS / sizeof(Uint16); | 586 inst->loopS = xmS.loopS / sizeof(Uint16); |
581 inst->loopE = (xmS.loopS + xmS.loopL) / sizeof(Uint16); | 587 inst->loopE = (xmS.loopS + xmS.loopL) / sizeof(Uint16); |
582 if ((xmS.size & 1) || (xmS.loopS & 1) || (xmS.loopL & 1)) | 588 if ((xmS.size & 1) || (xmS.loopS & 1) || (xmS.loopL & 1)) |
589 { | |
583 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | 590 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
584 "Samp #%d/%d: size=%d, loopS=%d or loopL=%d not divisible by 2 for 16-bit sample.\n", | 591 "Samp #%d/%d: size=%d, loopS=%d or loopL=%d not divisible by 2 for 16-bit sample.\n", |
585 neinst, nsample, xmS.size, xmS.loopS, xmS.loopL); | 592 neinst, nsample, xmS.size, xmS.loopS, xmS.loopL); |
593 } | |
586 } | 594 } |
587 else | 595 else |
588 { | 596 { |
589 // 8-bit sample | 597 // 8-bit sample |
590 inst->size = xmS.size; | 598 inst->size = xmS.size; |
733 !dmf_read_str(inFile, &xmI1.instName, sizeof(xmI1.instName)) || | 741 !dmf_read_str(inFile, &xmI1.instName, sizeof(xmI1.instName)) || |
734 !dmf_read_byte(inFile, &xmI1.instType) || | 742 !dmf_read_byte(inFile, &xmI1.instType) || |
735 !dmf_read_le16(inFile, &xmI1.nsamples)) | 743 !dmf_read_le16(inFile, &xmI1.nsamples)) |
736 { | 744 { |
737 JSSERROR(DMERR_FREAD, DMERR_FREAD, | 745 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
738 "Failed to read primary extended instrument header #%d\n", neinst); | 746 "Failed to read primary extended instrument header #%d.\n", |
747 neinst); | |
739 } | 748 } |
740 | 749 |
741 // If there are samples, there is header #2 | 750 // If there are samples, there is header #2 |
742 if (xmI1.nsamples == 0) | 751 if (xmI1.nsamples == 0) |
743 { | 752 { |
754 // Allocate instrument | 763 // Allocate instrument |
755 JSSDEBUG("Allocating extended instrument #%d [%d]\n", | 764 JSSDEBUG("Allocating extended instrument #%d [%d]\n", |
756 neinst, module->nextInstruments); | 765 neinst, module->nextInstruments); |
757 | 766 |
758 if ((einst = jssAllocateExtInstrument()) == NULL) | 767 if ((einst = jssAllocateExtInstrument()) == NULL) |
768 { | |
759 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | 769 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
760 "Could not allocate extended instrument #%d.\n", | 770 "Could not allocate extended instrument #%d.\n", |
761 neinst); | 771 neinst); |
772 } | |
762 | 773 |
763 module->extInstruments[neinst] = einst; | 774 module->extInstruments[neinst] = einst; |
764 | 775 |
765 // Get instrument header #2 | 776 // Get instrument header #2 |
766 if (!dmf_read_le32(inFile, &xmI2.headSize) || | 777 if (!dmf_read_le32(inFile, &xmI2.headSize) || |
767 !dmf_read_str(inFile, &xmI2.sNumForNotes, sizeof(xmI2.sNumForNotes))) | 778 !dmf_read_str(inFile, &xmI2.sNumForNotes, sizeof(xmI2.sNumForNotes))) |
768 { | 779 { |
769 JSSERROR(DMERR_FREAD, DMERR_FREAD, | 780 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
770 "Could not read secondary instrument header part #1 for #%d.\n", neinst); | 781 "Could not read secondary instrument header part #1 for #%d.\n", |
782 neinst); | |
771 } | 783 } |
772 | 784 |
773 if (!jssXMLoadEnvelopePoints(inFile, &xmI2.volumeEnv) || | 785 if (!jssXMLoadEnvelopePoints(inFile, &xmI2.volumeEnv) || |
774 !jssXMLoadEnvelopePoints(inFile, &xmI2.panningEnv)) | 786 !jssXMLoadEnvelopePoints(inFile, &xmI2.panningEnv)) |
775 { | 787 { |
776 JSSERROR(DMERR_FREAD, DMERR_FREAD, | 788 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
777 "Could not read envelope point data for instrument #%d.\n", neinst); | 789 "Could not read envelope point data for instrument #%d.\n", |
790 neinst); | |
778 } | 791 } |
779 | 792 |
780 if (!dmf_read_byte(inFile, &xmI2.volumeEnv.npoints) || | 793 if (!dmf_read_byte(inFile, &xmI2.volumeEnv.npoints) || |
781 !dmf_read_byte(inFile, &xmI2.panningEnv.npoints) || | 794 !dmf_read_byte(inFile, &xmI2.panningEnv.npoints) || |
782 | 795 |
793 | 806 |
794 !dmf_read_le16(inFile, &xmI2.fadeOut) || | 807 !dmf_read_le16(inFile, &xmI2.fadeOut) || |
795 !dmf_read_le16(inFile, &xmI2.ARESERVED)) | 808 !dmf_read_le16(inFile, &xmI2.ARESERVED)) |
796 { | 809 { |
797 JSSERROR(DMERR_FREAD, DMERR_FREAD, | 810 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
798 "Could not read secondary instrument header part #2 for #%d.\n", neinst); | 811 "Could not read secondary instrument header part #2 for #%d.\n", |
812 neinst); | |
799 } | 813 } |
800 | 814 |
801 // Skip the extra data after header #2 | 815 // Skip the extra data after header #2 |
802 remainder = xmI1.headSize - (dmftell(inFile) - pos); | 816 remainder = xmI1.headSize - (dmftell(inFile) - pos); |
803 if (remainder > 0) | 817 if (remainder > 0) |