# HG changeset patch # User drewp@bigasterisk.com # Date 2013-06-13 21:59:32 # Node ID 41c6fbe95214b919536e5f353e36e225fbec9691 # Parent 022e997b50c422738b87a39a37671dbd9b063652 drag sub into curve area to get a curve+subterm and a 0..1 fade at the current play time Ignore-this: ac77acf1cfbcfbce2f6b77da670b407 diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -90,6 +90,9 @@ class Main(object): self.makeStatusLines(wtree.get_object("status")) + + self.acceptDragsOnCurveViews() + def connect(w): w.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL, targets=[('text/uri-list', 0, 0)], @@ -110,6 +113,34 @@ class Main(object): # may not work wtree.get_object("paned1").set_position(600) + def acceptDragsOnCurveViews(self): + w = self.wtree.get_object("curves") + w.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL, + targets=[('text/uri-list', 0, 0)], + actions=gtk.gdk.ACTION_COPY) + def recv(widget, context, x, y, selection, + targetType, time): + subUri = URIRef(selection.data.strip()) + print "into curves", subUri + with self.graph.currentState( + tripleFilter=(subUri, RDFS.label, None)) as current: + subName = current.label(subUri) + + try: + self.makeSubterm(subName, withCurve=True, + sub=subUri, + expr="%s(t)" % subName) + except SubtermExists: + # we're not making sure the expression/etc are + # correct-- user mihgt need to fix things + pass + curveView = self.curvesetView.row(subName).curveView + t = self.lastSeenInputTime # curveView.current_time() # new curve hasn't heard the time yet. this has gotten too messy- everyone just needs to be able to reach the time source + print "time", t + curveView.add_points([(t - .5, 0), + (t, 1)]) + w.connect("drag-data-received", recv) + def onDataReceived(self, widget, context, x, y, selection, targetType, time): data = selection.data.strip() @@ -125,7 +156,6 @@ class Main(object): pass curveView = self.curvesetView.row(subName).curveView t = self.lastSeenInputTime # curveView.current_time() # new curve hasn't heard the time yet. this has gotten too messy- everyone just needs to be able to reach the time source - print "time", t curveView.add_points([(t - .5, 0), (t, 1)]) @@ -190,6 +220,15 @@ class Main(object): return self.currentSong() def makeSubterm(self, newname, withCurve=False, expr=None, sub=None): + """ + raises SubtermExists if we had a subterm with a sub with the given + name. what about a no-sub term with the same label? who knows + """ + assert isinstance(newname, Literal), repr(newname) + if withCurve: + self.curveset.new_curve(newname, renameIfExisting=False) + if newname in self.all_subterm_labels(): + raise SubtermExists("have a subterm who sub is named %r" % newname) with self.graph.currentState() as current: song = self.currentSong() for i in range(1000): @@ -211,10 +250,24 @@ class Main(object): quads.append((uri, L9['expression'], Literal(expr), ctx)) self.graph.patch(Patch(addQuads=quads)) - if withCurve: - self.curveset.new_curve(newname) return uri - + + def all_subterm_labels(self): + """ + Literal labels of subs in subterms. doesn't currently include labels of the + subterm resources. I'm not sure what I'm going to do with + those. + """ + labels = [] + with self.graph.currentState() as current: + for st in current.objects( + current.value(self.session, L9['currentSong']), + L9['subterm']): + sub = current.value(st, L9['sub']) + if sub is not None: + labels.append(current.label(sub)) + return labels + def set_subterms_from_graph(self): """rebuild all the gtktable 'subterms' widgets and the self.currentSubterms list""" @@ -285,6 +338,7 @@ class Main(object): self.music.playOrPause(t=times[0] if times else None) def onSave(self, *args): + # only doing curves still. I hope to eliminate all this. with self.graph.currentState() as g: song = g.value(self.session, L9['currentSong']) diff --git a/light9/curvecalc/curve.py b/light9/curvecalc/curve.py --- a/light9/curvecalc/curve.py +++ b/light9/curvecalc/curve.py @@ -2,6 +2,7 @@ from __future__ import division import glob, time, logging, ast from bisect import bisect_left,bisect import louie as dispatcher +from rdflib import Literal from bcf2000 import BCF2000 @@ -143,7 +144,7 @@ class Curveset(object): curves = None # curvename : curve def __init__(self, sliders=False): """sliders=True means support the hardware sliders""" - self.curves = {} # name : Curve + self.curves = {} # name (str) : Curve self.curveName = {} # reverse self.sliderCurve = {} # slider number (1 based) : curve name self.sliderNum = {} # reverse @@ -194,6 +195,8 @@ class Curveset(object): return sorted(self.curves.keys(), key=self.sorter) def add_curve(self,name,curve): + if isinstance(name, Literal): + name = str(name) if name in self.curves: raise ValueError("can't add a second curve named %r" % name) self.curves[name] = curve @@ -218,10 +221,14 @@ class Curveset(object): def get_time_range(self): return 0, dispatcher.send("get max time")[0][1] - def new_curve(self,name): + def new_curve(self, name, renameIfExisting=True): + if isinstance(name, Literal): + name = str(name) if name=="": print "no name given" return + if not renameIfExisting and name in self.curves: + return while name in self.curves: name=name+"-1" diff --git a/light9/curvecalc/curvecalc.glade b/light9/curvecalc/curvecalc.glade --- a/light9/curvecalc/curvecalc.glade +++ b/light9/curvecalc/curvecalc.glade @@ -671,6 +671,7 @@ Mousewheel zoom; C-p play/pause music at mouse +Drag sub into curve area for new curve+subterm Keys in a selected curve: C to collapse; R to rebuild broken canvas widget; 1..5 add point at time cursor; q,w,e,r,t,y set marker at time cursor Curve point bindings: B1 drag point; C-B1 curve add point; S-B1 sketch points; B1 drag select points Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; chan(name); curvename(t) eval curve diff --git a/light9/curvecalc/curveview.py b/light9/curvecalc/curveview.py --- a/light9/curvecalc/curveview.py +++ b/light9/curvecalc/curveview.py @@ -2,6 +2,7 @@ from __future__ import division import math, time, logging import gtk, goocanvas import louie as dispatcher +from rdflib import Literal from light9.curvecalc.zoomcontrol import RegionZoom from light9.curvecalc import cursors from light9.curvecalc.curve import introPad, postPad @@ -1183,6 +1184,8 @@ class Curvesetview(object): self.newcurvename.set('') def add_curve(self, name, slider=None, knobEnabled=False): + if isinstance(name, Literal): + name = str(name) curve = self.curveset.curves[name] f = CurveRow(name, curve, self.curveset.markers, slider, knobEnabled, self.zoomControl) @@ -1192,9 +1195,12 @@ class Curvesetview(object): f.curveView.goLive() def row(self, name): + if isinstance(name, Literal): + name = str(name) matches = [r for r in self.allCurveRows if r.name == name] if not matches: - raise ValueError("no curveRow named %r" % name) + raise ValueError("no curveRow named %r. only %s" % + (name, [r.name for r in self.allCurveRows])) return matches[0] def goLive(self):