Add shared piano recording/playback and mono key fallback
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user