changeset 1049:2930523b8bfe

curvecalc can add its own new curves to the graph Ignore-this: 5a34428186aa092508985890ba0d317f
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 29 May 2014 06:59:44 +0000
parents 86732ba7d9ae
children edf46615712a
files light9/curvecalc/curve.py light9/namespaces.py
diffstat 2 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/light9/curvecalc/curve.py	Thu May 29 06:48:21 2014 +0000
+++ b/light9/curvecalc/curve.py	Thu May 29 06:59:44 2014 +0000
@@ -4,7 +4,8 @@
 import louie as dispatcher
 from rdflib import Literal
 from light9 import showconfig
-from light9.namespaces import L9
+from light9.namespaces import L9, RDF, RDFS
+from light9.rdfdb.patch import Patch
 
 from bcf2000 import BCF2000
 
@@ -15,7 +16,9 @@
 
 class Curve(object):
     """curve does not know its name. see Curveset"""
-    def __init__(self):
+    def __init__(self, uri, pointsStorage='graph'):
+        self.uri = uri
+        self.pointsStorage = pointsStorage
         self.points = [] # x-sorted list of (x,y)
         self._muted = False
 
@@ -179,7 +182,7 @@
             self.sliderIgnoreInputUntil = {}
         else:
             self.sliders = None
-        self.markers = Markers()
+        self.markers = Markers(uri=None, pointsStorage='file')
 
         graph.addHandler(self.loadCurvesForSong)
 
@@ -195,23 +198,20 @@
         self.curveName.clear()
         self.sliderCurve.clear()
         self.sliderNum.clear()
-        self.markers = Markers()
+        self.markers = Markers(uri=None, pointsStorage='file')
         
         self.currentSong = self.graph.value(self.session, L9['currentSong'])
         if self.currentSong is None:
             return
 
         for uri in self.graph.objects(self.currentSong, L9['curve']):
-            c = Curve()
-            c.uri = uri
             pts = self.graph.value(uri, L9['points'])
+            c = Curve(uri, pointsStorage='file' if pts is None else 'graph')
             if pts is not None:
                 c.set_from_string(pts)
-                c.pointsStorage = 'graph'
             else:
                 diskPts = self.graph.value(uri, L9['pointsFile'])
                 c.load(os.path.join(showconfig.curvesDir(), diskPts))
-                c.pointsStorage = 'file'
 
             curvename = self.graph.label(uri)
             if not curvename:
@@ -298,11 +298,17 @@
         while name in self.curves:
            name=name+"-1"
 
-        c = Curve()
-        # missing some new attrs here, uri pointsStorage
-        s,e = self.get_time_range()
-        c.points.extend([(s,0), (e,0)])
-        self.add_curve(name,c)
+        uri = self.currentSong + ('/curve/c-%f' % time.time())
+        c = Curve(uri)
+        s, e = self.get_time_range()
+        c.points.extend([(s, 0), (e, 0)])
+        ctx = self.currentSong
+        self.graph.patch(Patch(addQuads=[
+            (self.currentSong, L9['curve'], uri, ctx),
+            (uri, RDF.type, L9['Curve'], ctx),
+            (uri, RDFS.label, Literal(name), ctx),
+            (uri, L9['points'], Literal(c.points_as_string()), ctx),
+            ]))
 
     def hw_slider_in(self, num, value):
         try:
--- a/light9/namespaces.py	Thu May 29 06:48:21 2014 +0000
+++ b/light9/namespaces.py	Thu May 29 06:59:44 2014 +0000
@@ -1,4 +1,4 @@
-from rdflib import Namespace, RDF
+from rdflib import Namespace, RDF, RDFS
 
 L9 = Namespace("http://light9.bigasterisk.com/")
 MUS = Namespace("http://light9.bigasterisk.com/music/")