Skip to content
Permalink
Browse files
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
wpwrak committed Feb 16, 2012
1 parent efcfe22 commit 44ad1f6ab3cc5f09c7f486056b3a2a408b193d7c
Showing with 33 additions and 20 deletions.
  1. +4 −2 experimental/N.fnp
  2. +26 −16 src/compiler/compiler.c
  3. +2 −1 src/compiler/compiler.h
  4. +1 −1 src/renderer/eval.c
@@ -1,4 +1,4 @@
imagefiles=pacman.jpg, ghost.jpg
imagefiles=pacman.jpg, ghost.jpg, pleiades.jpg
decay=0.6
image1_a=0.6
image2_a=0.6
@@ -8,6 +8,7 @@ midi "Faderfox LV3" {
fad8 = fader(8, 7);

green1 = button(1, 16);
green2 = button(2, 16);
green8 = button(8, 16);

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

green1 = button(green1);
green2 = button(green2);
green8 = button(green8);

joy1x = range(joy1x);
@@ -30,7 +32,7 @@ joy2y = range(joy2y);
per_frame:
image1_zoom = fad1*5+0.1;
image2_zoom = fad8*6+0.1;
image1_index = green1;
image1_index = green1+2*green2;
image2_index = !green8;

sx = 1.06;
@@ -411,11 +411,18 @@ static const char *assign_image_name(struct parser_comm *comm,
struct compiler_sc *sc = comm->u.sc;
char *totalname;
struct image *img;
#endif

if(number > IMAGE_COUNT)
return strdup("image number out of bounds");
#ifndef STANDALONE
if(number > sc->p->n_images) {
int i;

sc->p->images = realloc(sc->p->images,
number*sizeof(struct image));
for(i = sc->p->n_images; i != number; i++) {
sc->p->images[i].pixbuf = NULL;
sc->p->images[i].filename = NULL;
}
sc->p->n_images = number;
}
number--;

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

sc = malloc(sizeof(struct compiler_sc));
if(sc == NULL) {
@@ -485,10 +491,8 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
free(sc);
return NULL;
}
for(i=0;i<IMAGE_COUNT;i++) {
sc->p->images[i].pixbuf = NULL;
sc->p->images[i].filename = NULL;
}
sc->p->images = NULL;
sc->p->n_images = 0;
sc->p->ref = 1;
sc->p->require = 0;
sc->p->original = NULL;
@@ -561,18 +565,23 @@ struct patch *patch_copy(struct patch *p)
{
struct patch *new_patch;
struct image *img;
int i;

new_patch = malloc(sizeof(struct patch));
assert(new_patch != NULL);
memcpy(new_patch, p, sizeof(struct patch));
new_patch->ref = 1;
new_patch->original = p;
new_patch->next = NULL;
for(img = new_patch->images;
img != new_patch->images+IMAGE_COUNT; img++) {
if(img->filename)
img->filename = strdup(img->filename);
pixbuf_inc_ref(img->pixbuf);
if(p->images) {
new_patch->images = malloc(p->n_images*sizeof(struct image));
for(i = 0; i != p->n_images; i++) {
img = new_patch->images+i;
*img = p->images[i];
if(img->filename)
img->filename = strdup(img->filename);
pixbuf_inc_ref(img->pixbuf);
}
}
new_patch->stim = stim_get(p->stim);
if(p->stim)
@@ -587,10 +596,11 @@ void patch_free(struct patch *p)
assert(p->ref);
if(--p->ref);
return;
for(img = p->images; img != p->images+IMAGE_COUNT; img++) {
for(img = p->images; img != p->images+p->n_images; img++) {
pixbuf_dec_ref(img->pixbuf);
free((void *) img->filename);
}
free(p->images);
stim_put(p->stim);
free(p);
}
@@ -600,7 +610,7 @@ struct patch *patch_refresh(struct patch *p)
struct image *img;
struct pixbuf *pixbuf;

for(img = p->images; img != p->images+IMAGE_COUNT; img++) {
for(img = p->images; img != p->images+p->n_images; img++) {
if(!img->pixbuf)
continue;
pixbuf = pixbuf_update(img->pixbuf);
@@ -230,7 +230,8 @@ struct image {

struct patch {
/* per-frame */
struct image images[IMAGE_COUNT]; /* images used in this patch */
struct image *images; /* images used in this patch */
int n_images; /* number of images */
float pfv_initial[COMP_PFV_COUNT]; /* patch initial conditions */
int pfv_allocation[COMP_PFV_COUNT]; /* where per-frame variables
are mapped in PFPU regf,
@@ -317,7 +317,7 @@ static rtems_task eval_task(rtems_task_argument argument)
for(i=0;i<IMAGE_COUNT;i++) {
int n = frd->image_index[i];

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

0 comments on commit 44ad1f6

Please sign in to comment.