3. Knobs Helper Functions
3.1. Drawing the value of a "lane"
A lane is considered to be 1/4th sized 4x8 strip of values, assigned to a particular knob.
<<knobs_function_declarations>>=
static void knobs_draw_lane(page_knobs_d *knobs, int lane);
<<knobs_functions>>=
static void knobs_draw_lane(page_knobs_d *knobs, int lane)
{
int x, y;
GFFLT val;
int sel;
int pos;
int c;
sel = knobs->selected[lane];
if (sel < 0) return;
x = (sel % 4);
y = (sel / 4);
pos = (y * 16) + (lane * 4 + x);
val = knobs->vals[pos];
for (c = 0; c < 4; c++) {
if (c == x) {
int ival;
ival = 1 << y;
monolith_page_mstate_led_col(knobs->mstate,
(lane * 4) + c, 0,
ival);
} else {
monolith_page_mstate_led_col(knobs->mstate,
(lane * 4) + c, 0,
0);
}
}
monolith_arcstate_mapval(knobs->astate, lane, val);
}
3.2. Redraw
Will redraw values on all lanes.
<<knobs_function_declarations>>=
static void knobs_redraw(page_knobs_d *knobs);
<<knobs_functions>>=
static void knobs_redraw(page_knobs_d *knobs)
{
int i;
for (i = 0; i < 4; i++) {
knobs_draw_lane(knobs, i);
}
}
3.3. get knob values
You'll need to know the lane (0-4), and the local position (x, y) relative to the lane. Top left is 0,0 for each lane.
<<knobs_function_declarations>>=
static GFFLT * knobs_val(page_knobs_d *knobs,
int lane,
int x, int y);
<<knobs_functions>>=
static GFFLT * knobs_val(page_knobs_d *knobs,
int lane,
int x, int y)
{
int pos;
if (lane < 0 || lane >= 4) return NULL;
if (x < 0 || x >= 4) return NULL;
if (y < 0 || y >= 8) return NULL;
pos = ((4 * lane) + x) + y * 16;
if (pos < 0 || pos >= 128) return NULL;
return &knobs->vals[pos];
}
3.4. selecting a knob in a lane
Selects + displays a knob at a lane.
<<knobs_function_declarations>>=
static void knobs_select(page_knobs_d *knobs,
int lane,
int x, int y);
<<knobs_functions>>=
static void knobs_select(page_knobs_d *knobs,
int lane,
int x, int y)
{
knobs->selected[lane] = y * 4 + x;
}
3.5. Incrementing selected value
Increments current value. Should definitely handle clamping
here. Lane is specified, along with how many clicks via
delta
, which can be positive + negative.
<<knobs_function_declarations>>=
static void knobs_increment(page_knobs_d *knobs,
int lane, int delta);
<<knobs_functions>>=
static void knobs_increment(page_knobs_d *knobs,
int lane, int delta)
{
GFFLT val;
int sel;
int x, y;
int pos;
sel = knobs->selected[lane];
if (sel < 0) return;
x = (sel % 4);
y = (sel / 4);
pos = (y * 16) + (lane * 4 + x);
val = knobs->vals[pos];
val += knobs->inc * delta;
if (val < 0) val = 0;
if (val > 1) val = 1;
knobs->vals[pos] = val;
}
3.6. Grid to knobs
Will convert grid XY location to knobs lane and local XY position.
<<knobs_function_declarations>>=
static void grid2knobs(int grid_x, int grid_y,
int *lane, int *knob_x, int *knob_y);
<<knobs_functions>>=
static void grid2knobs(int grid_x, int grid_y,
int *lane, int *knob_x, int *knob_y)
{
*lane = 0;
*knob_x = 0;
*knob_y = 0;
if (grid_x < 0 || grid_x >= 16) return;
if (grid_y < 0 || grid_y >= 8) return;
*lane = grid_x / 4;
*knob_x = grid_x % 4;
*knob_y = grid_y;
}
prev | home | next