diff -r ae37d35a419c -r 9be99c2fb279 annot-server/static/js/pianoroll.js --- a/annot-server/static/js/pianoroll.js Mon Jan 12 14:08:09 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,269 +0,0 @@ -// Config vars -var logger = false; -var sceneWidth = 1920; -var prHeight1 = 435; -var prHeight2 = 645; -var sceneHeight = prHeight1 + prHeight2; -var sceneBgColor = 0xFFFFFF; -var lineColor = 0x444444; -var pixelsPerSecond1 = Math.floor(sceneWidth / 10); // nb of pixels per second -var manualFramerate = pixelsPerSecond1 / 4; -var pixelsPerSecond2 = Math.floor(sceneWidth / 60); // nb of pixels per second -var lineInterval = 5000; // means line every 5 seconds -var nbLines = -1; -var noteHeight = 110; -var noteColors = [0xB90000, 0x4BDD71, 0xAF931E, 0x1C28BA, 0x536991]; -var colorsReg = {} -// Vars -var noteDict = []; -// Timecode method -var timePageLoaded = Date.now(); -var offsetMusic = false; - - -//create an new instance of a pixi stage -var stage = new PIXI.Stage(sceneBgColor); - -//create a renderer instance. -var renderer = PIXI.autoDetectRenderer(sceneWidth, sceneHeight); - -//add the renderer view element to the DOM -document.getElementById("canvasContainer").appendChild(renderer.view); - -var uberContainer = new PIXI.DisplayObjectContainer(); -uberContainer.position.x = Math.floor(sceneWidth*9/10); -uberContainer.position.y = 0; -stage.addChild(uberContainer); - - -function PianoRoll(parentContainer, xInit, yInit, height, linesDown, pixelsPerSecond, width, noteColors, colorsReg){ - var _this = this; - this.container = new PIXI.DisplayObjectContainer(); - this.container.position.x = xInit; - this.container.position.y = yInit; - parentContainer.addChild(this.container); - - this.linesDown = linesDown; - this.height = height; - this.pixelsPerSecond = pixelsPerSecond; - this.width = width; - this.noteColors = noteColors; - this.colorsReg = colorsReg || {} - - this.addNote = function(note, startTime, duration, velocity, canal){ - //console.log("coucou 1", note, timeFromZero, ts, velocity, pixelsPerSecond, container, prHeight); - var beginX = (offsetMusic + startTime) * this.pixelsPerSecond / 1000; - var width = duration * this.pixelsPerSecond / 1000; - // We draw the rectangle - var graphics = new PIXI.Graphics(); - //console.log("beginX = ", beginX, "canal = ", canal, "color = ", noteColor[canal], "width = ", width, "note = ", note, "velocity = ", velocity); - var color = this.colorsReg[canal]; - if(typeof(color) === 'undefined') { - var colorsRegSize = Object.keys(this.colorsReg).length - if(colorsRegSize < this.noteColors.length) { - color = this.colorsReg[canal] = this.noteColors[colorsRegSize]; - } - else { - color = this.colorsReg[canal] = parseInt(randomColor({ luminosity: 'light', hue: 'random', format:'hex'}).replace(/^#/, ''), 16); - } - } - graphics.beginFill(color, (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(0, Math.floor(y - (noteHeight/2) + ((this.height / 128)/2)), width, noteHeight); - graphics.endFill(); - graphics.x = beginX; - this.container.addChild(graphics); - }; - - this.addLine = function(lineNb){ - var graphics = new PIXI.Graphics(); - var x = -this.container.x; - graphics.beginFill(0xFFFF00); - graphics.lineStyle(1, lineColor); - var y = this.linesDown ? this.height - 20 : 0; - graphics.moveTo(x, y); - graphics.lineTo(x, y + 20); - graphics.endFill(); - this.container.addChild(graphics); - // Add text - var totalSec = lineNb * lineInterval / 1000; - var hours = parseInt( totalSec / 3600 ) % 24; - var minutes = parseInt( totalSec / 60 ) % 60; - var seconds = totalSec % 60; - var timeStr = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds); - var fontObj = { font: "10pt Arial", fill: "#444444" }; - var t = new PIXI.Text(timeStr, fontObj); - 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