Skip to content

Add loop playback support#121

Merged
grimmdude merged 3 commits intomasterfrom
feature/loop-playback
Mar 22, 2026
Merged

Add loop playback support#121
grimmdude merged 3 commits intomasterfrom
feature/loop-playback

Conversation

@grimmdude
Copy link
Copy Markdown
Owner

Summary

  • Adds a loop property to the Player class — when true, playback restarts automatically at end-of-file instead of stopping
  • Marks the internal playLoop() method as @private in JSDoc to clarify it is not a public looping API
  • The endOfFile event is still emitted on each loop iteration so consumers can react

Usage

const player = new Player();
player.loop = true;
player.loadFile('song.mid');
player.play(); // restarts automatically at end

Closes #105

Test plan

  • All existing tests pass (42 passing)
  • Manual test: play a MIDI file with loop = false (default) — should stop at end
  • Manual test: play a MIDI file with loop = true — should restart seamlessly at end
  • Verify endOfFile event fires on each loop iteration

🤖 Generated with Claude Code

grimmdude and others added 3 commits March 21, 2026 22:26
Add a `loop` property to the Player class. When set to true, playback
automatically restarts from the beginning when the end of the file is
reached, instead of stopping. The `endOfFile` event is still emitted
on each loop iteration.

Also marks the internal `playLoop()` method as `@private` in JSDoc to
clarify it is not a public API for looping songs.

Closes #105

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Hoist endOfFile() check above the tracks forEach so it runs once
  instead of once per track. This fixes endOfFile firing N times
  (once per track) and the loop restart logic running repeatedly.
- Reset scheduledTime when looping to prevent drift-correction from
  clamping delays to 0 after a restart.
- Use Date.now() consistently instead of mixing with (new Date()).getTime().
- Add three automated tests for the loop feature: restart on loop,
  single endOfFile per iteration, and stop when loop is false.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change assert from <= 1 (allows zero) to strict equality with 1,
since sinon fake timers make timing deterministic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@grimmdude grimmdude merged commit 608ac98 into master Mar 22, 2026
2 checks passed
@grimmdude grimmdude mentioned this pull request Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loop functionality?

1 participant