Enable set_scene_bpm and set_mesh_bpm blocks in sound toolbox#417
Conversation
Both blocks had input_value BPM fields but were missing from the toolbox. Adds them with math_number shadow blocks defaulting to 60 BPM. https://claude.ai/code/session_01WHfBDw4GAS4LdEpdjWGGm2
📝 WalkthroughWalkthroughToolbox and block definitions for sound were updated: MIDI note fields were converted to value inputs with shadow math_number defaults, a new create_instrument block (with frequency/attack/decay/sustain/release shadow inputs) was added to the toolbox, generators were updated to read inputs via valueToCode, and locale strings for create_instrument were reformatted with a newline. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
…adow blocks - midi_note: NOTE field_number → input_value with math_number shadow (default 60) - create_instrument: FREQUENCY, ATTACK, DECAY, SUSTAIN, RELEASE field_number → input_value with math_number shadows (defaults: 440, 0.1, 0.5, 0.7, 1) - Update generators to use valueToCode instead of getFieldValue for these inputs - Update toolbox shadow blocks accordingly, including nested midi_note in play_notes - Revert unintended set_mesh_bpm uncomment https://claude.ai/code/session_01WHfBDw4GAS4LdEpdjWGGm2
…elated set_scene_bpm - Add \n before attack in create_instrument message across all locales so ATTACK, DECAY, SUSTAIN, RELEASE render on their own line - Remove set_scene_bpm toolbox addition that was not requested https://claude.ai/code/session_01WHfBDw4GAS4LdEpdjWGGm2
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
toolbox.js (1)
3214-3329:⚠️ Potential issue | 🟠 MajorPR objective not met: BPM toolbox blocks are still not enabled.
set_mesh_bpmremains commented (Line [3316]-[3329]) andset_scene_bpmis not present intoolboxSound.contents, so these blocks are still inaccessible in the sound toolbox.🔧 Proposed fix
{ kind: "block", type: "play_notes", inputsInline: true, inputs: { ... }, }, - /*{ + { + kind: "block", + type: "set_scene_bpm", + inputs: { + BPM: { + shadow: { + type: "math_number", + fields: { + NUM: 60, + }, + }, + }, + }, + }, + { kind: "block", type: "set_mesh_bpm", inputs: { BPM: { shadow: { type: "math_number", fields: { NUM: 60, }, }, }, }, - },*/ + }, { kind: "block", type: "instrument", },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@toolbox.js` around lines 3214 - 3329, The sound toolbox still lacks BPM blocks because the set_mesh_bpm block is left commented out and set_scene_bpm is missing from toolboxSound.contents; uncomment the existing set_mesh_bpm block (restore the block object with type "set_mesh_bpm" and its BPM input shadow math_number NUM:60) and add a similar block object for "set_scene_bpm" into toolboxSound.contents so both BPM controls are available in the sound toolbox (use the same inputs structure as the existing set_mesh_bpm block and place them alongside the other sound blocks such as "play_sound" and "play_notes").
🧹 Nitpick comments (1)
blocks/sound.js (1)
131-133: Consider preserving numeric bounds now that inputs accept expressions.Line [131] and Lines [294-316] removed field-level numeric limits when switching to
input_value. Please clamp/validate at generation/runtime (e.g., MIDI 0–127,FREQUENCY > 0,ATTACK/DECAY/RELEASE >= 0,SUSTAINin 0–1) so invalid expressions don’t produce unstable audio behavior.Also applies to: 294-316
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@blocks/sound.js` around lines 131 - 133, Replace removed field-level numeric limits by validating and clamping values where code reads input values for the sound block (e.g., the "NOTE" input and the other inputs referenced around lines 294-316 such as FREQUENCY, ATTACK, DECAY, RELEASE, SUSTAIN). In the generator/runtime path that consumes these input_value fields (look for the functions that serialize/compile block inputs or the sound synthesis routine that uses NOTE, FREQUENCY, ATTACK, DECAY, RELEASE, SUSTAIN), coerce expressions to numbers, validate ranges and clamp: NOTE to 0–127, FREQUENCY > 0, ATTACK/DECAY/RELEASE >= 0, and SUSTAIN to 0–1; if conversion fails or values are out of bounds, fall back to safe defaults and/or emit a warning so invalid expressions don’t produce unstable audio.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@toolbox.js`:
- Around line 3214-3329: The sound toolbox still lacks BPM blocks because the
set_mesh_bpm block is left commented out and set_scene_bpm is missing from
toolboxSound.contents; uncomment the existing set_mesh_bpm block (restore the
block object with type "set_mesh_bpm" and its BPM input shadow math_number
NUM:60) and add a similar block object for "set_scene_bpm" into
toolboxSound.contents so both BPM controls are available in the sound toolbox
(use the same inputs structure as the existing set_mesh_bpm block and place them
alongside the other sound blocks such as "play_sound" and "play_notes").
---
Nitpick comments:
In `@blocks/sound.js`:
- Around line 131-133: Replace removed field-level numeric limits by validating
and clamping values where code reads input values for the sound block (e.g., the
"NOTE" input and the other inputs referenced around lines 294-316 such as
FREQUENCY, ATTACK, DECAY, RELEASE, SUSTAIN). In the generator/runtime path that
consumes these input_value fields (look for the functions that serialize/compile
block inputs or the sound synthesis routine that uses NOTE, FREQUENCY, ATTACK,
DECAY, RELEASE, SUSTAIN), coerce expressions to numbers, validate ranges and
clamp: NOTE to 0–127, FREQUENCY > 0, ATTACK/DECAY/RELEASE >= 0, and SUSTAIN to
0–1; if conversion fails or values are out of bounds, fall back to safe defaults
and/or emit a warning so invalid expressions don’t produce unstable audio.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 31a325e8-fea9-4d98-89c1-83a95135d0fb
📒 Files selected for processing (11)
blocks/sound.jsgenerators/generators.jslocale/de.jslocale/en.jslocale/es.jslocale/fr.jslocale/it.jslocale/pl.jslocale/pt.jslocale/sv.jstoolbox.js
Summary
Update sound blocks to use shadow blocks
Key Changes
Implementation Details
https://claude.ai/code/session_01WHfBDw4GAS4LdEpdjWGGm2
Summary by CodeRabbit
New Features
Improvements
Localization