Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

compiler: load images

  • Loading branch information...
commit 9aa2377c4f91e4b93608b1894e5a54dd99a95ad9 1 parent fc9b0c8
Sébastien Bourdeauducq authored
2  src/gui/patcheditor.c
@@ -152,7 +152,7 @@ static void run_callback(mtk_event *e, void *arg)
152 152
 
153 153
 	mtk_cmd(appid, "status.set(-text \"Ready.\")");
154 154
 	mtk_req(appid, code, 32768, "ed.text");
155  
-	p = patch_compile(code, rmc);
  155
+	p = patch_compile_filename(current_filename, code, rmc);
156 156
 	if(p == NULL)
157 157
 		return;
158 158
 
2  src/gui/performance.c
@@ -298,7 +298,7 @@ static struct patch *compile_patch(const char *filename)
298 298
 	buf[r] = 0;
299 299
 	fclose(fd);
300 300
 
301  
-	return patch_compile(buf, dummy_rmc);
  301
+	return patch_compile_filename(filename, buf, dummy_rmc);
302 302
 }
303 303
 
304 304
 static rtems_task comp_task(rtems_task_argument argument)
3  src/pixbuf/manager.c
@@ -53,7 +53,8 @@ struct pixbuf *pixbuf_search(char *filename)
53 53
 
54 54
 void pixbuf_inc_ref(struct pixbuf *p)
55 55
 {
56  
-	p->refcnt++;
  56
+	if(p != NULL)
  57
+		p->refcnt++;
57 58
 }
58 59
 
59 60
 void pixbuf_dec_ref(struct pixbuf *p)
65  src/renderer/compiler.c
@@ -15,6 +15,7 @@
15 15
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16
  */
17 17
 
  18
+#include <assert.h>
18 19
 #include <stdio.h>
19 20
 #include <stdlib.h>
20 21
 #include <stdarg.h>
@@ -24,11 +25,13 @@
24 25
 #include <fpvm/schedulers.h>
25 26
 #include <fpvm/pfpu.h>
26 27
 
  28
+#include "../pixbuf/pixbuf.h"
27 29
 #include "compiler.h"
28 30
 
