Changeset - e3de5d1208ca
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 9 years ago 2016-06-11 17:16:55
drewp@bigasterisk.com
refactor makeNewNote
Ignore-this: b1f934761ccb6359f9625cf4cc5969f8
1 file changed with 29 insertions and 27 deletions:
0 comments (0 inline, 0 general)
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -218,51 +218,53 @@ Polymer
 
    ko.computed(updateZoomFlattened.bind(@))
 
  ready: ->
 

	
 
  attached: ->
 
    root = @closest('light9-timeline-editor')
 
    setupDrop @, @$.rows, root, (effect, pos) =>
 

	
 
      U = (x) -> @graph.Uri(x)
 
      quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: @song}
 

	
 
      # we could probably accept some initial overrides right on the
 
      # effect uri, maybe as query params
 
      
 
      if not @graph.contains(effect, RDF + 'type', U(':Effect'))
 
        log("drop #{effect} is not an effect")
 
        return
 
      
 
      dropTime = @zoomInX.invert(pos.e(1))
 
      @makeNewNote(effect, dropTime)
 
      
 
      newNote = graph.nextNumberedResource("#{@song}/n")
 
      newCurve = graph.nextNumberedResource("#{newNote}c")
 
      points = graph.nextNumberedResources("#{newCurve}p", 4)
 
  makeNewNote: (effect, dropTime) ->
 
    U = (x) -> @graph.Uri(x)
 
    quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: @song}
 
      
 
      curveQuads = [
 
          quad(@song, U(':note'), newNote)
 
          quad(newNote, RDF + 'type', U(':Note'))
 
          quad(newNote, U(':originTime'), @graph.LiteralRoundedFloat(dropTime))
 
          quad(newNote, U(':effectClass'), effect)
 
          quad(newNote, U(':curve'), newCurve)
 
          quad(newCurve, RDF + 'type', U(':Curve'))
 
          quad(newCurve, U(':attr'), U(':strength'))
 
        ]        
 
      pointQuads = []
 
      for i in [0...4]
 
        pt = points[i]
 
        pointQuads.push(quad(newCurve, U(':point'), pt))
 
        pointQuads.push(quad(pt, U(':time'), @graph.LiteralRoundedFloat(i)))
 
        pointQuads.push(quad(pt, U(':value'), @graph.LiteralRoundedFloat(i == 1 or i == 2)))
 
      
 
      patch = {
 
        delQuads: []
 
        addQuads: curveQuads.concat(pointQuads)
 
        }
 
      @graph.applyAndSendPatch(patch)
 
      
 
    newNote = @graph.nextNumberedResource("#{@song}/n")
 
    newCurve = @graph.nextNumberedResource("#{newNote}c")
 
    points = @graph.nextNumberedResources("#{newCurve}p", 4)
 

	
 
    curveQuads = [
 
        quad(@song, U(':note'), newNote)
 
        quad(newNote, RDF + 'type', U(':Note'))
 
        quad(newNote, U(':originTime'), @graph.LiteralRoundedFloat(dropTime))
 
        quad(newNote, U(':effectClass'), effect)
 
        quad(newNote, U(':curve'), newCurve)
 
        quad(newCurve, RDF + 'type', U(':Curve'))
 
        quad(newCurve, U(':attr'), U(':strength'))
 
      ]        
 
    pointQuads = []
 
    for i in [0...4]
 
      pt = points[i]
 
      pointQuads.push(quad(newCurve, U(':point'), pt))
 
      pointQuads.push(quad(pt, U(':time'), @graph.LiteralRoundedFloat(i)))
 
      pointQuads.push(quad(pt, U(':value'), @graph.LiteralRoundedFloat(i == 1 or i == 2)))
 

	
 
    patch = {
 
      delQuads: []
 
      addQuads: curveQuads.concat(pointQuads)
 
      }
 
    @graph.applyAndSendPatch(patch)
 

	
 
Polymer
 
  is: "light9-timeline-time-axis",
 
  # for now since it's just one line calling dia,
 
  # light9-timeline-editor does our drawing work.
 

	
0 comments (0 inline, 0 general)