# HG changeset patch # User drewp@bigasterisk.com # Date 2016-06-12 00:24:57 # Node ID 6906cacaa2180e6f4d2e0740b75232a4c3233d49 # Parent 74d803ff3c11e2549775cd4b43f19333120d31b9 KC and SEQ share inotify code to reload effect code Ignore-this: 2ae8142fda67b2290f4d0af219781c69 diff --git a/bin/keyboardcomposer b/bin/keyboardcomposer --- a/bin/keyboardcomposer +++ b/bin/keyboardcomposer @@ -19,6 +19,7 @@ from light9.namespaces import L9, RDF from light9.tkdnd import initTkdnd, dragSourceRegister, dropTargetRegister from light9.rdfdb import clientsession from light9.rdfdb.syncedgraph import SyncedGraph +from light9.effect.sequencer import CodeWatcher import light9.effect.effecteval from bcf2000 import BCF2000 @@ -163,7 +164,11 @@ class KeyboardComposer(tk.Frame, SubClie self.make_buttons() self.graph.addHandler(self.redraw_sliders) - self.send_levels_loop() + + self.codeWatcher = CodeWatcher( + onChange=lambda: self.graph.addHandler(self.redraw_sliders)) + + self.send_levels_loop(delay=.05) self.graph.addHandler(self.rowFromGraph) def make_buttons(self): diff --git a/light9/collector/device.py b/light9/collector/device.py --- a/light9/collector/device.py +++ b/light9/collector/device.py @@ -51,6 +51,7 @@ def resolve(deviceType, deviceAttr, valu rgbs = [hex_to_rgb(v) for v in values] return rgb_to_hex([max(*component) for component in zip(*rgbs)]) # angles should perhaps use average; gobo choice use the most-open one + return max(values) def toOutputAttrs(deviceType, deviceAttrSettings): diff --git a/light9/effect/effecteval.py b/light9/effect/effecteval.py --- a/light9/effect/effecteval.py +++ b/light9/effect/effecteval.py @@ -31,7 +31,7 @@ class EffectEval(object): """ def __init__(self, graph, effect): self.graph = graph - self.effect = effect + self.effect = effect # effect : [(dev, attr, value, isScaled)] self.effectOutputs = {} diff --git a/light9/effect/sequencer.py b/light9/effect/sequencer.py --- a/light9/effect/sequencer.py +++ b/light9/effect/sequencer.py @@ -74,7 +74,27 @@ class Note(object): """ effectSettings = [(L9['strength'], self.evalCurve(t))] return self.effectEval.outputFromEffect(effectSettings, t) - + + +class CodeWatcher(object): + def __init__(self, onChange): + self.onChange = onChange + + self.notifier = INotify() + self.notifier.startReading() + self.notifier.watch( + FilePath(effecteval.__file__.replace('.pyc', '.py')), + callbacks=[self.codeChange]) + + def codeChange(self, watch, path, mask): + def go(): + log.info("reload effecteval") + reload(effecteval) + self.onChange() + # in case we got an event at the start of the write + reactor.callLater(.1, go) + + class Sequencer(object): def __init__(self, graph, sendToCollector): @@ -88,29 +108,13 @@ class Sequencer(object): self.graph.addHandler(self.compileGraph) self.update() - self.watchCode() - - def watchCode(self): - self.notifier = INotify() - self.notifier.startReading() - self.notifier.watch( - FilePath(effecteval.__file__.replace('.pyc', '.py')), - callbacks=[self.codeChange]) - - def codeChange(self, watch, path, mask): - def go(): - reload(effecteval) - self.graph.addHandler(self.compileGraph) - # in case we got an event at the start of the write - reactor.callLater(.1, go) + self.codeWatcher = CodeWatcher( + onChange=lambda: self.graph.addHandler(self.compileGraph)) def compileGraph(self): """rebuild our data from the graph""" g = self.graph - log.info("compileGraph") - reload(effecteval) - for song in g.subjects(RDF.type, L9['Song']): self.notes[song] = [] for note in g.objects(song, L9['note']):