7. Seq16 State Management
7.1. Schema Contents
7.1.1. Steps
The step pattern data, encoded as a msgpack blob of 16 8-bit ints.
<<seq16_schema_generation>>=
monolith_param_mkblob(*schema, 0,
"steps", 5,
NULL, 0, NULL);
7.1.1.1. msgpack generation
7.1.1.1.1. Write
<<seq16_function_declarations>>=
static int seq16_data_write_seq(cmp_ctx_t *c, uint8_t *vals);
<<seq16_functions>>=
static int seq16_data_write_seq(cmp_ctx_t *c, uint8_t *vals)
{
int i;
int rc;
if (!cmp_write_array(c, 16)) return 0;
for (i = 0; i < 16; i++) {
rc = cmp_write_u8(c, vals[i]);
if (!rc) return 0;
}
return 1;
}
7.1.1.1.2. Read
<<seq16_function_declarations>>=
static int seq16_data_read_seq(cmp_ctx_t *c, uint8_t *vals);
<<seq16_functions>>=
static int seq16_data_read_seq(cmp_ctx_t *c, uint8_t *vals)
{
int i;
int rc;
uint32_t size;
if (!cmp_read_array(c, &size)) return 0;
if (size != 16) {
fprintf(stderr,
"size of 16 expected, got %d\n",
size);
return 0;
}
for (i = 0; i < 16; i++) {
rc = cmp_read_u8(c, &vals[i]);
if (!rc) return 0;
}
return 1;
}
7.1.1.2. saving steps blob
<<seq16_data_save>>=
{
cmp_ctx_t cmp;
moncmp_d m;
size_t sz;
uint8_t *buf;
sz = 0;
moncmp_init_getsize(&cmp, &sz);
seq16_data_write_seq(&cmp, seq16->seq);
buf = calloc(1, sz);
moncmp_init_write(&m, &cmp, buf);
seq16_data_write_seq(&cmp, seq16->seq);
monolith_param_setblob_default(schema, 0, buf, sz);
}
7.1.1.3. reading steps blob
<<seq16_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);
seq16_data_read_seq(&cmp, seq16->seq);
}
7.1.2. Size
The set step size of the pattern.
7.1.2.1. Schema Entry
<<seq16_schema_generation>>=
monolith_param_mkint(*schema, 1,
"size", 4,
seq16->size);
7.1.2.2. Reading the Size
<<seq16_data_load>>=
monolith_param_int(schema,
1,
&seq16->size);
7.1.3. Playhead State
7.1.3.1. Schema Entry
<<seq16_schema_generation>>=
monolith_param_mkint(*schema, 2,
"playhead", 8,
seq16->playhead);
7.1.3.2. Reading playhead state
<<seq16_data_load>>=
monolith_param_int(schema,
2,
&seq16->playhead);
7.2. Seq16 Schema Generation
<<seq16_function_declarations>>=
static int seq16_schema(page_seq16_d *seq16,
monolith_state_schema **schema);
<<seq16_functions>>=
static int seq16_schema(page_seq16_d *seq16,
monolith_state_schema **schema)
{
monolith_state_schema_init(schema, 3);
<<seq16_schema_generation>>
return 1;
}
7.3. Seq16 State Save
<<seq16_function_declarations>>=
static int seq16_save(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len);
<<seq16_functions>>=
static int seq16_save(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len)
{
page_seq16_d *seq16;
monolith_state_schema *schema;
seq16 = monolith_page_data_get(pg);
seq16_schema(seq16, &schema);
<<seq16_data_save>>
monolith_state_write_schema(s, schema,
"seq16", 5,
key, len);
monolith_state_schema_cleanup(&schema);
return 1;
}
<<seq16_assign_callbacks>>=
monolith_page_save_set(pg, seq16_save);
7.4. Seq16 State Load
<<seq16_function_declarations>>=
static int seq16_load(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len);
<<seq16_functions>>=
static int seq16_load(monolith_page *pg,
monolith_state *s,
const char *key,
unsigned int len)
{
page_seq16_d *seq16;
monolith_state_schema *schema;
int rc;
monolith_state_schema_init(&schema, 3);
seq16 = monolith_page_data_get(pg);
seq16_schema(seq16, &schema);
rc = monolith_state_read_schema(s, schema,
"seq16", 5,
key, len);
if (rc) {
<<seq16_data_load>>
seq16_redraw(seq16);
}
monolith_state_schema_cleanup(&schema);
return rc;
}
<<seq16_assign_callbacks>>=
monolith_page_load_set(pg, seq16_load);
prev | home | next