Changeset - 7eb3676b8fd6
[Not reviewed]
default
0 7 0
Drew Perttula - 8 years ago 2017-05-23 06:58:02
drewp@bigasterisk.com
more of the fixed add-to-song service
Ignore-this: 44b96a929b79ab201a80a6914b117f9d
7 files changed with 42 insertions and 19 deletions:
0 comments (0 inline, 0 general)
bin/effecteval
Show inline comments
 
@@ -41,49 +41,49 @@ def currentSong():
 
        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):
 
        self.wideOpenCors()
 
        dropped = URIRef(self.get_argument('drop'))
 

	
 
        try:
 
            song = URIRef(self.get_argument('uri'))
 
        except Exception: # which?
 
            song = yield currentSong()
 

	
 
        event = self.get_argument('event') or 'default'
 
        event = self.get_argument('event', default='default')
 
            
 
        log.info("adding to %s", song)
 

	
 
        p = yield songEffectPatch(self.settings.graph, dropped, song, event, ctx=song)
 
        self.settings.graph.patch(p)
 
        
 
class SongEffectsUpdates(cyclone.websocket.WebSocketHandler):
 
    def connectionMade(self, *args, **kwargs):
 
        self.graph = self.settings.graph
 
        self.graph.addHandler(self.updateClient)
 
        
 
    def updateClient(self):
 
        # todo: abort if client is gone
 
        playlist = self.graph.value(showconfig.showUri(), L9['playList'])
 
        songs = list(self.graph.items(playlist))
 
        out = []
 
        for s in songs:
 
            out.append({'uri': s, 'label': self.graph.label(s)})
 
            out[-1]['effects'] = [{'uri': uri, 'label': self.graph.label(uri)} for uri in sorted(self.graph.objects(s, L9['effect']))]
 
        self.sendMessage({'songs': out})
 
        
 
        
 
