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: 6cd45f7
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: 86c7ca6
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Jan 14, 2012

  1. gui/performance.c (compile_patch): don't use "fd"; malloc buffer for …

    …patch file
    
    This patch makes the following changes to compile_patch:
    
    - rename "fd" to "file": "fd" is customarily used for numeric file
      descriptors, the kind returned by open(), not streams.
    
    - instead of assuming a fixed maximum patch file size of 32 kB
      (which is reasonably generous for current use), fstat() the
      file, then allocate a buffer
    wpwrak committed Jan 14, 2012
    Copy the full SHA
    4e3d18c View commit details
  2. Copy the full SHA
    76e829a View commit details
  3. gui/performance.c: share skipping of unsuitable patches

    simple_mode_next and refresh_callback did pretty much the same thing.
    Now the skipping is done only once, in skip_unsuitable.
    wpwrak committed Jan 14, 2012
    Copy the full SHA
    86c7ca6 View commit details
Showing with 108 additions and 84 deletions.
  1. +108 −84 src/gui/performance.c
192 changes: 108 additions & 84 deletions src/gui/performance.c
Original file line number Diff line number Diff line change
@@ -284,21 +284,32 @@ static void dummy_rmc(const char *msg)

static struct patch *compile_patch(const char *filename)
{
FILE *fd;
FILE *file;
struct stat st;
int r;
char buf[32768];
char *buf = NULL;
struct patch *p;

fd = fopen(filename, "r");
if(fd == NULL) return NULL;
r = fread(buf, 1, 32767, fd);
if(r <= 0) {
fclose(fd);
file = fopen(filename, "r");
if(file == NULL)
return NULL;
}
if(fstat(fileno(file), &st) < 0)
goto fail;
buf = malloc(st.st_size+1);
r = fread(buf, 1, st.st_size, file);
if(r <= 0)
goto fail;
buf[r] = 0;
fclose(fd);
fclose(file);

p = patch_compile_filename(filename, buf, dummy_rmc);
free(buf);
return p;

return patch_compile_filename(filename, buf, dummy_rmc);
fail:
free(buf);
fclose(file);
return NULL;
}

static rtems_task comp_task(rtems_task_argument argument)
@@ -380,89 +391,110 @@ static int suitable_for_simple(struct patch *p)
return suitable;
}

static void skip_unsuitable(void)
{
int looped;

looped = simple_mode_current;
while(!suitable_for_simple(patches[simple_mode_current].p)) {
simple_mode_current++;
if(simple_mode_current == npatches)
simple_mode_current = 0;
if(looped == simple_mode_current)
break;
}
}

static void simple_mode_event(mtk_event *e, int *next)
{
if(e->type != EVENT_TYPE_PRESS)
return;
if(e->press.code == MTK_KEY_F1)
osd_event(patches[simple_mode_current].filename);
if(e->press.code == MTK_KEY_F11)
*next = 1;
if(e->press.code == MTK_KEY_F9)
*next = -1;
}

static void simple_mode_next(int next)
{
simple_mode_current += next;
skip_unsuitable();
renderer_pulse_patch(patches[simple_mode_current].p);
if(as_mode)
update_next_as_time();
}

static void configured_mode_event(mtk_event *e)
{
int index;

if(e->type == EVENT_TYPE_PRESS) {
index = keycode_to_index(e->press.code);
if(index != -1) {
index = keyboard_patches[index];
if(index != -1)
renderer_add_patch(patches[index].p);
}
} else if(e->type == EVENT_TYPE_RELEASE) {
index = keycode_to_index(e->release.code);
if(index != -1) {
index = keyboard_patches[index];
if(index != -1)
renderer_del_patch(patches[index].p);
}
} else if(e->type == EVENT_TYPE_IR) {
index = e->press.code;
index = ir_patches[index];
if(index != -1)
renderer_pulse_patch(patches[index].p);
} else if(e->type == EVENT_TYPE_MIDI_NOTEON) {
if(((e->press.code & 0x0f0000) >> 16) == midi_channel) {
index = e->press.code & 0x7f;
index = midi_patches[index];
if(index != -1)
renderer_add_patch(patches[index].p);
}
} else if(e->type == EVENT_TYPE_MIDI_NOTEOFF) {
if(((e->press.code & 0x0f0000) >> 16) == midi_channel) {
index = e->press.code & 0x7f;
index = midi_patches[index];
if(index != -1)
renderer_del_patch(patches[index].p);
}
} else if(e->type == EVENT_TYPE_OSC) {
index = e->press.code & 0x3f;
index = osc_patches[index];
if(index != -1)
renderer_pulse_patch(patches[index].p);
}
}

