Changeset - 47f7f5ac81e8
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 20 months ago 2023-06-02 23:15:20
drewp@bigasterisk.com
skip effect compute if we have no devs for the effect
1 file changed with 3 insertions and 0 deletions:
0 comments (0 inline, 0 general)
light9/effect/effecteval2.py
Show inline comments
 
@@ -71,47 +71,50 @@ class EffectEval2:
 
            func = self.lib.getFunc(effectFunction)
 

	
 
            # This should be in EffectFunctionLibrary
 
            funcArgs = list(inspect.signature(func).parameters.values())
 

	
 
            self.config = Config(effectFunction, esettings, devSettings, func, funcArgs)
 
        except Exception:
 
            log.error(f"while compiling {self.uri}")
 
            traceback.print_exc()
 

	
 
    def compute(self, songTime: float, inputs: EffectSettings) -> DeviceSettings:
 
        """
 
        calls our function using inputs (publishedAttr attrs, e.g. :strength)
 
        and effect-level settings including a special attr called :deviceSettings
 
        with DeviceSettings as its value
 
        """
 
        if self.config is None:
 
            return DeviceSettings(self.graph, [])
 

	
 
        c = self.config
 
        kw = {}
 
        for arg in c.funcArgs:
 
            if arg.annotation == DeviceSettings:
 
                v = c.devSettings
 
                if v is None: # asked for ds but we have none
 
                    log.debug("%s asked for devs but we have none in config", self.uri)
 
                    return DeviceSettings(self.graph, [])
 
            elif arg.name == 'songTime':
 
                v = songTime
 
            else:
 
                eaForName = EffectAttr(L9[arg.name])
 
                v = self._getEffectAttrValue(eaForName, inputs)
 

	
 
            kw[arg.name] = v
 
        log.debug('calling %s with %s', c.func, kw)
 
        return c.func(**kw)
 

	
 
    def _getEffectAttrValue(self, attr: EffectAttr, inputs: EffectSettings) -> VTUnion:
 
        c = self.config
 
        if c is None:
 
            raise
 
        try:
 
            return inputs.getValue(self.uri, attr, defaultToZero=False)
 
        except KeyError:
 
            pass
 
        try:
 
            return c.esettings.getValue(self.uri, attr, defaultToZero=False)
 
        except KeyError:
 
            pass
 
        return self.lib.getDefaultValue(c.effectFunction, attr)
0 comments (0 inline, 0 general)