Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: m-labs/flickernoise
base: d64b327
...
head fork: m-labs/flickernoise
compare: cc6b764
  • 7 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
12 src/compiler/compiler.c
View
@@ -188,6 +188,7 @@ static void pfv_bind_callback(void *_sc, struct fpvm_sym *sym, int reg)
{
struct compiler_sc *sc = _sc;
struct sym *s = FPVM2SYM(sym);
+ struct sym_stim *r;
int pfv;
pfv = pfv_from_sym(s);
@@ -195,8 +196,8 @@ static void pfv_bind_callback(void *_sc, struct fpvm_sym *sym, int reg)
pfv_update_patch_requires(sc, pfv);
sc->p->pfv_allocation[pfv] = reg;
}
- if(s->stim_regs)
- s->stim_regs->pfv = sc->p->perframe_regs+reg;
+ for(r = s->stim; r; r = r->next)
+ r->regs->pfv = sc->p->perframe_regs+reg;
}
static bool init_pfv(struct compiler_sc *sc)
@@ -269,6 +270,7 @@ static void pvv_bind_callback(void *_sc, struct fpvm_sym *sym, int reg)
{
struct compiler_sc *sc = _sc;
struct sym *s = FPVM2SYM(sym);
+ struct sym_stim *r;
int pvv;
pvv = pvv_from_sym(s);
@@ -276,8 +278,8 @@ static void pvv_bind_callback(void *_sc, struct fpvm_sym *sym, int reg)
pvv_update_patch_requires(sc, pvv);
sc->p->pvv_allocation[pvv] = reg;
}
- if(s->stim_regs)
- s->stim_regs->pvv = sc->p->pervertex_regs+reg;
+ for(r = s->stim; r; r = r->next)
+ r->regs->pvv = sc->p->pervertex_regs+reg;
}
static bool init_pvv(struct compiler_sc *sc)
@@ -509,7 +511,9 @@ struct patch *patch_compile(const char *basedir, const char *patch_code,
if(!finalize_pvv(sc)) goto fail;
if(!schedule_pvv(sc)) goto fail;
+#ifndef STANDALONE
symtab_free();
+#endif
stim_db_free(); /* @@@ */
free(sc);
2  src/compiler/idgen
View
@@ -56,7 +56,7 @@ sed 's/#.*//;/^ *$/d' $1 | LANG=C sort | {
.pfv_idx = $2,
.pvv_idx = $3,
.flags = $flags,
- .stim_regs = NULL,
+ .stim = NULL,
},
EOF
i=`expr $i + 1`
14 src/compiler/parser.y
View
@@ -379,6 +379,7 @@ assignment ::= ident(I) TOK_ASSIGN midi_fn_type(T) TOK_LPAREN ident(D)
TOK_RPAREN opt_semi. {
struct sym *sym = I->sym;
struct stimuli *stim = compiler_get_stimulus(state->comm->u.sc);
+ struct sym_stim *ref;
free(I);
if(sym->flags & SF_LIVE) {
@@ -387,19 +388,22 @@ assignment ::= ident(I) TOK_ASSIGN midi_fn_type(T) TOK_LPAREN ident(D)
free(D);
return;
}
- if(sym->stim_regs) {
- FAIL("\"%s\" is already used as control variable",
- sym->fpvm_sym.name);
+ ref = malloc(sizeof(struct sym_stim));
+ if(!ref) {
+ FAIL("out of memory");
free(D);
return;
}
- sym->stim_regs = stim_bind(stim, D->sym, T);
+ ref->regs = stim_bind(stim, D->sym, T);
free(D);
- if(!sym->stim_regs) {
+ if(!ref->regs) {
FAIL("cannot add stimulus for MIDI input \"%s\"",
sym->fpvm_sym.name);
return;
}
+ ref->next = sym->stim;
+ sym->stim = ref;
+ sym->flags |= SF_ASSIGNED;
}
midi_fn_type(T) ::= TOK_RANGE. { T = ft_range; }
11 src/compiler/ptest/ptest.c
View
@@ -366,6 +366,7 @@ static void add_midi(const char *s)
static void play_midi(struct patch *patch)
{
struct sym *sym;
+ struct sym_stim *r;
float f = 0;
sym = unique(trace_var);
@@ -374,12 +375,13 @@ static void play_midi(struct patch *patch)
trace_var);
exit(1);
}
- if (!sym->stim_regs) {
+ if (!sym->stim) {
fprintf(stderr, "\"%s\" is not a control variable\n",
trace_var);
exit(1);
}
- sym->stim_regs->pfv = &f;
+ for (r = sym->stim; r; r = r->next)
+ r->regs->pfv = &f;
while (midi) {
stim_midi_ctrl(patch->stim,
@@ -395,12 +397,15 @@ static void compile(const char *pgm)
struct patch *patch;
patch = patch_compile("/", pgm, report);
- if (!patch)
+ if (!patch) {
+ symtab_free();
exit(1);
+ }
if (!quiet)
show_patch(patch);
if (trace_var)
play_midi(patch);
+ symtab_free();
/*
* We can't use patch_free here because that function also accesses
* image data, which isn't available in standalone builds. A simple
22 src/compiler/symtab.c
View
@@ -107,7 +107,7 @@ struct sym *unique(const char *s)
new->fpvm_sym.name = strdup(s);
new->pfv_idx = new->pvv_idx = -1;
new->flags = 0;
- new->stim_regs = NULL;
+ new->stim = NULL;
return new;
}
@@ -133,7 +133,7 @@ struct sym *unique_n(const char *s, int n)
new->fpvm_sym.name = strdup_n(s, n);
new->pfv_idx = new->pvv_idx = -1;
new->flags = 0;
- new->stim_regs = NULL;
+ new->stim = NULL;
return new;
}
@@ -148,12 +148,28 @@ void symtab_init(void)
}
+static void free_stim(struct sym *sym)
+{
+ struct sym_stim *next;
+
+ while(sym->stim) {
+ next = sym->stim->next;
+ free(sym->stim);
+ sym->stim = next;
+ }
+}
+
+
void symtab_free(void)
{
int i;
- for(i = 0; i != num_user_syms; i++)
+ for(i = 0; i != num_well_known; i++)
+ free_stim(well_known+i);
+ for(i = 0; i != num_user_syms; i++) {
free((void *) user_syms[i].fpvm_sym.name);
+ free_stim(user_syms+i);
+ }
free(user_syms);
user_syms = NULL;
num_user_syms = allocated = 0;
8 src/compiler/symtab.h
View
@@ -20,11 +20,15 @@
#define SF_LIVE (1 << 2) /* variable is written to by FN */
#define SF_FIXED (SF_SYSTEM | SF_LIVE)
+struct sym_stim {
+ struct stim_regs *regs;
+ struct sym_stim *next;
+};
+
struct sym {
struct fpvm_sym fpvm_sym;
int pfv_idx, pvv_idx; /* index; -1 if not a variable known to FN */
- struct stim_regs *stim_regs;
- /* NULL if not a control variable */
+ struct sym_stim *stim; /* NULL if not a control variable */
int flags;
};
15 src/compiler/test/stimerr
View
@@ -26,19 +26,4 @@ expect <<EOF
line 4: cannot add MIDI input "bar" near '}'
EOF
-
-#------------------------------------------------------------------------------
-
-ptest_fail "stimuli, errors: bind control variable twice" -c -q << EOF
-midi "foo" {
- bar = pot(0);
-}
-
-foo = range(bar);
-foo = range(bar);
-EOF
-expect <<EOF
-line 7: "foo" is already used as control variable near 'EOF'
-EOF
-
###############################################################################
10 src/compiler/test/stimin
View
@@ -197,5 +197,15 @@ expect <<EOF
0
EOF
+#------------------------------------------------------------------------------
+
+ptest "stimuli, input, MIDI: test -Wundefined" -c -q -Wundefined <<EOF
+midi "foo" { bar = switch(1, 0); }
+foo = button(bar);
+per_frame:
+ sx = foo;
+EOF
+expect <<EOF
+EOF
###############################################################################
106 src/compiler/test/stimmulti
View
@@ -0,0 +1,106 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+ptest "stimuli, multi: bind control variable twice (same device)" -c -q \
+ -v sx -m 0=0 -m 0=127 -m 1=0 -m 1=127 -m 0=0 << EOF
+midi "foo" {
+ foo = pot(0);
+ bar = pot(1);
+}
+
+sx = range(foo);
+sx = range(bar);
+EOF
+expect <<EOF
+0
+1
+0
+1
+0
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "stimuli, multi: bind control variable twice (2 devs, same addr)" -c -q \
+ -v sx -m 0=0 -m 0=127 -m 0=0 -m 0=127 -m 0=0 << EOF
+midi "foo" {
+ foo_pot = pot(0);
+}
+
+midi "bar" {
+ bar_pot = pot(0);
+}
+
+sx = range(foo_pot);
+sx = range(bar_pot);
+EOF
+expect <<EOF
+0
+1
+0
+1
+0
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "stimuli, multi: bind control variable twice (2 devs, diff addr)" -c -q \
+ -v sx -m 0=0 -m 0=127 -m 1=0 -m 1=127 -m 0=0 << EOF
+midi "foo" {
+ foo_pot = pot(0);
+}
+
+midi "bar" {
+ bar_pot = pot(1);
+}
+
+sx = range(foo_pot);
+sx = range(bar_pot);
+EOF
+expect <<EOF
+0
+1
+0
+1
+0
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "stimuli, multi: bind control element twice (1)" -c -q \
+ -v foo -m 0=0 -m 0=63 -m 0=127 -m 0=0 << EOF
+midi "foo" {
+ bar = pot(0);
+}
+
+foo = range(bar);
+bar = button(bar);
+EOF
+expect <<EOF
+0
+0.496063
+1
+0
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "stimuli, multi: bind control element twice (2)" -c -q \
+ -v bar -m 0=0 -m 0=63 -m 0=127 -m 0=0 << EOF
+midi "foo" {
+ bar = pot(0);
+}
+
+foo = range(bar);
+bar = button(bar);
+EOF
+expect <<EOF
+0
+0
+1
+0
+EOF
+
+###############################################################################
60 src/renderer/stimuli.c
View
@@ -101,25 +101,21 @@ static void midi_proc_button_switch(struct s_midi_ctrl *ct, int value)
void stim_midi_ctrl(struct stimuli *s, int chan, int ctrl, int value)
{
- struct s_midi_ctrl *ct;
+ struct s_midi_ctrl *ct = NULL;
midi_last[chan][ctrl] = value;
if(!s)
return;
- if(s->midi[chan]) {
+ if(s->midi[chan])
ct = s->midi[chan]->ctrl[ctrl];
- if(ct) {
- ct->proc(ct, value);
- return;
- }
- }
-
- if(s->midi[0]) {
+ if(!ct && s->midi[0])
ct = s->midi[0]->ctrl[ctrl];
- if(ct)
- ct->proc(ct, value);
+
+ while(ct) {
+ ct->proc(ct, value);
+ ct = ct->next;
}
}
@@ -142,15 +138,14 @@ static struct stim_regs *stim_add_midi_ctrl(struct stimuli *s, int chan,
}
ch = s->midi[chan];
- if(!ch->ctrl[ctrl]) {
- ch->ctrl[ctrl] = calloc(1, sizeof(struct s_midi_ctrl));
- if(!ch->ctrl[ctrl])
- return NULL;
- }
- ct = ch->ctrl[ctrl];
+ ct = calloc(1, sizeof(struct s_midi_ctrl));
+ if(!ct)
+ return NULL;
ct->proc = proc;
ct->regs.pfv = ct->regs.pvv = NULL;
+ ct->next = ch->ctrl[ctrl];
+ ch->ctrl[ctrl] = ct;
return &ct->regs;
}
@@ -176,6 +171,7 @@ struct stimuli *stim_get(struct stimuli *s)
void stim_put(struct stimuli *s)
{
+ struct s_midi_ctrl **ct, *next;
int i, j;
if(!s)
@@ -184,8 +180,14 @@ void stim_put(struct stimuli *s)
return;
for(i = 0; i != MIDI_CHANS+1; i++)
if(s->midi[i]) {
- for(j = 0; j != MIDI_CTRLS; j++)
- free(s->midi[i]->ctrl[j]);
+ for(j = 0; j != MIDI_CTRLS; j++) {
+ ct = s->midi[i]->ctrl+j;
+ while(*ct) {
+ next = (*ct)->next;
+ free(*ct);
+ *ct = next;
+ }
+ }
free(s->midi[i]);
}
free(s);
@@ -216,16 +218,14 @@ void stim_redirect(struct stimuli *s, void *new)
for(i = 0; i != MIDI_CHANS+1; i++) {
if(!s->midi[i])
continue;
- for(j = 0; j != MIDI_CTRLS; j++) {
- ct = s->midi[i]->ctrl[j];
- if (!ct)
- continue;
- if(ct->regs.pfv)
- ct->regs.pfv = (void *) ct->regs.pfv+d;
- if(ct->regs.pvv)
- ct->regs.pvv = (void *) ct->regs.pvv+d;
- reset_control(ct, i, j);
- }
+ for(j = 0; j != MIDI_CTRLS; j++)
+ for(ct = s->midi[i]->ctrl[j]; ct; ct = ct->next) {
+ if(ct->regs.pfv)
+ ct->regs.pfv = (void *) ct->regs.pfv+d;
+ if(ct->regs.pvv)
+ ct->regs.pvv = (void *) ct->regs.pvv+d;
+ reset_control(ct, i, j);
+ }
}
s->target = new;
}
@@ -348,7 +348,7 @@ struct stim_regs *stim_bind(struct stimuli *s, const void *handle,
const struct stim_db_midi_ctrl *ctrl;
for(dev = db; dev; dev = dev->next)
- for(ctrl = db->ctrls; ctrl; ctrl = ctrl->next)
+ for(ctrl = dev->ctrls; ctrl; ctrl = ctrl->next)
if(ctrl->handle == handle)
return do_bind(s, ctrl, fn);
return NULL;
1  src/renderer/stimuli.h
View
@@ -43,6 +43,7 @@ struct s_midi_ctrl {
void (*proc)(struct s_midi_ctrl *sct, int value);
struct stim_regs regs;
long last; /* for midi_proc_diff_* */
+ struct s_midi_ctrl *next;
};
struct s_midi_chan {

No commit comments for this range

Something went wrong with that request. Please try again.