Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/flickernoise
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d64b327
Choose a base ref
...
head repository: m-labs/flickernoise
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cc6b764
Choose a head ref
  • 7 commits
  • 11 files changed
  • 1 contributor

Commits on Feb 14, 2012

  1. stimuli: refuse to bind the same control twice

    Also added the corresponding test to test/stimerr
    wpwrak committed Feb 14, 2012
    Copy the full SHA
    6f45831 View commit details
  2. compiler: set SF_ASSIGNED for control variables to prevent -Wundefine…

    …d warning
    
    Also added a test case to test/stimin
    wpwrak committed Feb 14, 2012
    Copy the full SHA
    cd8c356 View commit details
  3. Copy the full SHA
    3d96b27 View commit details
  4. ptest: free the symbol table in ptest (and not patch_compile)

    This defers removal of the stimuli from the symbol table, which was
    introduced when allowing binding control variables multiple times.
    wpwrak committed Feb 14, 2012
    Copy the full SHA
    1a78844 View commit details
  5. Copy the full SHA
    0963d9c View commit details
  6. Copy the full SHA
    9823551 View commit details
  7. Copy the full SHA
    cc6b764 View commit details
12 changes: 8 additions & 4 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
@@ -188,15 +188,16 @@ 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);
if(pfv >= 0) {
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,15 +270,16 @@ 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);
if(pvv >= 0) {
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 changes: 1 addition & 1 deletion src/compiler/idgen
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 5 deletions src/compiler/parser.y
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 3 deletions src/compiler/ptest/ptest.c
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 3 deletions src/compiler/symtab.c
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 2 deletions src/compiler/symtab.h
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 15 deletions src/compiler/test/stimerr
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/compiler/test/stimin
Original file line number Diff line number Diff line change
@@ -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 changes: 106 additions & 0 deletions src/compiler/test/stimmulti
Original file line number Diff line number Diff line change
@@ -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

###############################################################################
Loading