Skip to content

Sync tempo widget BPM changes to engine in real time#5793

Open
Ady0333 wants to merge 5 commits intosugarlabs:masterfrom
Ady0333:fix/tempo-widget-live-bpm
Open

Sync tempo widget BPM changes to engine in real time#5793
Ady0333 wants to merge 5 commits intosugarlabs:masterfrom
Ady0333:fix/tempo-widget-live-bpm

Conversation

@Ady0333
Copy link
Contributor

@Ady0333 Ady0333 commented Feb 18, 2026

Summary

This PR fixes a real-time desynchronization between the Tempo widget and the playback engine. When BPM was changed using the Tempo widget (slider, buttons, or input), _updateBPM() only updated the block’s visual value on the canvas. The engine continued using the old BPM until the program was stopped and run again.


What changed

After updating the block value, _updateBPM() now also propagates the BPM to the engine:

  • For setmasterbpm / setmasterbpm2: updates Singer.masterBPM and Singer.defaultBPMFactor
  • For setbpm3 / setbpm2: updates the top value of each running turtle’s singer.bpm stack

Example:

Singer.masterBPM = bpmValue;
Singer.defaultBPMFactor = TONEBPM / bpmValue;


Why this change was needed

The engine computes note timing from:

TONEBPM / (tur.singer.bpm.length > 0 ? last(tur.singer.bpm) : Singer.masterBPM);

Since _updateBPM() never updated these engine values, the metronome ticked at the new tempo while notes continued playing at the old one. This broke the expected real-time behavior of the Tempo widget.


Scope

  • Affects only js/widgets/tempo.js
  • No changes to block execution flow
  • No impact on programs that do not modify BPM during execution

Verification

  • Changed BPM during execution and confirmed notes adjust immediately
  • Verified metronome and playback stay synchronized
  • All tests pass and lint is clean

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

1 similar comment
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Ady0333
Copy link
Contributor Author

Ady0333 commented Feb 18, 2026

@walterbender and @vanshika2720, the pr is ready please review it once.

@vanshika2720
Copy link
Contributor

vanshika2720 commented Feb 18, 2026

@Ady0333 please pull the latest master, rebase it into your branch, and push again.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Ady0333
Copy link
Contributor Author

Ady0333 commented Feb 18, 2026

@vanshika2720

Copy link
Contributor

@vanshika2720 vanshika2720 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walterbender I’ve reviewed the changes — the real-time BPM sync is correctly implemented and scoped. I don’t see any blocking issues from my side. Looks good for approval.

@Ady0333
Copy link
Contributor Author

Ady0333 commented Feb 18, 2026

@walterbender I’ve reviewed the changes — the real-time BPM sync is correctly implemented and scoped. I don’t see any blocking issues from my side. Looks good for approval.

@vanshika2720 Thanks!!

@walterbender
Copy link
Member

Please remove the unrelated changes

@Ady0333
Copy link
Contributor Author

Ady0333 commented Feb 22, 2026

Please remove the unrelated changes

Yes sir sure!!!

@Ady0333 Ady0333 force-pushed the fix/tempo-widget-live-bpm branch from 9751244 to 14c3bce Compare February 22, 2026 23:42
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Ashutoshx7
Copy link
Contributor

@Ady0333 Hi
lint failing and also Performance CI

overall this pr looks good
one small suggestion we should probably add a quick validation check before updating the engine state

@walterbender
Copy link
Member

Everything seems good but I don't know why we are seeing the Lighthouse errors.

@Ady0333
Copy link
Contributor Author

Ady0333 commented Mar 9, 2026

Everything seems good but I don't know why we are seeing the Lighthouse errors.

Apologize for this. I will fix them .

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

✅ All Jest tests passed! This PR is ready to merge.

1 similar comment
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

✅ All Jest tests passed! This PR is ready to merge.

Ady0333 added 4 commits March 9, 2026 23:59
Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
Update the global location comment in tempo.js to point to js/logoconstants.js
instead of js/activity.js where TONEBPM is actually defined.

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
Resolve npm ci failures by updating the lock file to match the current
package.json dependencies. This fixes CI failures in GitHub Actions.

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
@Ady0333 Ady0333 force-pushed the fix/tempo-widget-live-bpm branch from bd6a6b0 to 5b96945 Compare March 9, 2026 18:36
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

GraphicsBlocks.test.js

The lock file was accidentally deleted in the previous commit.
This restores it so that npm ci can run successfully in CI workflows.

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

GraphicsBlocks.test.js

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.

4 participants