diff minijss/jssmod.c @ 2285:25398f2eba64

Merge.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 18 Jun 2019 14:23:02 +0300
parents 167ec99e57a5
children 69a5af2eb1ea
line wrap: on
line diff
--- a/minijss/jssmod.c	Tue Jun 18 07:38:05 2019 +0300
+++ b/minijss/jssmod.c	Tue Jun 18 14:23:02 2019 +0300
@@ -1,7 +1,7 @@
 /*
  * miniJSS - Module structure and handling routines
  * Programmed and designed by Matti 'ccr' Hamalainen
- * (C) Copyright 2006-2015 Tecnic Software productions (TNSP)
+ * (C) Copyright 2006-2019 Tecnic Software productions (TNSP)
  */
 #include "jssmod.h"
 
@@ -343,7 +343,7 @@
 
     // Check arguments
     if (nrows <= 0 || nchannels <= 0)
-        JSSERROR(DMERR_INVALID_ARGS, NULL, "Invalid nrows=%i or nchannels=%i.\n", nrows, nchannels);
+        JSSERROR(DMERR_INVALID_ARGS, NULL, "Invalid nrows=%d or nchannels=%d.\n", nrows, nchannels);
 
     // Allocate a pattern structure
     if ((pattern = dmMalloc0(sizeof(JSSPattern))) == NULL)
@@ -353,14 +353,15 @@
     pattern->data = dmMalloc(nrows * nchannels * sizeof(JSSNote));
     if (pattern->data == NULL)
     {
-        dmFree(pattern);
-        JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern data (nrows=%i, nchannels=%i).\n", nrows,
-             nchannels);
+        jssFreePattern(pattern);
+        JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern data (nrows=%d, nchannels=%d).\n",
+            nrows, nchannels);
     }
 
     // Initialize structure
     pattern->nrows     = nrows;
     pattern->nchannels = nchannels;
+    pattern->nmap      = nchannels;
 
     pnote = pattern->data;
     for (int row = 0; row < nrows; row++)
@@ -372,6 +373,22 @@
         pnote++;
     }
 
+    // Initialize pattern channel map
+    pattern->map = dmMalloc(nchannels * sizeof(pattern->map[0]));
+    pattern->used = dmMalloc(nchannels * sizeof(pattern->used[0]));
+    if (pattern->map == NULL || pattern->used == NULL)
+    {
+        jssFreePattern(pattern);
+        JSSERROR(DMERR_MALLOC, NULL, "Could not allocate pattern map (nchannels=%d).\n",
+             nchannels);
+    }
+
+    for (int chn = 0; chn < nchannels; chn++)
+    {
+        pattern->map[chn] = chn;
+        pattern->used[chn] = TRUE;
+    }
+
     return pattern;
 }
 
@@ -380,6 +397,8 @@
 {
     if (pattern != NULL)
     {
+        dmFree(pattern->used);
+        dmFree(pattern->map);
         dmFree(pattern->data);
         dmFree(pattern);
     }