changeset 1183:ae17e0a004f4

Move jssXMLoadPatterns() closer to the pattern unpacking functions.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 11:34:07 +0200
parents 9d32da6ba785
children d144ebb1cdea
files minijss/jloadxm.c
diffstat 1 files changed, 81 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/minijss/jloadxm.c	Thu Mar 05 11:33:22 2015 +0200
+++ b/minijss/jloadxm.c	Thu Mar 05 11:34:07 2015 +0200
@@ -234,6 +234,87 @@
 }
 
 
+static int jssXMLoadPatterns(DMResource *inFile, JSSModule *module, XMHeader *xmH)
+{
+    int index, result;
+    XMPattern xmP;
+
+    for (index = 0; index < module->npatterns; index++)
+    {
+        // Get the pattern header
+        off_t remainder, pos = dmftell(inFile);
+
+        if (!dmf_read_le32(inFile, &xmP.headSize) ||
+            !dmf_read_byte(inFile, &xmP.packing) ||
+            !dmf_read_le16(inFile, &xmP.nrows) ||
+            !dmf_read_le16(inFile, &xmP.size))
+            JSSERROR(DMERR_FREAD, DMERR_FREAD,
+            "Could not read pattern header data #%d.\n",
+            index);
+
+
+        // Check the header
+        if (xmP.packing != 0)
+            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
+            "Pattern #%d packing type unsupported (%d)\n",
+            index, xmP.packing);
+
+        if (xmP.nrows == 0)
+            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
+            "Pattern #%d has %d rows, invalid data.\n",
+            index, xmP.nrows);
+
+        if (xmP.size > 0)
+        {
+            // Allocate and unpack pattern
+            module->patterns[index] = jssAllocatePattern(xmP.nrows, module->nchannels);
+            if (module->patterns[index] == NULL)
+                JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
+                "Could not allocate memory for pattern #%d\n", index);
+
+            switch (module->intVersion)
+            {
+                case 0x0104:
+                    result = jssXMUnpackPattern104(inFile, xmP.size, module->patterns[index]);
+                    break;
+                case 0x0102:
+                    result = jssXMUnpackPattern102(inFile, xmP.size, module->patterns[index]);
+                    break;
+            }
+
+            if (result != 0)
+                JSSERROR(result, result, "Error in unpacking pattern #%d data\n", index);
+        }
+
+        // Skip extra data (if the file is damaged)
+        remainder = xmP.headSize - (dmftell(inFile) - pos);
+        if (remainder > 0)
+        {
+            JSSDEBUG("xmP Skipping: %li\n", remainder);
+            dmfseek(inFile, remainder, SEEK_CUR);
+        }
+    }
+
+    // Allocate the empty pattern
+    module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels);
+
+    /* Convert song orders list by replacing nonexisting patterns
+     * with pattern number jsetMaxPatterns.
+     */
+    for (index = 0; index < module->norders; index++)
+    {
+        int tmp = xmH->orderList[index];
+        if (tmp >= module->npatterns ||
+            module->patterns[tmp] == NULL)
+            tmp = jsetMaxPatterns;
+
+        module->orderList[index] = tmp;
+    }
+
+    return DMERR_OK;
+}
+
+
 /* Convert XM envelope structure to JSS envelope structure
  */
 static int jssXMConvertEnvelope(
@@ -673,87 +754,6 @@
 }
 
 
-static int jssXMLoadPatterns(DMResource *inFile, JSSModule *module, XMHeader *xmH)
-{
-    int index, result;
-    XMPattern xmP;
-
-    for (index = 0; index < module->npatterns; index++)
-    {
-        // Get the pattern header
-        off_t remainder, pos = dmftell(inFile);
-
-        if (!dmf_read_le32(inFile, &xmP.headSize) ||
-            !dmf_read_byte(inFile, &xmP.packing) ||
-            !dmf_read_le16(inFile, &xmP.nrows) ||
-            !dmf_read_le16(inFile, &xmP.size))
-            JSSERROR(DMERR_FREAD, DMERR_FREAD,
-            "Could not read pattern header data #%d.\n",
-            index);
-
-
-        // Check the header
-        if (xmP.packing != 0)
-            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
-            "Pattern #%d packing type unsupported (%d)\n",
-            index, xmP.packing);
-
-        if (xmP.nrows == 0)
-            JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
-            "Pattern #%d has %d rows, invalid data.\n",
-            index, xmP.nrows);
-
-        if (xmP.size > 0)
-        {
-            // Allocate and unpack pattern
-            module->patterns[index] = jssAllocatePattern(xmP.nrows, module->nchannels);
-            if (module->patterns[index] == NULL)
-                JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
-                "Could not allocate memory for pattern #%d\n", index);
-
-            switch (module->intVersion)
-            {
-                case 0x0104:
-                    result = jssXMUnpackPattern104(inFile, xmP.size, module->patterns[index]);
-                    break;
-                case 0x0102:
-                    result = jssXMUnpackPattern102(inFile, xmP.size, module->patterns[index]);
-                    break;
-            }
-
-            if (result != 0)
-                JSSERROR(result, result, "Error in unpacking pattern #%d data\n", index);
-        }
-
-        // Skip extra data (if the file is damaged)
-        remainder = xmP.headSize - (dmftell(inFile) - pos);
-        if (remainder > 0)
-        {
-            JSSDEBUG("xmP Skipping: %li\n", remainder);
-            dmfseek(inFile, remainder, SEEK_CUR);
-        }
-    }
-
-    // Allocate the empty pattern
-    module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels);
-
-    /* Convert song orders list by replacing nonexisting patterns
-     * with pattern number jsetMaxPatterns.
-     */
-    for (index = 0; index < module->norders; index++)
-    {
-        int tmp = xmH->orderList[index];
-        if (tmp >= module->npatterns ||
-            module->patterns[tmp] == NULL)
-            tmp = jsetMaxPatterns;
-
-        module->orderList[index] = tmp;
-    }
-
-    return DMERR_OK;
-}
-
-
 static int jssXMLoadInstruments(DMResource *inFile, JSSModule *module)
 {
     int index;