changeset 1433:e3de5d1208ca

refactor makeNewNote Ignore-this: b1f934761ccb6359f9625cf4cc5969f8
author drewp@bigasterisk.com
date Sat, 11 Jun 2016 17:16:55 +0000
parents 185f3e2208c3
children b8d42a411e17
files light9/web/timeline/timeline.coffee
diffstat 1 files changed, 29 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/timeline/timeline.coffee	Sat Jun 11 17:16:11 2016 +0000
+++ b/light9/web/timeline/timeline.coffee	Sat Jun 11 17:16:55 2016 +0000
@@ -221,9 +221,7 @@
   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
@@ -233,33 +231,37 @@
         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",