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>
This commit is contained in:
2026-10-28 11:10:06 +02:00
co-authored by Claude Opus 5.5
parent 5d8600d6bf
commit 1aff1e987b
4 changed files with 26 additions and 8 deletions
+20 -2
View File
@@ -90,6 +90,7 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
| 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-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-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 |
--- ---
@@ -348,7 +349,7 @@ V2 play commands replace the ambiguous `continuous_loop` / `segment_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; optionally in `duration`/`pause_duration` segments (F-077) | none, or `duration` + `pause_duration` | | `"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, the ~0.5 s gap between loops): 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. 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.
@@ -1599,10 +1600,27 @@ Subsystem: `src/Player/Player.cpp`
| Sent | Behaviour | | Sent | Behaviour |
|---|---| |---|---|
| neither (or both `0`) | Unchanged: back-to-back loops (with the ~0.5 s engine gap) until `playback.stop`. | | 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`. | | 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. | | 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. `total_duration` is never read for `infinite`. `interval` with `total_duration: 0` still works as before.
Subsystem: `src/Player/Player.cpp` (`validatePlayParams`, `setMelodyAttributes`) 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`
+1 -1
View File
@@ -202,7 +202,7 @@ Exact timing, for all modes:
- **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`. - **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. - **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`). - **`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`).
- **Gap between loops:** whenever the run has no end time (`single`, `infinite`, `interval` with `total_duration: 0`), the engine waits ~0.5 s after each loop before starting the next one. `timed` and `interval` with a `total_duration` loop with no gap. - **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):
+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");
} }
+2 -1
View File
@@ -31,8 +31,9 @@
// 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.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.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.5.0" #define FW_VERSION "2.5.1"
// ═══════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════
// SemVer — lightweight 3-part version struct // SemVer — lightweight 3-part version struct