Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

compiler: load images

  • Loading branch information...
commit 9aa2377c4f91e4b93608b1894e5a54dd99a95ad9 1 parent fc9b0c8
@sbourdeauducq sbourdeauducq authored
View
2  src/gui/patcheditor.c
@@ -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;
View
2  src/gui/performance.c
@@ -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)
View
3  src/pixbuf/manager.c
@@ -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)
View
65 src/renderer/compiler.c
@@ -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>
@@ -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;
@@ -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) {
@@ -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) {
@@ -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;
@@ -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);
}
View
9 src/renderer/compiler.h
@@ -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,
@@ -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 */
@@ -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 */
View
33 src/renderer/renderer.c
@@ -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)
{
@@ -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();
}
@@ -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;
@@ -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;
@@ -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();
@@ -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;
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.