Skip to content

Commit 9aa2377

Browse files
author
Sebastien Bourdeauducq
committedNov 22, 2011
compiler: load images
1 parent fc9b0c8 commit 9aa2377

File tree

6 files changed

+86
-28
lines changed

6 files changed

+86
-28
lines changed
 

Diff for: ‎src/gui/patcheditor.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void run_callback(mtk_event *e, void *arg)
152152

153153
mtk_cmd(appid, "status.set(-text \"Ready.\")");
154154
mtk_req(appid, code, 32768, "ed.text");
155-
p = patch_compile(code, rmc);
155+
p = patch_compile_filename(current_filename, code, rmc);
156156
if(p == NULL)
157157
return;
158158

Diff for: ‎src/gui/performance.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static struct patch *compile_patch(const char *filename)
298298
buf[r] = 0;
299299
fclose(fd);
300300

301-
return patch_compile(buf, dummy_rmc);
301+
return patch_compile_filename(filename, buf, dummy_rmc);
302302
}
303303

304304
static rtems_task comp_task(rtems_task_argument argument)

Diff for: ‎src/pixbuf/manager.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ struct pixbuf *pixbuf_search(char *filename)
5353

5454
void pixbuf_inc_ref(struct pixbuf *p)
5555
{
56-
p->refcnt++;
56+
if(p != NULL)
57+
p->refcnt++;
5758
}
5859

5960
void pixbuf_dec_ref(struct pixbuf *p)

Diff for: ‎src/renderer/compiler.c

+64-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
#include <assert.h>
1819
#include <stdio.h>
1920
#include <stdlib.h>
2021
#include <stdarg.h>
@@ -24,11 +25,13 @@
2425
#include <fpvm/schedulers.h>
2526
#include <fpvm/pfpu.h>
2627

28+
#include "../pixbuf/pixbuf.h"
2729
#include "compiler.h"
2830

