Changeset - 13e3cbe9071a
[Not reviewed]
default
0 4 0
Drew Perttula - 8 years ago 2017-05-25 06:12:55
drewp@bigasterisk.com
momentary-add button support
Ignore-this: 6269d0492f1b5ec4e112b3b932708b04
4 files changed with 75 insertions and 36 deletions:
0 comments (0 inline, 0 general)
bin/effecteval
Show inline comments
 
@@ -54,30 +54,36 @@ class SongEffects(PrettyErrorHandler, cy
 

	
 
    @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', default='default')
 
            
 
        
 
        note = self.get_argument('note', default=None)
 
        if note is not None:
 
            note = URIRef(note)
 

	
 
        log.info("adding to %s", song)
 

	
 
        p = yield songNotePatch(self.settings.graph, dropped, song, event, ctx=song)
 
        note, p = yield songNotePatch(self.settings.graph, dropped, song, event, ctx=song, note=note)
 
        
 
        self.settings.graph.patch(p)
 
        self.settings.graph.suggestPrefixes({'song': URIRef(song + '/')})
 
        self.write(json.dumps({'note': note}))
 
        
 
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:
light9/effect/edit.py
Show inline comments
 
@@ -59,69 +59,95 @@ def songEffectPatch(graph, dropped, song
 
            raise NotImplementedError(
 
                "don't know how to add an effect from %r (types=%r)" %
 
                (dropped, droppedTypes))
 

	
 
        _maybeAddMusicLine(quads, effect, song, ctx)
 

	
 
    print "adding"
 
    for qq in quads:
 
        print qq
 
    returnValue(Patch(addQuads=quads))
 

	
 
@inlineCallbacks
 
def songNotePatch(graph, dropped, song, event, ctx):
 
def songNotePatch(graph, dropped, song, event, ctx, note=None):
 
    """
 
    drop into effectsequencer timeline
 

	
 
    ported from timeline.coffee makeNewNote
 
    """
 
    with graph.currentState(
 
            tripleFilter=(dropped, None, None)) as g:
 
        droppedTypes = list(g.objects(dropped, RDF.type))
 

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

	
 
    if L9['Effect'] in droppedTypes:
 
    if note:
 
        musicStatus = yield getMusicStatus()
 
        songTime = musicStatus['t']
 
        note = graph.sequentialUri(song + '/n')
 
        curve = graph.sequentialUri(note + 'c')
 
        quads.extend([
 
            (song, L9['note'], note, ctx),
 
            (note, RDF.type, L9['Note'], ctx),
 
            (note, L9['curve'], curve, ctx),
 
            (note, L9['effectClass'], dropped, ctx),
 
            (note, L9['originTime'], Literal(songTime), ctx),
 
            (curve, RDF.type, L9['Curve'], ctx),
 
            (curve, L9['attr'], L9['strength'], ctx),
 
            ])
 
        if event == 'default':
 
            coords = [(0 - fade, 0), (0, 1), (20, 1), (20 + fade, 0)]
 
        elif event == 'start':
 
            coords = [(0 - fade, 0), (0, 1), (20, 1), (20 + fade, 0)]
 
        elif event == 'end':
 
            raise
 
        _finishCurve(graph, note, quads, ctx, songTime)
 
    else:
 
        if L9['Effect'] in droppedTypes:
 
            musicStatus = yield getMusicStatus()
 
            songTime = musicStatus['t']
 
            note = _makeNote(graph, song, note, quads, ctx, dropped, songTime, event, fade)
 
        else:
 
            raise NotImplementedError(event)
 
        for t,v in coords:
 
            pt = graph.sequentialUri(curve + 'p')
 
            quads.extend([
 
                (curve, L9['point'], pt, ctx),
 
                (pt, L9['time'], Literal(t), ctx),
 
                (pt, L9['value'], Literal(v), ctx),
 
                ])
 
            raise NotImplementedError
 

	
 
    returnValue((note, Patch(addQuads=quads)))
 

	
 

	
 
def _point(ctx, uri, t, v):
 
    return [
 
        (uri, L9['time'], Literal(round(t, 3)), ctx),
 
        (uri, L9['value'], Literal(round(v, 3)), ctx)
 
        ]
 
    
 
def _finishCurve(graph, note, quads, ctx, songTime):
 
    with graph.currentState() as g:
 
        origin = g.value(note, L9['originTime']).toPython()
 
        curve = g.value(note, L9['curve'])
 

	
 
    pt2 = graph.sequentialUri(curve + 'p')
 
    pt3 = graph.sequentialUri(curve + 'p')
 
    quads.extend(
 
        [(curve, L9['point'], pt2, ctx)] + _point(ctx, pt2, songTime - origin, 1) +
 
        [(curve, L9['point'], pt3, ctx)] + _point(ctx, pt3, songTime - origin + .5, 0)
 
        )
 
    
 
    returnValue(Patch(addQuads=quads))
 
    
 

	
 
def _makeNote(graph, song, note, quads, ctx, dropped, songTime, event, fade):
 
    note = graph.sequentialUri(song + '/n')
 
    curve = graph.sequentialUri(note + 'c')
 
    quads.extend([
 
        (song, L9['note'], note, ctx),
 
        (note, RDF.type, L9['Note'], ctx),
 
        (note, L9['curve'], curve, ctx),
 
        (note, L9['effectClass'], dropped, ctx),
 
        (note, L9['originTime'], Literal(songTime), ctx),
 
        (curve, RDF.type, L9['Curve'], ctx),
 
        (curve, L9['attr'], L9['strength'], ctx),
 
        ])
 
    if event == 'default':
 
        coords = [(0 - fade, 0), (0, 1), (20, 1), (20 + fade, 0)]
 
    elif event == 'start':
 
        coords = [(0 - fade, 0), (0, 1), ]
 
    elif event == 'end': # probably unused- goes to _finishCurve instead
 
        coords = [(20, 1), (20 + fade, 0)]
 
    else:
 
        raise NotImplementedError(event)
 
    for t,v in coords:
 
        pt = graph.sequentialUri(curve + 'p')
 
        quads.extend([(curve, L9['point'], pt, ctx)] + _point(ctx, pt, t, v))
 
    return note
 
    
 
def _songHasEffect(graph, song, uri):
 
    """does this song have an effect of class uri or a sub curve for sub
 
    uri? this should be simpler to look up."""
 
    return False # todo
 

	
 
def musicCurveForSong(uri):
 
    return URIRef(uri + 'music')
 
    
 
def _newEffect(graph, song, ctx):
 
    effect = graph.sequentialUri(song + "/effect-")
 
    quads = [
light9/subserver/effects.coffee
Show inline comments
 
@@ -24,36 +24,41 @@ class Model
 
    ]
 
  
 

	
 
model = new Model()
 

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

	
 
lastMomentaryNote = null
 

	
 
model.addMomentary = (e) ->
 
  $.ajax({
 
    type: 'POST'
 
    url: '/effectEval/songEffects'
 
    data: {drop: e.uri, event: 'start'}
 
    success: (data) ->
 
      lastMomentaryNote = JSON.parse(data)['note']
 

	
 
  })
 

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

	
 
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'
 
)
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -454,37 +454,39 @@ Polymer
 
  updateStrengthCurveEtc: (originTime, curve, yForV, effect) ->
 
    U = (x) -> @graph.Uri(x)
 
    [@pointUris, @worldPts] = getCurvePoints(@graph, curve, originTime) # (song time, value)
 

	
 
    curveWidth = =>
 
      tMin = @graph.floatValue(@worldPts[0].uri, U(':time'))
 
      tMax = @graph.floatValue(@worldPts[3].uri, U(':time'))
 
      tMax - tMin            
 

	
 
    screenPts = ($V([@zoomInX(pt.e(1)), @offsetTop + (1 - pt.e(2)) * @offsetHeight]) for pt in @worldPts)
 
    @dia.setNote(@uri, screenPts, effect)
 

	
 
    leftX = Math.max(2, screenPts[1].e(1) + 5)
 
    rightX = screenPts[2].e(1) - 5
 
    leftX = Math.max(2, screenPts[Math.min(1, screenPts.length - 1)].e(1) + 5)
 
    rightX = screenPts[Math.min(2, screenPts.length - 1)].e(1) - 5
 
    if screenPts.length < 3
 
      rightX = leftX + 120
 
    w = 114
 
    h = 80
 
    @inlineRect = {
 
      left: leftX,
 
      top: @offsetTop + @offsetHeight - h - 5,
 
      width: w,
 
      height: h,
 
      display: if rightX - leftX > w then 'block' else 'none'
 
      }
 

	
 
    if screenPts[3].e(1) - screenPts[0].e(1) < 100
 
    if screenPts[screenPts.length - 1].e(1) - screenPts[0].e(1) < 100
 
      @clearAdjusters()
 
      # also kill their connectors
 
      return
 

	
 
    @makeCurveAdjusters(curveWidth, yForV, @worldPts)
 
    
 
  makeCurveAdjusters: (curveWidth, yForV, worldPts) ->
 
    U = (x) -> @graph.Uri(x)
 

	
 
    if 0
 
      @adjusterIds[@uri+'/offset'] = true
 
      @setAdjuster(@uri+'/offset', => new AdjustableFloatObject({
0 comments (0 inline, 0 general)