class EffectUpdates(cyclone.websocket.WebSocketHandler):
 
    """
light9/effect/edit.py
Show inline comments
 
import json
 
import cyclone.httpclient
 
from twisted.internet.defer import inlineCallbacks, returnValue
 
from rdflib import URIRef, Literal
 

	
 
from light9 import networking
 
from light9.namespaces import L9, RDF, RDFS
 
from light9.rdfdb.patch import Patch
 
from light9.curvecalc.curve import CurveResource
 

	
 
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 songEffectPatch(graph, dropped, song, event, ctx):
 
    """
 
    some uri was 'dropped' in the timeline. event is 'default' or 'start' or 'end'.
 
    """
 
    with graph.currentState(
 
            tripleFilter=(dropped, None, None)) as g:
 
        droppedTypes = list(g.objects(dropped, RDF.type))
 
        droppedLabel = g.label(dropped)
 
        droppedCodes = list(g.objects(dropped, L9['code']))
 

	
 
    quads = []
 
    fade = 2 if event == 'default' else 0
 

	
 
    if _songHasEffect(graph, song, dropped):
 
        # bump the existing curve
 
        pass
 
    else:
 
        effect, q = _newEffect(graph, song, ctx)
 
        quads.extend(q)
 

	
 
        curve = graph.sequentialUri(song + "/curve-")
 
        yield _newEnvelopeCurve(graph, ctx, curve, droppedLabel, fade)
 
        quads.extend([
 
            (song, L9['curve'], curve, ctx),
 
            (effect, RDFS.label, droppedLabel, ctx),
 
            (effect, L9['code'], Literal('env = %s' % curve.n3()), ctx),
 
            ])
 

	
light9/rdfdb/currentstategraphapi.py
Show inline comments
 
import logging, traceback, time, itertools
 
from rdflib import ConjunctiveGraph
 
from light9.rdfdb.rdflibpatch import contextsForStatement as rp_contextsForStatement
 
log = logging.getLogger("currentstate")
 

	
 
class ReadOnlyConjunctiveGraph(object):
 
    """similar to rdflib's ReadOnlyGraphAggregate but takes one CJ in, instead
 
    of a bunch of Graphs"""
 
    def __init__(self, graph):
 
        self.graph = graph
 

	
 
    def __getattr__(self, attr):
 
        if attr in ['subjects', 'value', 'objects', 'triples']: # not complete
 
        if attr in ['subjects', 'value', 'objects', 'triples', 'label']: # not complete
 
            return getattr(self.graph, attr)
 
        raise TypeError("can't access %r of read-only graph" % attr)
 

	
 

	
 
class CurrentStateGraphApi(object):
 
    """
 
    mixin for SyncedGraph, separated here because these methods work together
 
    """
 

	
 
    def currentState(self, context=None, tripleFilter=(None, None, None)):
 
        """
 
        a graph you can read without being in an addHandler
 

	
 
        you can save some time by passing a triple filter, and we'll only give you the matching triples
 
        """
 
        if context is not None:
 
            raise NotImplementedError("currentState with context arg")
 

	
 
        class Mgr(object):
 
            def __enter__(self2):
 
                # this should be a readonly view of the existing
 
                # graph, maybe with something to guard against
 
                # writes/patches happening while reads are being
 
                # done. Typical usage will do some reads on this graph
light9/rdfdb/syncedgraph.py
Show inline comments
 
@@ -104,48 +104,52 @@ class SyncedGraph(CurrentStateGraphApi, 
 
        if p.isNoop():
 
            log.info("skipping no-op patch")
 
            return
 
        
 
        # these could fail if we're out of sync. One approach:
 
        # Rerequest the full state from the server, try the patch
 
        # again after that, then give up.
 
        debugKey = '[id=%s]' % (id(p) % 1000)
 
        log.debug("\napply local patch %s %s", debugKey, p)
 
        try:
 
            patchQuads(self._graph,
 
                       deleteQuads=p.delQuads,
 
                       addQuads=p.addQuads,
 
                       perfect=True)
 
        except ValueError as e:
 
            log.error(e)
 
            self.sendFailed(None)
 
            return
 
        log.debug('runDepsOnNewPatch')
 
        self.runDepsOnNewPatch(p)
 
        log.debug('sendPatch')
 
        self._sender.sendPatch(p).addErrback(self.sendFailed)
 
        log.debug('patch is done %s', debugKey)
 

	
 
    def suggestPrefixes(self, prefixes):
 
        song note edit should put song: to the song uri
 
        self.addlPrefixes.update(prefixes)
 

	
 
    def sendFailed(self, result):
 
        """
 
        we asked for a patch to be queued and sent to the master, and
 
        that ultimately failed because of a conflict
 
        """
 
        log.warn("sendFailed")
 
        self.resync()
 
        
 
        #i think we should receive back all the pending patches,
 
        #do a resync here,
 
        #then requeue all the pending patches (minus the failing one?) after that's done.
 

	
 
    def _onPatch(self, p):
 
        """
 
        central server has sent us a patch
 
        """
 
        log.debug('_onPatch server has sent us %s', p)
 
        patchQuads(self._graph, p.delQuads, p.addQuads, perfect=True)
 
        log.debug("graph now has %s statements" % len(self._graph))
 
        try:
 
            self.runDepsOnNewPatch(p)
 
        except Exception:
 
            # don't reflect this error back to the server; we did
 
            # receive its patch correctly. However, we're in a bad
light9/subserver/effects.coffee
Show inline comments
 
@@ -12,35 +12,50 @@ class Model
 
      {label: "bumpyhues", expr: "hsv(t*.5,.4,1)*notch(t*.01)"},
 
      ]
 

	
 
  subtermLink: (label, expr) =>
 
    "http://chase?"+$.param({
 
      subtermName: label
 
      subtermExpr: label + '_env(t) * ' + expr
 
      curve: label + '_env'
 
    })
 
  subtermExprs: (chase) =>
 
    [
 
      'chase(t, names=LABEL, ontime=0.5, offset=0.2)'.replace(/LABEL/g, chase.label)
 
    ]
 
  
 

	
 
model = new Model()
 

	
 
model.addToCurrentSong = (e) ->
 
  $.ajax({
 
    type: 'POST'
 
    url: '/effectEval/songEffects'
 
    data: {drop: e.uri}
 
  })
 

	
 
model.addMomentary = (e) ->
 
  $.ajax({
 
    type: 'POST'
 
    url: '/effectEval/songEffects'
 
    data: {drop: e.uri, event: 'start'}
 
  })
 

	
 
model.addMomentaryUp = (e) ->
 
  $.ajax({
 
    type: 'POST'
 
    url: '/effectEval/songEffects'
 
    data: {drop: e.uri, event: 'end'}
 
  })
 
  
 

	
 
reconnectingWebSocket "../effectsUpdates", (msg) ->
 
  model.chases(msg.chases) if msg.chases?
 
  model.classes(msg.classes) if msg.classes?
 

	
 
# this sort of works to stop clicks in <input> from following the
 
# submaster hyperlink, but it may make certain clicks act wrong
 
$(document).on('click', 'a', (ev) ->
 
  return false if ev.target.tagName == 'INPUT'
 
)
 

	
 
ko.applyBindings(model)
 
\ No newline at end of file
light9/subserver/effects.jade
Show inline comments
 
@@ -9,33 +9,34 @@ html
 
    p: a(href='.') Go to Submasters
 

	
 

	
 
    div(data-bind="foreach: moreExprs")
 
      div.resource.chase
 
        span(data-bind="text: label")
 
        | 
 
        a.resource(data-bind="attr: {href: $root.subtermLink(label, expr)}, text: expr")
 
    
 
    div(data-bind="foreach: chases")
 
      div.resource.chase
 
        | Chase
 
        a(data-bind="attr: {href: uri}, text: label")
 
        ul(data-bind="foreach: $parent.subtermExprs($data)")
 
          li: a.resource(data-bind="attr: {href: $root.subtermLink($parent.label, $data)}, text: $data")
 

	
 

	
 
    div(data-bind="foreach: classes")
 
      div.resource.effectClass
 
        h2
 
          | Effect class
 
          | 
 
          a(data-bind="attr: {href: uri}, text: label")
 
          button(data-bind="click: $root.addToCurrentSong") Add to current song
 
          button(data-bind="event: { mousedown: $root.addMomentary, mouseup: $root.addMomentaryUp }") Add momentary
 
        div
 
          code(data-bind="text: code")
 
        
 
    #status
 
      
 
    script(src="/lib/jquery/dist/jquery.min.js")
 
    script(src="/lib/knockout/dist/knockout.js")
 
    script(src="/websocket.js")
 
    script(src="effects.js")
 
\ No newline at end of file
show/dance2017/playlist.n3
Show inline comments
 
@prefix : <http://light9.bigasterisk.com/> .
 
@prefix show: <http://light9.bigasterisk.com/show/> .
 
@prefix sh: <http://light9.bigasterisk.com/show/dance2017/> .
 
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
 

	
 
show:dance2017 :musicRoot "show/dance2016/music/pad";
 
:spectrogramUrlRoot "/show/dance2016/spectrogram" .
 

	
 
show:dance2017 :playList (
 
  sh:song1  sh:song2  sh:song3  sh:song4  sh:song5
 
  sh:song6  sh:song7  sh:song8  sh:song9  sh:song10
 
  sh:song11 sh:song12 sh:song13 sh:song14 sh:song15
 
  sh:song16 sh:song17 sh:song18
 
) .
 

	
 
sh:song1 a :Song; rdfs:label  "01"; :songFilename "01.wav" .
 
sh:song2 a :Song; rdfs:label  "02"; :songFilename "02.wav" .
 
sh:song3 a :Song; rdfs:label  "03"; :songFilename "03.wav" .
 
sh:song4 a :Song; rdfs:label  "04"; :songFilename "04.wav" .
 
sh:song5 a :Song; rdfs:label  "05"; :songFilename "05.wav" .
 
sh:song6 a :Song; rdfs:label  "06"; :songFilename "06.wav" .
 
sh:song7 a :Song; rdfs:label  "07"; :songFilename "07.wav" .
 
sh:song8 a :Song; rdfs:label  "08"; :songFilename "08.wav" .
 
sh:song9 a :Song; rdfs:label  "09"; :songFilename "09.wav" .
 
sh:song10 a :Song; rdfs:label "10"; :songFilename "10.wav" .
 
sh:song11 a :Song; rdfs:label "11"; :songFilename "11.wav" .
 
sh:song12 a :Song; rdfs:label "12"; :songFilename "12.wav" .
 
sh:song13 a :Song; rdfs:label "13"; :songFilename "13.wav" .
 
sh:song14 a :Song; rdfs:label "14"; :songFilename "14.wav" .
 
sh:song15 a :Song; rdfs:label "15"; :songFilename "15.wav" .
 
sh:song16 a :Song; rdfs:label "16"; :songFilename "16.wav" .
 
sh:song17 a :Song; rdfs:label "17"; :songFilename "17.wav" .
 
sh:song1 a :Song; rdfs:label  "01"; :songFilename "01-out.wav" .
 
sh:song2 a :Song; rdfs:label  "02"; :songFilename "02-out.wav" .
 
sh:song3 a :Song; rdfs:label  "03"; :songFilename "03-out.wav" .
 
sh:song4 a :Song; rdfs:label  "04"; :songFilename "04-out.wav" .
 
sh:song5 a :Song; rdfs:label  "05"; :songFilename "05-out.wav" .
 
sh:song6 a :Song; rdfs:label  "06"; :songFilename "06-out.wav" .
 
sh:song7 a :Song; rdfs:label  "07"; :songFilename "07-out.wav" .
 
sh:song8 a :Song; rdfs:label  "08"; :songFilename "08-out.wav" .
 
sh:song9 a :Song; rdfs:label  "09"; :songFilename "09-out.wav" .
 
sh:song10 a :Song; rdfs:label "10"; :songFilename "10-out.wav" .
 
sh:song11 a :Song; rdfs:label "11"; :songFilename "11-out.wav" .
 
sh:song12 a :Song; rdfs:label "12"; :songFilename "12-out.wav" .
 
sh:song13 a :Song; rdfs:label "13"; :songFilename "13-out.wav" .
 
sh:song14 a :Song; rdfs:label "14"; :songFilename "14-out.wav" .
 
sh:song15 a :Song; rdfs:label "15"; :songFilename "15-africaout.wav" .
 
sh:song16 a :Song; rdfs:label "16"; :songFilename "16-out.wav" .
 
sh:song17 a :Song; rdfs:label "17"; :songFilename "17-out.wav" .
 

	
 

	
0 comments (0 inline, 0 general)