Skip to content

Commit 44ad1f6

Browse files
committedFeb 16, 2012
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)
1 parent efcfe22 commit 44ad1f6

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed
 

‎experimental/N.fnp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
imagefiles=pacman.jpg, ghost.jpg
1+
imagefiles=pacman.jpg, ghost.jpg, pleiades.jpg
22
decay=0.6
33
image1_a=0.6
44
image2_a=0.6
@@ -8,6 +8,7 @@ midi "Faderfox LV3" {
88
fad8 = fader(8, 7);
99

1010
green1 = button(1, 16);
11+
green2 = button(2, 16);
1112
green8 = button(8, 16);
1213

1314
joy1x = pot(9, 1);
@@ -20,6 +21,7 @@ fad1 = range(fad1);
2021
fad8 = range(fad8);
2122

2223
green1 = button(green1);
24+
green2 = button(green2);
2325
green8 = button(green8);
2426

2527
joy1x = range(joy1x);
@@ -30,7 +32,7 @@ joy2y = range(joy2y);
3032
per_frame:
3133
image1_zoom = fad1*5+0.1;
3234
image2_zoom = fad8*6+0.1;
33-
image1_index = green1;
35+
image1_index = green1+2*green2;
3436
image2_index = !green8;
3537

3638
sx = 1.06;

‎src/compiler/compiler.c

+26-16
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,18 @@ static const char *assign_image_name(struct parser_comm *comm,
411411
struct compiler_sc *sc = comm->u.sc;
412412
char *totalname;
413413
struct image *img;
414-
#endif
415414

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+
}
419426
number--;
420427

421428
if(*name == '/')
@@ -472,7 +479,6 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
472479
{
473480
struct compiler_sc *sc;
474481
struct patch *p;
475-
int i;
476482

477483
sc = malloc(sizeof(struct compiler_sc));
478484
if(sc == NULL) {
@@ -485,10 +491,8 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
485491
free(sc);
486492
return NULL;
487493
}
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;
492496
sc->p->ref = 1;
493497
sc->p->require = 0;
494498
sc->p->original = NULL;
@@ -561,18 +565,23 @@ struct patch *patch_copy(struct patch *p)
561565
{
562566
struct patch *new_patch;
563567
struct image *img;
568+
int i;
564569

565570
new_patch = malloc(sizeof(struct patch));
566571
assert(new_patch != NULL);
567572
memcpy(new_patch, p, sizeof(struct patch));
568573
new_patch->ref = 1;
569574
new_patch->original = p;
570575
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+
}
576585
}
577586
new_patch->stim = stim_get(p->stim);
578587
if(p->stim)
@@ -587,10 +596,11 @@ void patch_free(struct patch *p)
587596
assert(p->ref);
588597
if(--p->ref);
589598
return;
590-
for(img = p->images; img != p->images+IMAGE_COUNT; img++) {
599+
for(img = p->images; img != p->images+p->n_images; img++) {
591600
pixbuf_dec_ref(img->pixbuf);
592601
free((void *) img->filename);
593602
}
603+
free(p->images);
594604
stim_put(p->stim);
595605
free(p);
596606
}
@@ -600,7 +610,7 @@ struct patch *patch_refresh(struct patch *p)
600610
struct image *img;
601611
struct pixbuf *pixbuf;
602612

603-
for(img = p->images; img != p->images+IMAGE_COUNT; img++) {
613+
for(img = p->images; img != p->images+p->n_images; img++) {
604614
if(!img->pixbuf)
605615
continue;
606616
pixbuf = pixbuf_update(img->pixbuf);

‎src/compiler/compiler.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ struct image {
230230

231231
struct patch {
232232
/* 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 */
234235
float pfv_initial[COMP_PFV_COUNT]; /* patch initial conditions */
235236
int pfv_allocation[COMP_PFV_COUNT]; /* where per-frame variables
236237
are mapped in PFPU regf,

‎src/renderer/eval.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static rtems_task eval_task(rtems_task_argument argument)
317317
for(i=0;i<IMAGE_COUNT;i++) {
318318
int n = frd->image_index[i];
319319

320-
frd->images[i] = n >= 0 && n < IMAGE_COUNT ?
320+
frd->images[i] = n >= 0 && n < p->n_images ?
321321
p->images[n].pixbuf : NULL;
322322
}
323323

0 commit comments

Comments
 (0)
Please sign in to comment.