10. Knobs Scheme Functions

10.1. Knobs Scheme Loader

The top-level scheme loader is called s9_load_knobs.

<<knobs_function_declarations>>=
void s9_load_knobs(void);
<<knobs_functions>>=
<<knobs_scheme_functions>>
static S9_PRIM knobs_primitives[] = {
<<knobs_scheme_entries>>
    {NULL}
};
void s9_load_knobs(void)
{
    monolith_scheme_add_primitives("monolith",
                                   knobs_primitives);
}

10.2. Create Knobs Page

A new knobs page is created with monolith:knobs-new.

<<knobs_scheme_entries>>=
{
    "monolith:knobs-new",
    pp_knobs_new, 1, 1,
    {S9_T_STRING, S9_T_ANY, S9_T_ANY}
},
<<knobs_scheme_functions>>=
static s9_cell pp_knobs_new(s9_cell x)
{
    const char *str;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    int rc;

    m = monolith_data_get();
    dict = monolith_dict_get(m);

    str = monolith_scheme_string(s9_car(x));

    rc = monolith_dict_newpage(dict, &pg, str, strlen(str));
    if(!rc) {
        return monolith_scheme_error(
            "Could not create knobs page (maybe it already exists?)",
            s9_car(x));
    }

    page_knobs(pg);
    return S9_UNSPECIFIC;
}

10.3. Set a Knob Value

<<knobs_scheme_entries>>=
{
    "monolith:knobs-val",
    pp_knobs_val, 5, 5,
    {S9_T_STRING, S9_T_INTEGER, S9_T_INTEGER}
},
<<knobs_scheme_functions>>=
static s9_cell pp_knobs_val(s9_cell x)
{
    const char *str;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    page_knobs_d *knobs;
    int rc;
    int lane, xpos, ypos;
    GFFLT val;
    GFFLT *pval;

    m = monolith_data_get();
    dict = monolith_dict_get(m);

    str = monolith_scheme_string(s9_car(x));

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if(!rc) {
        return monolith_scheme_error(
            "Could not find step page",
            s9_car(x));
    }

    x = s9_cdr(x);
    lane = monolith_scheme_integer(NULL, s9_car(x));
    if (lane < 0 || lane >= 4) {
        return monolith_scheme_error(
            "Lane out of bounds",
            s9_car(x));
    }
    x = s9_cdr(x);
    xpos = monolith_scheme_integer(NULL, s9_car(x));
    if (xpos < 0 || xpos >= 4) {
        return monolith_scheme_error(
            "xpos out of bounds",
            s9_car(x));
    }
    x = s9_cdr(x);
    ypos = monolith_scheme_integer(NULL, s9_car(x));
    if (ypos < 0 || ypos >= 8) {
        return monolith_scheme_error(
            "ypos out of bounds",
            s9_car(x));
    }
    x = s9_cdr(x);

    knobs = monolith_page_data_get(pg);

    val = REAL2FLOAT(s9_car(x));

    if (val < 0 || val >= 1) {
        return monolith_scheme_error(
            "value out of bounds",
            s9_car(x));
    }

    pval = knobs_val(knobs, lane, xpos, ypos);

    if (pval == NULL) {
        printf("Weird NULL value.\n");
        return S9_UNSPECIFIC;
    }


    *pval = val;

    if (monolith_page_selected(pg)) {
        knobs_draw_lane(knobs, lane);
    }

    return S9_UNSPECIFIC;
}

10.4. Select a Knob

<<knobs_scheme_entries>>=
{
    "monolith:knobs-select",
    pp_knobs_select, 4, 4,
    {S9_T_STRING, S9_T_INTEGER, S9_T_INTEGER}
},
<<knobs_scheme_functions>>=
static s9_cell pp_knobs_select(s9_cell x)
{
    const char *str;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    page_knobs_d *knobs;
    int rc;
    int lane, xpos, ypos;

    m = monolith_data_get();
    dict = monolith_dict_get(m);

    str = monolith_scheme_string(s9_car(x));

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if (!rc) {
        return monolith_scheme_error(
            "Could not find knobs page",
            s9_car(x));
    }

    x = s9_cdr(x);
    lane = monolith_scheme_integer(NULL, s9_car(x));
    if (lane < 0 || lane >= 4) {
        return monolith_scheme_error(
            "Lane out of bounds",
            s9_car(x));
    }
    x = s9_cdr(x);
    xpos = monolith_scheme_integer(NULL, s9_car(x));
    if (xpos < 0 || xpos >= 4) {
        return monolith_scheme_error(
            "xpos ane out of bounds",
            s9_car(x));
    }
    x = s9_cdr(x);
    ypos = monolith_scheme_integer(NULL, s9_car(x));
    if (ypos < 0 || ypos >= 8) {
        return monolith_scheme_error(
            "ypos ane out of bounds",
            s9_car(x));
    }

    knobs = monolith_page_data_get(pg);

    knobs_select(knobs, lane, xpos, ypos);

    if (monolith_page_selected(pg)) {
        knobs_draw_lane(knobs, lane);
    }
    return S9_UNSPECIFIC;
}

10.5. Assign Aux Knob

<<knobs_scheme_entries>>=
{
    "monolith:knobs-aux-assign",
    pp_knobs_aux_assign, 4, 4,
    {S9_T_STRING, S9_T_INTEGER, S9_T_INTEGER}
},
<<knobs_scheme_functions>>=
static s9_cell pp_knobs_aux_assign(s9_cell x)
{
    const char *str;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    page_knobs_d *knobs;
    int rc;
    int lane, xpos, ypos;

    m = monolith_data_get();
    dict = monolith_dict_get(m);

    str = monolith_scheme_string(s9_car(x));

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if(!rc) {
        return monolith_scheme_error(
            "Could not find step page",
            s9_car(x));
    }

    x = s9_cdr(x);
    lane = monolith_scheme_integer(NULL, s9_car(x));
    x = s9_cdr(x);
    xpos = monolith_scheme_integer(NULL, s9_car(x));
    x = s9_cdr(x);
    ypos = monolith_scheme_integer(NULL, s9_car(x));

    knobs = monolith_page_data_get(pg);

    knobs_aux_knob(knobs, lane, xpos, ypos);
    return S9_UNSPECIFIC;
}



prev | home | next