Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

images: make images array variable

We can now have as many images as memory permits.

Also updated N.fnp:

- green 1 toggles between pac man and ghost (as before)
- green 2 toggles between pac man pleiades
- green 8 toggles between ghost and pac man (as before)
  • Loading branch information...
commit 44ad1f6ab3cc5f09c7f486056b3a2a408b193d7c 1 parent efcfe22
Werner Almesberger authored February 15, 2012
6  experimental/N.fnp
... ...
@@ -1,4 +1,4 @@
1  
-imagefiles=pacman.jpg, ghost.jpg
  1
+imagefiles=pacman.jpg, ghost.jpg, pleiades.jpg
2 2
 decay=0.6
3 3
 image1_a=0.6
4 4
 image2_a=0.6
@@ -8,6 +8,7 @@ midi "Faderfox LV3" {
8 8
 	fad8 = fader(8, 7);
9 9
 
10 10
 	green1 = button(1, 16);
  11
+	green2 = button(2, 16);
11 12
 	green8 = button(8, 16);
12 13
 
13 14
 	joy1x = pot(9, 1);
@@ -20,6 +21,7 @@ fad1 = range(fad1);
20 21
 fad8 = range(fad8);
21 22
 
22 23
 green1 = button(green1);
  24
+green2 = button(green2);
23 25
 green8 = button(green8);
24 26
 
25 27
 joy1x = range(joy1x);
@@ -30,7 +32,7 @@ joy2y = range(joy2y);
30 32
 per_frame:
31 33
 	image1_zoom = fad1*5+0.1;
32 34
 	image2_zoom = fad8*6+0.1;
33  
-	image1_index = green1;
  35
+	image1_index = green1+2*green2;
34 36
 	image2_index = !green8;
35 37
 
36 38
 	sx = 1.06;
42  src/compiler/compiler.c
@@ -411,11 +411,18 @@ static const char *assign_image_name(struct parser_comm *comm,
411 411
 	struct compiler_sc *sc = comm->u.sc;
412 412
 	char *totalname;
413 413
 	struct image *img;
414  
-#endif
415 414
 
416  
-	if(number > IMAGE_COUNT)
417  
-		return strdup("image number out of bounds");
418  
-#ifndef STANDALONE
  415
+	if(number > sc->p->n_images) {
  416
+		int i;
  417
+
  418
+		sc->p->images = realloc(sc->p->images,
  419
+		    number*sizeof(struct image));
  420
+		for(i = sc->p->n_images; i != number; i++) {
  421
+			sc->p->images[i].pixbuf = NULL;
  422
+			sc->p->images[i].filename = NULL;
  423
+		}
  424
+		sc->p->n_images = number;
  425
+	}
419 426
 	number--;
420 427
 	
421 428
 	if(*name == '/')
@@ -472,7 +479,6 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
472 479
 {
473 480
 	struct compiler_sc *sc;
474 481
 	struct patch *p;
475  
-	int i;
476 482
 
477 483
 	sc = malloc(sizeof(struct compiler_sc));
478 484
 	if(sc == NULL) {
@@ -485,10 +491,8 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
485 491
 		free(sc);
486 492
 		return NULL;
487 493
 	}
488  
-	for(i=0;i<IMAGE_COUNT;i++) {
489  
-		sc->p->images[i].pixbuf = NULL;
490  
-		sc->p->images[i].filename = NULL;
491  
-	}
  494
+	sc->p->images = NULL;
  495
+	sc->p->n_images = 0;
492 496
 	sc->p->ref = 1;
493 497
 	sc->p->require = 0;
494 498
 	sc->p->original = NULL;
@@ -561,6 +565,7 @@ struct patch *patch_copy(struct patch *p)
561 565
 {
562 566
 	struct patch *new_patch;
563 567
 	struct image *img;
  568
+	int i;
564 569
 
565 570
 	new_patch = malloc(sizeof(struct patch));
566 571
 	assert(new_patch != NULL);
@@ -568,11 +573,15 @@ struct patch *patch_copy(struct patch *p)
568 573
 	new_patch->ref = 1;
569 574
 	new_patch->original = p;
570 575
 	new_patch->next = NULL;
571  
-	for(img = new_patch->images;
572  
-	    img != new_patch->images+IMAGE_COUNT; img++) {
573  
-		if(img->filename)
574  
-			img->filename = strdup(img->filename);
575  
-		pixbuf_inc_ref(img->pixbuf);
  576
+	if(p->images) {
  577
+		new_patch->images = malloc(p->n_images*sizeof(struct image));
  578
+		for(i = 0; i != p->n_images; i++) {
  579
+			img = new_patch->images+i;
  580
+			*img = p->images[i];
  581
+			if(img->filename)
  582
+				img->filename = strdup(img->filename);
  583
+			pixbuf_inc_ref(img->pixbuf);
  584
+		}
576 585
 	}
577 586
 	new_patch->stim = stim_get(p->stim);
578 587
 	if(p->stim)
@@ -587,10 +596,11 @@ void patch_free(struct patch *p)
587 596
 	assert(p->ref);
588 597
 	if(--p->ref);
589 598
 		return;
590  
-	for(img = p->images; img != p->images+IMAGE_COUNT; img++) {
  599
+	for(img = p->images; img != p->images+p->n_images; img++) {
591 600
 		pixbuf_dec_ref(img->pixbuf);
592 601
 		free((void *) img->filename);
593 602
 	}
  603
+	free(p->images);
594 604
 	stim_put(p->stim);
595 605
 	free(p);
596 606
 }
@@ -600,7 +610,7 @@ struct patch *patch_refresh(struct patch *p)
600 610
 	struct image *img;
601 611
 	struct pixbuf *pixbuf;
602 612
 
603  
-	for(img = p->images; img != p->images+IMAGE_COUNT; img++) {
  613
+	for(img = p->images; img != p->images+p->n_images; img++) {
604 614
 		if(!img->pixbuf)
605 615
 			continue;
606 616
 		pixbuf = pixbuf_update(img->pixbuf);
3  src/compiler/compiler.h
@@ -230,7 +230,8 @@ struct image {
230 230
 
231 231
 struct patch {
232 232
 	/* per-frame */
233  
-	struct image images[IMAGE_COUNT];	/* images used in this patch */
  233
+	struct image *images;	/* images used in this patch */
  234
+	int n_images;		/* number of images */
234 235
 	float pfv_initial[COMP_PFV_COUNT];	/* patch initial conditions */
235 236
 	int pfv_allocation[COMP_PFV_COUNT];	/* where per-frame variables
236 237
 						   are mapped in PFPU regf,
2  src/renderer/eval.c
@@ -317,7 +317,7 @@ static rtems_task eval_task(rtems_task_argument argument)
317 317
 		for(i=0;i<IMAGE_COUNT;i++) {
318 318
 			int n = frd->image_index[i];
319 319
 
320  
-			frd->images[i] = n >= 0 && n < IMAGE_COUNT ?
  320
+			frd->images[i] = n >= 0 && n < p->n_images ?
321 321
 			    p->images[n].pixbuf : NULL;
322 322
 		}
323 323
 		

0 notes on commit 44ad1f6

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