comparison bin/effecteval @ 1181:c677bf37a1b4

effect list has button to add to current song Ignore-this: 336da00ee802890c5b75af5b0d2ab255
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 15 Jun 2014 15:47:15 +0000
parents 6c4981f61bf8
children 102a456be7db
comparison
equal deleted inserted replaced
1180:6c4981f61bf8 1181:c677bf37a1b4
34 (song, L9['effect'], uri, ctx), 34 (song, L9['effect'], uri, ctx),
35 ])) 35 ]))
36 36
37 def clamp(x, lo, hi): 37 def clamp(x, lo, hi):
38 return max(lo, min(hi, x)) 38 return max(lo, min(hi, x))
39
40 @inlineCallbacks
41 def getMusicStatus():
42 returnValue(json.loads((yield cyclone.httpclient.fetch(
43 networking.musicPlayer.path('time'), timeout=.5)).body))
39 44
40 @inlineCallbacks 45 @inlineCallbacks
41 def newEnvelopeCurve(graph, ctx, uri, label): 46 def newEnvelopeCurve(graph, ctx, uri, label):
42 """this does its own patch to the graph""" 47 """this does its own patch to the graph"""
43 48
44 musicStatus = json.loads((yield cyclone.httpclient.fetch( 49 musicStatus = yield getMusicStatus()
45 networking.musicPlayer.path('time'), timeout=.5)).body)
46 songTime=musicStatus['t'] 50 songTime=musicStatus['t']
47 songDuration=musicStatus['duration'] 51 songDuration=musicStatus['duration']
48 52
49 cr = CurveResource(graph, uri) 53 cr = CurveResource(graph, uri)
50 cr.newCurve(ctx, label=Literal(label)) 54 cr.newCurve(ctx, label=Literal(label))
67 ] 71 ]
68 return effect, quads 72 return effect, quads
69 73
70 def musicCurveForSong(uri): 74 def musicCurveForSong(uri):
71 return URIRef(uri + 'music') 75 return URIRef(uri + 'music')
76
77 @inlineCallbacks
78 def currentSong():
79 s = (yield getMusicStatus())['song']
80 if s is None:
81 raise ValueError("no current song")
82 returnValue(URIRef(s))
72 83
73 class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler): 84 class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler):
85 def wideOpenCors(self):
86 self.set_header('Access-Control-Allow-Origin', '*')
87 self.set_header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS')
88 self.set_header('Access-Control-Max-Age', '1000')
89 self.set_header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With')
90
91 def options(self):
92 self.wideOpenCors()
93 self.write('')
94
74 @inlineCallbacks 95 @inlineCallbacks
75 def post(self): 96 def post(self):
76 song = URIRef(self.get_argument('uri')) 97 self.wideOpenCors()
77 dropped = URIRef(self.get_argument('drop')) 98 dropped = URIRef(self.get_argument('drop'))
99
100 try:
101 song = URIRef(self.get_argument('uri'))
102 except Exception: # which?
103 song = yield currentSong()
104
105 log.info("adding to %s", song)
106
78 ctx = song 107 ctx = song
79 graph = self.settings.graph 108 graph = self.settings.graph
80 109
81 with graph.currentState( 110 with graph.currentState(
82 tripleFilter=(dropped, None, None)) as g: 111 tripleFilter=(dropped, None, None)) as g: