Skip to content

fix(musicutils): correct octave check for "ti" in getNumNote#7447

Open
Harshit-Mishra2212 wants to merge 1 commit into
sugarlabs:masterfrom
Harshit-Mishra2212:fix/getNumNote-ti-octave
Open

fix(musicutils): correct octave check for "ti" in getNumNote#7447
Harshit-Mishra2212 wants to merge 1 commit into
sugarlabs:masterfrom
Harshit-Mishra2212:fix/getNumNote-ti-octave

Conversation

@Harshit-Mishra2212

Copy link
Copy Markdown
Contributor

Description

getNumNote in musicutils.js converts a numeric pitch value into a solfege note name and octave. When the resulting note is "ti", the octave should be decremented by 1 -- this is a standard musical convention since "ti" sits at the boundary between octaves in the solfege system.

The existing check was:

if (note[num] === "ti") {
    octave -= 1;
}

Here note is a string like "ti" and num is the modulo result (0–11). note[num] indexes a character from the string at position num but since "ti" is only 2 characters long, note[num] is undefined for any num >= 2. For num === 0 (the only case where "ti" can appear, since NOTESTABLE[0] === "ti"), note[0] gives "t", not "ti". So this condition is always false and the octave decrement never fires.

As a result, every call to getNumNote that produces a "ti" note returns an octave that is 1 too high.

The fix is a one-character change: note[num]note.

Related Issue

No related issue -- bug identified through code analysis.

PR Category

  • Bug Fix

Changes Made

  • js/utils/musicutils.js: change note[num] === "ti" to note === "ti" in getNumNote
  • js/utils/__tests__/musicutils.test.js: add 3 test assertions covering the "ti" octave decrement path, which had zero coverage

Testing Performed

  • Ran npm test -- musicutils - all tests pass
  • Ran full test suite npm test - no regressions introduced

Checklist

  • I have tested these changes locally and they work as expected.
  • I have updated tests that prove the effectiveness of these changes.
  • I have updated the documentation to reflect these changes.
  • I have followed the project's coding style guidelines.
  • I have run npm run lint and npx prettier --check . with no errors.
  • I have enabled "Allow edits from maintainers"

@github-actions github-actions Bot added bug fix Fixes a bug or incorrect behavior size/XS Extra small: < 10 lines changed area/javascript Changes to JS source files area/tests Changes to test files labels May 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🧪 Jest Test Results

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

Coverage: Statements: 48.09% | Branches: 39.62% | Functions: 52.88% | Lines: 48.49%
Master Coverage: Statements: 48.09% | Branches: 39.61% | Functions: 52.88% | Lines: 48.49%

@mahesh-09-12 mahesh-09-12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good to me - the fix addresses the octave check correctly, and the added tests cover the affected path well

@github-actions

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with master.

Please rebase your branch:

# Add upstream remote (one-time setup)
git remote add upstream https://github.com/sugarlabs/musicblocks.git

# Fetch latest master and rebase
git fetch upstream
git rebase upstream/master

# Resolve any conflicts, then:
git push --force-with-lease origin YOUR_BRANCH

Tip: Enable "Allow edits from maintainers" on this PR so we can auto-rebase for you next time. This only grants access to your PR branch. Your fork's other branches are not affected.

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

🧪 Jest Test Results

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

Coverage: Statements: 48.23% | Branches: 39.77% | Functions: 52.95% | Lines: 48.63%
Master Coverage: Statements: 48.23% | Branches: 39.77% | Functions: 52.95% | Lines: 48.62%

Note: These failures may be introduced by this PR or may already exist in the master branch.
Tip: Update your branch with the latest master and rerun tests.
If the same failures are present on master, they are likely not introduced by this PR.

Failed Tests:

aidebugger.test.js

@Harshit-Mishra2212

Copy link
Copy Markdown
Contributor Author

Rebased on latest master to resolve merge conflict. The upstream changes added temperament support to getNumNote - the ti octave fix applies cleanly to the new implementation.

@vyagh vyagh requested review from Ashutoshx7 and omsuneri June 11, 2026 13:00
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 area/tests Changes to test files bug fix Fixes a bug or incorrect behavior size/XS Extra small: < 10 lines changed

Projects

Development

Successfully merging this pull request may close these issues.

2 participants