changeset 1063:4e449d40f42c

inputdemo sends updates to curvecalc, which edits the curve. doesn't display right Ignore-this: 5a71a9a6c85d533c79872c93d1c3f5a8
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 02 Jun 2014 01:03:22 +0000
parents 0f51a1a5785e
children c5e44bab7c9a
files bin/curvecalc light9/curvecalc/curve.py light9/curvecalc/curveedit.py
diffstat 3 files changed, 57 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/bin/curvecalc	Mon Jun 02 00:44:47 2014 +0000
+++ b/bin/curvecalc	Mon Jun 02 01:03:22 2014 +0000
@@ -30,21 +30,21 @@
 
 from run_local import log
 from light9 import showconfig, networking
-from light9.rdfdb import clientsession
+from light9.curvecalc import curveview 
 from light9.curvecalc.curve import Curveset
-from light9.curvecalc import curveview 
+from light9.curvecalc.curveedit import serveCurveEdit
 from light9.curvecalc.musicaccess import Music
-from light9.wavelength import wavelength
-from light9.namespaces import L9
+from light9.curvecalc.output import Output
 from light9.curvecalc.subterm import Subterm
 from light9.curvecalc.subtermview import add_one_subterm
-from light9.curvecalc.output import Output
+from light9.editchoicegtk import EditChoice, Local
 from light9.gtkpyconsole import togglePyConsole
-from light9.rdfdb.syncedgraph import SyncedGraph
+from light9.namespaces import L9
+from light9.observable import Observable
+from light9.rdfdb import clientsession
 from light9.rdfdb.patch import Patch
-from light9.editchoicegtk import EditChoice, Local
-from light9.observable import Observable
-from light9.curvecalc.curveedit import serveCurveEdit
+from light9.rdfdb.syncedgraph import SyncedGraph
+from light9.wavelength import wavelength
 
 class SubtermExists(ValueError):
     pass
@@ -483,7 +483,7 @@
             song = g.value(session, L9['currentSong'])
             json.dump({"song": song, "hoverTime" : times[0]}, requestHandler)
         
-    serveCurveEdit(networking.curveCalc.port, hoverTimeResponse)
+    serveCurveEdit(networking.curveCalc.port, hoverTimeResponse, start.curveset)
 
 def main():
     startTime = time.time()
--- a/light9/curvecalc/curve.py	Mon Jun 02 00:44:47 2014 +0000
+++ b/light9/curvecalc/curve.py	Mon Jun 02 01:03:22 2014 +0000
@@ -100,6 +100,14 @@
         # missing a check that this isn't the same X as the neighbor point
         return i
 
+    def live_input_point(self, new_pt):
+        x, y = new_pt
+        exist = self.points_between(x, x + .01)
+        for pt in exist:
+            self.remove_point(pt)
+        self.insert_pt(new_pt)
+        # now simplify to the left
+        
     def set_points(self, updates):
         for i, pt in updates:
             self.points[i] = pt
@@ -123,6 +131,7 @@
         return range(leftidx, rightidx)
         
     def points_between(self, x1, x2):
+        """returns (x,y) points"""
         return [self.points[i] for i in self.indices_between(x1,x2)]
 
     def point_before(self, x):
@@ -191,6 +200,13 @@
 
         graph.addHandler(self.loadCurvesForSong)
 
+    def curveFromUri(self, uri):
+        # self.curves should be indexed by this
+        for c in self.curves.values():
+            if c.uri == uri:
+                return c
+        raise KeyError("no curve %s" % uri)
+
     def loadCurvesForSong(self):
         """
         current curves will track song's curves.
--- a/light9/curvecalc/curveedit.py	Mon Jun 02 00:44:47 2014 +0000
+++ b/light9/curvecalc/curveedit.py	Mon Jun 02 01:03:22 2014 +0000
@@ -1,21 +1,48 @@
 """
 this may be split out from curvecalc someday, since it doesn't
 need to be tied to a gui """
+import cgi
 from twisted.internet import reactor
 import cyclone.web, cyclone.httpclient, cyclone.websocket
-
+from rdflib import URIRef
 from lib.cycloneerr import PrettyErrorHandler
+from run_local import log
+from louie import dispatcher
 
-
-def serveCurveEdit(port, hoverTimeResponse):
+def serveCurveEdit(port, hoverTimeResponse, curveset):
     """
     /hoverTime requests actually are handled by the curvecalc gui
     """
-
+    curveEdit = CurveEdit(curveset)
+    
     class HoverTime(PrettyErrorHandler, cyclone.web.RequestHandler):
         def get(self):
             hoverTimeResponse(self)
 
+    class LiveInputPoint(PrettyErrorHandler, cyclone.web.RequestHandler):
+        def post(self):
+            params = cgi.parse_qs(self.request.body)
+            curve = URIRef(params['curve'][0])
+            value = float(params['value'][0])
+            curveEdit.liveInputPoint(curve, value)
+            self.set_status(204)
+            
     reactor.listenTCP(port, cyclone.web.Application(handlers=[
         (r'/hoverTime', HoverTime),
+        (r'/liveInputPoint', LiveInputPoint),
         ], debug=True))
+
+    
+class CurveEdit(object):
+    def __init__(self, curveset):
+        self.curveset = curveset
+        dispatcher.connect(self.inputTime, "input time")
+        self.currentTime = 0
+        
+    def inputTime(self, val):
+        self.currentTime = val
+        
+    def liveInputPoint(self, curveUri, value):
+        curve = self.curveset.curveFromUri(curveUri)
+        curve.live_input_point((self.currentTime, value))
+