changeset 1365:a6ca5e87ab3e

a bit more usage of runHandler in timeline element Ignore-this: 7f8b7ddd8c7501b8231755c4a172ad2c
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 06 Jun 2016 07:07:19 +0000
parents b7023c28dd4f
children 106226e1eafc
files light9/web/light9-timeline-audio.html light9/web/timeline-elements.html light9/web/timeline.coffee
diffstat 3 files changed, 41 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/light9-timeline-audio.html	Mon Jun 06 06:45:01 2016 +0000
+++ b/light9/web/light9-timeline-audio.html	Mon Jun 06 07:07:19 2016 +0000
@@ -30,37 +30,39 @@
    Polymer({
        is: "light9-timeline-audio",
        properties: {
-           graph: {type: Object, notify: true, observer: '_imgSrc'},
-           show: {type: String, notify: true, observer: '_imgSrc'},
-           song: {type: String, notify: true, observer: '_imgSrc'}, // song
+           graph: {type: Object, notify: true},
+           show: {type: String, notify: true},
+           song: {type: String, notify: true},
            zoom: {type: Object, notify: true},
            imgSrc: { type: String, notify: true},
            imgWidth: { computed: '_imgWidth(zoom)' },
            imgLeft: { computed: '_imgLeft(zoom)' },
        },
+       observers: [
+           'setImgSrc(graph, show, song)'
+       ],
        ready: function() {
            this.zoom = {duration: 0};
-       },
-       
-       _imgSrc: function() {
-           try {
-               // Should be subscriptions to root and filename
-               // that get replaced when the song changes.
-               if (this.graph && this.show && !this.subscribed) {
-                   this.subscribed = true;
-                   this.graph.subscribe(this.graph.Uri(this.show), null, null,
-                                        this._imgSrc.bind(this));
+       },       
+       setImgSrc: function() {
+           graph.runHandler(function() {
+               try {
+                   var root = this.graph.stringValue(
+                       this.graph.Uri(this.show),
+                       this.graph.Uri(':spectrogramUrlRoot'));
+               } catch(e) {
+                   return;
                }
                
-               var root = this.graph.stringValue(
-                   this.graph.Uri(this.show),
-                   this.graph.Uri(':spectrogramUrlRoot'));
-               var filename = this.graph.stringValue(
-                   this.song, this.graph.Uri(':songFilename'));
+               try {
+                   var filename = this.graph.stringValue(
+                       this.song, this.graph.Uri(':songFilename'));
+               } catch(e) {
+                   return;
+               }
+               
                this.imgSrc = root + '/' + filename.replace('.wav', '.png');
-           } catch(e) {
-               log(e)
-           }
+           }.bind(this));
        },
        _imgWidth: function(zoom) {
            if (!zoom.duration) {
--- a/light9/web/timeline-elements.html	Mon Jun 06 06:45:01 2016 +0000
+++ b/light9/web/timeline-elements.html	Mon Jun 06 07:07:19 2016 +0000
@@ -96,7 +96,9 @@
       </light9-timeline-audio>
       <template is="dom-repeat" items="{{rows}}">
         <light9-timeline-graph-row graph="{{graph}}"
-                                   zoom-in-x="{{zoomInX}}">
+                                   zoom-in-x="{{zoomInX}}"
+                                   row-index="{{item}}"
+        >
         </light9-timeline-graph-row>
       </template>
     </div>
--- a/light9/web/timeline.coffee	Mon Jun 06 06:45:01 2016 +0000
+++ b/light9/web/timeline.coffee	Mon Jun 06 07:07:19 2016 +0000
@@ -187,9 +187,18 @@
     graph: { type: Object, notify: true }
     zoomInX: { type: Object, notify: true }
     noteUris: { type: Array, notify: true }
-  ready: ->
+    rowIndex: { type: Object, notify: true }
+  observers: [
+    'onGraph(graph, zoomInX)'
+    ]
+  onGraph: ->
+    @graph.runHandler(@update.bind(@))
+  update: ->
+    U = (x) -> @graph.Uri(x)
+
     @noteUris = []
-    @push('noteUris', 'http://light9.bigasterisk.com/show/dance2016/song1/n1')
+    for note in @graph.objects(@song, U(':note'))
+      @push('noteUris', note)
   
 
 Polymer
@@ -199,9 +208,10 @@
   properties:
     graph: { type: Object, notify: true }
     uri: { type: String, notify: true }
-    zoomInX: { type: Object, notify: true, observer: 'update' }
+    zoomInX: { type: Object, notify: true }
   observers: [
     'onUri(graph, uri)'
+    'update(graph, uri, zoomInX)'
     ]
   ready: ->
 
@@ -232,7 +242,7 @@
       setNote(@uri, (screenPos(pt) for pt in worldPts))
 
     catch e
-      log('during resize, ', e)
+      log("during resize of #{@uri}: #{@e}")
 
 Polymer
   is: "light9-timeline-adjusters"
@@ -251,7 +261,7 @@
     graph.runHandler(@update.bind(@))
   update: (parentAdjs, graph, song, dia) ->
     U = (x) -> @graph.Uri(x)
-    @adjs = @parentAdjs.slice()
+    @adjs = (@parentAdjs || []).slice()
     for note in @graph.objects(@song, U(':note'))
       @push('adjs', new AdjustableFloatObject({
         graph: @graph