# HG changeset patch # User cavaliet # Date 1414492365 -3600 # Node ID bdcc964b3c01a5e2e9cded5e418a86fa103a8483 # Parent 99658249716cea03078b804f14cb7b7772b68e12 good optimisation for piano roll diff -r 99658249716c -r bdcc964b3c01 annot-server/static/js/pianoroll.js --- a/annot-server/static/js/pianoroll.js Mon Oct 27 17:22:48 2014 +0100 +++ b/annot-server/static/js/pianoroll.js Tue Oct 28 11:32:45 2014 +0100 @@ -40,8 +40,8 @@ stage.addChild(uberContainer); -function PianoRoll(parentContainer, xInit, yInit, height, linesDown, pixelsPerSecond){ - +function PianoRoll(parentContainer, xInit, yInit, height, linesDown, pixelsPerSecond, width){ + var _this = this; this.container = new PIXI.DisplayObjectContainer(); this.container.position.x = xInit; this.container.position.y = yInit; @@ -50,6 +50,7 @@ this.linesDown = linesDown; this.height = height; this.pixelsPerSecond = pixelsPerSecond; + this.width = width; this.addNote = function(note, startTime, duration, velocity, canal){ //console.log("coucou 1", note, timeFromZero, ts, velocity, pixelsPerSecond, container, prHeight); @@ -60,8 +61,9 @@ //console.log("beginX = ", beginX, "canal = ", canal, "color = ", noteColor[canal], "width = ", width, "note = ", note, "velocity = ", velocity); graphics.beginFill(noteColor[canal], (velocity / 128)); var y = (128-note) * this.height / 128; // (128-note) because y = 0 is for note = 128 and y = 128 for note = 0 - graphics.drawRect(beginX, Math.floor(y - (noteHeight/2) + ((this.height / 128)/2)), width, noteHeight); + graphics.drawRect(0, Math.floor(y - (noteHeight/2) + ((this.height / 128)/2)), width, noteHeight); graphics.endFill(); + graphics.x = beginX; this.container.addChild(graphics); }; @@ -86,17 +88,35 @@ t.x = x + 2; t.y = this.linesDown ? this.height - 15 : 2; this.container.addChild(t); - } + }; this.moveTo = function(diffTime){ this.container.x = Math.floor(diffTime*this.pixelsPerSecond); }; + this.removePassedObjets = function(){ + var nbChilds = _this.container.children.length; + var i = 0, childIsNowDisplayed = false; + while(i