Skip to content

fix: resolve ReferenceErrors in Sampler, Tuner, and TurtleActions#7774

Merged
walterbender merged 3 commits into
sugarlabs:masterfrom
KeerthiKumarR:fix/sampler-tuner-reference-errors
Jul 10, 2026
Merged

fix: resolve ReferenceErrors in Sampler, Tuner, and TurtleActions#7774
walterbender merged 3 commits into
sugarlabs:masterfrom
KeerthiKumarR:fix/sampler-tuner-reference-errors

Conversation

@KeerthiKumarR

@KeerthiKumarR KeerthiKumarR commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Opening the Tuner or triggering audio/timbre actions from the Sampler widget resulted in uncaught console errors (ReferenceError: TunerUtils is not defined and ReferenceError: MusicBlocks is not defined), preventing sample tuning and timbre selection from functioning correctly in interactive browser sessions. Additionally, playing recorded audio left playback buttons stuck without properly resetting icon animations or playback toggle states.

Fix

  • Tuner Registration & Export: Registered "widgets/tuner" in MUSICBLOCKS_EXTRAS (js/activity.js) so tuner.js loads before sampler.js, and exported window.TunerUtils = TunerUtils in js/widgets/tuner.js so SamplerWidget can access pitch conversion utilities globally.
  • Global MusicBlocks Guard: Changed else if (MusicBlocks.isRun) to check typeof MusicBlocks !== "undefined" && MusicBlocks.isRun across all 6 turtle action files (ToneActions.js, DrumActions.js, OrnamentActions.js, MeterActions.js, IntervalsActions.js, VolumeActions.js) so accessing action listeners does not throw ReferenceError when running inside browser editor sessions.
  • Sampler Property & Canvas Guards: Added null checks before reading .connections or styling samplerCanvas in SamplerWidget (js/widgets/sampler.js).
  • Recording Playback Context & Button Animations:
    • Resumed browser Web Audio context (await Tone.start() / Tone.context.resume()) when playing recordings (js/utils/synthutils.js) and added a reliable duration completion handler so playback = false resets when audio finishes playing.
    • Updated this.pause(), this.resume(), and _playbackBtn.onclick in SamplerWidget (js/widgets/sampler.js) to directly update image src attributes (img.src), ensuring smooth and reliable icon toggling (play-button.svgpause-button.svg and playback.svgstop-button.svg).

PR Category

  • Bug Fix

Changes Made

  • Modified js/activity.js (Added widgets/tuner to MUSICBLOCKS_EXTRAS)
  • Modified js/widgets/tuner.js (Exported TunerDisplay and TunerUtils to window)
  • Modified js/widgets/sampler.js (Added .connections and samplerCanvas null checks; updated play/pause and playback button handlers to directly update img.src)
  • Modified js/utils/synthutils.js (Resumed Tone.start() / Tone.context.resume() on recording playback, added duration completion timeout fallback, and cleaned up timeout in _disposeRecordingPlayer)
  • Modified js/turtleactions/ToneActions.js, DrumActions.js, OrnamentActions.js, MeterActions.js, IntervalsActions.js, VolumeActions.js (Guarded global MusicBlocks check with typeof MusicBlocks !== "undefined")

Testing Performed

  • npm run lint — passes with 0 errors
  • npx prettier --check . — passes
  • npm test — all tests passed successfully across sampler.test.js, tuner.test.js, and all 9 turtleactions test suites

@github-actions github-actions Bot added bug fix Fixes a bug or incorrect behavior size/L Large: 250-499 lines changed area/javascript Changes to JS source files labels Jul 9, 2026
@KeerthiKumarR

Copy link
Copy Markdown
Contributor Author

@walterbender @Ashutoshx7 please take a look when u got time!

@walterbender

Copy link
Copy Markdown
Member

Did you also test by running the sampler widget? And trying to use some of the other code paths you changed?

@KeerthiKumarR

Copy link
Copy Markdown
Contributor Author

Did you also test by running the sampler widget? And trying to use some of the other code paths you changed?
Thanks @walterbender! I have tested and verified the fixes locally:

The ReferenceError: TunerUtils is not defined and ReferenceError: MusicBlocks is not defined console errors are resolved.
Opening Tuner from Sampler and triggering audio/timbre actions work smoothly.
Recorded audio playback and play/pause button icon animations update and reset correctly.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.22%. Comparing base (c98a065) to head (f8589f9).

Files with missing lines Patch % Lines
js/widgets/sampler.js 77.48% 34 Missing ⚠️
js/utils/synthutils.js 42.30% 15 Missing ⚠️
js/turtleactions/IntervalsActions.js 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7774      +/-   ##
==========================================
- Coverage   58.23%   58.22%   -0.01%     
==========================================
  Files         174      174              
  Lines       57787    57872      +85     
==========================================
+ Hits        33650    33696      +46     
- Misses      24137    24176      +39     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@walterbender walterbender merged commit 1267b95 into sugarlabs:master Jul 10, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/javascript Changes to JS source files bug fix Fixes a bug or incorrect behavior size/L Large: 250-499 lines changed

Projects

Development

Successfully merging this pull request may close these issues.

2 participants