changeset 1770:48e4e25f37a3

starting BrickLayout. WIP Ignore-this: 4c6ff2700352e5f28fab6f9a7a5f5a3e
author drewp@bigasterisk.com
date Sun, 03 Jun 2018 04:51:43 +0000
parents 59be536746eb
children 792bf30de608
files light9/web/timeline/timeline.coffee
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/timeline/timeline.coffee	Sat Jun 02 05:52:33 2018 +0000
+++ b/light9/web/timeline/timeline.coffee	Sun Jun 03 04:51:43 2018 +0000
@@ -276,18 +276,25 @@
     }))
 )
 
-nr=0
+
 class BrickLayout
   constructor: (@viewState, @numRows) ->
     @noteRow = {} # uristr: row, t0, t1
   addNote: (n) ->
-    @noteRow[n.uri.value] = {row: nr%6, t0: 0, t1: 0}
-    nr++
+    @noteRow[n.uri.value] = {row: 0, t0: 0, t1: 0}
+    
   setNoteSpan: (n, t0, t1) ->
     @noteRow[n.uri.value].t0 = t0
     @noteRow[n.uri.value].t1 = t1
+    @_recompute()
   delNote: (n) ->
     delete @noteRow[n.uri.value]
+  _recompute: ->
+    notesByWidth = _.sortBy([{dur: row.t1 - row.t0 + row.t0 * .0001, uri: u} for u, row of @noteRow], 'dur')
+    notesByWidth.reverse()
+    for n in notesByWidth
+      @noteRow[n.uri].row = 0
+    
   rowBottom: (row) -> @viewState.rowsY() + 20 + 150 * row + 140
   yForVFor: (n) ->
     row = @noteRow[n.uri.value].row