6. Sliders Scheme Functions

6.1. Scheme Loader

The top-level scheme loader is called s9_load_sliders.

<<sliders_function_declarations>>=
void s9_load_sliders(void);
<<sliders_functions>>=
<<sliders_scheme_functions>>
static S9_PRIM sliders_primitives[] = {
<<sliders_scheme_entries>>
    {NULL}
};
void s9_load_sliders(void)
{
    add_primitives("monolith", sliders_primitives);
}

6.2. Create New Sliders Page

A new sliders page is created with monolith:grid-new.

<<sliders_scheme_entries>>=
{"monolith:sliders-new", pp_sliders_new, 1, 1, {STR, ___, ___}},
<<sliders_scheme_functions>>=
static cell pp_sliders_new(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 = string(car(x));

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

    page_sliders(pg);
    return UNSPECIFIC;
}

6.3. Select Slider

In Scheme, the slider can be selected in scheme using the function monolith:sliders-select.

<<sliders_scheme_entries>>=
{"monolith:sliders-select", pp_sliders_select, 2, 2, {STR,INT,___}},
<<sliders_scheme_functions>>=
static cell pp_sliders_select(cell x)
{
    const char *str;
    cell cstr;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    int rc;
    int slider;
    char name[] = "monolith:sliders-select";
    page_sliders_d *slide;

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

    cstr = car(x);
    str = string(cstr);
    x = cdr(x);

    slider = integer_value(name, car(x));

    if(slider < 0 || slider >= 8) {
        return error("Slider number is out of range", car(x));
    }

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if(!rc) {
        return error(
            "Could not find sliders page",
            car(x));
    }

    if(!is_sliders(pg)) {
        return error("This is not a sliders page", cstr);
    }

    slide = monolith_page_data_get(pg);
    slide->curslider = slider;

    return UNSPECIFIC;
}

6.4. Set Slider Value

In Scheme, the value of a particular slider can be selected using the function monolith:sliders-set.

<<sliders_scheme_entries>>=
{"monolith:sliders-set", pp_sliders_set, 3, 3, {STR,INT,REA}},
<<sliders_scheme_functions>>=
static cell pp_sliders_set(cell x)
{
    const char *str;
    cell cstr;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    int rc;
    int slider;
    page_sliders_d *slide;
    int mantissa;
    int exponent;
    cell real;
    char name[] = "monolith:sliders-set";
    GFFLT val;
    s9_cell cslider;

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

    cstr = car(x);
    str = string(cstr);
    x = cdr(x);

    cslider = car(x);
    slider = integer_value(name, cslider);
    x = cdr(x);
    real = car(x);

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if(!rc) {
        return error(
            "Could not find sliders page",
            car(x));
    }

    if(!is_sliders(pg)) {
        return error("This is not a sliders page", cstr);
    }

    if(slider < 0 || slider >= 8) {
        return error("Slider number is out of range", cslider);
    }

    slide = monolith_page_data_get(pg);

    mantissa = s9_bignum_to_int(s9_real_mantissa(real));
    exponent = s9_real_exponent(real);

    val = mantissa * pow(10, exponent);

    if(val < 0) val = 0;
    if(val > 1) val = 1;

    slide->vals[slider] = val;

    sliders_update_monome(slide, slider, val);
    sliders_update_arc(slide, slider, val);

    return UNSPECIFIC;
}

6.5. Get Slider Value

In Scheme, the value of a particular slider can be retreived using the function monolith:sliders-get.

<<sliders_scheme_entries>>=
{"monolith:sliders-get", pp_sliders_get, 2, 2, {STR,INT,___}},
<<sliders_scheme_functions>>=
static cell pp_sliders_get(cell x)
{
    const char *str;
    cell cstr;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    int rc;
    int slider;
    page_sliders_d *slide;
    GFFLT val;
    unsigned int ival;
    s9_cell cslider;
    char name[] = "monolith:sliders-get";

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

    cstr = car(x);
    str = string(cstr);
    x = cdr(x);

    cslider = car(x);
    slider = integer_value(name, cslider);

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if(!rc) {
        return error(
            "Could not find sliders page",
            car(x));
    }

    if(!is_sliders(pg)) {
        return error("This is not a sliders page", cstr);
    }

    if(slider < 0 || slider >= 8) {
        return error("Slider value is out of range", cslider);
    }

    slide = monolith_page_data_get(pg);

    val = slide->vals[slider];
    ival = floor(val); /* get non-decimal part */
    val = floor(1e4 * (ival + (val - ival))); /* get 4 decimal places */
    return s9_make_real(1, -4, s9_make_integer(val));
}

6.6. Set Increment

In Scheme, the incrementer can be set with the function monolith:sliders-increment-set.

