diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -22,6 +22,7 @@ import twisted from twisted.web.xmlrpc import Proxy from rdflib import Literal, URIRef, RDF from rdflib.Graph import Graph +import rdflib import logging log = logging.getLogger() logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s") @@ -85,8 +86,19 @@ class Expr(object): glo['ncos'] = lambda x: (math.cos(x * (2 * math.pi)) + 1) / 2 glo['within'] = lambda a, b: a < t < b glo['bef'] = lambda x: t < x - glo['aft'] = lambda x: x < t - glo['smoove'] = lambda x: -2 * (x ** 3) + 3 * (x ** 2) + + + def smoove(x): + return -2 * (x ** 3) + 3 * (x ** 2) + glo['smoove'] = smoove + + def aft(t, x, smooth=0): + left = x - smooth / 2 + right = x + smooth / 2 + if left < t < right: + return smoove((t - left) / (right - left)) + return t > x + glo['aft'] = lambda x, smooth=0: aft(t, x, smooth) def chan(name): return Submaster.Submaster( @@ -113,6 +125,8 @@ class Expr(object): glo['noise'] = smooth_random glo['notch'] = notch_random + + return glo exprglo = Expr() @@ -352,8 +366,18 @@ def createSubtermGraph(song, subterms): def add_subterms_for_song(graph, song, curveset, subterms, root, ssv): for st in graph.objects(song, L9['subterm']): - add_one_subterm(graph, graph.value(st, L9['sub']), curveset, subterms, - root, ssv, graph.value(st, L9['expression'])) + try: + add_one_subterm(graph, graph.value(st, L9['sub']), curveset, subterms, + root, ssv, graph.value(st, L9['expression'])) + except rdflib.exceptions.UniquenessError: + print "working around curvecalc save corruption" + # curvecalc put all the expressions on one subterm, which is wrong + for expr in graph.objects(st, L9['expression']): + add_one_subterm(graph, graph.value(st, L9['sub']), + curveset, subterms, + root, ssv, + expr) + def graphPathForSubterms(song): return showconfig.subtermsForSong(showconfig.songFilenameFromURI(song)) + ".n3"