Skip to content

Commit

Permalink
compiler: load images
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Bourdeauducq committed Nov 22, 2011
1 parent fc9b0c8 commit 9aa2377
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/gui/patcheditor.c
Expand Up @@ -152,7 +152,7 @@ static void run_callback(mtk_event *e, void *arg)

mtk_cmd(appid, "status.set(-text \"Ready.\")");
mtk_req(appid, code, 32768, "ed.text");
p = patch_compile(code, rmc);
p = patch_compile_filename(current_filename, code, rmc);
if(p == NULL)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/performance.c
Expand Up @@ -298,7 +298,7 @@ static struct patch *compile_patch(const char *filename)
buf[r] = 0;
fclose(fd);

return patch_compile(buf, dummy_rmc);
return patch_compile_filename(filename, buf, dummy_rmc);
}

static rtems_task comp_task(rtems_task_argument argument)
Expand Down
3 changes: 2 additions & 1 deletion src/pixbuf/manager.c
Expand Up @@ -53,7 +53,8 @@ struct pixbuf *pixbuf_search(char *filename)

void pixbuf_inc_ref(struct pixbuf *p)
{
p->refcnt++;
if(p != NULL)
p->refcnt++;
}

void pixbuf_dec_ref(struct pixbuf *p)
Expand Down
65 changes: 64 additions & 1 deletion src/renderer/compiler.c
Expand Up @@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Expand All @@ -24,11 +25,13 @@
#include <fpvm/schedulers.h>
#include <fpvm/pfpu.h>

#include "../pixbuf/pixbuf.h"
#include "compiler.h"

