Changeset - aec09f94c030
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 7 years ago 2018-05-31 20:48:43
drewp@bigasterisk.com
fix notes drawing themselves after they should be gone
Ignore-this: 8ce4b8b194dbc13836d22535de92294d
1 file changed with 12 insertions and 0 deletions:
0 comments (0 inline, 0 general)
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -351,34 +351,41 @@ coffeeElementSetup(class TimeZoomed exte
 
    
 
    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)
 

	
 
  isActiveNote: (note) ->
 
    return @noteByUriStr.has(note.value)
 

	
 
  _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)
 
    # this must come before the first Note.draw
 
    @noteByUriStr.set(uri.value, note)
 
    note.initWatchers()
 

	
 
  _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/)
 

	
 
@@ -427,48 +434,53 @@ coffeeElementSetup(class TimeAxis extend
 
      dependOn = [@viewState.zoomSpec.t1(), @viewState.zoomSpec.t2()]
 
      pxPerTick = 50
 
      axis = d3.axisTop(@viewState.zoomInX).ticks(@viewState.width() / pxPerTick)
 
      d3.select(@$.axis).call(axis)
 
)
 

	
 

	
 
# 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 = new Set() # id string
 

	
 
  initWatchers: ->
 
    @graph.runHandler(@draw.bind(@), "note draw #{@uri.value}")
 
    ko.computed @draw.bind(@)
 

	
 
  destroy: ->
 
    log('destroy', @uri.value)
 
    @isDetached = true
 
    @clearAdjusters()
 
    @parentElem.updateInlineAttrs(@uri, null)
 

	
 
  clearAdjusters: ->
 
    @adjusterIds.forEach (i) =>
 
      @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'))
 
      if @graph.uriValue(curve, U(':attr')).equals(curveAttr)
 
        return @project.getCurvePoints(curve, originTime)
 
    throw new Error("curve #{@uri.value} has no attr #{curveAttr.value}")
 

	
 
  draw: ->
 
    if not @parentElem.isActiveNote(@uri)
 
      # stale redraw call
 
      return
 
    U = (x) => @graph.Uri(x)
 
    [pointUris, worldPts] = @getCurvePoints(@uri, U(':strength'))
 
    effect = @graph.uriValue(@uri, U(':effectClass'))
 

	
 
    yForV = (v) => @rowBotY + (@rowTopY - @rowBotY) * v
 
    dependOn = [@viewState.zoomSpec.t1(), @viewState.zoomSpec.t2(), @viewState.width()]
 
    screenPts = (new PIXI.Point(@viewState.zoomInX(pt.e(1)), yForV(pt.e(2))) for pt in worldPts)
 

	
 
    @container.removeChildren()
 
    @graphics = new PIXI.Graphics({nativeLines: false})
 
    @graphics.interactive = true
 
    @container.addChild(@graphics)
0 comments (0 inline, 0 general)