fix: Bug fixes and improvements

- fix(demo-lfo-effects): Fix math.sin() usage (was angle.__sin__())
- feat(pipeline): Add set_effect_intensity() method for runtime effect control
  - Allows changing effect intensity during pipeline execution
  - Returns False if effect not found or intensity out of range
  - Used by LFO modulation demo

The demo-lfo-effects.py script now works correctly with proper
math.sin() usage and the new set_effect_intensity() method provides
a clean API for runtime effect intensity control.
This commit is contained in:
2026-03-21 19:27:06 -07:00
parent 915598629a
commit 247f572218
2 changed files with 31 additions and 1 deletions

View File

@@ -984,6 +984,35 @@ class Pipeline:
"""Get historical frame times for sparklines/charts.""" """Get historical frame times for sparklines/charts."""
return [f.total_ms for f in self._frame_metrics] return [f.total_ms for f in self._frame_metrics]
def set_effect_intensity(self, effect_name: str, intensity: float) -> bool:
"""Set the intensity of an effect in the pipeline.
Args:
effect_name: Name of the effect to modify
intensity: New intensity value (0.0 to 1.0)
Returns:
True if successful, False if effect not found or not an effect stage
"""
if not 0.0 <= intensity <= 1.0:
return False
stage = self._stages.get(effect_name)
if not stage:
return False
# Check if this is an EffectPluginStage
from engine.pipeline.adapters.effect_plugin import EffectPluginStage
if isinstance(stage, EffectPluginStage):
# Access the underlying effect plugin
effect = stage._effect
if hasattr(effect, "config"):
effect.config.intensity = intensity
return True
return False
class PipelineRunner: class PipelineRunner:
"""High-level pipeline runner with animation support.""" """High-level pipeline runner with animation support."""

View File

@@ -14,6 +14,7 @@ Effects modulated:
The LFO uses a sine wave to oscillate intensity between 0.0 and 1.0. The LFO uses a sine wave to oscillate intensity between 0.0 and 1.0.
""" """
import math
import sys import sys
import time import time
from dataclasses import dataclass from dataclasses import dataclass
@@ -64,7 +65,7 @@ class LFOEffectDemo:
angle = ( angle = (
(elapsed * effect_cfg.frequency + effect_cfg.phase_offset) * 2 * 3.14159 (elapsed * effect_cfg.frequency + effect_cfg.phase_offset) * 2 * 3.14159
) )
lfo_value = 0.5 + 0.5 * (angle.__sin__()) lfo_value = 0.5 + 0.5 * math.sin(angle)
# Scale to intensity range # Scale to intensity range
intensity = effect_cfg.min_intensity + lfo_value * ( intensity = effect_cfg.min_intensity + lfo_value * (