# HG changeset patch # User Drew Perttula # Date 2017-05-29 23:32:30 # Node ID 3c8c9a1deece5ca330168a421416c5d96b8a7c66 # Parent 519480f2e51c84fd6da62e87934815140b15d090 drag LightSample into timeline to make a new effect Ignore-this: d27d547ab00fa7c695f8e1d3313a4dcf diff --git a/light9/web/paint/paint-elements.coffee b/light9/web/paint/paint-elements.coffee --- a/light9/web/paint/paint-elements.coffee +++ b/light9/web/paint/paint-elements.coffee @@ -149,7 +149,7 @@ Polymer {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 = [] diff --git a/light9/web/timeline/timeline.coffee b/light9/web/timeline/timeline.coffee --- a/light9/web/timeline/timeline.coffee +++ b/light9/web/timeline/timeline.coffee @@ -276,19 +276,50 @@ Polymer 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}