3. The Main Norns Interface

This is the key interface that should be spawned at startup. It provides an interactive menu for things like selecting pages, quitting/powering off the norns, etc.

3.1. DONE Norns Main Menu Data

CLOSED: [2019-11-23 Sat 13:01] The actual thing you use to start the menu

3.1.1. DONE typedef + struct

CLOSED: [2019-11-22 Fri 20:24]

<<norns_typedefs>>=
typedef struct norns_main_menu norns_main_menu;
<<norns_structs>>=
struct norns_main_menu {
    monolith_d *m;
    norns_menu menu;
    monolith_dict_entry **pglst;
    int npages;
    norns_menu_item *page_items;
<<norns_aux_menu_data>>
};

3.1.2. DONE init + cleanup

CLOSED: [2019-11-22 Fri 20:24]

<<norns_funcdefs>>=
void norns_main_menu_init(norns_main_menu *menu,
                          norns_videobuf *buf,
                          norns_poll_d *poll,
                          monolith_d *m);
<<norns_functions>>=
<<main_menu_functions>>

static norns_menu_item menu_items[] =
{
<<main_menu_items>>
};


void norns_main_menu_init(norns_main_menu *menu,
                          norns_videobuf *buf,
                          norns_poll_d *poll,
                          monolith_d *m)
{
    menu->m = m;
    menu->pglst = NULL;
    menu->npages = 0;
    menu->page_items = NULL;

<<norns_aux_menu_init>>

    norns_menu_init(&menu->menu,
                    "Main Menu",
                    buf,
                    menu_items,
                    sizeof(menu_items)/sizeof(*menu_items),
                    poll,
                    menu);
}
<<norns_funcdefs>>=
void norns_main_menu_clean(norns_main_menu *menu);
<<norns_functions>>=
void norns_main_menu_clean(norns_main_menu *menu)
{
    if (menu->pglst != NULL) {
        monolith_pagelist_destroy(&menu->pglst);
        menu->pglst = NULL;
    }

    if (menu->page_items != NULL) {
        free(menu->page_items);
        menu->page_items = NULL;
    }
}

3.2. DONE Norns Main Menu Items

CLOSED: [2020-04-05 Sun 22:08] These are the menu items for the main norns menu.

3.2.1. DONE (Re-)selecting the Main Menu

CLOSED: [2019-11-23 Sat 13:48] reselects and populates the main menu

<<norns_funcdefs>>=
void norns_main_menu_select(norns_main_menu *menu);
<<norns_functions>>=
void norns_main_menu_select(norns_main_menu *menu)
{
    norns_menu_reinit(&menu->menu,
                      "Main Menu",
                      menu_items,
                      sizeof(menu_items)/sizeof(*menu_items),
                      menu);
}

3.2.2. DONE Power Off

CLOSED: [2019-11-23 Sat 13:03] Runs /sbin/poweroff.

<<main_menu_items>>=
{"poweroff", menu_poweroff},
<<main_menu_functions>>=
void monolith_norns_draw(monolith_d *m);
static void menu_poweroff(norns_menu *menu, int val)
{
    norns_videobuf *vb;
    monolith_d *m;

    vb = menu->buf;
    norns_videobuf_clear(vb);
    norns_draw_string(vb, 63 - (8*2), 28, 0x20, 0x00, "bye.");
    m = monolith_data_get();
    monolith_norns_draw(m);
    monolith_audio_stop(m);
    system("/sbin/poweroff");
}

3.2.3. DONE Quitting

CLOSED: [2019-11-23 Sat 13:10] Just quits, allowing for it to be started from a host computer.

<<main_menu_items>>=
{"quit", menu_quit},
<<main_menu_functions>>=
void monolith_norns_quit(monolith_d *m);
static void menu_quit(norns_menu *menu, int val)
{
    norns_videobuf *vb;
    norns_main_menu *mm;

    vb = menu->buf;
    mm = menu->ud;
    norns_videobuf_clear(vb);
    norns_draw_string(vb, 63 - (4*5), 28, 0x20, 0x00, "quit.");
    monolith_norns_quit(mm->m);
    monolith_norns_draw(monolith_data_get());
}

3.2.4. DONE Page Selection

CLOSED: [2019-11-23 Sat 18:42]

3.2.4.1. Menu Item

