4. The Norns Menu Page

Keeping things within the paradigm of monolith, the main norns interface is wrapped inside of a page. This page must be created and selected at startup.

4.1. DONE Creating the page

CLOSED: [2019-11-22 Fri 21:03]

4.1.1. DONE Norns Menu Creation Main

CLOSED: [2019-11-22 Fri 15:14]

<<norns_funcdefs>>=
static void page_norns(monolith_page *pg);
<<norns_functions>>=
norns_framebuffer * monolith_norns_framebuffer(monolith_d *m);
norns_videobuf * monolith_norns_videobuf(monolith_d *m);
norns_poll_d * monolith_norns_poll(monolith_d *m);
static void page_norns(monolith_page *pg)
{
    norns_main_menu *menu;
    monolith_d *m;
    norns_videobuf *buf;
    norns_poll_d *poll;

    menu = calloc(1, sizeof(norns_main_menu));
    if(menu == NULL) return;

    m = monolith_page_monolith(pg);

    buf = monolith_norns_videobuf(m);

    if (buf == NULL) {
        fprintf(stderr, "videobuffer is not initialized\n");
        return;
    }

    poll = monolith_norns_poll(m);

    if (poll == NULL) {
        fprintf(stderr, "event listener is not started\n");
        return;
    }

    norns_main_menu_init(menu, buf, poll, m);
<<norns_assign_callbacks>>
    monolith_page_data_set(pg, menu);
    norns_main_menu_draw(menu);
    {
        norns_framebuffer *fb;
        fb = monolith_norns_framebuffer(m);
        norns_videobuf_copy(buf, fb);
    }
    fprintf(stderr, "Created page norns\n");
}

4.1.2. In C (norns_menu_new)

<<norns_funcdefs>>=
void norns_menu_new(monolith_d *m);

4.1.3. In Janet (monolith/norns-menu-new)

<<norns_janet_entries>>=
{
"monolith/norns-menu-new",
j_norns_menu_new,
"Create a norns menu page."
},
<<norns_janet>>=
static Janet j_norns_menu_new(int32_t argc, Janet *argv)
{
    const char *str;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    int rc;

    janet_fixarity(argc, 1);
    m = monolith_data_get();
    dict = monolith_dict_get(m);

    str = (const char *)janet_unwrap_string(argv[0]);
    rc = monolith_dict_newpage(dict, &pg, str, strlen(str));

    if (!rc) {
        printf("Could not create norns page %s "
               "(maybe it already exists?)",
               str);
        return janet_wrap_nil();
    }

    page_norns(pg);
    return janet_wrap_nil();
}

4.2. DONE Norns Menu Page Creation

CLOSED: [2020-04-10 Fri 20:57]

4.2.1. DONE Norns Open

CLOSED: [2020-04-10 Fri 20:57]

<<norns_funcdefs>>=
static void norns_open(monolith_page *pg);
<<norns_functions>>=
static void norns_open(monolith_page *pg)
{
    fprintf(stderr, "Norns page open\n");
}
<<norns_assign_callbacks>>=
monolith_page_open_set(pg, norns_open);

4.2.2. DONE Norns Free

CLOSED: [2019-11-22 Fri 15:14]

<<norns_funcdefs>>=
static void norns_free(monolith_page *pg);
<<norns_functions>>=
static void norns_free(monolith_page *pg)
{
    norns_main_menu *menu;
    menu = (norns_main_menu *)monolith_page_data_get(pg);
    if(menu == NULL) return;
    norns_main_menu_clean(menu);
    free(menu);
}
<<norns_assign_callbacks>>=
monolith_page_free_set(pg, norns_free);



prev | home | next