7. Line16 Page Creation

7.1. Line16 Creation Main

A new line16 page is created with the function page_line16.

<<line16_function_declarations>>=
static void page_line16(monolith_page *pg);
<<line16_functions>>=
static void page_line16(monolith_page *pg)
{
    page_line16_d *line16;
    line16 = calloc(1, sizeof(page_line16_d));
    if(line16 == NULL) return;
    page_line16_init(pg, line16);
    if(line16_type == 0) {
        page_line16_runtime_init(monolith_page_monolith(pg));
    }
<<line16_assign_callbacks>>
    monolith_page_data_set(pg, line16);
}

7.2. Line16 Set Typeflag

<<line16_assign_callbacks>>=
monolith_page_type_set(pg, line16_type);

7.3. Line16 Open

When a line16 page is opened, the monome and arc states are recalled.

<<line16_function_declarations>>=
static void line16_open(monolith_page *pg);
<<line16_functions>>=
static void line16_open(monolith_page *pg)
{
    page_line16_d *line16;
    line16 = monolith_page_data_get(pg);
    if(line16 == NULL) return;
    monolith_page_mstate_recall(line16->mstate);
    monolith_page_arcstate_recall(line16->arcstate);
    line16_state_copy(line16);
}
<<line16_assign_callbacks>>=
monolith_page_open_set(pg, line16_open);

7.4. Line16 Free

<<line16_function_declarations>>=
static void line16_free(monolith_page *pg);
<<line16_functions>>=
static void line16_free(monolith_page *pg)
{
    page_line16_d *line16;
    line16 = (page_line16_d *)monolith_page_data_get(pg);
    if(line16 == NULL) return;
    page_line16_cleanup(line16);
    free(line16);
}
<<line16_assign_callbacks>>=
monolith_page_free_set(pg, line16_free);

7.5. Line16 Press Callback

7.5.1. Main Presser

<<line16_function_declarations>>=
static void line16_press(monolith_page *pg, int x, int y, int s);
<<line16_functions>>=
static void line16_press(monolith_page *pg, int x, int y, int s)
{
    page_line16_d *l;

    l = (page_line16_d *)monolith_page_data_get(pg);

    if(s) line16_press_top(l, x, y);
}
<<line16_assign_callbacks>>=
monolith_page_press_set(pg, line16_press);

7.5.2. Actions

Actions and intersections are rolled up into one bundle. The structure consists of a set of conditionals. The program will go through all the conditionals until it one of them returns true.

7.5.2.1. Top Press

<<line16_function_declarations>>=
static void line16_press_top(page_line16_d *l,
                             int x,
                             int y);
<<line16_functions>>=
static void line16_press_top(page_line16_d *l,
                             int x,
                             int y)
{
    if(y == 0) {
        line16_press_select(l, x);
    } else if(y >= 1 && y <= 5) {
        line16_press_config(l, x, y);
    } else if (y == 7) {
        line16_press_control(l, x);
    }
}
7.5.2.2. Select a Point

This is the top row. When a point is selected, the button associated with that columm will be lit up, and the values will be displayed on the arc.

<<line16_function_declarations>>=
static void line16_press_select(page_line16_d *l, int val);
<<line16_functions>>=
static void line16_press_select(page_line16_d *l, int val)
{
    line16_select_point(l, val);
}
7.5.2.3. Configure a Point

This is any point between the 2nd and 6th rows. Each column corresponds to a point on the line.

The first button is a toggle that controls if the point is active or not.

The next 4 buttons configure the slope of the line. Mode 1 is linear, modes 2 is positive exponential, mode 3 is negative exponential, and mode 4 is bezier.

<<line16_function_declarations>>=
static void line16_press_config(page_line16_d *l,
                                int x,
                                int y);