<<sliders_scheme_entries>>=
{"monolith:sliders-increment-set", pp_sliders_increment_set, 2, 2, {STR,REA,___}},
<<sliders_scheme_functions>>=
static cell pp_sliders_increment_set(cell x)
{
    const char *str;
    cell cstr;
    cell real;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    page_sliders_d *slide;
    GFFLT val;
    int mantissa;
    int exponent;
    int rc;

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

    cstr = car(x);
    str = string(cstr);
    x = cdr(x);

    real = car(x);

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if(!rc) {
        return error(
            "Could not find sliders page",
            car(x));
    }

    if(!is_sliders(pg)) {
        return error("This is not a sliders page", cstr);
    }

    slide = monolith_page_data_get(pg);

    mantissa = s9_bignum_to_int(s9_real_mantissa(real));
    exponent = s9_real_exponent(real);
    val = mantissa * pow(10, exponent);

    page_sliders_increment_set(slide, val);

    return UNSPECIFIC;
}

6.7. Griffin Lock

<<sliders_scheme_entries>>=
{"monolith:sliders-griffin-lock",
pp_sliders_griffin_lock,
2, 2,
{STR,INT,___}},
<<sliders_scheme_functions>>=
static cell pp_sliders_griffin_lock(cell x)
{
    page_sliders_d *slide;
    monolith_dict *dict;
    monolith_page *pg;
    monolith_d *m;
    int state;
    int rc;
    const char *str;
    cell cstr;

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

    cstr = car(x);
    str = string(cstr);
    x = cdr(x);

    state = integer_value("monolith:sliders-griffin-lock",
                           car(x));

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));

    if(!rc) {
        return error(
            "Could not find sliders page",
            car(x));
    }

    if(!is_sliders(pg)) {
        return error("This is not a sliders page", cstr);
    }

    slide = monolith_page_data_get(pg);
    page_sliders_griffin_lock(slide, state);
    return UNSPECIFIC;
}

6.8. Arc Slider Set

<<sliders_scheme_entries>>=
{"monolith:sliders-arc-set",
pp_sliders_arc_set,
3, 3,
{STR,INT,INT}},
<<sliders_scheme_functions>>=
static cell pp_sliders_arc_set(cell x)
{
    page_sliders_d *slide;
    monolith_dict *dict;
    monolith_page *pg;
    monolith_d *m;
    int arc;
    int slider;
    int rc;
    const char *str;
    cell cstr;
    char name[] = "monolith:sliders-arc-set";

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

    cstr = car(x);
    str = string(cstr);
    x = cdr(x);

    arc = integer_value(name, car(x));
    x = cdr(x);

    slider = integer_value(name, car(x));
    x = cdr(x);

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));

    if(!rc) {
        return error(
            "Could not find sliders page",
            car(x));
    }

    if(!is_sliders(pg)) {
        return error("This is not a sliders page", cstr);
    }

    slide = monolith_page_data_get(pg);

    page_sliders_arc_set(slide, arc, slider);
    sliders_update_arc(slide, slider, slide->vals[slider]);
    return UNSPECIFIC;
}

6.9. Set Arc Increment

In Scheme, the incrementer can be set with the function monolith:sliders-increment-set.

<<sliders_scheme_entries>>=
{
    "monolith:sliders-arc-increment-set",
    pp_sliders_arc_increment_set,
    2, 2,
    {STR,REA,___}
},
<<sliders_scheme_functions>>=
static cell pp_sliders_arc_increment_set(cell x)
{
    const char *str;
    cell cstr;
    cell real;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    page_sliders_d *slide;
    GFFLT val;
    int mantissa;
    int exponent;
    int rc;

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

    cstr = car(x);
    str = string(cstr);
    x = cdr(x);

    real = car(x);

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if(!rc) {
        return error(
            "Could not find sliders page",
            car(x));
    }

    if(!is_sliders(pg)) {
        return error("This is not a sliders page", cstr);
    }

    slide = monolith_page_data_get(pg);

    mantissa = s9_bignum_to_int(s9_real_mantissa(real));
    exponent = s9_real_exponent(real);
    val = mantissa * pow(10, exponent);

    page_sliders_arc_increment_set(slide, val);

    return UNSPECIFIC;
}

6.10. Push Internal FTable

The function monolith:sliders-push-ftable will push the internal ftable wrapped around the values onto the Runt Stack, to be used with other nodes.

<<sliders_scheme_entries>>=
{
    "monolith:sliders-push-ftable",
    pp_sliders_push_ftable,
    1, 1,
    {STR,___,___}
},
<<sliders_scheme_functions>>=
static cell pp_sliders_push_ftable(cell x)
{
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    page_sliders_d *slide;
    runt_vm *vm;
    sp_ftbl *ft;
    int rc;
    const char *str;
    cell cstr;
    runt_stacklet *out;

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

    cstr = car(x);
    str = string(cstr);
    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));

    if (!rc) {
        return error(
            "Could not find sliders page",
            car(x));
    }

    if(!is_sliders(pg)) {
        return error("This is not a sliders page", cstr);
    }

    slide = monolith_page_data_get(pg);

    ft = page_sliders_ftable(slide);

    rc = runt_ppush(vm, &out);

    /* TODO: better scheme-runt error checking */

    if (rc != RUNT_OK) {
        return error("Runt Stack problem.", cstr);
    }

    rgf_stacklet_ftable(vm, out, ft);

    return UNSPECIFIC;
}



prev | home | next