2931
struct compiler_sc {
3032
struct patch *p;
3133

34+
const char *basedir;
3235
report_message rmc;
3336
int linenr;
3437

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

560563
while(*right == ' ') right++;
561564
if(*right == 0) return true;
565+
566+
if(strncmp(left, "imagefile", 9) == 0) {
567+
int image_n;
568+
char *totalname;
569+
570+
image_n = atoi(left+9);
571+
if((image_n < 1) || (image_n > IMAGE_COUNT)) {
572+
comp_report(sc, "warning l.%d: ignoring image with out of bounds number %d", sc->linenr, image_n);
573+
return true;
574+
}
575+
totalname = malloc(strlen(sc->basedir) + strlen(right) + 0);
576+
if(totalname == NULL) return true;
577+
strcpy(totalname, sc->basedir);
578+
strcat(totalname, right);
579+
pixbuf_dec_ref(sc->p->images[image_n]);
580+
sc->p->images[image_n] = pixbuf_get(totalname);
581+
free(totalname);
582+
}
562583

563584
pfv = pfv_from_name(sc, left);
564585
if(pfv >= 0) {
@@ -631,11 +652,12 @@ static bool parse_patch(struct compiler_sc *sc, char *patch_code)
631652
return true;
632653
}
633654

634-
struct patch *patch_compile(const char *patch_code, report_message rmc)
655+
struct patch *patch_compile(const char *basedir, const char *patch_code, report_message rmc)
635656
{
636657
struct compiler_sc *sc;
637658
struct patch *p;
638659
char *patch_code_copy;
660+
int i;
639661

640662
sc = malloc(sizeof(struct compiler_sc));
641663
if(sc == NULL) {
@@ -648,10 +670,13 @@ struct patch *patch_compile(const char *patch_code, report_message rmc)
648670
free(sc);
649671
return NULL;
650672
}
673+
for(i=0;i<IMAGE_COUNT;i++)
674+
sc->p->images[i] = NULL;
651675
sc->p->require = 0;
652676
sc->p->original = NULL;
653677
sc->p->next = NULL;
654678

679+
sc->basedir = basedir;
655680
sc->rmc = rmc;
656681
sc->linenr = 0;
657682

@@ -683,7 +708,45 @@ struct patch *patch_compile(const char *patch_code, report_message rmc)
683708
return NULL;
684709
}
685710

711+
struct patch *patch_compile_filename(const char *filename, const char *patch_code, report_message rmc)
712+
{
713+
char *basedir;
714+
char *c;
715+
struct patch *p;
716+
717+
basedir = strdup(filename);
718+
if(basedir == NULL) return NULL;
719+
c = strrchr(basedir, '/');
720+
if(c != NULL) {
721+
c++;
722+
*c = 0;
723+
p = patch_compile(basedir, patch_code, rmc);
724+
} else
725+
p = patch_compile("/", patch_code, rmc);
726+
free(basedir);
727+
return p;
728+
}
729+
730+
struct patch *patch_copy(struct patch *p)
731+
{
732+
struct patch *new_patch;
733+
int i;
734+
735+
new_patch = malloc(sizeof(struct patch));
736+
assert(new_patch != NULL);
737+
memcpy(new_patch, p, sizeof(struct patch));
738+
new_patch->original = p;
739+
new_patch->next = NULL;
740+
for(i=0;i<IMAGE_COUNT;i++)
741+
pixbuf_inc_ref(new_patch->images[i]);
742+
return new_patch;
743+
}
744+
686745
void patch_free(struct patch *p)
687746
{
747+
int i;
748+
749+
for(i=0;i<IMAGE_COUNT;i++)
750+
pixbuf_dec_ref(p->images[i]);
688751
free(p);
689752
}

Diff for: ‎src/renderer/compiler.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include <rtems.h>
2222
#include <bsp/milkymist_pfpu.h>
2323

24+
#include "framedescriptor.h"
25+
#include "../pixbuf/pixbuf.h"
26+
2427
enum {
2528
pfv_sx = 0,
2629
pfv_sy,
@@ -199,6 +202,7 @@ enum {
199202

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

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

221-
struct patch *patch_compile(const char *patch_code, report_message rmc);
224+
struct patch *patch_compile(const char *basedir, const char *patch_code, report_message rmc);
225+
struct patch *patch_compile_filename(const char *filename, const char *patch_code, report_message rmc);
226+
struct patch *patch_copy(struct patch *p);
222227
void patch_free(struct patch *p);
223228

224229
#endif /* __COMPILER_H */

Diff for: ‎src/renderer/renderer.c

+11-22
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,9 @@ void renderer_unlock_patch()
5050
rtems_semaphore_release(patch_lock);
5151
}
5252

53-
static struct patch *copy_patch(struct patch *p)
54-
{
55-
struct patch *new_patch;
56-
57-
/* Copy memory as the patch will be modified
58-
* by the evaluator (current regs).
59-
*/
60-
new_patch = malloc(sizeof(struct patch));
61-
assert(new_patch != NULL);
62-
memcpy(new_patch, p, sizeof(struct patch));
63-
new_patch->original = p;
64-
new_patch->next = NULL;
65-
return new_patch;
66-
}
53+
/* Copy patches as they will be modified
54+
* by the evaluator (current regs).
55+
*/
6756

6857
void renderer_pulse_patch(struct patch *p)
6958
{
@@ -72,9 +61,9 @@ void renderer_pulse_patch(struct patch *p)
7261
renderer_lock_patch();
7362
if(!mashup_en && (mashup_head->next == NULL)) {
7463
oldpatch = mashup_head;
75-
mashup_head = copy_patch(p);
64+
mashup_head = patch_copy(p);
7665
current_patch = mashup_head;
77-
free(oldpatch);
66+
patch_free(oldpatch);
7867
}
7968
renderer_unlock_patch();
8069
}
@@ -93,12 +82,12 @@ void renderer_add_patch(struct patch *p)
9382
}
9483
p1 = p1->next;
9584
}
96-
new_patch = copy_patch(p);
85+
new_patch = patch_copy(p);
9786
if(!mashup_en) {
9887
p1 = mashup_head;
9988
mashup_head = new_patch;
10089
current_patch = mashup_head;
101-
free(p1);
90+
patch_free(p1);
10291
} else {
10392
new_patch->next = mashup_head;
10493
mashup_head = new_patch;
@@ -124,7 +113,7 @@ void renderer_del_patch(struct patch *p)
124113
if(mashup_head == current_patch)
125114
renderer_get_patch(1);
126115
p1 = mashup_head->next;
127-
free(mashup_head);
116+
patch_free(mashup_head);
128117
mashup_head = p1;
129118
} else {
130119
p1 = mashup_head;
@@ -138,7 +127,7 @@ void renderer_del_patch(struct patch *p)
138127
if(p1->next == current_patch)
139128
renderer_get_patch(1);
140129
p2 = p1->next->next;
141-
free(p1->next);
130+
patch_free(p1->next);
142131
p1->next = p2;
143132
}
144133
renderer_unlock_patch();
@@ -169,7 +158,7 @@ void renderer_start(int framebuffer_fd, struct patch *p)
169158
assert(sc == RTEMS_SUCCESSFUL);
170159

171160
assert(mashup_head == NULL);
172-
mashup_head = copy_patch(p);
161+
mashup_head = patch_copy(p);
173162
current_patch = mashup_head;
174163
mashup_en = 0;
175164

@@ -197,7 +186,7 @@ void renderer_stop()
197186

198187
while(mashup_head != NULL) {
199188
p = mashup_head->next;
200-
free(mashup_head);
189+
patch_free(mashup_head);
201190
mashup_head = p;
202191
}
203192
rtems_semaphore_delete(patch_lock);

0 commit comments

Comments
 (0)
Please sign in to comment.