<<line16_functions>>=
static void line16_press_config(page_line16_d *l,
                                int x,
                                int y)
{
    int s;
    if (y == 1) {
        s = l->state[x];
        s = s ? 0 : 1;
        monolith_page_mstate_led_set(l->mstate,
                                     x, y, s);
        line16_state_set(l, x, s);
    } else if (y >= 2 || y <= 5) {
        line16_line *line;

        switch(y) {
            case 2:
                s = SLOPE_LINEAR;
                break;
            case 3:
                s = SLOPE_EXP_POSITIVE;
                break;
            case 4:
                s = SLOPE_EXP_NEGATIVE;
                break;
            case 5:
                s = SLOPE_BEZIER;
                break;
        }
        line = &l->lines[l->selected_line];
        line16_point_type_set(l, l->selected_line, x, s);
        line16_draw_point_type(&line->points[x],
                               x,
                               l->mstate);
    }
}
7.5.2.4. Control Panel

<<line16_function_declarations>>=
static void line16_press_control(page_line16_d *l, int x);
<<line16_functions>>=
static void line16_press_control(page_line16_d *l, int x)
{
    line16_point *pt;
    int t;
    int tmp;
    if (x == 0) {
        pt = line16_get_point(l, l->selected_point);
        if (pt != NULL) {
            t = pt->type & (1<<2);
            if (t == 0) t = 1;
            else t = 0;
            tmp = pt->type;
            tmp &= ~(1<<2);
            tmp |= (t<<2);
            pt->type = tmp;
            line16_draw_point_togmode(pt, l->mstate);
        }
    }

    /* select a point in binary */

    if (x >= 12 && x <= 15) {
        int bit;
        int selected;

        bit = x - 12;
        selected = l->selected_line;

        if (selected & (1 << bit)) {
            selected &= ~(1 << bit);
        } else {
            selected |= 1 << bit;
        }

        l->selected_line = selected;
        line16_state_copy(l);
        line16_draw_selected_line(l->selected_line,
                                  l->mstate);
        line16_redraw_points(l);
        line16_select_point(l, l->selected_point);


        if (l->selected_line != l->playing_line) {
            monolith_page_mstate_led_row16(l->mstate, 6, 0);
        }
    }
}

7.6. Line16 Turn Callback

This will change the global playback rate of the line, assuming the line isn't being controlled form graforge.

<<line16_function_declarations>>=
static void line16_turn(monolith_page *pg, int s);
<<line16_functions>>=
static void line16_turn(monolith_page *pg, int s)
{
    GFFLT rate;
    page_line16_d *l;

    l = (page_line16_d *)monolith_page_data_get(pg);

    rate = l->rate;

    rate += 0.1 * s;

    if(rate < 0) rate = 0;

    if(rate > 500) rate = 500;

    l->rate = rate;
}
<<line16_assign_callbacks>>=
monolith_page_turn_set(pg, line16_turn);

7.7. Line16 Push Callback

The push callback will reset the global playback rate to be 1.

<<line16_function_declarations>>=
static void line16_push(monolith_page *pg, int s);
<<line16_functions>>=
static void line16_push(monolith_page *pg, int s)
{
    page_line16_d *l;

    l = (page_line16_d *)monolith_page_data_get(pg);

    l->rate = 1;
}
<<line16_assign_callbacks>>=
monolith_page_push_set(pg, line16_push);

7.8. Line16 Delta Callback

<<line16_function_declarations>>=
static void line16_delta(monolith_page *pg, int n, int delta);
<<line16_functions>>=
static void line16_delta(monolith_page *pg, int n, int delta)
{
    page_line16_d *l;
    line16_point *pt;
    GFFLT *val;
    line16_line *line;

    l = (page_line16_d *)monolith_page_data_get(pg);

    line = &l->lines[l->selected_line];

    if(l->selected_point < 0) return;

    pt = &line->points[l->selected_point];

    val = NULL;
    switch(n) {
        case 0:
            val = &pt->val;
            break;
        case 1:
            val = &pt->dur;
            break;
        case 2:
            val = &pt->aux[0];
            break;
        case 3:
            val = &pt->aux[1];
            break;
    }

    if(val == NULL) return;

    *val = line16_increment(*val, delta);

    monolith_arcstate_mapval(l->arcstate, n, *val);
}
<<line16_assign_callbacks>>=
monolith_page_delta_set(pg, line16_delta);



prev | home | next