struct compiler_sc {
struct patch *p;

const char *basedir;
report_message rmc;
int linenr;

Expand Down Expand Up @@ -559,6 +562,24 @@ static bool process_top_assign(struct compiler_sc *sc, char *left, char *right)

while(*right == ' ') right++;
if(*right == 0) return true;

if(strncmp(left, "imagefile", 9) == 0) {
int image_n;
char *totalname;

image_n = atoi(left+9);
if((image_n < 1) || (image_n > IMAGE_COUNT)) {
comp_report(sc, "warning l.%d: ignoring image with out of bounds number %d", sc->linenr, image_n);
return true;
}
totalname = malloc(strlen(sc->basedir) + strlen(right) + 0);
if(totalname == NULL) return true;
strcpy(totalname, sc->basedir);
strcat(totalname, right);
pixbuf_dec_ref(sc->p->images[image_n]);
sc->p->images[image_n] = pixbuf_get(totalname);
free(totalname);
}

pfv = pfv_from_name(sc, left);
if(pfv >= 0) {
Expand Down Expand Up @@ -631,11 +652,12 @@ static bool parse_patch(struct compiler_sc *sc, char *patch_code)
return true;
}

struct patch *patch_compile(const char *patch_code, report_message rmc)
struct patch *patch_compile(const char *basedir, const char *patch_code, report_message rmc)
{
struct compiler_sc *sc;
struct patch *p;
char *patch_code_copy;
int i;

sc = malloc(sizeof(struct compiler_sc));
if(sc == NULL) {
Expand All @@ -648,10 +670,13 @@ struct patch *patch_compile(const char *patch_code, report_message rmc)
free(sc);
return NULL;
}
for(i=0;i<IMAGE_COUNT;i++)
sc->p->images[i] = NULL;
sc->p->require = 0;
sc->p->original = NULL;
sc->p->next = NULL;

sc->basedir = basedir;
sc->rmc = rmc;
sc->linenr = 0;

Expand Down Expand Up @@ -683,7 +708,45 @@ struct patch *patch_compile(const char *patch_code, report_message rmc)
return NULL;
}

struct patch *patch_compile_filename(const char *filename, const char *patch_code, report_message rmc)
{
char *basedir;
char *c;
struct patch *p;

basedir = strdup(filename);
if(basedir == NULL) return NULL;
c = strrchr(basedir, '/');
if(c != NULL) {
c++;
*c = 0;
p = patch_compile(basedir, patch_code, rmc);
} else
p = patch_compile("/", patch_code, rmc);
free(basedir);
return p;
}

struct patch *patch_copy(struct patch *p)
{
struct patch *new_patch;
int i;

new_patch = malloc(sizeof(struct patch));
assert(new_patch != NULL);
memcpy(new_patch, p, sizeof(struct patch));
new_patch->original = p;
new_patch->next = NULL;
for(i=0;i<IMAGE_COUNT;i++)
pixbuf_inc_ref(new_patch->images[i]);
return new_patch;
}

void patch_free(struct patch *p)
{
int i;

for(i=0;i<IMAGE_COUNT;i++)
pixbuf_dec_ref(p->images[i]);
free(p);
}
9 changes: 7 additions & 2 deletions src/renderer/compiler.h
Expand Up @@ -21,6 +21,9 @@
#include <rtems.h>
#include <bsp/milkymist_pfpu.h>

#include "framedescriptor.h"
#include "../pixbuf/pixbuf.h"

enum {
pfv_sx = 0,
pfv_sy,
Expand Down Expand Up @@ -199,6 +202,7 @@ enum {

struct patch {
/* per-frame */
struct pixbuf *images[IMAGE_COUNT]; /* < images used in this patch */
float pfv_initial[COMP_PFV_COUNT]; /* < patch initial conditions */
int pfv_allocation[COMP_PFV_COUNT]; /* < where per-frame variables are mapped in PFPU regf, -1 if unmapped */
int perframe_prog_length; /* < how many instructions in perframe_prog */
Expand All @@ -213,12 +217,13 @@ struct patch {
unsigned int require; /* < bitmask: dmx, osc, midi, video */
void *original; /* < original patch (with initial register values) */
struct patch *next; /* < used when chaining patches in mashups */

};

typedef void (*report_message)(const char *);

struct patch *patch_compile(const char *patch_code, report_message rmc);
struct patch *patch_compile(const char *basedir, const char *patch_code, report_message rmc);
struct patch *patch_compile_filename(const char *filename, const char *patch_code, report_message rmc);
struct patch *patch_copy(struct patch *p);
void patch_free(struct patch *p);

#endif /* __COMPILER_H */
33 changes: 11 additions & 22 deletions src/renderer/renderer.c
Expand Up @@ -50,20 +50,9 @@ void renderer_unlock_patch()
rtems_semaphore_release(patch_lock);
}

static struct patch *copy_patch(struct patch *p)
{
struct patch *new_patch;

/* Copy memory as the patch will be modified
* by the evaluator (current regs).
*/
new_patch = malloc(sizeof(struct patch));
assert(new_patch != NULL);
memcpy(new_patch, p, sizeof(struct patch));
new_patch->original = p;
new_patch->next = NULL;
return new_patch;
}
/* Copy patches as they will be modified
* by the evaluator (current regs).
*/

void renderer_pulse_patch(struct patch *p)
{
Expand All @@ -72,9 +61,9 @@ void renderer_pulse_patch(struct patch *p)
renderer_lock_patch();
if(!mashup_en && (mashup_head->next == NULL)) {
oldpatch = mashup_head;
mashup_head = copy_patch(p);
mashup_head = patch_copy(p);
current_patch = mashup_head;
free(oldpatch);
patch_free(oldpatch);
}
renderer_unlock_patch();
}
Expand All @@ -93,12 +82,12 @@ void renderer_add_patch(struct patch *p)
}
p1 = p1->next;
}
new_patch = copy_patch(p);
new_patch = patch_copy(p);
if(!mashup_en) {
p1 = mashup_head;
mashup_head = new_patch;
current_patch = mashup_head;
free(p1);
patch_free(p1);
} else {
new_patch->next = mashup_head;
mashup_head = new_patch;
Expand All @@ -124,7 +113,7 @@ void renderer_del_patch(struct patch *p)
if(mashup_head == current_patch)
renderer_get_patch(1);
p1 = mashup_head->next;
free(mashup_head);
patch_free(mashup_head);
mashup_head = p1;
} else {
p1 = mashup_head;
Expand All @@ -138,7 +127,7 @@ void renderer_del_patch(struct patch *p)
if(p1->next == current_patch)
renderer_get_patch(1);
p2 = p1->next->next;
free(p1->next);
patch_free(p1->next);
p1->next = p2;
}
renderer_unlock_patch();
Expand Down Expand Up @@ -169,7 +158,7 @@ void renderer_start(int framebuffer_fd, struct patch *p)
assert(sc == RTEMS_SUCCESSFUL);

assert(mashup_head == NULL);
mashup_head = copy_patch(p);
mashup_head = patch_copy(p);
current_patch = mashup_head;
mashup_en = 0;

Expand Down Expand Up @@ -197,7 +186,7 @@ void renderer_stop()

while(mashup_head != NULL) {
p = mashup_head->next;
free(mashup_head);
patch_free(mashup_head);
mashup_head = p;
}
rtems_semaphore_delete(patch_lock);
Expand Down

0 comments on commit 9aa2377

Please sign in to comment.