Changeset - fa11008d9b22
[Not reviewed]
default
0 2 0
Drew Perttula - 7 years ago 2018-05-15 07:08:11
drewp@bigasterisk.com
fix viewstate tracking. zoom current notes with the time slider.
Ignore-this: ed3f5322d71aab3025bc4c52951d1dfc
2 files changed with 28 insertions and 26 deletions:
0 comments (0 inline, 0 general)
light9/web/timeline/timeline-elements.html
Show inline comments
 
<link rel="import" href="/lib/polymer/polymer.html">
 
<link rel="import" href="/lib/polymer/lib/utils/render-status.html">
 
<link rel="import" href="/lib/iron-resizable-behavior/iron-resizable-behavior.html">
 
<link rel="import" href="/lib/iron-ajax/iron-ajax.html">
 
<link rel="import" href="light9-timeline-audio.html">
 
<link rel="import" href="../rdfdb-synced-graph.html">
 
<link rel="import" href="../light9-music.html">
 
<link rel="import" href="../edit-choice.html">
 
@@ -198,12 +199,15 @@
 
      
 

	
 
<!-- seconds labels -->
 
<dom-module id="light9-timeline-time-axis">
 
  <template>
 
    <style>
 
     :host {
 
         display: block;
 
     }
 
      div {
 
          width: 100%;
 
          height: 31px;
 
      }
 
      svg {
 
          width: 100%;
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -107,14 +107,14 @@ coffeeElementSetup(class TimelineEditor 
 
    show: {value: 'http://light9.bigasterisk.com/show/dance2017'}
 
    songTime: {type: Number, notify: true}
 
    songDuration: {type: Number, notify: true}
 
    songPlaying: {type: Boolean, notify: true}
 
    selection: {type: Object, notify: true}
 
  @getter_observers: [
 
    'setSong(playerSong, followPlayerSong)',
 
    'onGraph(graph)',
 
    '_onSong(playerSong, followPlayerSong)',
 
    '_onGraph(graph)',
 
    '_onSongDuration(songDuration, viewState)',
 
    '_onSongTime(songTime, viewState)',
 
  ]
 
  ready: ->
 
    super.ready()
 
    
 
@@ -131,54 +131,48 @@ coffeeElementSetup(class TimelineEditor 
 
    window.viewState = @viewState
 
    @setAdjuster = (adjId, makeAdjustable) =>
 
      ac = @$.adjustersCanvas
 
      setTimeout((()=>ac.setAdjuster(adjId, makeAdjustable)),10)
 

	
 
    ko.computed(@zoomOrLayoutChanged.bind(@))
 
    setTimeout =>
 

	
 
      @trackMouse()
 
      @bindKeys()
 
      @bindWheelZoom(@dia)
 
      setTimeout => # depends on child node being ready
 

	
 
          @forwardMouseEventsToAdjustersCanvas()
 
        , 400
 

	
 
      @makeZoomAdjs()
 

	
 
      zoomed = @$.zoomed
 
      setupDrop(@$.dia.shadowRoot.querySelector('svg'),
 
                zoomed.$.rows, @, zoomed.onDrop.bind(zoomed))
 

	
 
      setInterval(@updateDebugSummary.bind(@), 100)
 
    , 500
 

	
 
    @addEventListener('iron-resize', @_onIronResize.bind(@))
 
    setTimeout(@_onIronResize.bind(@), 1000) # when children are packed
 
    Polymer.RenderStatus.afterNextRender(this, @_onIronResize.bind(@))
 
    
 
    #if anchor == loadtest
 
    #  add note and delete it repeatedly
 
    #  disconnect the graph, make many notes, drag a point over many steps, measure lag somewhere
 
    #zoomed = @$.zoomed 
 
    #setupDrop(@dia.shadowRoot.querySelector('svg'),
 
    #          zoomed.$.rows, @, zoomed.onDrop.bind(zoomed))
 

	
 
  _onIronResize: ->
 
    @viewState.setWidth(@offsetWidth)
 
    @viewState.audioY(@$.audio.offsetTop)
 
    @viewState.audioH(@$.audio.offsetHeight)
 
    @viewState.zoomedTimeY(@$.zoomed.$.time.offsetTop) if @$.zoomed?.$?.time?
 
    @viewState.zoomedTimeH(30) #@$.zoomed.$.time.offsetHeight)
 
    if @$.zoomed?.$?.time?
 
      @viewState.zoomedTimeY(@$.zoomed.$.time.offsetTop)
 
      @viewState.zoomedTimeH(@$.zoomed.$.time.offsetHeight)
 
      
 
    log('editor resized')
 
  _onSongTime: (t) ->
 
    @viewState.cursor.t(t)
 
    
 
  _onSongDuration: (d) ->
 
    d = 700 if d < 1 # bug is that asco isn't giving duration, but 0 makes the scale corrupt
 
    @viewState.zoomSpec.duration(d)
 
    
 
  setSong: (s) ->
 
  _onSong: (s) ->
 
    @song = @playerSong if @followPlayerSong
 
  onGraph: (graph) ->
 
    
 
  _onGraph: (graph) ->
 
    @project = new Project(graph)
 

	
 
  updateDebugSummary: ->
 
    elemCount = (tag) -> document.getElementsByTagName(tag).length
 
    @debug = "#{window.debug_zoomOrLayoutChangedCount} layout change,
 
     #{elemCount('light9-timeline-note')} notes,
 
@@ -187,17 +181,18 @@ coffeeElementSetup(class TimelineEditor 
 
     #{window.debug_adjsCount} adjuster items registered,
 
     #{window.debug_adjUpdateDisplay} adjuster updateDisplay calls,
 
    "
 

	
 
  zoomOrLayoutChanged: ->
 
    vs = @viewState
 
    vs.width()
 
    dependOn = [vs.zoomSpec.t1(), vs.zoomSpec.t2(), vs.width()]
 

	
 
    @$.zoomed.gatherNotes() if @$.zoomed?.gatherNotes?
 
  
 
    # todo: these run a lot of work purely for a time change
 
    if @$.zoomed?.$?.audio?
 
      vs.zoomSpec.t1()
 
      #@dia.setTimeAxis(vs.width(), @$.zoomed.$.audio.offsetTop, vs.zoomInX)
 
      @$.adjustersCanvas.updateAllCoords()
 

	
 
  trackMouse: ->
 
    # not just for show- we use the mouse pos sometimes
 
    for evName in ['mousemove', 'touchmove']
 
@@ -245,25 +240,25 @@ coffeeElementSetup(class TimelineEditor 
 

	
 
  makeZoomAdjs: ->
 
    yMid = => @$.audio.offsetTop + @$.audio.offsetHeight / 2
 
    
 
    valForPos = (pos) =>
 
        x = pos.e(1)
 
        t = @fullZoomX.invert(x)
 
        t = @viewState.fullZoomX.invert(x)
 
    @setAdjuster('zoom-left', => new AdjustableFloatObservable({
 
      observable: @viewState.zoomSpec.t1,
 
      getTarget: () =>
 
        $V([@fullZoomX(@viewState.zoomSpec.t1()), yMid()])
 
        $V([@viewState.fullZoomX(@viewState.zoomSpec.t1()), yMid()])
 
      getSuggestedTargetOffset: () => $V([50, 0])
 
      getValueForPos: valForPos
 
    }))
 

	
 
    @setAdjuster('zoom-right', => new AdjustableFloatObservable({
 
      observable: @viewState.zoomSpec.t2,
 
      getTarget: () =>
 
        $V([@fullZoomX(@viewState.zoomSpec.t2()), yMid()])
 
        $V([@viewState.fullZoomX(@viewState.zoomSpec.t2()), yMid()])
 
      getSuggestedTargetOffset: () => $V([-50, 0])
 
      getValueForPos: valForPos
 
    }))
 

	
 
    panObs = ko.pureComputed({
 
        read: () =>
 
@@ -312,13 +307,13 @@ coffeeElementSetup(class TimeZoomed exte
 
    })
 
     
 
  ready: ->
 
    super.ready()
 
     
 
    @addEventListener('iron-resize', @update.bind(@))
 
    @update()
 
    Polymer.RenderStatus.afterNextRender(this, @update.bind(@))
 
    
 
    @$.rows.appendChild(@renderer.view);
 
  
 
  update: ->
 
    @renderer.resize(@clientWidth, @clientHeight)
 
    @renderer.render(@stage)
 
@@ -328,12 +323,14 @@ coffeeElementSetup(class TimeZoomed exte
 
      log('updateZoomFlattened')
 
      @zoomFlattened = ko.toJS(@viewState.zoomSpec)
 
    ko.computed(updateZoomFlattened.bind(@))
 
  
 
  onGraph: ->
 
    @graph.runHandler(@gatherNotes.bind(@), 'zoom notes')
 
    # not working- worked around in zoomOrLayoutChanged
 
    #ko.computed(@gatherNotes.bind(@))
 
    
 
  gatherNotes: ->
 
    U = (x) => @graph.Uri(x)
 

	
 
    log('assign rows',@song, 'graph has', @graph.quads().length)
 
    graphics = new PIXI.Graphics({nativeLines: true})
 
@@ -348,12 +345,13 @@ coffeeElementSetup(class TimeZoomed exte
 
        if @graph.uriValue(curve, U(':attr')).equals(U(':strength'))
 

	
 
          [@pointUris, @worldPts] = @project.getCurvePoints(curve, originTime)
 
          curveWidthCalc = () => @_curveWidth(@worldPts)
 

	
 
          h = 150 #@offsetHeight
 
          dependOn = [@viewState.zoomSpec.t1(), @viewState.zoomSpec.t2(), @viewState.width()]
 
          screenPts = ($V([@viewState.zoomInX(pt.e(1)), @offsetTop + (1 - pt.e(2)) * h]) for pt in @worldPts)
 
          graphics.beginFill(0xFF3300);
 
          graphics.lineStyle(4, 0xffd900, 1)
 

	
 
          graphics.moveTo(screenPts[0].e(1), screenPts[0].e(2))
 
          for p in screenPts.slice(1)
0 comments (0 inline, 0 general)