Changeset - 9f7e31bf3f0c
[Not reviewed]
default
0 3 0
Drew Perttula - 8 years ago 2017-06-10 08:38:39
drewp@bigasterisk.com
new fade adjusters
Ignore-this: aa37b28e07ac053ae58f083e160b009c
3 files changed with 62 insertions and 3 deletions:
0 comments (0 inline, 0 general)
light9/web/edit-choice.html
Show inline comments
 
@@ -9,15 +9,16 @@
 
         background: #141448;
 
     }
 
     #box.dragging {
 
         background: rgba(126, 52, 245, 0.0784313725490196);
 
     }
 
     a {
 
         color: #5555e0;
 
         color: #8e8eff;
 
         padding: 3px;
 
         display: inline-block;
 
         font-size: 145%;
 
     }
 
    
 
     
 
    </style>
 
    <div id="box">
 
      <!-- maybe use resource-display for this part -->
light9/web/timeline/adjustable.coffee
Show inline comments
 
@@ -120,15 +120,61 @@ class window.AdjustableFloatObject exten
 
    
 
  subscribe: (onChange) ->
 
    # only works on one subscription at a time
 
    throw new Error('multi subscribe not implemented') if @_onChange
 
    @_onChange = onChange
 

	
 
    
 
  continueDrag: (pos) ->
 
    # pos is vec2 of pixels relative to the drag start
 
    super(pos)
 
    newValue = @config.getValueForPos(@_editorCoordinates())
 
    
 
    @config.graph.patchObject(@config.subj, @config.pred,
 
                              @config.graph.LiteralRoundedFloat(newValue),
 
                              @config.ctx)
 
                              
 
class window.AdjustableFade extends Adjustable
 
  constructor: (@yForV, @i0, @i1, @note, offset) ->
 
    @config = {
 
      getSuggestedTargetOffset: -> offset
 
      getTarget: @getTarget.bind(@)
 
    }
 
    super(@config)
 

	
 
  getTarget: ->
 
    mid = @note.worldPts[@i0].x(.5).add(@note.worldPts[@i1].x(.5))
 
    $V([@note.zoomInX(mid.e(1)), @yForV(mid.e(2))])
 

	
 
  _getValue: ->
 
    mid = @note.worldPts[@i0].x(.5).add(@note.worldPts[@i1].x(.5))
 
    mid.e(1)
 

	
 
   continueDrag: (pos) ->
 
    # pos is vec2 of pixels relative to the drag start
 
    super(pos)
 
    graph = @note.graph
 
    U = (x) => graph.Uri(x)
 

	
 
    goalCenterSec = @note.zoomInX.invert(@initialTarget.e(1) + pos.e(1))
 

	
 
    diamSec = @note.worldPts[@i1].e(1) - @note.worldPts[@i0].e(1)
 
    newSec0 = goalCenterSec - diamSec / 2
 
    newSec1 = goalCenterSec + diamSec / 2
 

	
 
    originSec = graph.floatValue(@note.uri, U(':originTime'))
 

	
 
    ctx = @note.song
 
    p0 = @_makePatch(graph, @i0, newSec0, originSec, ctx)
 
    p1 = @_makePatch(graph, @i1, newSec1, originSec, ctx)
 

	
 
    graph.applyAndSendPatch(@_addPatches(p0, p1))
 

	
 
  _makePatch: (graph, idx, newSec, originSec, ctx) ->
 
    graph.getObjectPatch(@note.worldPts[idx].uri,
 
                         graph.Uri(':time'),
 
                         graph.LiteralRoundedFloat(newSec - originSec), ctx)
 

	
 
  _addPatches: (p0, p1) ->
 
    {
 
      addQuads: p0.addQuads.concat(p1.addQuads),
 
      delQuads: p0.delQuads.concat(p1.delQuads)
 
    }
 
\ No newline at end of file
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -272,12 +272,15 @@ Polymer
 
      getTarget: () => $V([@fullZoomX(panObs()), yMid()])
 
      getSuggestedTargetOffset: () => $V([0, 0])
 
      getValueForPos: valForPos
 
      }))
 
      
 

	
 
# plan: in here, turn all the notes into simple js objects with all
 
# their timing data and whatever's needed for adjusters. From that, do
 
# the brick layout. update only changing adjusters.
 
Polymer
 
  is: 'light9-timeline-time-zoomed'
 
  behaviors: [ Polymer.IronResizableBehavior ]
 
  properties:
 
    graph: { type: Object, notify: true }
 
    selection: { type: Object, notify: true }
 
@@ -508,12 +511,13 @@ Polymer
 
  _updateAdjusters: (screenPts, curveWidthCalc, yForV) ->   
 
    if screenPts[screenPts.length - 1].e(1) - screenPts[0].e(1) < 100
 
      @clearAdjusters()
 
    else
 
      @_makeOffsetAdjuster(yForV, curveWidthCalc)
 
      @_makeCurvePointAdjusters(yForV, @worldPts)
 
      @_makeFadeAdjusters(yForV)
 

	
 
  _updateInlineAttrs: (screenPts) ->
 
    leftX = Math.max(2, screenPts[Math.min(1, screenPts.length - 1)].e(1) + 5)
 
    rightX = screenPts[Math.min(2, screenPts.length - 1)].e(1) - 5
 
    if screenPts.length < 3
 
      rightX = leftX + 120
 
@@ -594,12 +598,21 @@ Polymer
 
        getValueForPos: (pos) =>
 
          @zoomInX.invert(pos.e(1)) - curveWidthCalc() / 2
 
        getSuggestedTargetOffset: () => $V([-10, 0])
 
      })
 
      adj
 
    
 
  _makeFadeAdjusters: (yForV) ->
 
    @_makeFadeAdjuster(yForV, @uri + '/fadeIn', 0, 1, $V([-50, -10]))
 
    n = @worldPts.length
 
    @_makeFadeAdjuster(yForV, @uri + '/fadeOut', n - 2, n - 1, $V([50, -10]))
 

	
 
  _makeFadeAdjuster: (yForV, adjId, i0, i1, offset) ->
 
    @adjusterIds[adjId] = true
 
    @setAdjuster adjId, => new AdjustableFade(yForV, i0, i1, @, offset)
 
    
 
  _suggestedOffset: (pt) ->
 
    if pt.e(2) > .5
 
      $V([0, 30])
 
    else
 
      $V([0, -30])
 
    
 
@@ -966,13 +979,12 @@ Polymer
 
    elem = @getOrCreateElem areaId, 'notes', 'path', attrs, (elem) =>
 
      @_addNoteListeners(elem, uri)
 
    elem.setAttribute('d', Drawing.svgPathFromPoints(curvePts))
 
    @_updateNotePathClasses(uri, elem)
 

	
 
  _addNoteListeners: (elem, uri) ->
 
    log("new note listeneers", uri)
 
    elem.addEventListener 'mouseenter', =>
 
      @selection.hover(uri)
 
    elem.addEventListener 'mousedown', (ev) =>
 
      sel = @selection.selected()
 
      if ev.getModifierState('Control')
 
        if uri in sel
0 comments (0 inline, 0 general)