Skip to content

WaitBlock bpmFactor operator precedence bug causes incorrect timing #7416

@netram75

Description

@netram75

Description

WaitBlock in js/blocks/ExtrasBlocks.js at line 402 computes bpmFactor using incorrect operator precedence:

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

Due to JavaScript operator precedence, / binds tighter than >, so this evaluates as (TONEBPM / bpm.length) > 0 instead of checking whether the bpm stack is non-empty. Since TONEBPM is 240, the condition is always true. When the bpm stack is empty, last([]) returns undefined, making bpmFactor undefined and noteBeatValue NaN. The Wait block silently computes incorrect timing.

Expected Behavior

When no BPM block is active, bpmFactor should fall back to Singer.masterBPM. The correct pattern is already used in RhythmBlockPaletteBlocks.js:183 and turtle-singer.js:1380:

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

How to Reproduce

  1. Open Music Blocks in the browser
  2. Place a Wait block with no Set BPM block wrapping it
  3. Run the program
  4. Open the console (Ctrl+Shift+J)
  5. noteBeatValue is NaN and wait duration is incorrect

Console log Errors

noteBeatValue evaluates to NaN when the bpm stack is empty.

Environment

  • Operating System: Windows 11
  • Browser: Chrome
  • Version of Software/Project: master

Checklist

  • I have read and followed the project's code of conduct.
  • I have searched for similar issues before creating this one.
  • I have provided all the necessary information to understand and reproduce the issue.
  • I am willing to contribute to the resolution of this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions