4. Grid Page Creation

A page is created with the function page_grid. This will take in a newly initialized monolith page, and then assigns callback functions.

The Grid page only requires use of the monome, so the press callback is the only thing required.

<<grid_function_declarations>>=
static void page_grid(monolith_page *pg);
<<grid_functions>>=
static void page_grid(monolith_page *pg)
{
    page_grid_d *grid;
    grid = calloc(1, sizeof(page_grid_d));
    if(grid == NULL) return;
    if(grid_type == 0) grid_init(monolith_page_monolith(pg));
    if(!monolith_page_mstate_new(pg, &grid->mstate)) return;
<<grid_assign_callbacks>>
    monolith_page_data_set(pg, grid);
}

4.1. Setting the Grid Type Flag

<<grid_assign_callbacks>>=
monolith_page_type_set(pg, grid_type);

4.2. Grid Open

<<grid_function_declarations>>=
static void grid_open(monolith_page *pg);
<<grid_functions>>=
static void grid_open(monolith_page *pg)
{
    page_grid_d *grid;
    grid = monolith_page_data_get(pg);
    if(grid == NULL) return;
    monolith_page_mstate_recall(grid->mstate);
}
<<grid_assign_callbacks>>=
monolith_page_open_set(pg, grid_open);

4.3. Grid Free

<<grid_function_declarations>>=
static void grid_free(monolith_page *pg);
<<grid_functions>>=
static void grid_free(monolith_page *pg)
{
    page_grid_d *grid;
    grid = (page_grid_d *)monolith_page_data_get(pg);
    if(grid == NULL) return;
    monolith_page_mstate_free(&grid->mstate);
    free(grid);
}
<<grid_assign_callbacks>>=
monolith_page_free_set(pg, grid_free);

4.4. Monome Press Callback

<<grid_function_declarations>>=
static void grid_press(monolith_page *pg, int x, int y, int s);
<<grid_functions>>=
static void grid_press(monolith_page *pg, int x, int y, int s)
{
    page_grid_d *grid;
    int curstate;
    if(s == 0) return;
    grid = monolith_page_data_get(pg);
    if(grid == NULL) return;

    curstate = monolith_page_mstate_get(grid->mstate, x, y);

    if(curstate) {
        monolith_page_mstate_set(grid->mstate, x, y, 0);
    } else {
        monolith_page_mstate_set(grid->mstate, x, y, 1);
    }
}
<<grid_assign_callbacks>>=
monolith_page_press_set(pg, grid_press);

4.5. TODO State Management

4.5.1. DONE Schema Generation

CLOSED: [2019-04-06 Sat 11:03] The Schema for the "grid" page is pretty straightforward. All it needs to save is the monome state.

<<grid_function_declarations>>=
static int grid_schema(page_grid_d *grid,
                       monolith_state_schema **schema);
<<grid_functions>>=
static int grid_schema(page_grid_d *grid,
                       monolith_state_schema **schema)
{
    monolith_state_schema_init(schema, 1);
    monolith_param_mkmstate(*schema, 0, "mstate", 6, grid->mstate);
    return 1;
}

4.5.2. TODO Grid Save Callback

<<grid_function_declarations>>=
static int grid_save(monolith_page *pg,
                     monolith_state *s,
                     const char *key,
                     unsigned int len);
<<grid_functions>>=
static int grid_save(monolith_page *pg,
                     monolith_state *s,
                     const char *key,
                     unsigned int len)
{
    page_grid_d *grid;
    monolith_state_schema *schema;
    grid = monolith_page_data_get(pg);
    grid_schema(grid, &schema);
    monolith_state_write_schema(s, schema, "grid", 4, key, len);
    monolith_state_schema_cleanup(&schema);
    return 1;
}
<<grid_assign_callbacks>>=
monolith_page_save_set(pg, grid_save);

4.5.3. TODO Grid Load Callback

<<grid_function_declarations>>=
static int grid_load(monolith_page *pg,
                     monolith_state *s,
                     const char *key,
                     unsigned int len);
<<grid_functions>>=
static int grid_load(monolith_page *pg,
                     monolith_state *s,
                     const char *key,
                     unsigned int len)
{
    page_grid_d *grid;
    monolith_state_schema *schema;
    int rc;
    grid = monolith_page_data_get(pg);

    grid_schema(grid, &schema);
    rc = monolith_state_read_schema(s, schema, "grid", 4, key, len);
    monolith_param_mstate(schema, 0, grid->mstate);
    if(monolith_page_selected(pg)) monolith_page_mstate_recall(grid->mstate);
    monolith_state_schema_cleanup(&schema);
    return rc;
}
<<grid_assign_callbacks>>=
monolith_page_load_set(pg, grid_load);



prev | home | next