Add shared piano recording/playback and mono key fallback

This commit is contained in:
Jage9
2026-02-23 00:36:36 -05:00
parent b4cf85ac44
commit 93b9d19455
13 changed files with 484 additions and 61 deletions

View File

@@ -105,6 +105,12 @@ PROPERTY_METADATA: dict[str, dict[str, object]] = {
def validate_update(_item: WorldItem, next_params: dict) -> dict:
"""Validate and normalize piano params."""
# Recording data is server-managed and not directly editable from client updates.
preserved_recording = _item.params.get("recording")
preserved_recording_length = _item.params.get("recordingLengthMs")
next_params.pop("recording", None)
next_params.pop("recordingLengthMs", None)
instrument = str(next_params.get("instrument", "piano")).strip().lower()
if instrument not in INSTRUMENT_OPTIONS:
raise ValueError(f"instrument must be one of: {', '.join(INSTRUMENT_OPTIONS)}.")
@@ -171,6 +177,11 @@ def validate_update(_item: WorldItem, next_params: dict) -> dict:
raise ValueError("emitRange must be between 5 and 20.")
next_params["emitRange"] = emit_range
if isinstance(preserved_recording, list):
next_params["recording"] = preserved_recording
if isinstance(preserved_recording_length, (int, float)):
next_params["recordingLengthMs"] = max(0, min(30_000, int(preserved_recording_length)))
return next_params