# HG changeset patch # User drewp@bigasterisk.com # Date 2018-05-27 00:13:00 # Node ID 0c89cd7cda43bfe39c32c0172f5f834ffc7f5031 # Parent 3c997bc6d380d35cdc1a55a19150694e3896f845 conserve notes between updates Ignore-this: f089716dc0eb7c98634c894f1c23f813 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 @@ -297,7 +297,7 @@ coffeeElementSetup(class TimeZoomed exte ] constructor: -> super() - @notes = [] + @noteByUriStr = new Map() @stage = new PIXI.Container() @stage.interactive=true @@ -333,6 +333,7 @@ coffeeElementSetup(class TimeZoomed exte _onGraph: (graph, setAdjuster, song, viewState, project)-> return unless @song # polymer will call again @graph.runHandler(@gatherNotes.bind(@), 'zoom notes') + onZoom: -> updateZoomFlattened = -> log('updateZoomFlattened') @@ -342,27 +343,38 @@ coffeeElementSetup(class TimeZoomed exte gatherNotes: -> U = (x) => @graph.Uri(x) return unless @song? - songNotes = @graph.objects(U(@song), U(':note')) - @stage.removeChildren() - n.destroy() for n in @notes - @notes = [] - + toRemove = new Set(@noteByUriStr.keys()) + noteNum = 0 for uri in _.sortBy(songNotes, 'id') - con = new PIXI.Container() - con.interactive=true - @stage.addChild(con) + had = toRemove.delete(uri.value) + if not had + @_addNote(uri, noteNum) + noteNum = noteNum + 1 - row = noteNum % 6 - rowTop = @viewState.rowsY() + 20 + 150 * row - note = new Note(@, con, @project, @graph, @selection, uri, @setAdjuster, U(@song), @viewState, rowTop, rowTop + 140) - @notes.push(note) - noteNum = noteNum + 1 + toRemove.forEach @_delNote.bind(@) @renderer.render(@stage) + _addNote: (uri, noteNum) -> + U = (x) => @graph.Uri(x) + con = new PIXI.Container() + con.interactive=true + @stage.addChild(con) + + row = noteNum % 6 + rowTop = @viewState.rowsY() + 20 + 150 * row + note = new Note(@, con, @project, @graph, @selection, uri, @setAdjuster, U(@song), @viewState, rowTop, rowTop + 140) + @noteByUriStr.set(uri.value, note) + + _delNote: (uriStr) -> + n = @noteByUriStr.get(uriStr) + @stage.removeChild(n.container) + n.destroy() + @noteByUriStr.delete(uriStr) + onDrop: (effect, pos) -> U = (x) => @graph.Uri(x) @@ -421,8 +433,9 @@ coffeeElementSetup(class TimeAxis extend # in the graph. class Note constructor: (@parentElem, @container, @project, @graph, @selection, @uri, @setAdjuster, @song, @viewState, @rowTopY, @rowBotY) -> - @adjusterIds = {} # id : true + @adjusterIds = new Set() # id @graph.runHandler(@draw.bind(@), 'note draw') + ko.computed @draw.bind(@) destroy: -> log('destroy', @uri.value) @@ -431,8 +444,9 @@ class Note @parentElem.updateInlineAttrs(@uri, null) clearAdjusters: -> - for i in Object.keys(@adjusterIds) + for i in @adjusterIds.keys() @setAdjuster(i, null) + @adjusterIds.clear() getCurvePoints: (subj, curveAttr) -> U = (x) => @graph.Uri(x) @@ -553,7 +567,7 @@ class Note U = (x) => @graph.Uri(x) adjId = @uri.value + '/p' + pointNum - @adjusterIds[adjId] = true + @adjusterIds.add(adjId) @setAdjuster adjId, => adj = new AdjustableFloatObject({ graph: @graph @@ -578,7 +592,7 @@ class Note U = (x) => @graph.Uri(x) adjId = @uri.value + '/offset' - @adjusterIds[adjId] = true + @adjusterIds.add(adjId) @setAdjuster adjId, => adj = new AdjustableFloatObject({ graph: @graph @@ -603,7 +617,7 @@ class Note _makeFadeAdjuster: (yForV, ctx, adjId, i0, i1, offset) -> return # not ready- AdjustableFade looks in Note object - @adjusterIds[adjId] = true + @adjusterIds.add(adjId) @setAdjuster adjId, => new AdjustableFade(yForV, i0, i1, @, offset, ctx) _suggestedOffset: (pt) ->