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
+229
-92
No files matched your search
+85
-33
@@ -28,6 +28,7 @@ static const char *TAG = "seqplay";
|
||||
typedef struct {
|
||||
char preset[ID_MAX];
|
||||
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
|
||||
int ngroups;
|
||||
} step_t;
|
||||
@@ -35,6 +36,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
step_t step[STEPS_MAX];
|
||||
int n, idx, count;
|
||||
int64_t t0; // time mode: when the step started (us)
|
||||
bool done;
|
||||
char last[ID_MAX]; // preset last uploaded for this lane
|
||||
} lane_t;
|
||||
@@ -47,6 +49,7 @@ static struct {
|
||||
lane_t *lane;
|
||||
int nlanes;
|
||||
bool loop;
|
||||
bool timed; // steps last seconds, not beats
|
||||
int loop_beat;
|
||||
bool anchor_on_pass_start;
|
||||
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));
|
||||
const cJSON *b = cJSON_GetObjectItem(s, "beats");
|
||||
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;
|
||||
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");
|
||||
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.pending_switch = false;
|
||||
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
|
||||
|
||||
// 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)
|
||||
{
|
||||
if (!s_run.active || s_run.pending_switch) {
|
||||
if (!s_run.active || s_run.pending_switch || s_run.timed) {
|
||||
return;
|
||||
}
|
||||
if (pass_start() && s_run.anchor_on_pass_start) {
|
||||
@@ -394,38 +460,12 @@ static void advance(void)
|
||||
if (l->done || !l->n) {
|
||||
continue;
|
||||
}
|
||||
int need = l->step[l->idx].beats;
|
||||
if (++l->count < need) {
|
||||
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);
|
||||
if (++l->count >= l->step[l->idx].beats) {
|
||||
step_lane(i, 0, &lane0_looped);
|
||||
}
|
||||
}
|
||||
s_run.loop_beat = lane0_looped ? 1 : s_run.loop_beat + 1;
|
||||
bool all_done = true;
|
||||
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);
|
||||
}
|
||||
finish_if_done();
|
||||
}
|
||||
|
||||
static void on_beat(bool downbeat)
|
||||
@@ -460,6 +500,7 @@ static void beat_task(void *arg)
|
||||
int64_t next = esp_timer_get_time();
|
||||
for (;;) {
|
||||
store_lock();
|
||||
advance_time();
|
||||
int64_t interval = 60LL * 1000000 / simulated_bpm();
|
||||
store_unlock();
|
||||
int64_t now = esp_timer_get_time();
|
||||
@@ -477,7 +518,11 @@ static void beat_task(void *arg)
|
||||
continue;
|
||||
}
|
||||
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()) {
|
||||
beat_info_t 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)
|
||||
{
|
||||
int at, tot;
|
||||
pass_position(&at, &tot);
|
||||
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) {
|
||||
return snprintf(buf, len, "%d/%d", tot, tot);
|
||||
}
|
||||
@@ -637,7 +685,11 @@ cJSON *seqplay_status(void)
|
||||
char ro[24];
|
||||
readout(ro, sizeof(ro));
|
||||
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, "zone_id", s_run.zone);
|
||||
cJSON_AddNumberToObject(o, "num_lanes", s_run.nlanes);
|
||||
|
||||
Reference in new issue
Block a user