8. Trig State Management
8.1. Schema Contents
8.1.1. Cell Pool
Is a representation of all or portions of the cell pool, stored as an array of cells in msgpack.
A cell is an array of 3 components: the cell position, (integer), the command word (uint32), and the data word (uint32).
8.1.1.1. DONE cell pool schema entry
CLOSED: [2020-05-05 Tue 18:24]
<<trig_schema_generation>>=
monolith_param_mkblob(*schema, 0,
"pool", 4,
NULL, 0, NULL);
8.1.1.2. TODO msgpack generation (WIP)
8.1.1.2.1. WIP Write
<<trig_function_declarations>>=
static int write_pool(cmp_ctx_t *c, trig_vm *tvm);
<<trig_functions>>=
static int write_pool(cmp_ctx_t *c, trig_vm *tvm)
{
trig_cell *pool;
int i;
int ncells;
int rc;
ncells = 0;
pool = tvm->cell;
for (i = 0; i < 32; i++) {
if (pool[i].data != 0 || pool[i].cmd != 0) ncells++;
}
if (!cmp_write_array(c, ncells)) return 0;
for (i = 0; i < 32; i++) {
if (pool[i].data != 0 || pool[i].cmd != 0) {
if (!cmp_write_array(c, 3)) return 0;
rc = cmp_write_u8(c, i);
if (!rc) return 0;
rc = cmp_write_u32(c, pool[i].cmd);
if (!rc) return 0;
rc = cmp_write_u32(c, pool[i].data);
if (!rc) return 0;
}
}
return 1;
}
8.1.1.2.2. DONE Read
CLOSED: [2020-05-06 Wed 13:32]
<<trig_function_declarations>>=
static int read_pool(cmp_ctx_t *c, trig_vm *tvm);
<<trig_functions>>=
static int read_pool(cmp_ctx_t *c, trig_vm *tvm)
{
int rc;
uint32_t ncells;
trig_cell *pool;
int i;
pool = tvm->cell;
if (!cmp_read_array(c, &ncells)) return 0;
for (i = 0; i < 32; i++) {
pool[i].data = 0;
pool[i].cmd = 0;
}
for (i = 0; i < ncells; i++) {
uint32_t tmp;
uint32_t dat, cmd;
uint8_t pos;
if (!cmp_read_array(c, &tmp)) return 0;
rc = cmp_read_u8(c, &pos);
if (!rc) return 0;
rc = cmp_read_u32(c, &cmd);
if (!rc) return 0;
rc = cmp_read_u32(c, &dat);
if (!rc) return 0;
pool[pos].cmd = cmd;
pool[pos].data = dat;
}
return 1;
}
8.1.1.3. DONE saving cell pool blob
CLOSED: [2020-05-05 Tue 18:32]
<<trig_data_save>>=
{
cmp_ctx_t cmp;
moncmp_d m;
size_t sz;
uint8_t *buf;
sz = 0;
moncmp_init_getsize(&cmp, &sz);
write_pool(&cmp, &trig->tvm);
/* freed by state_schema_cleanup */
buf = calloc(1, sz);
moncmp_init_write(&m, &cmp, buf);
write_pool(&cmp, &trig->tvm);
monolith_param_setblob_default(schema, 0, buf, sz);
}
8.1.1.4. DONE reading cell pool blob
CLOSED: [2020-05-06 Wed 13:32]
<<trig_data_load>>=
{
size_t sz;
cmp_ctx_t cmp;
uint8_t *buf;
moncmp_d m;
sz = 0;
monolith_param_blob(schema, 0,
(void **)&buf,
(unsigned int *)&sz);
moncmp_init_read(&m, &cmp, buf, sz);
read_pool(&cmp, &trig->tvm);
}
8.1.2. Program Start Position
When the program starts/restarts, where to jump back to. It's just been 0 for now, but it is nice to think ahead.
8.1.2.1. DONE Start Position Schema Entry
CLOSED: [2020-05-05 Tue 18:18]
<<trig_schema_generation>>=
monolith_param_mkint(*schema, 1,
"startpos", 8,
trig->tvm.istate.ipos);
8.1.2.2. DONE Reading Start Position
CLOSED: [2020-05-05 Tue 18:21]
<<trig_data_load>>=
monolith_param_int(schema,
1,
&trig->tvm.istate.ipos);
8.2. Trig Schema Generation
A new sliders schema is created and initialized with the function trig_schema
.
<<trig_function_declarations>>=
static int trig_schema(page_trig_d *trig,
monolith_state_schema **schema);
<<trig_functions>>=
static int trig_schema(page_trig_d *trig,
monolith_state_schema **schema)
{
monolith_state_schema_init(schema, 2);
<<trig_schema_generation>>
return 1;
}
8.3. Trig State Save
<<trig_function_declarations>>=
static int trig_save(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len);
<<trig_functions>>=
static int trig_save(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len)
{
page_trig_d *trig;
monolith_state_schema *schema;
trig = monolith_page_data_get(pg);
trig_schema(trig, &schema);
<<trig_data_save>>
monolith_state_write_schema(s, schema,
"trig", 4,
key, len);
monolith_state_schema_cleanup(&schema);
return 1;
}
<<trig_assign_callbacks>>=
monolith_page_save_set(pg, trig_save);
8.4. Trig State Load
<<trig_function_declarations>>=
static int trig_load(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len);
<<trig_functions>>=
static int trig_load(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len)
{
page_trig_d *trig;
monolith_state_schema *schema;
int rc;
trig = monolith_page_data_get(pg);
trig_schema(trig, &schema);
rc = monolith_state_read_schema(s, schema, "trig", 4, key, len);
if (rc) {
<<trig_data_load>>
redraw(trig);
}
monolith_state_schema_cleanup(&schema);
return rc;
}
<<trig_assign_callbacks>>=
monolith_page_load_set(pg, trig_load);
prev | home | next