Skip to content

Commit

Permalink
mappa: rework screens to be part of LUTs
Browse files Browse the repository at this point in the history
This change allows the screen UIs to be set by each LUT,
giving the user the flexibility to have a button activate
a layer, and hence also change the display.

The combination of one LUT having the input/lights/screen
is a good one, to allow easier UX of developing/testing mappings.

Signed-off-by: Harry van Haaren <[email protected]>
  • Loading branch information
harryhaaren committed Nov 3, 2018
1 parent adb08e9 commit e2ab18e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 47 deletions.
91 changes: 52 additions & 39 deletions ctlra/mappa.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ int32_t mappa_screen_func(struct ctlra_dev_t *ctlra_dev, uint32_t screen_idx,
}

/* invoke callbacks here *BASED ON LUT* for screen sources */
struct avtka_t *a = dev->avtka_screens[screen_idx];
struct avtka_t *a = lut->avtka_screens[screen_idx];
if(!a) {
return 0;
}

float dial_value = 0.1;
struct source_t *s = dev->screen_sources[0];
struct source_t *s = lut->screen_sources[0];
if(s && s->source.func) {
s->source.func(&dial_value, s->token_buf, s->token_size,
s->source.userdata);
Expand Down Expand Up @@ -522,6 +522,13 @@ lut_destroy(struct lut_t *lut)
free(lut);
}

static void
mappa_avtka_event_cb(struct avtka_t *avtka, uint32_t item_id, float v,
void *userdata)
{
struct dev_t *dev = userdata;
}

struct lut_t *
lut_create(struct dev_t *dev, const struct ctlra_dev_info_t *info,
const char *name)
Expand All @@ -547,6 +554,31 @@ lut_create(struct dev_t *dev, const struct ctlra_dev_info_t *info,
if(!lut->sources)
goto fail;

/* allocate AVTKA screen resources */
/* TODO: implement pixel widths etc here */
struct avtka_opts_t opts = {
.w = 480,
.h = 272,
.event_callback = mappa_avtka_event_cb,
.event_callback_userdata = dev,
.offscreen_only = 1, /* pixel buffer - no window shown */
};

struct avtka_t *a = avtka_create("mappa_screen", &opts);
if(!a) {
printf("failed to create avtka instance, quitting\n");
goto fail;
}
struct avtka_item_opts_t item = {
.name = "Dial 1",
.x = 10, .y = 10, .w = 50, .h = 50,
.draw = AVTKA_DRAW_DIAL,
.interact = AVTKA_INTERACT_DRAG_V,
};
uint32_t d1 = avtka_item_create(a, &item);
lut->avtka_screens[0] = a;
printf("avtka %p : d1 = %d\n", a, d1);

lut->name = strdup(name);
return lut;

Expand All @@ -573,13 +605,6 @@ lut_create_add_to_dev(struct mappa_t *m,
return lut;
}

static void
mappa_avtka_event_cb(struct avtka_t *avtka, uint32_t item_id, float v,
void *userdata)
{
struct dev_t *dev = userdata;
}

struct dev_t *
dev_create(struct mappa_t *m, struct ctlra_dev_t *ctlra_dev,
const struct ctlra_dev_info_t *info)
Expand All @@ -598,34 +623,6 @@ dev_create(struct mappa_t *m, struct ctlra_dev_t *ctlra_dev,
* layers */
dev->active_lut = lut_create(dev, info, "active_lut");

/* create AVTKA instances for each screen */
/* TODO: implement pixel widths etc here */
struct avtka_opts_t opts = {
.w = 480,
.h = 272,
.event_callback = mappa_avtka_event_cb,
.event_callback_userdata = dev,
/* raw pixel buffer only - no window shown */
.offscreen_only = 1,
};

struct avtka_t *a = avtka_create("mappa_screen", &opts);
if(!a) {
printf("failed to create avtka instance, quitting\n");
return 0;
}
struct avtka_item_opts_t item = {
.name = "Dial 1",
.x = 10, .y = 10, .w = 50, .h = 50,
.draw = AVTKA_DRAW_DIAL,
.interact = AVTKA_INTERACT_DRAG_V,
};
uint32_t d1 = avtka_item_create(a, &item);
dev->avtka_screens[0] = a;
printf("avtka %p : d1 = %d\n", a, d1);

dev->screen_sources[0] = NULL;

dev->self = m;
dev->id = m->dev_ids++;
TAILQ_INSERT_TAIL(&m->dev_list, dev, tailq);
Expand Down Expand Up @@ -1055,8 +1052,7 @@ config_file_bind_screen_feedback(struct mappa_t *m, struct dev_t *dev,
}
printf("screen found, s = %p\n", s);

/* TODO: enable LUTs to remap the UI */
dev->screen_sources[0] = s;
lut->screen_sources[0] = s;
}

/* returns 0 on success, or # of FAILED bindings otherwise */
Expand Down Expand Up @@ -1133,6 +1129,22 @@ dev_luts_flatten_feedback(struct dev_t *dev, struct lut_t *lut)
return 0;
}

static int32_t
dev_luts_flatten_screen_sources(struct dev_t *dev, struct lut_t *lut)
{
const uint32_t count = 1;
for(uint32_t i = 0; i < count; i++) {
struct source_t *s = lut->screen_sources[i];
dev->active_lut->screen_sources[i] = 0;
if(s && s->source.func) {
dev->active_lut->screen_sources[i] = s;
printf("SCREEN source %s (id %d) set for event %d\n",
s->source.name, s->id, i);
}
}
return 0;
}

static int32_t
dev_luts_flatten(struct dev_t *dev)
{
Expand Down Expand Up @@ -1162,6 +1174,7 @@ dev_luts_flatten(struct dev_t *dev)
dev_luts_flatten_event(dev, l, e);
}
dev_luts_flatten_feedback(dev, l);
dev_luts_flatten_screen_sources(dev, l);
}
i++;
if(i > 10)
Expand Down
13 changes: 5 additions & 8 deletions ctlra/mappa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ struct lut_t {
* The size of the array is defined by the number of feedback items
* on the device */
struct source_t **sources;

/* TODO: refactor to have a screen struct */
uint32_t screen_count;
struct avtka_t *avtka_screens[2];
struct source_t *screen_sources[1];
};
TAILQ_HEAD(lut_list_t, lut_t);

Expand Down Expand Up @@ -133,14 +138,6 @@ struct dev_t {
/* dev id for mappa bindings */
uint32_t id;

/* TODO: refactor to have a screen struct */
uint32_t screen_count;
struct avtka_t *avtka_screens[2];
/* dynamically allocated array of float values to contain the
* resulting float values of the screen-mapped source_t-s? */
//float screen_values[8];
struct source_t *screen_sources[1];

/* contains the path of the file that was used to map it, or NULL
* if there is no mapping applied */
/* TODO: should we allow multiple files to apply to one dev? */
Expand Down

0 comments on commit e2ab18e

Please sign in to comment.