Skip to content

Issue 4724#6520

Draft
shaikhibrahim2000 wants to merge 2 commits intosugarlabs:masterfrom
shaikhibrahim2000:issue-4724
Draft

Issue 4724#6520
shaikhibrahim2000 wants to merge 2 commits intosugarlabs:masterfrom
shaikhibrahim2000:issue-4724

Conversation

@shaikhibrahim2000
Copy link
Copy Markdown

Description

This PR fully addresses #4724 — fixing both issues with Custom Pitch Blocks:

  1. Identity Loss: Custom Pitch Blocks were reverting to regular Pitch Blocks when dragged from the palette.
  2. Missing Preview Sound: Clicking on notes in the Custom Pitch Block's pie menu produced static noise or silence instead of a pitch preview.

Root Cause

Identity Loss (js/blocks.js)

The switch statement that handles block replacement when dragging from the palette had no case for "customNote". Without it, custom pitch blocks fell through to the default behavior and were replaced with regular pitch blocks.

Missing Preview Sound (js/piemenus.js + js/utils/synthutils.js)

The __selectionChanged handler in piemenuCustomNotes (js/piemenus.js) had two problems:

  1. No audio context initializationTone.start() was never called. Modern browsers require this after user interaction before audio can play.

  2. getNote() can't parse custom note names — Custom notes like C(+0¢) were passed through getNote(), which only understands standard note names (C, D, E...), producing invalid output that caused the frequency lookup to fail.

Additionally, getCustomFrequency() in synthutils.js could not handle pitch-index labels (e.g., "0", "1") — when custom temperament data stores entries as plain ratio numbers instead of [ratio, name, octave] arrays, the function failed to find a match and returned a string instead of a frequency.

Changes

js/blocks.js

  • Added case "customNote" to the block replacement switch statement so Custom Pitch Blocks retain their identity when dragged from the palette.

js/utils/synthutils.js — getCustomFrequency()

  • Added a fallback after the existing note-name matching loop: when no match is found, it checks if the note is a pitch-index key (e.g., "0") in the temperament data and computes the frequency directly from the ratio.

js/piemenus.js — piemenuCustomNotes.__selectionChanged()

  • Made the handler async and added Tone.start() for proper audio context initialization.
  • Replaced getNote() (which can't parse custom note names) with direct note + octave passed to getCustomFrequency().

Testing

  • All existing tests pass (3861 tests, 123 suites)
  • Manually verified:
    • Custom Pitch Blocks retain their identity when dragged from the palette
    • Pie menu plays clean preview sounds for both regular and Define Temperament workflows

PR Category

  • Bug Fix
  • Feature
  • Performance
  • Tests
  • Documentation

@github-actions github-actions bot added bug fix Fixes a bug or incorrect behavior size/M Medium: 50-249 lines changed area/javascript Changes to JS source files labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

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

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/M Medium: 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant