diff --git a/light9/effect/sequencer/eval_faders.py b/light9/effect/sequencer/eval_faders.py --- a/light9/effect/sequencer/eval_faders.py +++ b/light9/effect/sequencer/eval_faders.py @@ -1,4 +1,3 @@ - import asyncio import logging import time @@ -13,9 +12,9 @@ from light9.effect.settings import Devic from light9.effect.simple_outputs import SimpleOutputs from light9.metrics import metrics from light9.namespaces import L9, RDF -from light9.newtypes import NoteUri +from light9.newtypes import NoteUri, UnixTime -log = logging.getLogger('sequencer') +log = logging.getLogger('seq.fader') class FaderEval: """peer to Sequencer, but this one takes the current :Fader settings -> sendToCollector @@ -37,8 +36,8 @@ class FaderEval: self.lastLoopSucceeded = False # self.codeWatcher = CodeWatcher(onChange=self.onCodeChange) - log.info('startupdating task') - asyncio.create_task(self.startUpdating()) + # have caller do this + #asyncio.create_task(self.startUpdating()) async def startUpdating(self): await self.graph.addAsyncHandler(self.update) @@ -58,25 +57,34 @@ class FaderEval: return self.compileFader(cast(URIRef, fader)) self.notes.append(compileFader()) - if self.notes: - asyncio.create_task(self.startUpdating()) + # if self.notes: + # asyncio.create_task(self.startUpdating()) @metrics('compile_fader').time() def compileFader(self, fader: URIRef) -> Note: - return Note(self.graph, NoteUri(cast(NoteUri, fader)), effecteval, - self.simpleOutputs, timed=False) + return Note(self.graph, cast(NoteUri, fader), + timed=False) + def _computeOutput(self) -> DeviceSettings: + notesSettings = [] + now = UnixTime(time.time()) + for note in self.notes: + effectSettings, report = note.outputCurrent() + + ee = effecteval.EffectEval(self.graph, note.effectClass, self.simpleOutputs) + deviceSettings, report = ee.outputFromEffect( + effectSettings, + songTime=now, # probably wrong + noteTime=now, # wrong + ) + notesSettings.append(deviceSettings) + return DeviceSettings.merge(self.graph, notesSettings) + + @metrics('update_call_fader').time() async def update(self): - settings = [] - for note in self.notes: - effectValue = self.graph.value(note.uri, L9['value']) - if effectValue is None: - log.info(f'skip note {note}, no :value') - continue - s, report = note.outputSettings(t=time.time(), strength=float(effectValue)) - settings.append(s) - devSettings = DeviceSettings.fromList(self.graph, settings) + log.info(f'update {len(self.notes)=}') + devSettings = self._computeOutput() with metrics('update_s3_send_fader').time(): # our measurement sendSecs = await self.sendToCollector(devSettings)