changeset 1564:f2e6d96d02de

minor comments and refactors, I think, except the removal of 'row update' logging made a big perf difference Ignore-this: 24fd2d60fdfab9acc94107b02f0bc18c
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 25 May 2017 04:04:42 +0000
parents 1b42120d97f5
children cd3e3f50096a
files bin/collector light9/effect/sequencer.py light9/web/timeline/timeline.coffee
diffstat 3 files changed, 36 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/bin/collector	Wed May 24 08:30:56 2017 +0000
+++ b/bin/collector	Thu May 25 04:04:42 2017 +0000
@@ -61,7 +61,10 @@
         now = time.time()
 
         msg = self.makeMsg(dev, attrs, outputMap)
-        
+
+        # this omits repeats, but can still send many
+        # messages/sec. Not sure if piling up messages for the browser
+        # could lead to slowdowns in the real dmx output.
         for client, seen in self.clients:
             for m, t in seen.items():
                 if t < now - 5:
--- a/light9/effect/sequencer.py	Wed May 24 08:30:56 2017 +0000
+++ b/light9/effect/sequencer.py	Thu May 25 04:04:42 2017 +0000
@@ -40,7 +40,8 @@
 
 
 def toCollectorJson(client, session, settings):
-    return json.dumps({'settings': settings.asList() if isinstance(settings, DeviceSettings) else settings,
+    assert isinstance(settings, DeviceSettings)
+    return json.dumps({'settings': settings.asList(),
                        'client': client,
                        'clientSession': session,
                        'sendTime': time.time(),
--- a/light9/web/timeline/timeline.coffee	Wed May 24 08:30:56 2017 +0000
+++ b/light9/web/timeline/timeline.coffee	Thu May 25 04:04:42 2017 +0000
@@ -346,8 +346,6 @@
   onGraph: ->
     @graph.runHandler(@update.bind(@), "row notes #{@rowIndex}")
   update: (patch) ->
-    console.time('row update')
-
     U = (x) -> @graph.Uri(x)
 
     notesForThisRow = []
@@ -366,7 +364,6 @@
       child.song = @song # could change, but all the notes will be rebuilt
       child.zoomInX = @zoomInX # missing binding; see onZoom
       return child      
-    console.timeEnd('row update')
 
   onZoom: ->
     for e in @children
@@ -802,6 +799,36 @@
   updateAllCoords: ->
     @redraw()
 
+  _adjAtPoint: (pt) ->
+    nearest = @qt.find(pt.e(1), pt.e(2))
+    if not nearest? or nearest.distanceFrom(pt) > 50
+      return null
+    return nearest?.adj
+
+  resizeUpdate: (ev) ->
+    @$.canvas.width = ev.target.offsetWidth
+    @$.canvas.height = ev.target.offsetHeight
+    @redraw()
+
+  redraw: (adjs) ->
+    @debounce('redraw', @_throttledRedraw.bind(@))
+
+  _throttledRedraw: () ->
+    console.time('adjs redraw')
+    @_layoutCenters()
+    
+    @ctx.clearRect(0, 0, @$.canvas.width, @$.canvas.height)
+
+    for adjId, adj of @adjs
+      ctr = adj.getCenter()
+      target = adj.getTarget()
+      @_drawConnector(ctr, target)
+      
+      @_drawAdjuster(adj.getDisplayValue(),
+                     Math.floor(ctr.e(1)) - 20, Math.floor(ctr.e(2)) - 10,
+                     Math.floor(ctr.e(1)) + 20, Math.floor(ctr.e(2)) + 10)
+    console.timeEnd('adjs redraw')
+
   _layoutCenters: ->
     # push Adjustable centers around to avoid overlaps
     # Todo: also don't overlap inlineattr boxes
@@ -829,36 +856,6 @@
       output.adj = adj
       @qt.add(output)
 
-  _adjAtPoint: (pt) ->
-    nearest = @qt.find(pt.e(1), pt.e(2))
-    if not nearest? or nearest.distanceFrom(pt) > 50
-      return null
-    return nearest?.adj
-
-  resizeUpdate: (ev) ->
-    @$.canvas.width = ev.target.offsetWidth
-    @$.canvas.height = ev.target.offsetHeight
-    @redraw()
-
-  redraw: (adjs) ->
-    @debounce('redraw', @_throttledRedraw.bind(@, adjs))
-
-  _throttledRedraw: (adjs) ->
-    console.time('adjs redraw')
-    @_layoutCenters()
-    
-    @ctx.clearRect(0, 0, @$.canvas.width, @$.canvas.height)
-
-    for adjId, adj of @adjs
-      ctr = adj.getCenter()
-      target = adj.getTarget()
-      @_drawConnector(ctr, target)
-      
-      @_drawAdjuster(adj.getDisplayValue(),
-                    Math.floor(ctr.e(1)) - 20, Math.floor(ctr.e(2)) - 10,
-                    Math.floor(ctr.e(1)) + 20, Math.floor(ctr.e(2)) + 10)
-    console.timeEnd('adjs redraw')
-
   _drawConnector: (ctr, target) ->
     @ctx.strokeStyle = '#aaa'
     @ctx.lineWidth = 2