diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -30,21 +30,21 @@ import logging 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 @@ def launch(args, graph, session, opts, s 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() diff --git a/light9/curvecalc/curve.py b/light9/curvecalc/curve.py --- a/light9/curvecalc/curve.py +++ b/light9/curvecalc/curve.py @@ -100,6 +100,14 @@ class Curve(object): # 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 @@ class Curve(object): 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 @@ class Curveset(object): 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. diff --git a/light9/curvecalc/curveedit.py b/light9/curvecalc/curveedit.py --- a/light9/curvecalc/curveedit.py +++ b/light9/curvecalc/curveedit.py @@ -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)) +