<<main_menu_items>>=
{"page select...", menu_page_select},
<<main_menu_functions>>=
static void menu_page_select(norns_menu *menu, int val)
{
    norns_videobuf *vb;
    norns_main_menu *mm;

    vb = menu->buf;
    mm = menu->ud;
    norns_videobuf_clear(vb);
    norns_main_menu_pagelist_select(mm);
    norns_menu_draw(menu);
    monolith_norns_draw(monolith_data_get());
}
3.2.4.2. DONE Selecting the Page Selector

CLOSED: [2019-11-23 Sat 18:41]

<<norns_funcdefs>>=
void norns_main_menu_pagelist_select(norns_main_menu *menu);

return_to_main is a callback that returns to the main menu screen. This is not only called in the page selection menu, but also the aux menu. For the latter, the menu will set the aux_menu flag to be 0 (as seen in <>)

<<norns_functions>>=
norns_poll_d * monolith_norns_poll(monolith_d *m);
static void return_to_main(norns_menu *menu, int pos)
{
    norns_main_menu *mm;
    norns_poll_d *poll;

    mm = menu->ud;
    norns_main_menu_select(mm);
    norns_menu_draw(menu);
    monolith_norns_draw(monolith_data_get());
<<aux_menu_return>>
    poll = monolith_norns_poll(mm->m);
    norns_menu_callbacks(menu, poll);

    /* if (mm->page_items != NULL) { */
    /*     norns_menu_item *page_items; */
    /*     page_items = mm->page_items; */
    /*     mm->page_items = NULL; */
    /*     mm->npages = 0; */
    /*     free(page_items); */
    /* } */

    /* if (mm->pglst != NULL) { */
    /*     monolith_pagelist_destroy(&mm->pglst); */
    /*     mm->pglst = NULL; */
    /* } */
}

static void select_page(norns_menu *menu, int pos)
{
    norns_main_menu *mm;
    monolith_page *pg;

    mm = menu->ud;

    /* Don't free stuff here for now. Later, maybe. */

    /* if (mm->page_items != NULL) { */
    /*     free(mm->page_items); */
    /*     mm->page_items = NULL; */
    /* } */

    /* if (menu->pglst != NULL) { */
    /*     monolith_pagelist_destroy(&menu->pglst); */
    /*     menu->pglst = NULL; */
    /* } */

    pg = monolith_dict_entry_page(mm->pglst[pos - 1]);
    monolith_curpage_set(mm->m, pg);
}

void norns_main_menu_pagelist_select(norns_main_menu *menu)
{
    int i;
    int sz;

    if (menu->page_items != NULL) {
        free(menu->page_items);
        menu->page_items = NULL;
    }

    if (menu->pglst != NULL) {
        monolith_pagelist_destroy(&menu->pglst);
        menu->pglst = NULL;
    }

    menu->npages = 0;
    monolith_pagelist_create(menu->m, &menu->pglst, &menu->npages);
    monolith_pagelist_sort(menu->pglst, menu->npages);

    sz = menu->npages + 1;
    menu->page_items = calloc(1,
                              sizeof(norns_menu_item) * sz);
    menu->page_items[0].name = "_ Main Menu";
    menu->page_items[0].select = return_to_main;

    for (i = 1; i < sz; i++) {
        menu->page_items[i].name =
            monolith_dict_entry_key(menu->pglst[i - 1]);
        menu->page_items[i].select = select_page;
    }

    norns_menu_reinit(&menu->menu,
                      "Page Selector",
                      menu->page_items,
                      sz,
                      menu);
}

3.2.5. WIP Aux Menu

<<main_menu_items>>=
{"aux...", menu_page_aux},

TODO: implement.

<<main_menu_functions>>=
static void menu_page_aux(norns_menu *menu, int val)
{
    norns_videobuf *vb;
    norns_main_menu *mm;

    vb = menu->buf;
    mm = menu->ud;
    norns_videobuf_clear(vb);
    norns_aux_menu_select(mm);
    norns_menu_janet_draw(menu, mm->aux_items);
    monolith_norns_draw(monolith_data_get());
}

3.3. Main Menu Drawing

<<norns_funcdefs>>=
void norns_main_menu_draw(norns_main_menu *menu);
<<norns_functions>>=
void norns_main_menu_draw(norns_main_menu *menu)
{
    norns_menu_draw(&menu->menu);
}



prev | home | next