changeset 1579:3c8c9a1deece

drag LightSample into timeline to make a new effect Ignore-this: d27d547ab00fa7c695f8e1d3313a4dcf
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 29 May 2017 23:32:30 +0000
parents 519480f2e51c
children 1db548d395fb
files light9/web/paint/paint-elements.coffee light9/web/timeline/timeline.coffee
diffstat 2 files changed, 41 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/paint/paint-elements.coffee	Mon May 29 21:04:05 2017 +0000
+++ b/light9/web/paint/paint-elements.coffee	Mon May 29 23:32:30 2017 +0000
@@ -149,7 +149,7 @@
         {attr: 'color', val: '#ffe897'},
     ]
   onSubj: (graph, @subj) ->
-    graph.runHandler(@loadAttrs.bind(@), 'loadAttrs #{subj}')
+    graph.runHandler(@loadAttrs.bind(@), "loadAttrs #{@subj}")
   loadAttrs: ->
     U = (x) -> @graph.Uri(x)
     @attrs = []
--- a/light9/web/timeline/timeline.coffee	Mon May 29 21:04:05 2017 +0000
+++ b/light9/web/timeline/timeline.coffee	Mon May 29 23:32:30 2017 +0000
@@ -276,19 +276,50 @@
 
   attached: ->
     root = @closest('light9-timeline-editor')
-    setupDrop @, @$.rows, root, (effect, pos) =>
-      U = (x) -> @graph.Uri(x)
+    setupDrop(@, @$.rows, root, @onDrop.bind(@))
+
+  onDrop: (effect, pos) ->
+    U = (x) -> @graph.Uri(x)
 
-      # 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'))
+    # 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'))
+      if @graph.contains(effect, RDF + 'type', U(':LightSample'))
+        effect = @makeEffect(effect)
+      else
         log("drop #{effect} is not an effect")
         return
+
+    dropTime = @zoomInX.invert(pos.e(1))
+    @makeNewNote(effect, dropTime)
+
+  makeEffect: (uri) ->
+    U = (x) -> @graph.Uri(x)
+    effect = U(uri + '/effect')
+    quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: effect}
+    
+    quads = [
+      quad(effect, U('rdf:type'), U(':Effect')),
+      quad(effect, U(':copiedFrom'), uri),
+      quad(effect, U('rdfs:label'), @graph.Literal('')),
+      quad(effect, U(':publishAttr'), U(':strength')),
+      ]
+
+    fromSettings = @graph.objects(uri, U(':setting'))
+
+    toSettings = @graph.nextNumberedResources(effect + '_set', fromSettings.length)
       
-      dropTime = @zoomInX.invert(pos.e(1))
-      @makeNewNote(effect, dropTime)
-      
+    for fs in fromSettings
+      ts = toSettings.pop()
+      # full copies of these since I may have to delete captures
+      quads.push(quad(effect, U(':setting'), ts))
+      quads.push(quad(ts, U(':deviceAttr'), @graph.uriValue(fs, U(':deviceAttr'))))
+      quads.push(quad(ts, U(':value'), @graph.uriValue(fs, U(':value'))))
+
+    @graph.applyAndSendPatch({delQuads: [], addQuads: quads})
+    return effect
+        
   makeNewNote: (effect, dropTime) ->
     U = (x) -> @graph.Uri(x)
     quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: @song}