Add min/max value range to audio value sources

Add min_value and max_value fields to AudioValueSource so audio
brightness can be mapped to a configurable range (e.g. silence =
30% brightness floor instead of fully black).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 20:41:49 +03:00
parent f96cd5f367
commit d45e59b0e6
3 changed files with 39 additions and 1 deletions

View File

@@ -91,6 +91,8 @@ class ValueSource:
mode=data.get("mode") or "rms",
sensitivity=float(data.get("sensitivity") or 1.0),
smoothing=float(data.get("smoothing") or 0.3),
min_value=float(data.get("min_value") or 0.0),
max_value=float(data["max_value"]) if data.get("max_value") is not None else 1.0,
)
if source_type == "adaptive_time":
@@ -167,10 +169,12 @@ class AudioValueSource(ValueSource):
into a scalar value for brightness modulation.
"""
audio_source_id: str = "" # references a MonoAudioSource
audio_source_id: str = "" # references an audio source (mono or multichannel)
mode: str = "rms" # rms | peak | beat
sensitivity: float = 1.0 # gain multiplier (0.15.0)
smoothing: float = 0.3 # temporal smoothing (0.01.0)
min_value: float = 0.0 # minimum output (0.01.0)
max_value: float = 1.0 # maximum output (0.01.0)
def to_dict(self) -> dict:
d = super().to_dict()
@@ -178,6 +182,8 @@ class AudioValueSource(ValueSource):
d["mode"] = self.mode
d["sensitivity"] = self.sensitivity
d["smoothing"] = self.smoothing
d["min_value"] = self.min_value
d["max_value"] = self.max_value
return d

View File

@@ -142,6 +142,8 @@ class ValueSourceStore:
mode=mode or "rms",
sensitivity=sensitivity if sensitivity is not None else 1.0,
smoothing=smoothing if smoothing is not None else 0.3,
min_value=min_value if min_value is not None else 0.0,
max_value=max_value if max_value is not None else 1.0,
)
elif source_type == "adaptive_time":
schedule_data = schedule or []
@@ -225,6 +227,10 @@ class ValueSourceStore:
source.sensitivity = sensitivity
if smoothing is not None:
source.smoothing = smoothing
if min_value is not None:
source.min_value = min_value
if max_value is not None:
source.max_value = max_value
elif isinstance(source, AdaptiveValueSource):
if schedule is not None:
if source.source_type == "adaptive_time" and len(schedule) < 2: