feat: sequence window, finer timeline, zone brightness to Wi-Fi drivers

- A sequence's length is a fixed window (window_beats / window_seconds), not its presets.
  The timeline is exactly the window long; clips past it are cut on save.
- The ruler adds finer ticks when zoomed in; Snap has Auto (follows the zoom), 0.25 s and 0.05 s.
  Steps and the window go down to 50 ms.
- Ctrl+wheel zooms around the pointer; the zoom buttons zoom around the last pointer position.
- Sequence start and the zone brightness slider reach Wi-Fi drivers (matched by hostname or MAC).
- A preset select with brightness also sends the brightness to Wi-Fi drivers, as ESP-NOW does.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Haiku 5.5 committed 2026-11-16 21:22:17 +13:00
1 parent 581b751904
commit a1c8ce853b
21 files changed
+419 -318

No files matched your search

+30 -1
View File
@@ -342,9 +342,11 @@ static bool wifi_selected(const cJSON *dev, const char *id, const cJSON *targets
{
if (cJSON_IsArray(targets) && cJSON_GetArraySize(targets) > 0) {
const cJSON *t;
// A Wi-Fi driver is named by its hostname, or by its MAC when the UI resolved the device to one
const cJSON *dmac = cJSON_GetObjectItem(dev, "mac");
cJSON_ArrayForEach(t, targets)
{
if (cJSON_IsString(t) && !strcmp(t->valuestring, id)) {
if (cJSON_IsString(t) && (!strcmp(t->valuestring, id) || (cJSON_IsString(dmac) && !strcasecmp(t->valuestring, dmac->valuestring)))) {
return true;
}
}
@@ -422,6 +424,12 @@ static void wifi_push(const cJSON *m, const cJSON *targets)
cJSON_AddTrueToObject(body, "select"); // a select restarts the pattern and fades in (fade)
wifi_drv_post(id, "/api/pattern", body);
}
// ESP-NOW carries b in the same frame as the select; the Wi-Fi driver takes it in its own call
if (cJSON_IsNumber(b)) {
cJSON *bb = cJSON_CreateObject();
cJSON_AddNumberToObject(bb, "brightness", b->valuedouble);
wifi_drv_post(id, "/api/brightness", bb);
}
}
}
@@ -553,6 +561,27 @@ const char *engine_zone_current(const char *zone_id)
return NULL;
}
int engine_zone_wifi_ids(const char *zone_id, char out[][GROUP_ID_MAX], int max)
{
char t[ZONE_TARGETS_MAX][GROUP_ID_MAX];
int nt = engine_zone_targets(zone_id, t, ZONE_TARGETS_MAX);
int n = 0;
const cJSON *d;
cJSON_ArrayForEach(d, store_coll("device"))
{
if (!d->string || !is_wifi(d)) {
continue;
}
for (int i = 0; i < nt && n < max; i++) {
if (wifi_in_group(d, d->string, t[i])) {
snprintf(out[n++], GROUP_ID_MAX, "%s", d->string);
break;
}
}
}
return n;
}
int engine_group_macs(const char *gid, char out[][13], int max)
{
int n = 0;
+2
View File
@@ -22,6 +22,8 @@ cJSON *engine_preset_payload(const char *preset_id);
// Drivers in group gid (a group id, "z<zone>" or a driver's own "d<mac>"), as 12-hex MACs from the
// device list. Call with the store locked.
int engine_group_macs(const char *gid, char out[][13], int max);
// Wi-Fi drivers (listed by hostname) in the zone's groups. Call with the store locked.
int engine_zone_wifi_ids(const char *zone_id, char out[][GROUP_ID_MAX], int max);
// The preset a zone last played (engine_play / engine_stop), or NULL. Call with the store locked.
const char *engine_zone_current(const char *zone_id);
// Record preset_id as what zone_id plays, when the UI has sent it to the drivers itself
+3 -1
View File
@@ -420,7 +420,9 @@ int api_effective_brightness(const char *mac, int zone_b)
cJSON_ArrayForEach(it, cJSON_GetObjectItem(g, "devices"))
{
char m[13];
if (api_mac(it, m) && !strcmp(m, mac)) {
// A Wi-Fi driver is listed by its hostname, not a MAC
bool same = (api_mac(it, m) && !strcmp(m, mac)) || (cJSON_IsString(it) && !strcmp(it->valuestring, mac));
if (same) {
v *= clamp255(cJSON_GetObjectItem(g, "output_brightness"), 255) / 255.0;
double c = clamp255(cJSON_GetObjectItem(g, "max_brightness"), 255) / 255.0;
if (c < cap) {
+32 -11
View File
@@ -568,7 +568,7 @@ static int load_lanes(player_t *p, const cJSON *seq)
double beats = num(s, "beats", 1);
beats = beats < 0.25 ? 1 : beats;
double secs = num(s, "seconds", 3);
secs = secs < 0.1 ? 0.1 : (secs > 3600 ? 3600 : secs);
secs = secs < 0.05 ? 0.05 : (secs > 3600 ? 3600 : secs);
if (st->anim && str_is(s, "length", "animation")) {
seqplay_length(st->id, &beats, &secs);
}
@@ -617,6 +617,21 @@ static void clear_drivers(const char *zone)
}
}
// One driver's combined brightness, sent as a v1 brightness message (ESP-NOW by MAC, Wi-Fi by hostname)
static void zone_brightness_push(const char *id, int zone_b)
{
cJSON *m = cJSON_CreateObject();
cJSON_AddStringToObject(m, "v", "1");
cJSON_AddNumberToObject(m, "b", api_effective_brightness(id, zone_b));
cJSON_AddTrueToObject(m, "save");
cJSON *messages = cJSON_CreateArray(), *targets = cJSON_CreateArray();
cJSON_AddItemToArray(messages, m);
cJSON_AddItemToArray(targets, cJSON_CreateString(id));
engine_push(messages, targets);
cJSON_Delete(messages);
cJSON_Delete(targets);
}
// Every driver the zone reaches gets its combined brightness with the zone's slider value
static void zone_brightness(const char *zone_id)
{
@@ -635,16 +650,13 @@ static void zone_brightness(const char *zone_id)
}
}
for (int i = 0; i < macs.n; i++) {
cJSON *m = cJSON_CreateObject();
cJSON_AddStringToObject(m, "v", "1");
cJSON_AddNumberToObject(m, "b", api_effective_brightness(macs.m[i], zone_b));
cJSON_AddTrueToObject(m, "save");
cJSON *messages = cJSON_CreateArray(), *targets = cJSON_CreateArray();
cJSON_AddItemToArray(messages, m);
cJSON_AddItemToArray(targets, cJSON_CreateString(macs.m[i]));
engine_push(messages, targets);
cJSON_Delete(messages);
cJSON_Delete(targets);
zone_brightness_push(macs.m[i], zone_b);
}
// Wi-Fi drivers are listed by hostname, so they are not among the MACs above
char w[MACS_MAX][GROUP_ID_MAX];
int nw = engine_zone_wifi_ids(zone_id, w, MACS_MAX);
for (int i = 0; i < nw; i++) {
zone_brightness_push(w[i], zone_b);
}
}
@@ -1246,6 +1258,15 @@ bool seqplay_sync(const char *mode)
void seqplay_length(const char *seq_id, double *beats, double *secs)
{
const cJSON *seq = cJSON_GetObjectItem(store_coll("sequence"), seq_id);
// The window is the sequence's length, whatever its presets run for (the editor pads every lane to it).
// Records saved before windows fall through to the lanes.
const cJSON *wb = cJSON_GetObjectItem(seq, "window_beats");
const cJSON *ws = cJSON_GetObjectItem(seq, "window_seconds");
if (cJSON_IsNumber(wb) && cJSON_IsNumber(ws) && wb->valuedouble > 0 && ws->valuedouble > 0) {
*beats = wb->valuedouble;
*secs = ws->valuedouble;
return;
}
const cJSON *opts = cJSON_GetObjectItem(seq, "lane_opts");
bool seq_timed = seq_oneshot(seq) || str_is(seq, "advance_mode", "time");
double b = 0, s = 0;