29 31
 struct compiler_sc {
30 32
 	struct patch *p;
31 33
 
  34
+	const char *basedir;
32 35
 	report_message rmc;
33 36
 	int linenr;
34 37
 
@@ -559,6 +562,24 @@ static bool process_top_assign(struct compiler_sc *sc, char *left, char *right)
559 562
 
560 563
 	while(*right == ' ') right++;
561 564
 	if(*right == 0) return true;
  565
+	
  566
+	if(strncmp(left, "imagefile", 9) == 0) {
  567
+		int image_n;
  568
+		char *totalname;
  569
+		
  570
+		image_n = atoi(left+9);
  571
+		if((image_n < 1) || (image_n > IMAGE_COUNT)) {
  572
+			comp_report(sc, "warning l.%d: ignoring image with out of bounds number %d", sc->linenr, image_n);
  573
+			return true;
  574
+		}
  575
+		totalname = malloc(strlen(sc->basedir) + strlen(right) + 0);
  576
+		if(totalname == NULL) return true;
  577
+		strcpy(totalname, sc->basedir);
  578
+		strcat(totalname, right);
  579
+		pixbuf_dec_ref(sc->p->images[image_n]);
  580
+		sc->p->images[image_n] = pixbuf_get(totalname);
  581
+		free(totalname);
  582
+	}
562 583
 
563 584
 	pfv = pfv_from_name(sc, left);
564 585
 	if(pfv >= 0) {
@@ -631,11 +652,12 @@ static bool parse_patch(struct compiler_sc *sc, char *patch_code)
631 652
 	return true;
632 653
 }
633 654
 
634  
-struct patch *patch_compile(const char *patch_code, report_message rmc)
  655
+struct patch *patch_compile(const char *basedir, const char *patch_code, report_message rmc)
635 656
 {
636 657
 	struct compiler_sc *sc;
637 658
 	struct patch *p;
638 659
 	char *patch_code_copy;
  660
+	int i;
639 661
 
640 662
 	sc = malloc(sizeof(struct compiler_sc));
641 663
 	if(sc == NULL) {
@@ -648,10 +670,13 @@ struct patch *patch_compile(const char *patch_code, report_message rmc)
648 670
 		free(sc);
649 671
 		return NULL;
650 672
 	}
  673
+	for(i=0;i<IMAGE_COUNT;i++)
  674
+		sc->p->images[i] = NULL;
651 675
 	sc->p->require = 0;
652 676
 	sc->p->original = NULL;
653 677
 	sc->p->next = NULL;
654 678
 
  679
+	sc->basedir = basedir;
655 680
 	sc->rmc = rmc;
656 681
 	sc->linenr = 0;
657 682
 
@@ -683,7 +708,45 @@ struct patch *patch_compile(const char *patch_code, report_message rmc)
683 708
 	return NULL;
684 709
 }
685 710
 
  711
+struct patch *patch_compile_filename(const char *filename, const char *patch_code, report_message rmc)
  712
+{
  713
+	char *basedir;
  714
+	char *c;
  715
+	struct patch *p;
  716
+	
  717
+	basedir = strdup(filename);
  718
+	if(basedir == NULL) return NULL;
  719
+	c = strrchr(basedir, '/');
  720
+	if(c != NULL) {
  721
+		c++;
  722
+		*c = 0;
  723
+		p = patch_compile(basedir, patch_code, rmc);
  724
+	} else
  725
+		p = patch_compile("/", patch_code, rmc);
  726
+	free(basedir);
  727
+	return p;
  728
+}
  729
+
  730
+struct patch *patch_copy(struct patch *p)
  731
+{
  732
+	struct patch *new_patch;
  733
+	int i;
  734
+	
  735
+	new_patch = malloc(sizeof(struct patch));
  736
+	assert(new_patch != NULL);
  737
+	memcpy(new_patch, p, sizeof(struct patch));
  738
+	new_patch->original = p;
  739
+	new_patch->next = NULL;
  740
+	for(i=0;i<IMAGE_COUNT;i++)
  741
+		pixbuf_inc_ref(new_patch->images[i]);
  742
+	return new_patch;
  743
+}
  744
+
686 745
 void patch_free(struct patch *p)
687 746
 {
  747
+	int i;
  748
+	
  749
+	for(i=0;i<IMAGE_COUNT;i++)
  750
+		pixbuf_dec_ref(p->images[i]);
688 751
 	free(p);
689 752
 }
9  src/renderer/compiler.h
@@ -21,6 +21,9 @@
21 21
 #include <rtems.h>
22 22
 #include <bsp/milkymist_pfpu.h>
23 23
 
  24
+#include "framedescriptor.h"
  25
+#include "../pixbuf/pixbuf.h"
  26
+
24 27
 enum {
25 28
 	pfv_sx = 0,
26 29
 	pfv_sy,
@@ -199,6 +202,7 @@ enum {
199 202
 
200 203
 struct patch {
201 204
 	/* per-frame */
  205
+	struct pixbuf *images[IMAGE_COUNT];		/* < images used in this patch */
202 206
 	float pfv_initial[COMP_PFV_COUNT]; 		/* < patch initial conditions */
203 207
 	int pfv_allocation[COMP_PFV_COUNT];		/* < where per-frame variables are mapped in PFPU regf, -1 if unmapped */
204 208
 	int perframe_prog_length;			/* < how many instructions in perframe_prog */
@@ -213,12 +217,13 @@ struct patch {
213 217
 	unsigned int require;				/* < bitmask: dmx, osc, midi, video */
214 218
 	void *original;					/* < original patch (with initial register values) */
215 219
 	struct patch *next;				/* < used when chaining patches in mashups */
216  
-
217 220
 };
218 221
 
219 222
 typedef void (*report_message)(const char *);
220 223
 
221  
-struct patch *patch_compile(const char *patch_code, report_message rmc);
  224
+struct patch *patch_compile(const char *basedir, const char *patch_code, report_message rmc);
  225
+struct patch *patch_compile_filename(const char *filename, const char *patch_code, report_message rmc);
  226
+struct patch *patch_copy(struct patch *p);
222 227
 void patch_free(struct patch *p);
223 228
 
224 229
 #endif /* __COMPILER_H */
33  src/renderer/renderer.c
@@ -50,20 +50,9 @@ void renderer_unlock_patch()
50 50
 	rtems_semaphore_release(patch_lock);
51 51
 }
52 52
 
53  
-static struct patch *copy_patch(struct patch *p)
54  
-{
55  
-	struct patch *new_patch;
56  
-	
57  
-	/* Copy memory as the patch will be modified
58  
-	 * by the evaluator (current regs).
59  
-	 */
60  
-	new_patch = malloc(sizeof(struct patch));
61  
-	assert(new_patch != NULL);
62  
-	memcpy(new_patch, p, sizeof(struct patch));
63  
-	new_patch->original = p;
64  
-	new_patch->next = NULL;
65  
-	return new_patch;
66  
-}
  53
+/* Copy patches as they will be modified
  54
+ * by the evaluator (current regs).
  55
+ */
67 56
 
68 57
 void renderer_pulse_patch(struct patch *p)
69 58
 {
@@ -72,9 +61,9 @@ void renderer_pulse_patch(struct patch *p)
72 61
 	renderer_lock_patch();
73 62
 	if(!mashup_en && (mashup_head->next == NULL)) {
74 63
 		oldpatch = mashup_head;
75  
-		mashup_head = copy_patch(p);
  64
+		mashup_head = patch_copy(p);
76 65
 		current_patch = mashup_head;
77  
-		free(oldpatch);
  66
+		patch_free(oldpatch);
78 67
 	}
79 68
 	renderer_unlock_patch();
80 69
 }
@@ -93,12 +82,12 @@ void renderer_add_patch(struct patch *p)
93 82
 		}
94 83
 		p1 = p1->next;
95 84
 	}
96  
-	new_patch = copy_patch(p);
  85
+	new_patch = patch_copy(p);
97 86
 	if(!mashup_en) {
98 87
 		p1 = mashup_head;
99 88
 		mashup_head = new_patch;
100 89
 		current_patch = mashup_head;
101  
-		free(p1);
  90
+		patch_free(p1);
102 91
 	} else {
103 92
 		new_patch->next = mashup_head;
104 93
 		mashup_head = new_patch;
@@ -124,7 +113,7 @@ void renderer_del_patch(struct patch *p)
124 113
 		if(mashup_head == current_patch)
125 114
 			renderer_get_patch(1);
126 115
 		p1 = mashup_head->next;
127  
-		free(mashup_head);
  116
+		patch_free(mashup_head);
128 117
 		mashup_head = p1;
129 118
 	} else {
130 119
 		p1 = mashup_head;
@@ -138,7 +127,7 @@ void renderer_del_patch(struct patch *p)
138 127
 		if(p1->next == current_patch)
139 128
 			renderer_get_patch(1);
140 129
 		p2 = p1->next->next;
141  
-		free(p1->next);
  130
+		patch_free(p1->next);
142 131
 		p1->next = p2;
143 132
 	}
144 133
 	renderer_unlock_patch();
@@ -169,7 +158,7 @@ void renderer_start(int framebuffer_fd, struct patch *p)
169 158
 	assert(sc == RTEMS_SUCCESSFUL);
170 159
 
171 160
 	assert(mashup_head == NULL);
172  
-	mashup_head = copy_patch(p);
  161
+	mashup_head = patch_copy(p);
173 162
 	current_patch = mashup_head;
174 163
 	mashup_en = 0;
175 164
 
@@ -197,7 +186,7 @@ void renderer_stop()
197 186
 
198 187
 	while(mashup_head != NULL) {
199 188
 		p = mashup_head->next;
200  
-		free(mashup_head);
  189
+		patch_free(mashup_head);
201 190
 		mashup_head = p;
202 191
 	}
203 192
 	rtems_semaphore_delete(patch_lock);

0 notes on commit 9aa2377

Please sign in to comment.
Something went wrong with that request. Please try again.