changeset 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 78973ed9e986
files bin/effecteval light9/subserver/effects.coffee light9/subserver/effects.jade
diffstat 3 files changed, 40 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/bin/effecteval	Sun Jun 15 08:41:02 2014 +0000
+++ b/bin/effecteval	Sun Jun 15 15:47:15 2014 +0000
@@ -36,13 +36,17 @@
         
 def clamp(x, lo, hi):
     return max(lo, min(hi, x))
+
+@inlineCallbacks
+def getMusicStatus():
+    returnValue(json.loads((yield cyclone.httpclient.fetch(
+        networking.musicPlayer.path('time'), timeout=.5)).body))
     
 @inlineCallbacks
 def newEnvelopeCurve(graph, ctx, uri, label):
     """this does its own patch to the graph"""
     
-    musicStatus = json.loads((yield cyclone.httpclient.fetch(
-        networking.musicPlayer.path('time'), timeout=.5)).body)
+    musicStatus = yield getMusicStatus()
     songTime=musicStatus['t']
     songDuration=musicStatus['duration']
     
@@ -69,12 +73,37 @@
     
 def musicCurveForSong(uri):
     return URIRef(uri + 'music')
+
+@inlineCallbacks
+def currentSong():
+    s = (yield getMusicStatus())['song']
+    if s is None:
+        raise ValueError("no current song")
+    returnValue(URIRef(s))
     
 class SongEffects(PrettyErrorHandler, cyclone.web.RequestHandler):
+    def wideOpenCors(self):
+        self.set_header('Access-Control-Allow-Origin', '*')
+        self.set_header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS')
+        self.set_header('Access-Control-Max-Age', '1000')
+        self.set_header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With')
+    
+    def options(self):
+        self.wideOpenCors()
+        self.write('')
+
     @inlineCallbacks
     def post(self):
-        song = URIRef(self.get_argument('uri'))
+        self.wideOpenCors()
         dropped = URIRef(self.get_argument('drop'))
+
+        try:
+            song = URIRef(self.get_argument('uri'))
+        except Exception: # which?
+            song = yield currentSong()
+            
+        log.info("adding to %s", song)
+
         ctx = song
         graph = self.settings.graph
         
--- a/light9/subserver/effects.coffee	Sun Jun 15 08:41:02 2014 +0000
+++ b/light9/subserver/effects.coffee	Sun Jun 15 15:47:15 2014 +0000
@@ -26,6 +26,13 @@
 
 model = new Model()
 
+model.addToCurrentSong = (e) ->
+  $.ajax({
+    type: 'POST'
+    url: '//localhost:8070/songEffects'
+    data: {drop: e.uri}
+  })
+
 reconnectingWebSocket "ws://localhost:8052/effectsUpdates", (msg) ->
   model.chases(msg.chases) if msg.chases?
   model.classes(msg.classes) if msg.classes?
--- a/light9/subserver/effects.jade	Sun Jun 15 08:41:02 2014 +0000
+++ b/light9/subserver/effects.jade	Sun Jun 15 15:47:15 2014 +0000
@@ -26,6 +26,7 @@
           | Effect class
           | 
           a(data-bind="attr: {href: uri}, text: label")
+          button(data-bind="click: $root.addToCurrentSong") Add to current song
         div
           code(data-bind="text: code")