annotate light9/effect/edit.py @ 1692:6fa4288da8a6

rdfdb is its own package now Ignore-this: 6b0b51464911b955687fefe6454fb91b
author drewp@bigasterisk.com
date Wed, 21 Mar 2018 08:31:45 +0000
parents 13e3cbe9071a
children 7772cc48e016
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
1 import json
1557
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
2 import cyclone.httpclient
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
3 from twisted.internet.defer import inlineCallbacks, returnValue
1557
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
4 from rdflib import URIRef, Literal
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
5
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
6 from light9 import networking
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
7 from light9.namespaces import L9, RDF, RDFS
1692
6fa4288da8a6 rdfdb is its own package now
drewp@bigasterisk.com
parents: 1566
diff changeset
8 from rdfdb.patch import Patch
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
9 from light9.curvecalc.curve import CurveResource
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
10
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
11 def clamp(x, lo, hi):
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
12 return max(lo, min(hi, x))
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
13
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
14
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
15 @inlineCallbacks
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
16 def getMusicStatus():
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
17 returnValue(json.loads((yield cyclone.httpclient.fetch(
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
18 networking.musicPlayer.path('time'), timeout=.5)).body))
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
19
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
20 @inlineCallbacks
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
21 def songEffectPatch(graph, dropped, song, event, ctx):
1558
7eb3676b8fd6 more of the fixed add-to-song service
Drew Perttula <drewp@bigasterisk.com>
parents: 1557
diff changeset
22 """
1560
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
23 some uri was 'dropped' in the curvecalc timeline. event is 'default' or 'start' or 'end'.
1558
7eb3676b8fd6 more of the fixed add-to-song service
Drew Perttula <drewp@bigasterisk.com>
parents: 1557
diff changeset
24 """
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
25 with graph.currentState(
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
26 tripleFilter=(dropped, None, None)) as g:
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
27 droppedTypes = list(g.objects(dropped, RDF.type))
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
28 droppedLabel = g.label(dropped)
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
29 droppedCodes = list(g.objects(dropped, L9['code']))
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
30
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
31 quads = []
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
32 fade = 2 if event == 'default' else 0
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
33
1557
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
34 if _songHasEffect(graph, song, dropped):
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
35 # bump the existing curve
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
36 pass
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
37 else:
1557
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
38 effect, q = _newEffect(graph, song, ctx)
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
39 quads.extend(q)
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
40
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
41 curve = graph.sequentialUri(song + "/curve-")
1557
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
42 yield _newEnvelopeCurve(graph, ctx, curve, droppedLabel, fade)
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
43 quads.extend([
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
44 (song, L9['curve'], curve, ctx),
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
45 (effect, RDFS.label, droppedLabel, ctx),
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
46 (effect, L9['code'], Literal('env = %s' % curve.n3()), ctx),
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
47 ])
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
48
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
49 if L9['EffectClass'] in droppedTypes:
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
50 quads.extend([
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
51 (effect, RDF.type, dropped, ctx),
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
52 ] + [(effect, L9['code'], c, ctx) for c in droppedCodes])
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
53 elif L9['Submaster'] in droppedTypes:
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
54 quads.extend([
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
55 (effect, L9['code'], Literal('out = %s * env' % dropped.n3()),
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
56 ctx),
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
57 ])
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
58 else:
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
59 raise NotImplementedError(
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
60 "don't know how to add an effect from %r (types=%r)" %
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
61 (dropped, droppedTypes))
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
62
1557
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
63 _maybeAddMusicLine(quads, effect, song, ctx)
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
64
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
65 print "adding"
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
66 for qq in quads:
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
67 print qq
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
68 returnValue(Patch(addQuads=quads))
1560
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
69
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
70 @inlineCallbacks
1566
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
71 def songNotePatch(graph, dropped, song, event, ctx, note=None):
1560
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
72 """
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
73 drop into effectsequencer timeline
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
74
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
75 ported from timeline.coffee makeNewNote
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
76 """
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
77 with graph.currentState(
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
78 tripleFilter=(dropped, None, None)) as g:
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
79 droppedTypes = list(g.objects(dropped, RDF.type))
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
80
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
81 quads = []
1566
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
82 fade = 2 if event == 'default' else 0.1
1560
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
83
1566
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
84 if note:
1560
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
85 musicStatus = yield getMusicStatus()
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
86 songTime = musicStatus['t']
1566
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
87 _finishCurve(graph, note, quads, ctx, songTime)
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
88 else:
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
89 if L9['Effect'] in droppedTypes:
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
90 musicStatus = yield getMusicStatus()
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
91 songTime = musicStatus['t']
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
92 note = _makeNote(graph, song, note, quads, ctx, dropped, songTime, event, fade)
1560
e993c5e1df1a fix effecteval to drop notes into new-style timeline
Drew Perttula <drewp@bigasterisk.com>
parents: 1558
diff changeset
93 else:
1566
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
94 raise NotImplementedError
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
95
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
96 returnValue((note, Patch(addQuads=quads)))
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
97
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
98
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
99 def _point(ctx, uri, t, v):
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
100 return [
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
101 (uri, L9['time'], Literal(round(t, 3)), ctx),
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
102 (uri, L9['value'], Literal(round(v, 3)), ctx)
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
103 ]
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
104
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
105 def _finishCurve(graph, note, quads, ctx, songTime):
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
106 with graph.currentState() as g:
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
107 origin = g.value(note, L9['originTime']).toPython()
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
108 curve = g.value(note, L9['curve'])
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
109
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
110 pt2 = graph.sequentialUri(curve + 'p')
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
111 pt3 = graph.sequentialUri(curve + 'p')
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
112 quads.extend(
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
113 [(curve, L9['point'], pt2, ctx)] + _point(ctx, pt2, songTime - origin, 1) +
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
114 [(curve, L9['point'], pt3, ctx)] + _point(ctx, pt3, songTime - origin + .5, 0)
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
115 )
1556
61f3f378cc62 move code for adding effect to current song to its own (testable) module
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
116
1566
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
117
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
118 def _makeNote(graph, song, note, quads, ctx, dropped, songTime, event, fade):
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
119 note = graph.sequentialUri(song + '/n')
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
120 curve = graph.sequentialUri(note + 'c')
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
121 quads.extend([
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
122 (song, L9['note'], note, ctx),
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
123 (note, RDF.type, L9['Note'], ctx),
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
124 (note, L9['curve'], curve, ctx),
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
125 (note, L9['effectClass'], dropped, ctx),
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
126 (note, L9['originTime'], Literal(songTime), ctx),
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
127 (curve, RDF.type, L9['Curve'], ctx),
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
128 (curve, L9['attr'], L9['strength'], ctx),
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
129 ])
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
130 if event == 'default':
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
131 coords = [(0 - fade, 0), (0, 1), (20, 1), (20 + fade, 0)]
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
132 elif event == 'start':
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
133 coords = [(0 - fade, 0), (0, 1), ]
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
134 elif event == 'end': # probably unused- goes to _finishCurve instead
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
135 coords = [(20, 1), (20 + fade, 0)]
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
136 else:
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
137 raise NotImplementedError(event)
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
138 for t,v in coords:
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
139 pt = graph.sequentialUri(curve + 'p')
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
140 quads.extend([(curve, L9['point'], pt, ctx)] + _point(ctx, pt, t, v))
13e3cbe9071a momentary-add button support
Drew Perttula <drewp@bigasterisk.com>
parents: 1562
diff changeset
141 return note
1557
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
142
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
143 def _songHasEffect(graph, song, uri):
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
144 """does this song have an effect of class uri or a sub curve for sub
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
145 uri? this should be simpler to look up."""
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
146 return False # todo
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
147
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
148 def musicCurveForSong(uri):
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
149 return URIRef(uri + 'music')
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
150
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
151 def _newEffect(graph, song, ctx):
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
152 effect = graph.sequentialUri(song + "/effect-")
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
153 quads = [
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
154 (song, L9['effect'], effect, ctx),
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
155 (effect, RDF.type, L9['Effect'], ctx),
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
156 ]
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
157 print "_newEffect", effect, quads
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
158 return effect, quads
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
159
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
160 @inlineCallbacks
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
161 def _newEnvelopeCurve(graph, ctx, uri, label, fade=2):
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
162 """this does its own patch to the graph"""
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
163
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
164 cr = CurveResource(graph, uri)
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
165 cr.newCurve(ctx, label=Literal(label))
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
166 yield _insertEnvelopePoints(cr.curve, fade)
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
167 cr.saveCurve()
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
168
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
169 @inlineCallbacks
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
170 def _insertEnvelopePoints(curve, fade=2):
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
171 # wrong: we might not be adding to the currently-playing song.
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
172 musicStatus = yield getMusicStatus()
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
173 songTime=musicStatus['t']
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
174 songDuration=musicStatus['duration']
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
175
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
176 t1 = clamp(songTime - fade, .1, songDuration - .1 * 2) + fade
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
177 t2 = clamp(songTime + 20, t1 + .1, songDuration)
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
178
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
179 curve.insert_pt((t1 - fade, 0))
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
180 curve.insert_pt((t1, 1))
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
181 curve.insert_pt((t2, 1))
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
182 curve.insert_pt((t2 + fade, 0))
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
183
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
184
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
185 def _maybeAddMusicLine(quads, effect, song, ctx):
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
186 """
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
187 add a line getting the current music into 'music' if any code might
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
188 be mentioning that var
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
189 """
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
190
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
191 for spoc in quads:
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
192 if spoc[1] == L9['code'] and 'music' in spoc[2]:
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
193 quads.extend([
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
194 (effect, L9['code'],
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
195 Literal('music = %s' % musicCurveForSong(song).n3()), ctx)
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
196 ])
104ff4606565 cleanup. internal names in edit.py
Drew Perttula <drewp@bigasterisk.com>
parents: 1556
diff changeset
197 break