Files
jimmyandClaude Opus 5.5 bfeeb958df feat: main's import/export, zones, audio API and web UI
Profiles, presets and sequences export and import as main's bundles.
Zones carry group_ids, preset_group_ids, sequence_ids, content_kind and
brightness; profiles seed rainbow as colour_cycle, and deleting a
profile also deletes its sequences. Groups, zones and sequences written
by older versions are migrated at boot.

/api/audio (status, event stream, start/stop, reset, anchor-bar,
devices) maps main's audio detector onto the mic's beat detector. Audio
start/stop picks whether mic beats or the BPM clock time sequences; the
clock's beats also go to the drivers while the mic is off.
/ws now greets from a post-handshake callback (httpd does not call the
handler for the upgrade).

The web UI is main's, plus v2's outputs editor, list search and
hostname/static IP settings; the bridge, Wi-Fi AP and led-tool parts
are gone. API tests follow main's behaviour (119 pass on the board).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:34:22 +13:00

52 lines
1.8 KiB
C

#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
typedef struct {
float bpm; // 0 until a tempo has been found
float confidence; // 0..1, how periodic the onsets are
bool locked; // beats are being emitted
uint32_t beat_count;
int64_t last_beat_us; // esp_timer time of the last beat, 0 if none
int meter; // beats per bar, 3 or 4
int bar_beat; // 1..meter of the last beat (best guess), 0 early on
bool bar_sure; // bar_beat is reliable, downbeats are being flashed
uint32_t downbeat_count;
uint32_t onset_count;
int64_t last_onset_us;
} beat_info_t;
// Event codes posted to subscriber queues
typedef enum {
BEAT_EVENT_ONSET,
BEAT_EVENT_BEAT,
} beat_event_t;
// Set up the detector and beat LED; call before feeding audio
esp_err_t beat_start(float sample_rate);
// Feed DC-free mono samples at full scale +/-1 (called from the mic task)
void beat_feed(const float *x, size_t n);
void beat_get_info(beat_info_t *out);
// The user tapped beat 1 just now: correct the bar position to match
void beat_tap(void);
// Forget the tempo and bar position and start tracking again
void beat_reset(void);
// Have beat_event_t values posted (without blocking) to a queue of
// beat_event_t. Returns ESP_ERR_NO_MEM when all subscriber slots are taken.
esp_err_t beat_subscribe(QueueHandle_t q);
void beat_unsubscribe(QueueHandle_t q);
// Called from the audio task the moment a beat is emitted, before any queue
// fan-out, so the radio can send it with minimal delay. Must not block.
typedef void (*beat_cb_t)(const beat_info_t *info, float bpm, bool downbeat);
void beat_set_callback(beat_cb_t cb);