feat: add setStereoSeparation method to ChiptuneJsPlayer#4
Open
indigo423 wants to merge 1 commit into
Open
Conversation
Add a main-thread entry point to update the stereo-separation render
param on a running module, and to update the worklet's persisted
this.config.stereoSeparation so subsequently-loaded modules inherit
the value without a reload.
Today the worklet's play() handler already reads
this.config.stereoSeparation and stamps it via
openmpt_module_set_render_param at module-create time, but consumers
have no way to mutate the config from the main thread after the
ChiptuneJsPlayer constructor's auto-config post. setStereoSeparation
fills that gap by posting a {cmd:'setStereoSeparation', val} message
that the worklet handles by mutating this.config and (when a module
is loaded) calling set_render_param immediately.
The worklet-side handler clamps incoming values to [0, 200] (the
libopenmpt documented range; 100 = default, 0 = mono) and falls back
to the default 100 on non-finite values, so callers can be liberal
in what they send.
Use case: an Amiga MOD player UI that exposes a "stereo separation"
slider letting listeners gradually collapse the classic hard-panned
field toward mono. Without this method the only way to change the
value after page load is to recreate the ChiptuneJsPlayer (destroys
the AudioContext + reloads the worklet, ~0.5s silence on every
slider tick).
The .min.js siblings are not regenerated in this PR -- I assume
minify.js runs as part of a release cut. Happy to add them if
preferred.
Assisted-by: ClaudeCode:claude-opus-4-7
Signed-off-by: Ronny Trommer <ronny@no42.org>
e35b889 to
baf8e51
Compare
indigo423
added a commit
to no42-org/CoolModFiles
that referenced
this pull request
May 12, 2026
Add a Stereo separation slider (0% mono → 100% libopenmpt default) to
the Sound pane. Persists under audio.stereoSeparation and rides the
ChiptuneJsPlayer constructor config so the worklet receives it via
the auto-posted {cmd:'config'} message — no per-track re-apply, no
race against audioWorklet.addModule().
Local vendored chiptune3 patch adds a typed setStereoSeparation
method; upstream PR DrSnuggles/chiptune#4 mirrors it.
Assisted-by: ClaudeCode:claude-opus-4-7
indigo423
added a commit
to no42-org/CoolModFiles
that referenced
this pull request
May 12, 2026
Add a Stereo separation slider (0% mono → 100% libopenmpt default) to
the Sound pane. Persists under audio.stereoSeparation and rides the
ChiptuneJsPlayer constructor config so the worklet receives it via
the auto-posted {cmd:'config'} message — no per-track re-apply, no
race against audioWorklet.addModule().
Local vendored chiptune3 patch adds a typed setStereoSeparation
method; upstream PR DrSnuggles/chiptune#4 mirrors it.
Assisted-by: ClaudeCode:claude-opus-4-7
Signed-off-by: Ronny Trommer <ronny@no42.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
setStereoSeparation(val)method toChiptuneJsPlayerand a matching'setStereoSeparation'case in the worklet'shandleMessage_. Mirrors the existingsetPitch/setTemposhape.Why
The worklet's
play()already readsthis.config.stereoSeparationand stamps it viaopenmpt_module_set_render_paramat module-create time, anddefaultCfg.stereoSeparationis a public config key, but there's currently no path from the main thread to mutate the value after the constructor's auto-config post. Today, changing stereo separation after page load means recreating theChiptuneJsPlayer— destroying theAudioContext, reloading the worklet, and giving the listener ~0.5s of silence on every tick of a UI slider.This method fills the gap symmetrically with the existing render-param consumer in
play():{cmd:'setStereoSeparation', val}from the main thread.this.config.stereoSeparationso subsequently-loaded modules inherit the value._openmpt_module_set_render_param(modulePtr, OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT, val)for an immediate audible update.The worklet clamps incoming values to
[0, 200](libopenmpt's documented range —100= default,0= mono,200= exaggerated) and falls back to100on non-finite values, so callers can be liberal in what they send.Use case
The CoolModFiles project is using this library and wants a "stereo separation" slider in the player UI so headphone listeners can gradually collapse the classic hard-panned MOD field toward mono. The slider lives in a settings panel and updates the value live as the user drags. A live demo is on https://mods.amiga.fans.
Diff
+14 lines, 2 files. No new dependencies, no API removals.chiptune3.js:setStereoSeparation(val) { this.postMsg('setStereoSeparation', val) }placed next tosetTempo.chiptune3.worklet.js: newcase 'setStereoSeparation'inhandleMessage_placed next tosetTempo.Notes
.min.jssiblings are not regenerated in this PR — I assumedminify.jsruns as part of a release cut. Happy to include them if you'd prefer.v3(current default).Thanks for
chiptune— it's the audio backbone of the site. Glad to send fixes back when we have them.