feat: sequences can step on time; searchable group pickers
- Sequences: advance_mode "time" makes each step last its `seconds` (0.1–3600) instead of beats; editor gets a "Steps last" selector. - UI: search box in the groups modal; searchable add pickers for zone groups and presets. - Preset "try" sends only to the current zone's groups, never broadcast. - led-driver: max_brightness ceiling from device config; follow a controller that restarted its beat counter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
38162d4b89
commit
d664026ee5
10 files changed
+225
-88
No files matched your search
+2
-2
@@ -168,7 +168,7 @@ A device is `{id: MAC, name, type: "led", transport: "espnow" | "wifi", address,
|
|||||||
|
|
||||||
## Sequences — `/sequences`
|
## Sequences — `/sequences`
|
||||||
|
|
||||||
A sequence is `{name, profile_id, lanes: [[step, ...], ...], lanes_group_ids: [[group ids], ...], group_ids, loop (default true), advance_mode: "beats", steps, step_duration_ms, sequence_transition}`. A step is `{preset_id, beats (default 1), group_ids?}`.
|
A sequence is `{name, profile_id, lanes: [[step, ...], ...], lanes_group_ids: [[group ids], ...], group_ids, loop (default true), advance_mode: "beats" | "time", steps, step_duration_ms, sequence_transition}`. A step is `{preset_id, beats (default 1), seconds (default 3, 0.1–3600), group_ids?}`. With `advance_mode` `beats` a step lasts `beats` beats; with `time` it lasts `seconds`.
|
||||||
|
|
||||||
| Method | Path | Description |
|
| Method | Path | Description |
|
||||||
|--------|------|-------------|
|
|--------|------|-------------|
|
||||||
@@ -186,7 +186,7 @@ A sequence is `{name, profile_id, lanes: [[step, ...], ...], lanes_group_ids: [[
|
|||||||
|
|
||||||
**Playback.** One sequence plays at a time, in one zone.
|
**Playback.** One sequence plays at a time, in one zone.
|
||||||
- **Start.** Each lane's first preset is uploaded to the lane's groups and selected, then the lane's other presets are uploaded, and every driver in the zone gets its combined brightness with the zone slider.
|
- **Start.** Each lane's first preset is uploaded to the lane's groups and selected, then the lane's other presets are uploaded, and every driver in the zone gets its combined brightness with the zone slider.
|
||||||
- **Advancing.** On each beat a lane counts towards its step's `beats`, then moves on: the next preset is uploaded (unless already there) and selected. A lane's groups are `lanes_group_ids[lane]`, else `group_ids`, else (single lane) the step's `group_ids`, else the zone's groups.
|
- **Advancing.** In `time` mode a lane moves on when its step's `seconds` are up, whatever the beat; the status then has `lane0_step_elapsed_ms` and `lane0_step_duration_ms` and `beat_readout` is empty. In `beats` mode, on each beat a lane counts towards its step's `beats`, then moves on: the next preset is uploaded (unless already there) and selected. A lane's groups are `lanes_group_ids[lane]`, else `group_ids`, else (single lane) the step's `group_ids`, else the zone's groups.
|
||||||
- **End.** Without `loop` the sequence ends after one pass. Its presets are cleared from the zone's groups, and the readout keeps `n/n`.
|
- **End.** Without `loop` the sequence ends after one pass. Its presets are cleared from the zone's groups, and the readout keeps `n/n`.
|
||||||
- **Switching.** Starting another sequence while one plays waits for the next beat. It waits for the next downbeat only when `sequence_switch_wait` is `downbeat` and the mic is timing. The current sequence holds meanwhile.
|
- **Switching.** Starting another sequence while one plays waits for the next beat. It waits for the next downbeat only when `sequence_switch_wait` is `downbeat` and the mic is timing. The current sequence holds meanwhile.
|
||||||
- **Beat source.** Beats come from the mic's beat detector while audio timing is on (`/api/audio/start`) and it has a tempo lock. Otherwise they come from a clock at `audio_simulated_bpm`, whose beats also go to the drivers. Beats closer than 0.3 s (200 BPM) are dropped.
|
- **Beat source.** Beats come from the mic's beat detector while audio timing is on (`/api/audio/start`) and it has a tempo lock. Otherwise they come from a clock at `audio_simulated_bpm`, whose beats also go to the drivers. Beats closer than 0.3 s (200 BPM) are dropped.
|
||||||
|
|||||||
+1
-1
Submodule led-driver updated: 495da4e366...97df6e3cbe.
+1
-1
@@ -135,7 +135,7 @@ static bool migrate_seq(cJSON *doc, const char *default_profile)
|
|||||||
for (size_t i = 0; i < sizeof(DEFAULT_KEYS) / sizeof(DEFAULT_KEYS[0]); i++) {
|
for (size_t i = 0; i < sizeof(DEFAULT_KEYS) / sizeof(DEFAULT_KEYS[0]); i++) {
|
||||||
const cJSON *v = cJSON_GetObjectItem(doc, DEFAULT_KEYS[i]);
|
const cJSON *v = cJSON_GetObjectItem(doc, DEFAULT_KEYS[i]);
|
||||||
bool bad = !v || (!strcmp(DEFAULT_KEYS[i], "group_ids") && !cJSON_IsArray(v)) ||
|
bool bad = !v || (!strcmp(DEFAULT_KEYS[i], "group_ids") && !cJSON_IsArray(v)) ||
|
||||||
(!strcmp(DEFAULT_KEYS[i], "advance_mode") && !(cJSON_IsString(v) && !strcmp(v->valuestring, "beats")));
|
(!strcmp(DEFAULT_KEYS[i], "advance_mode") && !(cJSON_IsString(v) && (!strcmp(v->valuestring, "beats") || !strcmp(v->valuestring, "time"))));
|
||||||
if (bad) {
|
if (bad) {
|
||||||
api_set(doc, DEFAULT_KEYS[i], cJSON_Duplicate(cJSON_GetObjectItem(defs, DEFAULT_KEYS[i]), true));
|
api_set(doc, DEFAULT_KEYS[i], cJSON_Duplicate(cJSON_GetObjectItem(defs, DEFAULT_KEYS[i]), true));
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|||||||
+85
-33
@@ -28,6 +28,7 @@ static const char *TAG = "seqplay";
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char preset[ID_MAX];
|
char preset[ID_MAX];
|
||||||
int beats;
|
int beats;
|
||||||
|
int ms; // time mode: how long the step plays
|
||||||
char group_ids[4][GROUP_ID_MAX]; // a single lane's step may carry its own groups
|
char group_ids[4][GROUP_ID_MAX]; // a single lane's step may carry its own groups
|
||||||
int ngroups;
|
int ngroups;
|
||||||
} step_t;
|
} step_t;
|
||||||
@@ -35,6 +36,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
step_t step[STEPS_MAX];
|
step_t step[STEPS_MAX];
|
||||||
int n, idx, count;
|
int n, idx, count;
|
||||||
|
int64_t t0; // time mode: when the step started (us)
|
||||||
bool done;
|
bool done;
|
||||||
char last[ID_MAX]; // preset last uploaded for this lane
|
char last[ID_MAX]; // preset last uploaded for this lane
|
||||||
} lane_t;
|
} lane_t;
|
||||||
@@ -47,6 +49,7 @@ static struct {
|
|||||||
lane_t *lane;
|
lane_t *lane;
|
||||||
int nlanes;
|
int nlanes;
|
||||||
bool loop;
|
bool loop;
|
||||||
|
bool timed; // steps last seconds, not beats
|
||||||
int loop_beat;
|
int loop_beat;
|
||||||
bool anchor_on_pass_start;
|
bool anchor_on_pass_start;
|
||||||
bool pending_switch; // a queued start takes over on the next beat; stop advancing meanwhile
|
bool pending_switch; // a queued start takes over on the next beat; stop advancing meanwhile
|
||||||
@@ -287,6 +290,9 @@ static int load_lanes(const cJSON *seq)
|
|||||||
api_id(pid ? pid : cJSON_GetObjectItem(s, "presetId"), st->preset, sizeof(st->preset));
|
api_id(pid ? pid : cJSON_GetObjectItem(s, "presetId"), st->preset, sizeof(st->preset));
|
||||||
const cJSON *b = cJSON_GetObjectItem(s, "beats");
|
const cJSON *b = cJSON_GetObjectItem(s, "beats");
|
||||||
st->beats = cJSON_IsNumber(b) && b->valuedouble >= 1 ? (int)b->valuedouble : 1;
|
st->beats = cJSON_IsNumber(b) && b->valuedouble >= 1 ? (int)b->valuedouble : 1;
|
||||||
|
const cJSON *sec = cJSON_GetObjectItem(s, "seconds");
|
||||||
|
double secs = cJSON_IsNumber(sec) ? sec->valuedouble : 3.0;
|
||||||
|
st->ms = secs < 0.1 ? 100 : (secs > 3600 ? 3600000 : (int)(secs * 1000));
|
||||||
const cJSON *g;
|
const cJSON *g;
|
||||||
cJSON_ArrayForEach(g, cJSON_GetObjectItem(s, "group_ids"))
|
cJSON_ArrayForEach(g, cJSON_GetObjectItem(s, "group_ids"))
|
||||||
{
|
{
|
||||||
@@ -351,6 +357,12 @@ static esp_err_t start_now(const char *seq_id, const char *zone_id, const char *
|
|||||||
}
|
}
|
||||||
const cJSON *loop = cJSON_GetObjectItem(seq, "loop");
|
const cJSON *loop = cJSON_GetObjectItem(seq, "loop");
|
||||||
s_run.loop = !loop || cJSON_IsTrue(loop) || (cJSON_IsNumber(loop) && loop->valuedouble != 0);
|
s_run.loop = !loop || cJSON_IsTrue(loop) || (cJSON_IsNumber(loop) && loop->valuedouble != 0);
|
||||||
|
const cJSON *mode = cJSON_GetObjectItem(seq, "advance_mode");
|
||||||
|
s_run.timed = cJSON_IsString(mode) && !strcmp(mode->valuestring, "time");
|
||||||
|
int64_t t_start = esp_timer_get_time();
|
||||||
|
for (int i = 0; i < s_run.nlanes; i++) {
|
||||||
|
s_run.lane[i].t0 = t_start;
|
||||||
|
}
|
||||||
s_run.loop_beat = 0;
|
s_run.loop_beat = 0;
|
||||||
s_run.pending_switch = false;
|
s_run.pending_switch = false;
|
||||||
s_run.anchor_on_pass_start = handoff ? downbeat : true;
|
s_run.anchor_on_pass_start = handoff ? downbeat : true;
|
||||||
@@ -379,9 +391,63 @@ static bool pass_start(void)
|
|||||||
|
|
||||||
static int readout(char *buf, size_t len); // forward
|
static int readout(char *buf, size_t len); // forward
|
||||||
|
|
||||||
|
// Move a lane on once its step is over. Sets *looped when lane 0 wrapped round.
|
||||||
|
static void step_lane(int i, int64_t now, bool *looped)
|
||||||
|
{
|
||||||
|
lane_t *l = &s_run.lane[i];
|
||||||
|
if (l->idx + 1 >= l->n) {
|
||||||
|
if (s_run.loop) {
|
||||||
|
*looped = *looped || i == 0;
|
||||||
|
l->count = 0;
|
||||||
|
l->idx = 0;
|
||||||
|
l->t0 = now;
|
||||||
|
l->last[0] = 0; // step 0 goes up again on each wrap
|
||||||
|
send_lane(i);
|
||||||
|
} else {
|
||||||
|
l->count = l->step[l->idx].beats;
|
||||||
|
l->done = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
l->count = 0;
|
||||||
|
l->idx++;
|
||||||
|
l->t0 = now;
|
||||||
|
send_lane(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void finish_if_done(void)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < s_run.nlanes; i++) {
|
||||||
|
if (!s_run.lane[i].done) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
readout(s_done_readout, sizeof(s_done_readout));
|
||||||
|
clear_drivers();
|
||||||
|
s_run.active = false;
|
||||||
|
ESP_LOGI(TAG, "sequence %s finished", s_run.seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time mode: called often; lanes move on when their step's seconds are up
|
||||||
|
static void advance_time(void)
|
||||||
|
{
|
||||||
|
if (!s_run.active || !s_run.timed || s_run.pending_switch) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int64_t now = esp_timer_get_time();
|
||||||
|
bool looped = false;
|
||||||
|
for (int i = 0; i < s_run.nlanes; i++) {
|
||||||
|
lane_t *l = &s_run.lane[i];
|
||||||
|
if (!l->done && l->n && now - l->t0 >= (int64_t)l->step[l->idx].ms * 1000) {
|
||||||
|
step_lane(i, now, &looped);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finish_if_done();
|
||||||
|
}
|
||||||
|
|
||||||
static void advance(void)
|
static void advance(void)
|
||||||
{
|
{
|
||||||
if (!s_run.active || s_run.pending_switch) {
|
if (!s_run.active || s_run.pending_switch || s_run.timed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pass_start() && s_run.anchor_on_pass_start) {
|
if (pass_start() && s_run.anchor_on_pass_start) {
|
||||||
@@ -394,38 +460,12 @@ static void advance(void)
|
|||||||
if (l->done || !l->n) {
|
if (l->done || !l->n) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int need = l->step[l->idx].beats;
|
if (++l->count >= l->step[l->idx].beats) {
|
||||||
if (++l->count < need) {
|
step_lane(i, 0, &lane0_looped);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (l->idx + 1 >= l->n) {
|
|
||||||
if (s_run.loop) {
|
|
||||||
lane0_looped = lane0_looped || i == 0;
|
|
||||||
l->count = 0;
|
|
||||||
l->idx = 0;
|
|
||||||
l->last[0] = 0; // step 0 goes up again on each wrap
|
|
||||||
send_lane(i);
|
|
||||||
} else {
|
|
||||||
l->count = need;
|
|
||||||
l->done = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
l->count = 0;
|
|
||||||
l->idx++;
|
|
||||||
send_lane(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s_run.loop_beat = lane0_looped ? 1 : s_run.loop_beat + 1;
|
s_run.loop_beat = lane0_looped ? 1 : s_run.loop_beat + 1;
|
||||||
bool all_done = true;
|
finish_if_done();
|
||||||
for (int i = 0; i < s_run.nlanes; i++) {
|
|
||||||
all_done = all_done && s_run.lane[i].done;
|
|
||||||
}
|
|
||||||
if (all_done) {
|
|
||||||
readout(s_done_readout, sizeof(s_done_readout));
|
|
||||||
clear_drivers();
|
|
||||||
s_run.active = false;
|
|
||||||
ESP_LOGI(TAG, "sequence %s finished", s_run.seq);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_beat(bool downbeat)
|
static void on_beat(bool downbeat)
|
||||||
@@ -460,6 +500,7 @@ static void beat_task(void *arg)
|
|||||||
int64_t next = esp_timer_get_time();
|
int64_t next = esp_timer_get_time();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
store_lock();
|
store_lock();
|
||||||
|
advance_time();
|
||||||
int64_t interval = 60LL * 1000000 / simulated_bpm();
|
int64_t interval = 60LL * 1000000 / simulated_bpm();
|
||||||
store_unlock();
|
store_unlock();
|
||||||
int64_t now = esp_timer_get_time();
|
int64_t now = esp_timer_get_time();
|
||||||
@@ -477,7 +518,11 @@ static void beat_task(void *arg)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
beat_event_t ev;
|
beat_event_t ev;
|
||||||
if (q && xQueueReceive(q, &ev, pdMS_TO_TICKS((next - now) / 1000) + 1) == pdTRUE && ev == BEAT_EVENT_BEAT &&
|
int64_t wait_ms = (next - now) / 1000;
|
||||||
|
if (wait_ms > 40) { // wake often enough to time steps in seconds
|
||||||
|
wait_ms = 40;
|
||||||
|
}
|
||||||
|
if (q && xQueueReceive(q, &ev, pdMS_TO_TICKS(wait_ms) + 1) == pdTRUE && ev == BEAT_EVENT_BEAT &&
|
||||||
audio_drives()) {
|
audio_drives()) {
|
||||||
beat_info_t bi;
|
beat_info_t bi;
|
||||||
beat_get_info(&bi);
|
beat_get_info(&bi);
|
||||||
@@ -601,8 +646,11 @@ static void pass_position(int *at, int *per_pass)
|
|||||||
static int readout(char *buf, size_t len)
|
static int readout(char *buf, size_t len)
|
||||||
{
|
{
|
||||||
int at, tot;
|
int at, tot;
|
||||||
pass_position(&at, &tot);
|
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
|
if (s_run.timed) { // seconds, not beats: no n/n readout
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
pass_position(&at, &tot);
|
||||||
if (tot > 0 && s_run.lane[0].done) {
|
if (tot > 0 && s_run.lane[0].done) {
|
||||||
return snprintf(buf, len, "%d/%d", tot, tot);
|
return snprintf(buf, len, "%d/%d", tot, tot);
|
||||||
}
|
}
|
||||||
@@ -637,7 +685,11 @@ cJSON *seqplay_status(void)
|
|||||||
char ro[24];
|
char ro[24];
|
||||||
readout(ro, sizeof(ro));
|
readout(ro, sizeof(ro));
|
||||||
cJSON_AddTrueToObject(o, "active");
|
cJSON_AddTrueToObject(o, "active");
|
||||||
cJSON_AddStringToObject(o, "advance_mode", "beats");
|
cJSON_AddStringToObject(o, "advance_mode", s_run.timed ? "time" : "beats");
|
||||||
|
if (s_run.timed && !l->done && l->idx < l->n) {
|
||||||
|
cJSON_AddNumberToObject(o, "lane0_step_elapsed_ms", (double)((esp_timer_get_time() - l->t0) / 1000));
|
||||||
|
cJSON_AddNumberToObject(o, "lane0_step_duration_ms", l->step[l->idx].ms);
|
||||||
|
}
|
||||||
cJSON_AddStringToObject(o, "sequence_id", s_run.seq);
|
cJSON_AddStringToObject(o, "sequence_id", s_run.seq);
|
||||||
cJSON_AddStringToObject(o, "zone_id", s_run.zone);
|
cJSON_AddStringToObject(o, "zone_id", s_run.zone);
|
||||||
cJSON_AddNumberToObject(o, "num_lanes", s_run.nlanes);
|
cJSON_AddNumberToObject(o, "num_lanes", s_run.nlanes);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Client-side search filter for modal lists (devices, zones, presets).
|
// Client-side search filter for modal lists (devices, groups, zones, presets).
|
||||||
// Hides .profiles-row children whose text doesn't match; re-applies when the list re-renders.
|
// Hides .profiles-row children whose text doesn't match; re-applies when the list re-renders.
|
||||||
|
|
||||||
function rowSearchText(row) {
|
function rowSearchText(row) {
|
||||||
@@ -75,6 +75,7 @@ function initListSearch(inputId, listId, modalId) {
|
|||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
initListSearch('devices-search', 'devices-list-modal', 'devices-modal');
|
initListSearch('devices-search', 'devices-list-modal', 'devices-modal');
|
||||||
|
initListSearch('groups-search', 'groups-list-modal', 'groups-modal');
|
||||||
initListSearch('zones-search', 'zones-list-modal', 'zones-modal');
|
initListSearch('zones-search', 'zones-list-modal', 'zones-modal');
|
||||||
initListSearch('presets-search', 'presets-list', 'presets-modal');
|
initListSearch('presets-search', 'presets-list', 'presets-modal');
|
||||||
});
|
});
|
||||||
+18
-1
@@ -1769,8 +1769,25 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// Send current editor values to zone devices (if any); never persist on device.
|
// Send current editor values to zone devices (if any); never persist on device.
|
||||||
const presetId = currentEditId || payload.name;
|
const presetId = currentEditId || payload.name;
|
||||||
const deviceNames = await deviceNamesForPresetOnCurrentZone(presetId);
|
const deviceNames = await deviceNamesForPresetOnCurrentZone(presetId);
|
||||||
|
// Only the current zone's groups; never broadcast to every driver.
|
||||||
|
const section = document.querySelector('.presets-section[data-zone-id]');
|
||||||
|
let groupIds = [];
|
||||||
|
if (section && section.dataset.zoneId) {
|
||||||
|
try {
|
||||||
|
const zr = await fetch(`/zones/${section.dataset.zoneId}`, {
|
||||||
|
headers: { Accept: 'application/json' },
|
||||||
|
});
|
||||||
|
if (zr.ok) groupIds = zoneGroupIdsFromTabData(await zr.json());
|
||||||
|
} catch (_) {
|
||||||
|
groupIds = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!groupIds.length) {
|
||||||
|
alert('The current zone has no groups to try this preset on.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Auto: load + immediate select. Manual: load only; first advance on the next audio beat.
|
// Auto: load + immediate select. Manual: load only; first advance on the next audio beat.
|
||||||
await sendPresetViaEspNow(presetId, payload, deviceNames, false, false, '2');
|
await sendPresetViaEspNow(presetId, payload, deviceNames, false, false, '2', { groupIds });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+48
-4
@@ -185,6 +185,7 @@ function normalizeSequenceLanes(doc) {
|
|||||||
.map((s) => ({
|
.map((s) => ({
|
||||||
preset_id: s.preset_id != null ? String(s.preset_id) : String(s.presetId || ''),
|
preset_id: s.preset_id != null ? String(s.preset_id) : String(s.presetId || ''),
|
||||||
beats: Math.max(1, parseInt(String(s.beats != null ? s.beats : 1), 10) || 1),
|
beats: Math.max(1, parseInt(String(s.beats != null ? s.beats : 1), 10) || 1),
|
||||||
|
seconds: Math.max(0.1, parseFloat(String(s.seconds != null ? s.seconds : 3)) || 3),
|
||||||
group_ids: Array.isArray(s.group_ids)
|
group_ids: Array.isArray(s.group_ids)
|
||||||
? s.group_ids.map((x) => String(x).trim()).filter(Boolean)
|
? s.group_ids.map((x) => String(x).trim()).filter(Boolean)
|
||||||
: [],
|
: [],
|
||||||
@@ -776,6 +777,26 @@ function renderSequenceStepRow(presetsMap, step) {
|
|||||||
beatsInp.style.width = '4rem';
|
beatsInp.style.width = '4rem';
|
||||||
beatWrap.appendChild(bl);
|
beatWrap.appendChild(bl);
|
||||||
beatWrap.appendChild(beatsInp);
|
beatWrap.appendChild(beatsInp);
|
||||||
|
beatWrap.classList.add('sequence-step-beats-wrap');
|
||||||
|
|
||||||
|
const secWrap = document.createElement('div');
|
||||||
|
secWrap.className = 'sequence-step-seconds-wrap';
|
||||||
|
secWrap.style.cssText = 'display:flex;align-items:center;gap:0.35rem;';
|
||||||
|
const sl = document.createElement('label');
|
||||||
|
sl.textContent = 'Seconds';
|
||||||
|
const secInp = document.createElement('input');
|
||||||
|
secInp.type = 'number';
|
||||||
|
secInp.className = 'sequence-step-seconds';
|
||||||
|
secInp.autocomplete = 'off';
|
||||||
|
secInp.min = '0.1';
|
||||||
|
secInp.max = '3600';
|
||||||
|
secInp.step = '0.1';
|
||||||
|
secInp.value = String(
|
||||||
|
step && step.seconds != null ? Math.max(0.1, parseFloat(String(step.seconds)) || 3) : 3,
|
||||||
|
);
|
||||||
|
secInp.style.width = '5rem';
|
||||||
|
secWrap.appendChild(sl);
|
||||||
|
secWrap.appendChild(secInp);
|
||||||
|
|
||||||
const editPresetBtn = document.createElement('button');
|
const editPresetBtn = document.createElement('button');
|
||||||
editPresetBtn.type = 'button';
|
editPresetBtn.type = 'button';
|
||||||
@@ -806,6 +827,7 @@ function renderSequenceStepRow(presetsMap, step) {
|
|||||||
top.appendChild(dragHandle);
|
top.appendChild(dragHandle);
|
||||||
top.appendChild(presetWrap);
|
top.appendChild(presetWrap);
|
||||||
top.appendChild(beatWrap);
|
top.appendChild(beatWrap);
|
||||||
|
top.appendChild(secWrap);
|
||||||
top.appendChild(editPresetBtn);
|
top.appendChild(editPresetBtn);
|
||||||
row.appendChild(top);
|
row.appendChild(top);
|
||||||
|
|
||||||
@@ -839,7 +861,8 @@ function renderSequenceLane(laneIndex, laneSteps, laneGroupIds, presetsMap, grou
|
|||||||
addStep.addEventListener('click', () => {
|
addStep.addEventListener('click', () => {
|
||||||
const stepsHost = wrap.querySelector('.sequence-lane-steps');
|
const stepsHost = wrap.querySelector('.sequence-lane-steps');
|
||||||
if (stepsHost) {
|
if (stepsHost) {
|
||||||
stepsHost.appendChild(renderSequenceStepRow(presetsMap, { preset_id: '', beats: 1 }));
|
stepsHost.appendChild(renderSequenceStepRow(presetsMap, { preset_id: '', beats: 1, seconds: 3 }));
|
||||||
|
applySequenceEditorMode();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const rmLane = document.createElement('button');
|
const rmLane = document.createElement('button');
|
||||||
@@ -862,7 +885,7 @@ function renderSequenceLane(laneIndex, laneSteps, laneGroupIds, presetsMap, grou
|
|||||||
|
|
||||||
const stepsHost = document.createElement('div');
|
const stepsHost = document.createElement('div');
|
||||||
stepsHost.className = 'sequence-lane-steps';
|
stepsHost.className = 'sequence-lane-steps';
|
||||||
const steps = Array.isArray(laneSteps) && laneSteps.length ? laneSteps : [{ preset_id: '', beats: 1 }];
|
const steps = Array.isArray(laneSteps) && laneSteps.length ? laneSteps : [{ preset_id: '', beats: 1, seconds: 3 }];
|
||||||
steps.forEach((s) => {
|
steps.forEach((s) => {
|
||||||
stepsHost.appendChild(renderSequenceStepRow(presetsMap, s));
|
stepsHost.appendChild(renderSequenceStepRow(presetsMap, s));
|
||||||
});
|
});
|
||||||
@@ -883,6 +906,18 @@ function refreshSequenceEditorLaneTitles() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Show the Beats or Seconds field on every step, to match the sequence's advance mode. */
|
||||||
|
function applySequenceEditorMode() {
|
||||||
|
const sel = document.getElementById('sequence-editor-mode');
|
||||||
|
const timed = !!sel && sel.value === 'time';
|
||||||
|
document.querySelectorAll('#sequence-editor-lanes .sequence-step-beats-wrap').forEach((e) => {
|
||||||
|
e.style.display = timed ? 'none' : 'flex';
|
||||||
|
});
|
||||||
|
document.querySelectorAll('#sequence-editor-lanes .sequence-step-seconds-wrap').forEach((e) => {
|
||||||
|
e.style.display = timed ? 'flex' : 'none';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function collectLanesFromEditor() {
|
function collectLanesFromEditor() {
|
||||||
const host = document.getElementById('sequence-editor-lanes');
|
const host = document.getElementById('sequence-editor-lanes');
|
||||||
const laneEls = host ? [...host.querySelectorAll('.sequence-lane')] : [];
|
const laneEls = host ? [...host.querySelectorAll('.sequence-lane')] : [];
|
||||||
@@ -903,7 +938,9 @@ function collectLanesFromEditor() {
|
|||||||
const presetId = presetSel && presetSel.value ? String(presetSel.value) : '';
|
const presetId = presetSel && presetSel.value ? String(presetSel.value) : '';
|
||||||
if (!presetId) return;
|
if (!presetId) return;
|
||||||
const beats = Math.max(1, parseInt(beatsInp && beatsInp.value ? beatsInp.value : '1', 10) || 1);
|
const beats = Math.max(1, parseInt(beatsInp && beatsInp.value ? beatsInp.value : '1', 10) || 1);
|
||||||
steps.push({ preset_id: presetId, beats });
|
const secInp = row.querySelector('.sequence-step-seconds');
|
||||||
|
const seconds = Math.max(0.1, parseFloat(secInp && secInp.value ? secInp.value : '3') || 3);
|
||||||
|
steps.push({ preset_id: presetId, beats, seconds });
|
||||||
});
|
});
|
||||||
lanes.push(steps);
|
lanes.push(steps);
|
||||||
});
|
});
|
||||||
@@ -961,6 +998,8 @@ async function openSequenceEditor(sequenceId, existing) {
|
|||||||
doc = {};
|
doc = {};
|
||||||
}
|
}
|
||||||
nameInput.value = doc.name || '';
|
nameInput.value = doc.name || '';
|
||||||
|
const modeSelOpen = document.getElementById('sequence-editor-mode');
|
||||||
|
if (modeSelOpen) modeSelOpen.value = doc.advance_mode === 'time' ? 'time' : 'beats';
|
||||||
|
|
||||||
const lanes = normalizeSequenceLanes(doc);
|
const lanes = normalizeSequenceLanes(doc);
|
||||||
lanesHost.innerHTML = '';
|
lanesHost.innerHTML = '';
|
||||||
@@ -974,6 +1013,7 @@ async function openSequenceEditor(sequenceId, existing) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
refreshSequenceEditorLaneTitles();
|
refreshSequenceEditorLaneTitles();
|
||||||
|
applySequenceEditorMode();
|
||||||
|
|
||||||
const edDel = document.getElementById('sequence-editor-delete-btn');
|
const edDel = document.getElementById('sequence-editor-delete-btn');
|
||||||
if (edDel) edDel.style.display = sequenceEditorId ? 'inline-block' : 'none';
|
if (edDel) edDel.style.display = sequenceEditorId ? 'inline-block' : 'none';
|
||||||
@@ -997,6 +1037,7 @@ function resolveZoneIdForPresetStripRefresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveSequenceEditor() {
|
async function saveSequenceEditor() {
|
||||||
|
const modeSel = document.getElementById('sequence-editor-mode');
|
||||||
const nameInput = document.getElementById('sequence-editor-name');
|
const nameInput = document.getElementById('sequence-editor-name');
|
||||||
const { lanes, lanes_group_ids } = collectLanesFromEditor();
|
const { lanes, lanes_group_ids } = collectLanesFromEditor();
|
||||||
const idxs = [];
|
const idxs = [];
|
||||||
@@ -1014,7 +1055,7 @@ async function saveSequenceEditor() {
|
|||||||
lanes: nonEmpty,
|
lanes: nonEmpty,
|
||||||
lanes_group_ids: nonEmptyLg,
|
lanes_group_ids: nonEmptyLg,
|
||||||
group_ids: nonEmptyLg[0] ? [...nonEmptyLg[0]] : [],
|
group_ids: nonEmptyLg[0] ? [...nonEmptyLg[0]] : [],
|
||||||
advance_mode: 'beats',
|
advance_mode: modeSel && modeSel.value === 'time' ? 'time' : 'beats',
|
||||||
loop: true,
|
loop: true,
|
||||||
steps: nonEmpty.length === 1 ? nonEmpty[0] : [],
|
steps: nonEmpty.length === 1 ? nonEmpty[0] : [],
|
||||||
};
|
};
|
||||||
@@ -1205,6 +1246,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const idx = host.querySelectorAll('.sequence-lane').length;
|
const idx = host.querySelectorAll('.sequence-lane').length;
|
||||||
host.appendChild(renderSequenceLane(idx, [], [], presetsMap, groupsMap));
|
host.appendChild(renderSequenceLane(idx, [], [], presetsMap, groupsMap));
|
||||||
refreshSequenceEditorLaneTitles();
|
refreshSequenceEditorLaneTitles();
|
||||||
|
applySequenceEditorMode();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const edMode = document.getElementById('sequence-editor-mode');
|
||||||
|
if (edMode) edMode.addEventListener('change', applySequenceEditorMode);
|
||||||
});
|
});
|
||||||
@@ -2561,3 +2561,25 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
|||||||
margin-top: 0.75rem;
|
margin-top: 0.75rem;
|
||||||
color: #ff6b6b;
|
color: #ff6b6b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Modal list search (list_search.js) */
|
||||||
|
.list-search-input {
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
padding: 0.5rem;
|
||||||
|
background-color: #3a3a3a;
|
||||||
|
border: 1px solid #4a4a4a;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: white;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-search-input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #6a5acd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-search-hidden {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
+38
-45
@@ -457,29 +457,29 @@ function renderZoneGroupsEditor(containerEl, rows, groupsMap) {
|
|||||||
const idsInRows = new Set(rows.map((r) => String(r.id)));
|
const idsInRows = new Set(rows.map((r) => String(r.id)));
|
||||||
const addWrap = document.createElement("div");
|
const addWrap = document.createElement("div");
|
||||||
addWrap.className = "zone-devices-add profiles-actions";
|
addWrap.className = "zone-devices-add profiles-actions";
|
||||||
const sel = document.createElement("select");
|
const groupLabel = (gid, g) => {
|
||||||
sel.className = "zone-device-add-select";
|
|
||||||
sel.appendChild(new Option("Add group…", ""));
|
|
||||||
entries.forEach(([gid, g]) => {
|
|
||||||
if (idsInRows.has(gid)) return;
|
|
||||||
const gn = g && g.name ? String(g.name).trim() : "";
|
const gn = g && g.name ? String(g.name).trim() : "";
|
||||||
const optLabel = gn ? `${gn} (${gid})` : `Group ${gid}`;
|
return gn ? `${gn} (${gid})` : `Group ${gid}`;
|
||||||
sel.appendChild(new Option(optLabel, gid));
|
};
|
||||||
});
|
const picker =
|
||||||
const addBtn = document.createElement("button");
|
typeof window.createSearchableAddPicker === "function"
|
||||||
addBtn.type = "button";
|
? window.createSearchableAddPicker({
|
||||||
addBtn.className = "btn btn-primary btn-small";
|
entries,
|
||||||
addBtn.textContent = "Add";
|
excludeIds: idsInRows,
|
||||||
addBtn.addEventListener("click", () => {
|
labelFor: groupLabel,
|
||||||
const gid = sel.value;
|
searchTextFor: (gid, g) => `${(g && g.name) || ""} ${gid}`,
|
||||||
|
onPick: (gid) => {
|
||||||
if (!gid || !groupsMap[gid]) return;
|
if (!gid || !groupsMap[gid]) return;
|
||||||
const gn = groupsMap[gid].name ? String(groupsMap[gid].name).trim() : gid;
|
const gn = groupsMap[gid].name ? String(groupsMap[gid].name).trim() : gid;
|
||||||
rows.push({ id: gid, name: gn });
|
rows.push({ id: gid, name: gn });
|
||||||
sel.value = "";
|
|
||||||
renderZoneGroupsEditor(containerEl, rows, groupsMap);
|
renderZoneGroupsEditor(containerEl, rows, groupsMap);
|
||||||
});
|
},
|
||||||
addWrap.appendChild(sel);
|
placeholder: "Search groups to add…",
|
||||||
addWrap.appendChild(addBtn);
|
emptyMessage: "No groups match your search.",
|
||||||
|
noItemsMessage: "All groups are already on this zone.",
|
||||||
|
})
|
||||||
|
: null;
|
||||||
|
if (picker) addWrap.appendChild(picker);
|
||||||
if (panel) {
|
if (panel) {
|
||||||
panel.addSlot.appendChild(addWrap);
|
panel.addSlot.appendChild(addWrap);
|
||||||
} else {
|
} else {
|
||||||
@@ -1027,35 +1027,28 @@ async function refreshEditTabPresetsUi(zoneId) {
|
|||||||
} else {
|
} else {
|
||||||
const addWrap = document.createElement("div");
|
const addWrap = document.createElement("div");
|
||||||
addWrap.className = "zone-devices-add profiles-actions";
|
addWrap.className = "zone-devices-add profiles-actions";
|
||||||
const sel = document.createElement("select");
|
const sorted = availableToAdd
|
||||||
sel.className = "zone-device-add-select";
|
.slice()
|
||||||
sel.setAttribute("aria-label", "Preset to add to this zone");
|
.sort((x, y) => {
|
||||||
sel.appendChild(new Option("Add preset…", ""));
|
const nx = (allPresets[x] && allPresets[x].name) || x;
|
||||||
const sorted = availableToAdd.slice().sort((a, b) => {
|
const ny = (allPresets[y] && allPresets[y].name) || y;
|
||||||
const na = (allPresets[a] && allPresets[a].name) || a;
|
return String(nx).localeCompare(String(ny), undefined, { sensitivity: "base" });
|
||||||
const nb = (allPresets[b] && allPresets[b].name) || b;
|
})
|
||||||
return String(na).localeCompare(String(nb), undefined, { sensitivity: "base" });
|
.map((id) => [id, allPresets[id] || {}]);
|
||||||
});
|
const picker = window.createSearchableAddPicker({
|
||||||
sorted.forEach((presetId) => {
|
entries: sorted,
|
||||||
const preset = allPresets[presetId] || {};
|
labelFor: (id, p) => `${p.name || id} — ${id}`,
|
||||||
const name = preset.name || presetId;
|
searchTextFor: (id, p) => `${p.name || ""} ${id} ${p.pattern || ""}`,
|
||||||
sel.appendChild(new Option(`${name} — ${presetId}`, presetId));
|
onPick: async (id) => {
|
||||||
});
|
if (typeof window.addPresetToTab !== "function") return;
|
||||||
const addBtn = document.createElement("button");
|
await window.addPresetToTab(id, zoneId);
|
||||||
addBtn.type = "button";
|
|
||||||
addBtn.className = "btn btn-primary btn-small";
|
|
||||||
addBtn.textContent = "Add";
|
|
||||||
addBtn.addEventListener("click", async () => {
|
|
||||||
const presetId = sel.value;
|
|
||||||
if (!presetId) return;
|
|
||||||
if (typeof window.addPresetToTab === "function") {
|
|
||||||
await window.addPresetToTab(presetId, zoneId);
|
|
||||||
sel.value = "";
|
|
||||||
await refreshEditTabPresetsUi(zoneId);
|
await refreshEditTabPresetsUi(zoneId);
|
||||||
}
|
},
|
||||||
|
placeholder: "Search presets to add…",
|
||||||
|
emptyMessage: "No presets match your search.",
|
||||||
|
noItemsMessage: "No presets to add.",
|
||||||
});
|
});
|
||||||
addWrap.appendChild(sel);
|
addWrap.appendChild(picker);
|
||||||
addWrap.appendChild(addBtn);
|
|
||||||
addEl.appendChild(addWrap);
|
addEl.appendChild(addWrap);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -214,6 +214,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<button class="btn btn-primary" id="create-group-btn">Create</button>
|
<button class="btn btn-primary" id="create-group-btn">Create</button>
|
||||||
</div>
|
</div>
|
||||||
|
<input type="search" id="groups-search" class="list-search-input" placeholder="Search groups…" autocomplete="off">
|
||||||
<div id="groups-list-modal" class="profiles-list"></div>
|
<div id="groups-list-modal" class="profiles-list"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -375,6 +376,13 @@
|
|||||||
<label for="sequence-editor-name">Name</label>
|
<label for="sequence-editor-name">Name</label>
|
||||||
<input type="text" id="sequence-editor-name" placeholder="Sequence name" style="width:100%;max-width:24rem;">
|
<input type="text" id="sequence-editor-name" placeholder="Sequence name" style="width:100%;max-width:24rem;">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="preset-editor-field">
|
||||||
|
<label for="sequence-editor-mode">Steps last</label>
|
||||||
|
<select id="sequence-editor-mode" class="zone-device-add-select">
|
||||||
|
<option value="beats">Beats</option>
|
||||||
|
<option value="time">Time (seconds)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div id="sequence-editor-beats-panel" style="margin:0 0 0.75rem 0;">
|
<div id="sequence-editor-beats-panel" style="margin:0 0 0.75rem 0;">
|
||||||
<label style="display:block;">
|
<label style="display:block;">
|
||||||
<input type="checkbox" id="sequence-editor-loop" checked>
|
<input type="checkbox" id="sequence-editor-loop" checked>
|
||||||
|
|||||||
Reference in new issue
Block a user