shithub: neindaw

Download patch

ref: 9b3691b57b3fc854f77cffb8b9000efc13ee2087
parent: 8291e90f0700652c6f3a3dce408244a67600ad46
author: Sigrid Haflínudóttir <[email protected]>
date: Mon May 11 08:24:02 EDT 2020

piper: add Inst struct to hold instance data

--- a/piper/piper.c
+++ b/piper/piper.c
@@ -4,13 +4,19 @@
 #include <bio.h>
 #include "piper.h"
 
+typedef struct Inst Inst;
 typedef struct Group Group;
 
+struct Inst {
+	void *aux;
+	int data;
+};
+
 struct Group {
 	char *path;
 	Synth *synth;
-	void **aux;
-	int numaux;
+	Inst *inst;
+	int numinst;
 	int clone;
 };
 
@@ -44,7 +50,8 @@
 	if (g != nil) {
 		s++;
 		i = i36(*s);
-		while (i >= g->numaux) { /* instance needs to be created */
+		aux = nil;
+		while (i >= g->numinst) { /* instance needs to be created */
 			seek(g->clone, 0, 0);
 			if ((n = read(g->clone, tmp, sizeof(tmp))) < 1)
 				sysfatal("clone failed");
@@ -53,11 +60,15 @@
 				sysfatal("memory");
 			if ((aux = g->synth->alloc(path)) == nil)
 				return e;
-			if ((g->aux = realloc(g->aux, sizeof(void*)*(g->numaux+1))) == nil)
+			if ((g->inst = realloc(g->inst, sizeof(Inst)*(g->numinst+1))) == nil)
 				sysfatal("memory");
-			g->aux[g->numaux++] = aux;
+			if ((path = smprint("%s/%s/data", g->path, tmp)) == nil)
+				sysfatal("memory");
+			if ((g->inst[g->numinst].data = open(path, OREAD)) < 0)
+				sysfatal("couldn't open data: %r");
+			g->inst[g->numinst++].aux = aux;
+			free(path);
 		}
-		aux = g->aux[i];
 		memset(&c, 0, sizeof(c));
 		g->synth->cmd(aux, &c);
 	}