3 Commits
Author SHA1 Message Date
bonaminandClaude Opus 5.5 1aff1e987b fix(BellEngine): remove hardcoded 0.5 s gap between melody loops (F-078, v2.5.1)
playbackLoop() slept 500 ms after every loop whenever the run had no end
time (infinite, interval with total_duration 0, v1 continuous_loop with no
total), so those modes paused between loops while timed / interval with a
total did not. The delay was meant to give Player time to pause/stop, but
play-once already stops synchronously in onMelodyLoopCompleted(), stop is
checked before every pass and pause after every loop. Every looping mode
now plays loop-to-loop with no gap; single is unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:10:06 +02:00
bonaminandClaude Opus 5.5 5d8600d6bf feat(Player): segmented mode "infinite" via duration + pause_duration (F-077, v2.5.0)
"infinite" now optionally plays duration ms, pauses pause_duration ms and
repeats until playback.stop, the same as "interval" with total_duration 0,
which is what people expect "infinite" to mean. Sending neither keeps the
old back-to-back looping; sending only one is rejected, since a duration
without a pause flickers paused/playing and a pause without a duration
never triggers. total_duration is never read for infinite.

api-reference.md now documents the exact timing of every mode: 500 ms
tick, loops never cut short, paused/stopping status transitions, pause
measured from the loop end, total_duration including pauses, and the
~0.5 s engine gap between loops when the run has no end time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 10:44:04 +02:00
bonaminandClaude Opus 5.5 ced38fda0b fix(Player): stop short pauses being skipped between segments (F-076, v2.4.2)
timeToResume() measured the pause from segmentCmpltTime, which still held
the previous loop's end while the engine finished the loop that was playing
when the pause was flagged. A pause_duration shorter than one melody loop
therefore resumed before the bells ever went quiet. Only start counting
once that loop has ended (segmentCmpltTime >= pauseTime).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 10:41:11 +02:00
5 changed files with 102 additions and 18 deletions
+59 -1
View File
@@ -88,6 +88,9 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
| F-073 | Confirmed delivery for `status/playback` + `control/reports` (QoS 1, PUBACK tracked, reset + republish/resend); AsyncMqttClient vendored + patched; all dependencies pinned | v2.4.0 | Stable | | F-073 | Confirmed delivery for `status/playback` + `control/reports` (QoS 1, PUBACK tracked, reset + republish/resend); AsyncMqttClient vendored + patched; all dependencies pinned | v2.4.0 | Stable |
| F-074 | Fix: `mode: "infinite"` no longer flips status playing/paused every ~0.5 s | v2.4.0 | Stable | | F-074 | Fix: `mode: "infinite"` no longer flips status playing/paused every ~0.5 s | v2.4.0 | Stable |
| F-075 | Play/stop command replies no longer wait for telemetry SD writes (deferred to TelemetryTask) | v2.4.1 | Stable | | F-075 | Play/stop command replies no longer wait for telemetry SD writes (deferred to TelemetryTask) | v2.4.1 | Stable |
| F-076 | Fix: a `pause_duration` shorter than one melody loop no longer gets skipped | v2.4.2 | Stable |
| F-077 | `mode: "infinite"` accepts optional `duration` + `pause_duration` for play/pause cycles forever | v2.5.0 | Stable |
| F-078 | Fix: no more hardcoded ~0.5 s gap between loops in `infinite` and `interval` with `total_duration: 0` | v2.5.1 | Stable |
--- ---
@@ -344,7 +347,10 @@ V2 play commands replace the ambiguous `continuous_loop` / `segment_duration` /
| `"single"` | Play exactly one melody loop, then stop | none | | `"single"` | Play exactly one melody loop, then stop | none |
| `"timed"` | Loop continuously for `duration` ms, stop at end of a full loop | `duration` | | `"timed"` | Loop continuously for `duration` ms, stop at end of a full loop | `duration` |
| `"interval"` | Loop for `duration` ms, pause for `pause_duration` ms, repeat until `total_duration` ms elapsed | `duration`, `pause_duration`, `total_duration` | | `"interval"` | Loop for `duration` ms, pause for `pause_duration` ms, repeat until `total_duration` ms elapsed | `duration`, `pause_duration`, `total_duration` |
| `"infinite"` | Loop forever until a `stop` command | none | | `"infinite"` | Loop forever until a `stop` command; optionally in `duration`/`pause_duration` segments (F-077) | none, or `duration` + `pause_duration` |
Exact per-mode timing (500 ms tick, loops never cut short, pause/status transitions, no gap between loops):
see `docs/reference/api-reference.md` → `playback.play` → Modes.
V1 timing fields (`segment_duration`, `continuous_loop`, `total_duration`) are still parsed when `mode` is absent, so the fix from F-024 continues to apply to V1 clients. V1 timing fields (`segment_duration`, `continuous_loop`, `total_duration`) are still parsed when `mode` is absent, so the fix from F-024 continues to apply to V1 clients.
@@ -1566,3 +1572,55 @@ held while telemetry is paused for OTA and done right after `resume()`. Before t
one write of the latest values. one write of the latest values.
Subsystem: `src/Telemetry/Telemetry.hpp`, `src/Telemetry/Telemetry.cpp` Subsystem: `src/Telemetry/Telemetry.hpp`, `src/Telemetry/Telemetry.cpp`
### F-076 — Fix short pauses being skipped
**Symptom.** Found while reviewing the pause logic for F-077 (2026-10-28): in a segmented play (`interval`, or
v1 `continuous_loop`), a `pause_duration` shorter than one melody loop could be skipped. Status went `paused`
then back to `playing`, but the bells never stopped between segments.
**Cause.** `timeToPause()` flags the pause when the segment time runs out, which is usually in the middle of a
loop. The engine finishes that loop before it actually waits. `timeToResume()` measured the pause from
`segmentCmpltTime`, but until that loop ends `segmentCmpltTime` still holds the end of the *previous* loop. If
`previous loop end + pause_duration` was already in the past, the next 500 ms tick resumed before the loop
had finished, so there was no silence.
**Fix.** `timeToResume()` only runs once `segmentCmpltTime >= pauseTime`, that is, once the loop that was
playing when the pause was flagged has ended. The silence now always lasts `pause_duration` (rounded up to the
500 ms timer tick), measured from the end of that loop. Pauses longer than one loop already worked this way.
Subsystem: `src/Player/Player.cpp`
### F-077 — Segmented `mode: "infinite"`
**Why.** "Play/pause forever" was only possible as `interval` with `total_duration: 0`, which nobody guesses.
`infinite` reads as "never stops on its own", and the pauses should be an option of it.
**Change.** `infinite` now reads `duration` and `pause_duration`:
| Sent | Behaviour |
|---|---|
| neither (or both `0`) | Unchanged: back-to-back loops until `playback.stop` (no gap since F-078). |
| both > 0 | Play `duration` ms, pause `pause_duration` ms, repeat until `playback.stop`. Same internal state as `interval` with `total_duration: 0`. |
| only one > 0 | Rejected: `Invalid infinite segments: duration and pause_duration must both be > 0, or both omitted`. A duration with no pause would pause and resume on the same tick, and a pause with no duration never triggers. |
`total_duration` is never read for `infinite`. `interval` with `total_duration: 0` still works as before.
Subsystem: `src/Player/Player.cpp` (`validatePlayParams`, `setMelodyAttributes`)
### F-078 — No gap between melody loops
**Symptom.** Whenever a run had no end time (`total_duration` 0: `infinite`, `interval` with `total_duration: 0`,
v1 `continuous_loop` with no total), the bells went quiet for ~0.5 s after each loop. `timed` and `interval`
with a total looped with no gap, so the same melody sounded different depending on the mode.
**Cause.** `BellEngine::playbackLoop()` ran `vTaskDelay(500)` after `onMelodyLoopCompleted()` whenever
`total_duration == 0` (or `continuous_loop` with no segments), to "give Player time to pause/stop".
**Fix.** The delay is removed. It wasn't needed: play-once (`single`) stops synchronously inside
`onMelodyLoopCompleted()` (`isPlaying = false` before the engine continues), stop clears `isPlaying`, which
`playbackLoop()` checks before every pass, and pause is checked in `engineLoop()` after every loop. Every looping
mode now starts the next loop right after the previous one; the last step's `speed` beat is the only spacing.
`single` is unaffected. Configurable inter-loop pauses are planned as a later setting.
Subsystem: `src/BellEngine/BellEngine.cpp`
+19 -7
View File
@@ -180,20 +180,29 @@ The SUCCESS reply means the board **accepted** the command, not that bells are r
| `speed` | int | no | ms per beat, 0–65535. Boot default 500. `0` is coerced to 300. | | `speed` | int | no | ms per beat, 0–65535. Boot default 500. `0` is coerced to 300. |
| `note_assignments` | int[] | no | Up to 16 integers, each 0–16. Index = melody note (0-based), value = **1-based bell channel** to ring for that note, `0` = silent. Boot default `[1,2,…,16]`. A shorter array leaves the remaining entries at their previous values. | | `note_assignments` | int[] | no | Up to 16 integers, each 0–16. Index = melody note (0-based), value = **1-based bell channel** to ring for that note, `0` = silent. Boot default `[1,2,…,16]`. A shorter array leaves the remaining entries at their previous values. |
| `mode` | string | no | `"single"` \| `"timed"` \| `"interval"` \| `"infinite"` — anything else is rejected. Selects the timing model — see below. | | `mode` | string | no | `"single"` \| `"timed"` \| `"interval"` \| `"infinite"` — anything else is rejected. Selects the timing model — see below. |
| `duration` | int | no | ms, ≥ 0. **Read only when `mode` is present**; must be > 0 for `timed`/`interval`. | | `duration` | int | no | ms, ≥ 0. **Read only when `mode` is present**; must be > 0 for `timed`/`interval`, optional for `infinite` (segment length). |
| `pause_duration` | int | no | ms between segments. Read when `mode` is `"interval"`, or when `mode` is absent. | | `pause_duration` | int | no | ms between segments. Read when `mode` is `"interval"` or `"infinite"`, or when `mode` is absent. |
| `total_duration` | int | no | ms. Read when `mode` is `"interval"`, or (with `continuous_loop: true`) when `mode` is absent. | | `total_duration` | int | no | ms. Read when `mode` is `"interval"`, or (with `continuous_loop: true`) when `mode` is absent. |
| `segment_duration` | int | no | ms. Legacy — read only when `mode` is absent. | | `segment_duration` | int | no | ms. Legacy — read only when `mode` is absent. |
| `continuous_loop` | bool | no | Legacy — read only when `mode` is absent. Defaults to `false` on every command (not sticky). | | `continuous_loop` | bool | no | Legacy — read only when `mode` is absent. Defaults to `false` on every command (not sticky). |
**How `mode` and `duration` interact** (`mode` present — `segment_duration` and `continuous_loop` are ignored): **Modes** (`mode` present — `segment_duration` and `continuous_loop` are ignored):
| `mode` | Behaviour | Fields read | | `mode` | Behaviour | Fields read |
|---|---|---| |---|---|---|
| `"single"` | Play the melody once, then stop. | — (`duration` ignored) | | `"single"` | Play the melody once, start to end, then stop. | none (`duration`, `pause_duration` and `total_duration` are ignored) |
| `"timed"` | Loop the melody; when `duration` ms have elapsed, finish the current loop and stop (status goes `stopping` → `idle`). | `duration` (> 0) | | `"timed"` | Loop the melody back-to-back. When `duration` ms have passed, finish the current loop, then stop. No pauses. | `duration` (> 0) |
| `"interval"` | Play for `duration` ms, pause `pause_duration` ms, repeat; stop after `total_duration` ms overall (`0` = forever). | `duration` (> 0), `pause_duration`, `total_duration` | | `"interval"` | Play for `duration` ms, pause for `pause_duration` ms, repeat. Stop once `total_duration` ms have passed since the start (pauses included); `0` = never stop. | `duration` (> 0), `pause_duration`, `total_duration` |
| `"infinite"` | Loop until `playback.stop`. | — | | `"infinite"` | Never stops on its own; runs until `playback.stop`. With no `duration`/`pause_duration`, loops the melody continuously. With both, plays for `duration` ms, pauses for `pause_duration` ms, and repeats forever (same as `interval` with `total_duration: 0`). | `duration` + `pause_duration` (both > 0, or both omitted). `total_duration` is ignored. |
Exact timing, for all modes:
- **Timing is checked every 500 ms**, so each `duration`, `pause_duration` and `total_duration` boundary is hit up to 0.5 s late.
- **A loop is never cut short** (only `playback.stop` and the overload guard do that). When `duration` or `total_duration` runs out mid-loop, the current loop finishes first.
- **Status during that last loop:** at a segment end, `status/playback` goes to `paused` straight away while the loop finishes ringing. At the end of a `timed`/`interval` run it goes to `stopping`, then `idle` when the loop ends. `single` goes from `playing` directly to `idle`.
- **The pause is measured from the end of that loop:** the bells are silent for the full `pause_duration`, then `status/playback` goes back to `playing` and a new `duration` segment starts.
- **`total_duration` (interval) counts from the start of the play, pauses included.** If it runs out during a pause, playback stops at once (`paused` → `idle`).
- **No gap between loops:** in every looping mode the next loop starts right after the previous one; the last step's beat (`speed`) is the only spacing. (Before v2.5.1, runs with no end time waited ~0.5 s between loops.)
**Legacy timing** (`mode` absent): **Legacy timing** (`mode` absent):
@@ -217,6 +226,7 @@ Errors are checked in this order; the first that applies is returned. Every one
| `Invalid total_duration: must be a non-negative integer (ms)` | same, for `total_duration` | | `Invalid total_duration: must be a non-negative integer (ms)` | same, for `total_duration` |
| `Invalid mode: must be single, timed, interval or infinite` | Unrecognised `mode` | | `Invalid mode: must be single, timed, interval or infinite` | Unrecognised `mode` |
| `Invalid duration: mode timed and interval require duration > 0` | `mode` is `timed`/`interval` and `duration` is missing or 0 | | `Invalid duration: mode timed and interval require duration > 0` | `mode` is `timed`/`interval` and `duration` is missing or 0 |
| `Invalid infinite segments: duration and pause_duration must both be > 0, or both omitted` | `mode` is `infinite` and only one of `duration` / `pause_duration` is > 0 |
| `Playback blocked: bell mechanism is disabled (bells.enable)` | Bells master switch off (`bells.disable`) | | `Playback blocked: bell mechanism is disabled (bells.enable)` | Bells master switch off (`bells.disable`) |
| `Playback blocked: bell overload protection active — wait for the bells to cool` | Load guard enabled and any bell is over its max load (the guard would force-stop immediately) | | `Playback blocked: bell overload protection active — wait for the bells to cool` | Load guard enabled and any bell is over its max load (the guard would force-stop immediately) |
| `Melody failed to load: file is empty or corrupt` | `/melodies/{pid}` exists on SD but is empty or has an odd byte count | | `Melody failed to load: file is empty or corrupt` | `/melodies/{pid}` exists on SD but is empty or has an odd byte count |
@@ -235,6 +245,8 @@ The ACK itself is always sent synchronously from the command's own dispatch, so
{ "v": 2, "req_id": "a1", "cmd": "playback.play", "contents": { "pid": "westminster", "speed": 400, "mode": "single" } } { "v": 2, "req_id": "a1", "cmd": "playback.play", "contents": { "pid": "westminster", "speed": 400, "mode": "single" } }
{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "url": "https://example.com/ABC123.bin", "mode": "timed", "duration": 120000 } } { "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "url": "https://example.com/ABC123.bin", "mode": "timed", "duration": 120000 } }
{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "mode": "interval", "duration": 15000, "pause_duration": 5000, "total_duration": 180000 } } { "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "mode": "interval", "duration": 15000, "pause_duration": 5000, "total_duration": 180000 } }
{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "mode": "infinite" } }
{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "mode": "infinite", "duration": 30000, "pause_duration": 10000 } }
{ "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "segment_duration": 15000, "pause_duration": 5000, "continuous_loop": true } } { "v": 2, "cmd": "playback.play", "contents": { "pid": "ABC123", "segment_duration": 15000, "pause_duration": 5000, "continuous_loop": true } }
``` ```
+3 -4
View File
@@ -249,10 +249,9 @@ void BellEngine::playbackLoop() {
// Mark segment completion and notify Player // Mark segment completion and notify Player
_player.segmentCmpltTime = millis(); _player.segmentCmpltTime = millis();
_player.onMelodyLoopCompleted(); // 🔥 Notify Player that melody actually finished! _player.onMelodyLoopCompleted(); // 🔥 Notify Player that melody actually finished!
if ((_player.continuous_loop && _player.segment_duration == 0) || _player.total_duration == 0) { // No delay before the next loop: the last step's beat already spaces it from the
vTaskDelay(pdMS_TO_TICKS(500)); //Give Player time to pause/stop // next loop's first step. Play-once stops synchronously inside onMelodyLoopCompleted(),
LOG_VERBOSE(TAG, "BellEngine - Loop completed in SINGLE Mode - waiting for Player to handle pause/stop"); // and engineLoop()/playbackLoop() check pause/stop before starting the next pass (F-078).
}
LOG_DEBUG(TAG, "BellEngine - 🎵 Melody loop completed with PRECISION"); LOG_DEBUG(TAG, "BellEngine - 🎵 Melody loop completed with PRECISION");
} }
+17 -5
View File
@@ -392,6 +392,12 @@ String Player::validatePlayParams(JsonVariant doc) const {
if (timedOrInterval && (doc["duration"] | 0u) == 0) { if (timedOrInterval && (doc["duration"] | 0u) == 0) {
return "Invalid duration: mode timed and interval require duration > 0"; return "Invalid duration: mode timed and interval require duration > 0";
} }
// Segments need both halves: a duration with no pause would pause and
// resume on the same tick, a pause with no duration never triggers.
if (strcmp(mode, "infinite") == 0 &&
((doc["duration"] | 0u) == 0) != ((doc["pause_duration"] | 0u) == 0)) {
return "Invalid infinite segments: duration and pause_duration must both be > 0, or both omitted";
}
} }
return String(); return String();
@@ -444,7 +450,8 @@ void Player::setMelodyAttributes(JsonVariant doc) {
// "single" → one loop, no timer (segment_duration=0, continuous_loop=false) // "single" → one loop, no timer (segment_duration=0, continuous_loop=false)
// "timed" → loop for duration ms (segment_duration=duration, continuous_loop=false) // "timed" → loop for duration ms (segment_duration=duration, continuous_loop=false)
// "interval" → timed segments with pauses (continuous_loop=true, all three fields) // "interval" → timed segments with pauses (continuous_loop=true, all three fields)
// "infinite" → loop forever (continuous_loop=true, total_duration=0) // "infinite" → loop forever (continuous_loop=true, total_duration=0),
// optionally in duration/pause_duration segments like "interval"
if (doc.containsKey("mode")) { if (doc.containsKey("mode")) {
const char* mode = doc["mode"] | "single"; const char* mode = doc["mode"] | "single";
uint32_t dur = doc["duration"] | 0; uint32_t dur = doc["duration"] | 0;
@@ -460,9 +467,10 @@ void Player::setMelodyAttributes(JsonVariant doc) {
total_duration = doc["total_duration"] | 0; total_duration = doc["total_duration"] | 0;
continuous_loop = true; continuous_loop = true;
} else if (strcmp(mode, "infinite") == 0) { } else if (strcmp(mode, "infinite") == 0) {
segment_duration = 0; // Validation guarantees duration and pause_duration are both set or both 0.
pause_duration = 0; segment_duration = dur;
total_duration = 0; pause_duration = doc["pause_duration"] | 0;
total_duration = 0; // never read — infinite has no end time
continuous_loop = true; continuous_loop = true;
} else { } else {
// "single" or unknown → one loop, no timer // "single" or unknown → one loop, no timer
@@ -804,7 +812,11 @@ bool Player::timeToPause(unsigned long now) {
// Check if it's time to resume playback // Check if it's time to resume playback
bool Player::timeToResume(unsigned long now) { bool Player::timeToResume(unsigned long now) {
if (isPaused) { // The pause is flagged mid-loop and the engine finishes that loop first, so
// until it does, segmentCmpltTime still holds the PREVIOUS loop's end. A
// pause_duration shorter than one loop would then resume before the bells
// ever went quiet — wait for the loop that was playing at pause time to end.
if (isPaused && segmentCmpltTime >= pauseTime) {
uint64_t timeToResume = segmentCmpltTime + (uint64_t)pause_duration; uint64_t timeToResume = segmentCmpltTime + (uint64_t)pause_duration;
if ((uint64_t)now >= timeToResume) { if ((uint64_t)now >= timeToResume) {
_pendingResumeReason = "Pause duration reached — resuming"; _pendingResumeReason = "Pause duration reached — resuming";
+4 -1
View File
@@ -29,8 +29,11 @@
// WiFi modem sleep off, vendored/patched AsyncMqttClient, pinned deps, // WiFi modem sleep off, vendored/patched AsyncMqttClient, pinned deps,
// WiFi/NTP task-retry, infinite-mode status flicker fix (F-071..F-074) // WiFi/NTP task-retry, infinite-mode status flicker fix (F-071..F-074)
// v2.4.1 - Play/stop replies no longer wait for telemetry SD writes (F-075) // v2.4.1 - Play/stop replies no longer wait for telemetry SD writes (F-075)
// v2.4.2 - Fixes pauses shorter than one melody loop being skipped (F-076)
// v2.5.0 - mode "infinite" accepts duration + pause_duration segments (F-077)
// v2.5.1 - Removes the hardcoded ~0.5 s gap between melody loops (F-078)
// ═══════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════
#define FW_VERSION "2.4.1" #define FW_VERSION "2.5.1"
// ═══════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════
// SemVer — lightweight 3-part version struct // SemVer — lightweight 3-part version struct