changeset 1582:d5761661ac31

fix sequencer to use DeviceSettings Ignore-this: d317447acc51379a6d06622aea7213a6
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 30 May 2017 07:37:17 +0000
parents 30c79f1dc4f8
children 5db651b08d77
files light9/effect/effecteval.py light9/effect/sequencer.py light9/effect/settings.py
diffstat 3 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/light9/effect/effecteval.py	Tue May 30 07:36:42 2017 +0000
+++ b/light9/effect/effecteval.py	Tue May 30 07:37:17 2017 +0000
@@ -8,6 +8,8 @@
 from noise import pnoise1
 import logging
 import time
+from light9.effect.settings import DeviceSettings
+
 
 log = logging.getLogger('effecteval')
 
@@ -75,6 +77,10 @@
                 sv = self.graph.value(setting, L9['scaledValue'])
                 if not (bool(v) ^ bool(sv)):
                     raise NotImplementedError
+                if d is None:
+                    raise TypeError('no device on %s' % effect)
+                if a is None:
+                    raise TypeError('no attr on %s' % effect)
 
                 settings.append((d, a, v if v is not None else sv, bool(sv)))
 
@@ -93,7 +99,7 @@
 
         strength = float(effectSettings[L9['strength']])
         if strength <= 0:
-            return []
+            return DeviceSettings(self.graph, [])
 
         out = {} # (dev, attr): value
 
@@ -109,11 +115,8 @@
             else:
                 out.update(func(effectSettings, strength, songTime, noteTime))
 
-        # todo: callers should prefer the dict form too
         outList = [(d, a, v) for (d, a), v in out.iteritems()]
-        outList.sort()
-        #import pprint; pprint.pprint(outList, width=170)
-        return outList
+        return DeviceSettings(self.graph, outList)
                             
     def simpleOutput(self, strength, colorScale):
         out = {}
--- a/light9/effect/sequencer.py	Tue May 30 07:36:42 2017 +0000
+++ b/light9/effect/sequencer.py	Tue May 30 07:37:17 2017 +0000
@@ -172,7 +172,7 @@
         g = self.graph
 
         sharedEffectOutputs = {}
-        
+
         for song in g.subjects(RDF.type, L9['Song']):
             self.notes[song] = []
             for note in g.objects(song, L9['note']):
@@ -199,7 +199,5 @@
         settings = []
         
         for note in self.notes.get(song, []):
-            outs = note.outputSettings(t)
-            #print 'out', outs
-            settings.extend(outs)
-        self.sendToCollector(settings)
+            settings.append(note.outputSettings(t))
+        self.sendToCollector(DeviceSettings.fromList(self.graph, settings))
--- a/light9/effect/settings.py	Tue May 30 07:36:42 2017 +0000
+++ b/light9/effect/settings.py	Tue May 30 07:37:17 2017 +0000
@@ -71,6 +71,19 @@
             compiled.setdefault(d, {})[a] = v
         return cls._fromCompiled(graph, compiled)
 
+    @classmethod
+    def fromList(cls, graph, others):
+        out = cls(graph, [])
+        for s in others:
+            if not isinstance(s, cls):
+                raise TypeError(s)
+            for row in s.asList(): # could work straight from s._compiled
+                if row[0] is None:
+                    raise TypeError('bad row %r' % (row,))
+                out._compiled.setdefault(row[0], {})[row[1]] = row[2]
+        out._delZeros()
+        return out
+        
     def _zeroForAttr(self, attr):
         if attr == L9['color']:
             return '#000000'