Skip to content

Commit

Permalink
stimuli: remember and update base pointer for stim_redirect
Browse files Browse the repository at this point in the history
Running a patch twice broke direct MIDI because pointers were updated
relative to the previous copy instead of the original patch. The commit
fixed the problem. The overall ugliness of the process remains, though.
  • Loading branch information
wpwrak committed Jan 30, 2012
1 parent 2f337e1 commit c037acc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ struct patch *patch_compile_filename(const char *filename,
struct stimuli *compiler_get_stimulus(struct compiler_sc *sc)
{
if(!sc->p->stim)
sc->p->stim = stim_new();
sc->p->stim = stim_new(sc->p);
return sc->p->stim;
}

Expand All @@ -568,7 +568,7 @@ struct patch *patch_copy(struct patch *p)
pixbuf_inc_ref(img->pixbuf);
}
new_patch->stim = stim_get(p->stim);
stim_redirect(p->stim, p, new_patch);
stim_redirect(p->stim, new_patch);
return new_patch;
}

Expand Down
15 changes: 10 additions & 5 deletions src/renderer/stimuli.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include "stimuli.h"

Expand Down Expand Up @@ -104,13 +105,15 @@ struct stim_regs *stim_add_midi_ctrl(struct stimuli *s, int chan, int ctrl,
return &ct->regs;
}

struct stimuli *stim_new(void)
struct stimuli *stim_new(const void *target)
{
struct stimuli *s;

s = calloc(1, sizeof(struct stimuli));
if(s)
if(s) {
s->ref = 1;
s->target = target;
}
return s;
}

Expand Down Expand Up @@ -138,10 +141,11 @@ void stim_put(struct stimuli *s)
free(s);
}

void stim_redirect(struct stimuli *s, const void *old, void *new)
void stim_redirect(struct stimuli *s, void *new)
{
int i, j;
struct s_midi_ctrl *ct;
ptrdiff_t d = new-s->target;

if(!s)
return;
Expand All @@ -153,9 +157,10 @@ void stim_redirect(struct stimuli *s, const void *old, void *new)
if (!ct)
continue;
if(ct->regs.pfv)
ct->regs.pfv = new+((void *) ct->regs.pfv-old);
ct->regs.pfv = (void *) ct->regs.pfv+d;
if(ct->regs.pvv)
ct->regs.pvv = new+((void *) ct->regs.pvv-old);
ct->regs.pvv = (void *) ct->regs.pvv+d;
}
}
s->target = new;
}
5 changes: 3 additions & 2 deletions src/renderer/stimuli.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct s_midi_chan {
struct stimuli {
struct s_midi_chan *midi[MIDI_CHANS];
int ref;
const void *target; /* reference address for pointer relocation */
};


Expand All @@ -48,9 +49,9 @@ void midi_proc_accel_linear(struct s_midi_ctrl *ct, int value);
void stim_midi_ctrl(struct stimuli *s, int chan, int ctrl, int value);
struct stim_regs *stim_add_midi_ctrl(struct stimuli *s, int chan, int ctrl,
void (*proc)(struct s_midi_ctrl *ct, int value));
struct stimuli *stim_new(void);
struct stimuli *stim_new(const void *target);
struct stimuli *stim_get(struct stimuli *s);
void stim_put(struct stimuli *s);
void stim_redirect(struct stimuli *s, const void *old, void *new);
void stim_redirect(struct stimuli *s, void *new);

#endif /* STIMULI_H */

0 comments on commit c037acc

Please sign in to comment.