Changeset - 0c89cd7cda43
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 7 years ago 2018-05-27 00:13:00
drewp@bigasterisk.com
conserve notes between updates
Ignore-this: f089716dc0eb7c98634c894f1c23f813
1 file changed with 27 insertions and 13 deletions:
0 comments (0 inline, 0 general)
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -294,13 +294,13 @@ coffeeElementSetup(class TimeZoomed exte
 
  @getter_observers: [
 
    '_onGraph(graph, setAdjuster, song, viewState, project)',
 
    'onZoom(viewState)',
 
  ]
 
  constructor: ->
 
    super()
 
    @notes = []
 
    @noteByUriStr = new Map()
 
    @stage = new PIXI.Container()
 
    @stage.interactive=true
 

	
 
    @renderer = PIXI.autoDetectRenderer({
 
      backgroundColor: 0x606060,
 
      antialias: true,
 
@@ -330,41 +330,53 @@ coffeeElementSetup(class TimeZoomed exte
 

	
 
    @renderer.render(@stage)
 

	
 
  _onGraph: (graph, setAdjuster, song, viewState, project)->
 
    return unless @song # polymer will call again
 
    @graph.runHandler(@gatherNotes.bind(@), 'zoom notes')
 
    
 
  onZoom: ->
 
    updateZoomFlattened = ->
 
      log('updateZoomFlattened')
 
      @zoomFlattened = ko.toJS(@viewState.zoomSpec)
 
    ko.computed(updateZoomFlattened.bind(@))
 

	
 
  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')
 
      had = toRemove.delete(uri.value)
 
      if not had
 
        @_addNote(uri, noteNum)
 
      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)
 
      @notes.push(note)
 
      noteNum = noteNum + 1
 
    @noteByUriStr.set(uri.value, note)
 

	
 
    @renderer.render(@stage)
 
  _delNote: (uriStr) ->
 
    n = @noteByUriStr.get(uriStr)
 
    @stage.removeChild(n.container)
 
    n.destroy()
 
    @noteByUriStr.delete(uriStr)
 

	
 
  onDrop: (effect, pos) ->
 
    U = (x) => @graph.Uri(x)
 

	
 
    return unless effect and effect.match(/^http/)
 

	
 
@@ -418,24 +430,26 @@ coffeeElementSetup(class TimeAxis extend
 

	
 

	
 
# Maintains a pixi object, some adjusters, and inlineattrs corresponding to a note
 
# 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)
 
    @isDetached = true
 
    @clearAdjusters()
 
    @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)
 
    originTime = @graph.floatValue(subj, U(':originTime'))
 

	
 
    for curve in @graph.objects(subj, U(':curve'))
 
@@ -550,13 +564,13 @@ class Note
 
      @_makePointAdjuster(yForV, worldPts, pointNum, ctx)
 

	
 
  _makePointAdjuster: (yForV, worldPts, pointNum, ctx) ->
 
    U = (x) => @graph.Uri(x)
 

	
 
    adjId = @uri.value + '/p' + pointNum
 
    @adjusterIds[adjId] = true
 
    @adjusterIds.add(adjId)
 
    @setAdjuster adjId, =>
 
      adj = new AdjustableFloatObject({
 
        graph: @graph
 
        subj: worldPts[pointNum].uri
 
        pred: U(':time')
 
        ctx: ctx
 
@@ -575,13 +589,13 @@ class Note
 
      adj
 

	
 
  _makeOffsetAdjuster: (yForV, curveWidthCalc, ctx) ->
 
    U = (x) => @graph.Uri(x)
 

	
 
    adjId = @uri.value + '/offset'
 
    @adjusterIds[adjId] = true
 
    @adjusterIds.add(adjId)
 
    @setAdjuster adjId, =>
 
      adj = new AdjustableFloatObject({
 
        graph: @graph
 
        subj: @uri
 
        pred: U(':originTime')
 
        ctx: ctx
 
@@ -600,13 +614,13 @@ class Note
 
    @_makeFadeAdjuster(yForV, ctx, @uri.value + '/fadeIn', 0, 1, $V([-50, -10]))
 
    n = worldPts.length
 
    @_makeFadeAdjuster(yForV, ctx, @uri.value + '/fadeOut', n - 2, n - 1, $V([50, -10]))
 

	
 
  _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) ->
 
    if pt.e(2) > .5
 
      $V([0, 30])
 
    else
0 comments (0 inline, 0 general)