static void event_callback(mtk_event *e, int count)
{
int i;
int index;
int next;
rtems_interval t;
int looped;

index = -1;
if(simple_mode) {
next = 0;
for(i=0;i<count;i++) {
if(e[i].type == EVENT_TYPE_PRESS) {
if(e[i].press.code == MTK_KEY_F1)
osd_event(patches[simple_mode_current].filename);
if(e[i].press.code == MTK_KEY_F11)
next = 1;
if(e[i].press.code == MTK_KEY_F9)
next = -1;
}
}
for(i=0;i<count;i++)
simple_mode_event(e+i, &next);
if(as_mode) {
t = rtems_clock_get_ticks_since_boot();
if(t >= next_as_time)
next = 1;
}
if(next) {
looped = simple_mode_current;
do {
simple_mode_current += next;
if(simple_mode_current == npatches)
simple_mode_current = 0;
if(simple_mode_current < 0)
simple_mode_current = npatches - 1;
} while(!suitable_for_simple(patches[simple_mode_current].p) && (looped != simple_mode_current));
renderer_pulse_patch(patches[simple_mode_current].p);
if(as_mode)
update_next_as_time();
}
if(next)
simple_mode_next(next);
if(dt_mode && (index != -1))
osd_event(patches[index].filename);
} else {
for(i=0;i<count;i++) {
if(e[i].type == EVENT_TYPE_PRESS) {
index = keycode_to_index(e[i].press.code);
if(index != -1) {
index = keyboard_patches[index];
if(index != -1)
renderer_add_patch(patches[index].p);
}
} else if(e[i].type == EVENT_TYPE_RELEASE) {
index = keycode_to_index(e[i].release.code);
if(index != -1) {
index = keyboard_patches[index];
if(index != -1)
renderer_del_patch(patches[index].p);
}
} else if(e[i].type == EVENT_TYPE_IR) {
index = e[i].press.code;
index = ir_patches[index];
if(index != -1)
renderer_pulse_patch(patches[index].p);
} else if(e[i].type == EVENT_TYPE_MIDI_NOTEON) {
if(((e[i].press.code & 0x0f0000) >> 16) == midi_channel) {
index = e[i].press.code & 0x7f;
index = midi_patches[index];
if(index != -1)
renderer_add_patch(patches[index].p);
}
} else if(e[i].type == EVENT_TYPE_MIDI_NOTEOFF) {
if(((e[i].press.code & 0x0f0000) >> 16) == midi_channel) {
index = e[i].press.code & 0x7f;
index = midi_patches[index];
if(index != -1)
renderer_del_patch(patches[index].p);
}
} else if(e[i].type == EVENT_TYPE_OSC) {
index = e[i].press.code & 0x3f;
index = osc_patches[index];
if(index != -1)
renderer_pulse_patch(patches[index].p);
}
}
for(i=0;i<count;i++)
configured_mode_event(e+i);
}
}

@@ -476,7 +508,6 @@ static void stop_callback(void)
static void refresh_callback(mtk_event *e, int count)
{
rtems_interval t;
int looped;
int index;

t = rtems_clock_get_ticks_since_boot();
@@ -491,14 +522,7 @@ static void refresh_callback(mtk_event *e, int count)
mtk_cmd(appid, "l_status.set(-text \"Ready.\")");

if(simple_mode) {
looped = simple_mode_current;
while(!suitable_for_simple(patches[simple_mode_current].p)) {
simple_mode_current++;
if(simple_mode_current == npatches)
simple_mode_current = 0;
if(looped == simple_mode_current)
break;
}
skip_unsuitable();
index = simple_mode_current;
} else
index = 0;