4. Sliders Page Creation
4.1. Sliders Page Creation Main
A new sliders page is created with the function page_sliders
.
static void page_sliders(monolith_page *pg);
static void page_sliders(monolith_page *pg)
{
page_sliders_d *slide;
slide = calloc(1, sizeof(page_sliders_d));
if(slide == NULL) return;
page_sliders_init(pg, slide);
if(sliders_type == 0) page_sliders_runtime_init(monolith_page_monolith(pg));
<<sliders_assign_callbacks>>
monolith_page_data_set(pg, slide);
}
4.2. Sliders Typeflag (setting)
monolith_page_type_set(pg, sliders_type);
4.3. Sliders Open
When a sliders page is opened, the monome state is set.
static void sliders_open(monolith_page *pg);
static void sliders_open(monolith_page *pg)
{
page_sliders_d *slide;
slide = monolith_page_data_get(pg);
if(slide == NULL) return;
monolith_page_mstate_recall(slide->mstate);
monolith_page_arcstate_recall(slide->arcstate);
}
monolith_page_open_set(pg, sliders_open);
4.4. Sliders Free
static void sliders_free(monolith_page *pg);
static void sliders_free(monolith_page *pg)
{
page_sliders_d *slide;
slide = (page_sliders_d *)monolith_page_data_get(pg);
if(slide == NULL) return;
page_sliders_cleanup(slide);
free(slide);
}
monolith_page_free_set(pg, sliders_free);
4.5. Sliders Press Callback
Any time the monome is pressed, a slider value is set. The Y value determines which slider is set, and the X value determines the value to be set. The value is normalized using the fucntion (x + 1)/16, where x is a value between 0 and 15. The zero value is obtained when the left-most row is pressed twice in a row. In order to do this, the previous point is stored.
The currently selected slider is set here as well. It is usually the same as the Y value, but this is not always the case.
static void sliders_press(monolith_page *pg, int x, int y, int s);
static void sliders_press(monolith_page *pg, int x, int y, int s)
{
page_sliders_d *slide;
if(s == 0) return;
slide = monolith_page_data_get(pg);
if(slide == NULL) return;
if(x == 0 && slide->px == x && slide->py == y) {
slide->vals[y] = 0;
x = -1; /* so it can be toggled back to 1 */
monolith_page_mstate_led_row(slide->mstate, 0, y, 0);
} else {
slide->vals[y] = (GFFLT)(x + 1) / 16.0;
monolith_page_mstate_led_row(slide->mstate, 0, y, (1 << (x + 1)) - 1);
}
if(x >= 8) {
x -= 8;
monolith_page_mstate_led_row(slide->mstate, 255, y, (1 << (x + 1)) - 1);
} else {
monolith_page_mstate_led_row(slide->mstate, 255, y, 0);
}
sliders_update_arc(slide, y, slide->vals[y]);
slide->px = x;
slide->py = y;
if(!slide->griffin_lock) slide->curslider = y;
}
monolith_page_press_set(pg, sliders_press);
4.6. Sliders Turn Callback
The turn callback does fine tuning of the slider value. The slider it increments
is the last selected slider, as indicated by the curslider
variable.
static void sliders_turn(monolith_page *pg, int s);
static void sliders_turn(monolith_page *pg, int s)
{
page_sliders_d *slide;
GFFLT *val;
slide = monolith_page_data_get(pg);
if(slide == NULL) return;
if(slide->curslider < 0) return;
val = &slide->vals[slide->curslider];
*val = *val + s*slide->inc;
if(*val > 1.0) *val = 1.0;
if(*val < 0.0) *val = 0.0;
sliders_update_monome(slide, slide->curslider, *val);
sliders_update_arc(slide, slide->curslider, *val);
}
monolith_page_turn_set(pg, sliders_turn);
The slider is updated on the monome with the function sliders_update_monome
.
It is turned into a function because it is also needed for the scheme function
monolith:sliders-set
.
static void sliders_update_monome(page_sliders_d *slide, int slider, GFFLT val);
static void sliders_update_monome(page_sliders_d *slide, int slider, GFFLT val)
{
unsigned short *grid;
unsigned short newval;
int cs;
grid = monolith_page_mstate_data_get(slide->mstate);
cs = slider;
if (val < 0.01) {
newval = 0; /* basically 0. turn off row entirely. */
} else {
newval = floor(val * 16);
newval = (1 << (newval)) - 1;
}
if (newval != grid[cs]) {
monolith_page_mstate_led_row(slide->mstate, 0, cs, newval & 255);
monolith_page_mstate_led_row(slide->mstate, 255, cs, newval >> 8);
}
}
static void sliders_update_arc(page_sliders_d *slide, int slider, GFFLT val);
static void sliders_update_arc(page_sliders_d *slide, int slider, GFFLT val)
{
int i;
for(i = 0; i < 4; i++) {
if(slider == slide->arc_slider[i]) {
monolith_arcstate_mapval(slide->arcstate,
i,
val);
}
}
}
4.7. Sliders Push Callback
The griffin push callback sets a local gate variable, which
can then be read by a patch via the function slidergate
.
static void sliders_push(monolith_page *pg, int s);
static void sliders_push(monolith_page *pg, int s)
{
page_sliders_d *slide;
slide = monolith_page_data_get(pg);
if(slide == NULL) return;
slide->gate = s;
}
monolith_page_push_set(pg, sliders_push);
4.8. Sliders Delta Callback
Arc Encoders. Eventually, this will be an alternative way to control slider levels.
static void sliders_delta(monolith_page *pg, int n, int delta);
static void sliders_delta(monolith_page *pg, int n, int delta)
{
page_sliders_d *slide;
GFFLT *val;
int s;
slide = monolith_page_data_get(pg);
if(slide == NULL) return;
s = slide->arc_slider[n];
val = &slide->vals[s];
*val = *val + delta*slide->arc_inc;
if(*val > 1.0) *val = 1.0;
if(*val < 0.0) *val = 0.0;
sliders_update_monome(slide, s, *val);
sliders_update_arc(slide, s, *val);
}
monolith_page_delta_set(pg, sliders_delta);
4.9. Sliders State Management Callbacks
4.9.1. Slider Schema Generation
A new sliders schema is created with the function sliders_schema
. It
must be freed manually.
static int sliders_schema(page_sliders_d *slide,
monolith_state_schema **schema);
static int sliders_schema(page_sliders_d *slide,
monolith_state_schema **schema)
{
int n;
char buf[4];
monolith_state_schema_init(schema, 9);
monolith_param_mkmstate(*schema, 0, "mstate", 6, slide->mstate);
buf[0] = 'p';
buf[2] = 0;
for(n = 1; n < 9; n++) {
buf[1] = n + 48; /* convert to ascii */
monolith_param_mkfloat(*schema, n, buf, 2, slide->vals[n - 1]);
}
return 1;
}
4.9.2. Sliders Save Callback
static int sliders_save(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len);
static int sliders_save(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len)
{
page_sliders_d *slide;
monolith_state_schema *schema;
slide = monolith_page_data_get(pg);
sliders_schema(slide, &schema);
monolith_state_write_schema(s, schema, "sliders", 7, key, len);
monolith_state_schema_cleanup(&schema);
return 1;
}
monolith_page_save_set(pg, sliders_save);
4.9.3. Sliders Load Callback
static int sliders_load(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len);
static int sliders_load(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len)
{
page_sliders_d *slide;
monolith_state_schema *schema;
int rc;
int n;
slide = monolith_page_data_get(pg);
sliders_schema(slide, &schema);
rc = monolith_state_read_schema(s, schema, "sliders", 7, key, len);
if (rc) {
monolith_param_mstate(schema, 0, slide->mstate);
if (monolith_page_selected(pg)) {
monolith_page_mstate_recall(slide->mstate);
}
for(n = 0; n < 8; n++) {
monolith_param_float(schema, n+1, &slide->vals[n]);
sliders_update_monome(slide, n, slide->vals[n]);
sliders_update_arc(slide, n, slide->vals[n]);
}
}
monolith_state_schema_cleanup(&schema);
return rc;
}
monolith_page_load_set(pg, sliders_load);
prev | home | next