client/annotviz/app/js/pianoroll.js
changeset 98 72d767c5142d
parent 96 f58715468f1e
child 103 123a611c7903
--- a/client/annotviz/app/js/pianoroll.js	Mon Jan 19 16:44:59 2015 +0100
+++ b/client/annotviz/app/js/pianoroll.js	Tue Jan 20 11:57:44 2015 +0100
@@ -5,7 +5,6 @@
 *
 */
 
-/* global window: false */
 'use strict';
 
 
@@ -13,6 +12,7 @@
 var randomColor = require('randomColor');
 var _ = require('lodash');
 
+var NTP_EPOCH_DELTA = 2208988800; //c.f. RFC 868
 
 function PianoRoll(options) {
     var _this = this;
@@ -72,6 +72,16 @@
         return graphics;
     };
 
+    this.addNoteRaw = function(data) {
+        var note = data.content[3];
+        var velocity = data.content[4];
+        var ts = (data.content[0] - NTP_EPOCH_DELTA)*1000;
+        var channel = data.content[2];
+        var sessionTs = data.content[1];
+
+        this.addNote(note, ts, sessionTs, velocity, channel, 0);
+    };
+
     this.addNote = function(note, startTime, sessionTs, velocity, channel, duration) {
 
         var ts = startTime;
@@ -186,11 +196,10 @@
     };
 
     this.removePassedObjets = function(){
-        var nbChilds = _this.container.children.length;
         var childrenToRemove = [];
         _(_this.container.children).forEach(function(child) {
-            return typeof(child) === 'undefined'
-                || (isHidden(child) && childrenToRemove.push(child));
+            return typeof(child) === 'undefined' ||
+                (isHidden(child) && childrenToRemove.push(child));
         });
         childrenToRemove.forEach(function(child) {
             _this.container.removeChild(child);
@@ -201,16 +210,16 @@
         if(!started) {
             this.startTs = Date.now();
             this.addLine();
+            started = true;
         }
-        var _this = this;
-        this.verticalLinesInterval = window.setInterval(function() { _this.addLine(); }, this.lineInterval);
-        this.cleanInterval = window.setInterval(function () { _this.removePassedObjets(); }, 1000 * this.width / this.pixelsPerSecond );
+        this.verticalLinesInterval = setInterval(function() { _this.addLine(); }, this.lineInterval);
+        this.cleanInterval = setInterval(function () { _this.removePassedObjets(); }, 1000 * this.width / this.pixelsPerSecond );
     };
 
     this.stop = function() {
         //window.clearInterval(this.moveInterval);
-        window.clearInterval(this.verticalLinesInterval);
-        window.clearInterval(this.cleanInterval);
+        clearInterval(this.verticalLinesInterval);
+        clearInterval(this.cleanInterval);
     };