feat: sequences v2, bridges, and sim-controller
Rework sequences (engine, seqplay, envelope, API, web UI), add bridge support, add the host sim-controller and rig simulation tests, and update docs, presets and project tooling config. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d664026ee5
commit
2543673bd8
68 files changed
+5761
-460
No files matched your search
+59
-14
@@ -1,6 +1,7 @@
|
||||
// Import/export bundles: main's util/profile_bundle.py. A profile bundle carries the profile, its
|
||||
// palette colours, zones, the presets they use and their sequences; preset and sequence bundles carry
|
||||
// one record (a sequence with its presets). Imports get new ids and belong to the importing profile.
|
||||
// one record (a sequence with its presets). Animations are sequences with kind "animation"; a profile
|
||||
// bundle carries the ones its zones and sequence steps fire. Imports get new ids and belong to the importing profile.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -50,6 +51,54 @@ static void sequence_preset_ids(const cJSON *seq, cJSON *set)
|
||||
}
|
||||
}
|
||||
|
||||
// Animations (sequences played once) that steps of seq fire
|
||||
static void sequence_animation_ids(const cJSON *seq, cJSON *set)
|
||||
{
|
||||
const cJSON *lane, *step;
|
||||
cJSON_ArrayForEach(lane, cJSON_GetObjectItem(seq, "lanes"))
|
||||
{
|
||||
cJSON_ArrayForEach(step, lane)
|
||||
{
|
||||
add_ref(set, cJSON_GetObjectItem(step, "animation_id"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Point a list field (or each step's animation_id) at the new sequence ids
|
||||
static void remap_ids(cJSON *rec, const char *key, const cJSON *smap)
|
||||
{
|
||||
cJSON *list = cJSON_GetObjectItem(rec, key);
|
||||
if (!cJSON_IsArray(list)) {
|
||||
return;
|
||||
}
|
||||
cJSON *mapped = cJSON_CreateArray(), *it;
|
||||
cJSON_ArrayForEach(it, list)
|
||||
{
|
||||
char k[24];
|
||||
if (api_id(it, k, sizeof(k))) {
|
||||
const cJSON *ns = cJSON_GetObjectItem(smap, k);
|
||||
cJSON_AddItemToArray(mapped, cJSON_CreateString(ns ? ns->valuestring : k));
|
||||
}
|
||||
}
|
||||
api_set(rec, key, mapped);
|
||||
}
|
||||
|
||||
static void remap_animation_steps(cJSON *seq, const cJSON *smap)
|
||||
{
|
||||
cJSON *lane, *step;
|
||||
cJSON_ArrayForEach(lane, cJSON_GetObjectItem(seq, "lanes"))
|
||||
{
|
||||
cJSON_ArrayForEach(step, lane)
|
||||
{
|
||||
char k[24];
|
||||
const cJSON *ns = api_id(cJSON_GetObjectItem(step, "animation_id"), k, sizeof(k)) ? cJSON_GetObjectItem(smap, k) : NULL;
|
||||
if (ns) {
|
||||
api_set(step, "animation_id", cJSON_CreateString(ns->valuestring));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool owned_by(const cJSON *rec, const char *profile)
|
||||
{
|
||||
char pid[24];
|
||||
@@ -107,6 +156,7 @@ static cJSON *export_profile(const char *id)
|
||||
cJSON_AddItemToObject(zones, key, cJSON_Duplicate(z, true));
|
||||
zone_preset_ids(z, pset);
|
||||
add_ref(sset, cJSON_GetObjectItem(z, "sequence_ids"));
|
||||
add_ref(sset, cJSON_GetObjectItem(z, "animation_ids"));
|
||||
}
|
||||
const cJSON *it;
|
||||
cJSON_ArrayForEach(it, sset)
|
||||
@@ -115,6 +165,7 @@ static cJSON *export_profile(const char *id)
|
||||
if (s && owned_by(s, id)) {
|
||||
cJSON_AddItemToObject(seqs, it->string, cJSON_Duplicate(s, true));
|
||||
sequence_preset_ids(s, pset);
|
||||
sequence_animation_ids(s, sset); // appended, so this loop reaches them too
|
||||
}
|
||||
}
|
||||
cJSON_ArrayForEach(it, pset)
|
||||
@@ -249,6 +300,11 @@ static const char *import_profile(const cJSON *b, const char *name, char *pid, s
|
||||
api_add("sequence", copy, nid, sizeof(nid));
|
||||
cJSON_AddStringToObject(smap, s->string, nid);
|
||||
}
|
||||
cJSON *imported;
|
||||
cJSON_ArrayForEach(imported, smap)
|
||||
{
|
||||
remap_animation_steps(cJSON_GetObjectItem(store_coll("sequence"), imported->valuestring), smap);
|
||||
}
|
||||
|
||||
const cJSON *zones_in = cJSON_GetObjectItem(b, "zones");
|
||||
const cJSON *order = cJSON_GetObjectItem(src, "zones");
|
||||
@@ -293,19 +349,8 @@ static const char *import_profile(const cJSON *b, const char *name, char *pid, s
|
||||
if (to) {
|
||||
api_set(copy, "default_preset", cJSON_Duplicate(to, false));
|
||||
}
|
||||
const cJSON *sids = cJSON_GetObjectItem(z, "sequence_ids");
|
||||
if (cJSON_IsArray(sids)) {
|
||||
cJSON *mapped = cJSON_CreateArray(), *sid;
|
||||
cJSON_ArrayForEach(sid, sids)
|
||||
{
|
||||
char k[24];
|
||||
if (api_id(sid, k, sizeof(k))) {
|
||||
const cJSON *ns = cJSON_GetObjectItem(smap, k);
|
||||
cJSON_AddItemToArray(mapped, cJSON_CreateString(ns ? ns->valuestring : k));
|
||||
}
|
||||
}
|
||||
api_set(copy, "sequence_ids", mapped);
|
||||
}
|
||||
remap_ids(copy, "sequence_ids", smap);
|
||||
remap_ids(copy, "animation_ids", smap);
|
||||
char nid[16];
|
||||
api_add("zone", copy, nid, sizeof(nid));
|
||||
cJSON_AddItemToArray(zone_ids, cJSON_CreateString(nid));
|
||||
|
||||
Reference in new issue
Block a user