annot-server/static/js/pianoroll.js
changeset 54 31cea001a298
parent 50 5ff6273e3626
child 58 726ee64f18a9
equal deleted inserted replaced
53:7e3156578f28 54:31cea001a298
    12 var manualFramerate = pixelsPerSecond1 / 4;
    12 var manualFramerate = pixelsPerSecond1 / 4;
    13 var pixelsPerSecond2 = Math.floor(sceneWidth / 60); // nb of pixels per second
    13 var pixelsPerSecond2 = Math.floor(sceneWidth / 60); // nb of pixels per second
    14 var lineInterval = 5000; // means line every 5 seconds
    14 var lineInterval = 5000; // means line every 5 seconds
    15 var nbLines = -1;
    15 var nbLines = -1;
    16 var noteHeight = 110;
    16 var noteHeight = 110;
    17 var noteColor = 0xB74141;
    17 var noteColor = [0x2222FF, 0xB74141, 
       
    18                  0x2222FF, 0xB74141, 
       
    19                  0x2222FF, 0xB74141, 
       
    20                  0x2222FF, 0xB74141, 
       
    21                  0x2222FF, 0xB74141, 
       
    22                  0x2222FF, 0xB74141, 
       
    23                  0x2222FF, 0xB74141, 
       
    24                  0x2222FF, 0xB74141, 
       
    25                  0x2222FF, 0xB74141, 
       
    26                  0x2222FF, 0xB74141, 
       
    27                  0x2222FF, 0xB74141, 
       
    28                  0x2222FF, 0xB74141, 
       
    29                  0x2222FF, 0xB74141, 
       
    30                  0x2222FF, 0xB74141, 
       
    31                  0x2222FF, 0xB74141, 
       
    32                  0x2222FF, 0xB74141, 
       
    33                  0x2222FF, 0xB74141, 
       
    34                  0x2222FF, 0xB74141, 
       
    35                  0x2222FF, 0xB74141, 
       
    36                  0x2222FF, 0xB74141, 
       
    37                  0x2222FF, 0xB74141, 
       
    38                  0x2222FF, 0xB74141];
    18 //var speed = 1; // container -x position at each frame. Speed = 1 ~ 100px for 2 seconds
    39 //var speed = 1; // container -x position at each frame. Speed = 1 ~ 100px for 2 seconds
    19 //var zeroTime = new Date("2014-10-06T12:16:43.000000Z").getTime();
    40 //var zeroTime = new Date("2014-10-06T12:16:43.000000Z").getTime();
    20 var noteDict = {};
    41 var noteDict = [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}];
    21 var pianoNotes = [1,0,1,0,1,1,0,1,0,1,0,1];//Do, Do#, Ré, Ré#, Mi, Fa, Fa#, Sol, Sol#, La, La#, Si
    42 var pianoNotes = [1,0,1,0,1,1,0,1,0,1,0,1];//Do, Do#, Ré, Ré#, Mi, Fa, Fa#, Sol, Sol#, La, La#, Si
    22 // Visual config
    43 // Visual config
    23 var drawPianoNotes = false;
    44 var drawPianoNotes = false;
    24 var drawHorizontalLines = false;
    45 var drawHorizontalLines = false;
    25 var drawVerticalLines = true;
    46 var drawVerticalLines = true;
   119     container1.x += 50*(pixelsPerSecond1/manualFramerate);
   140     container1.x += 50*(pixelsPerSecond1/manualFramerate);
   120     container2.x += 50*(pixelsPerSecond2/manualFramerate);
   141     container2.x += 50*(pixelsPerSecond2/manualFramerate);
   121     renderer.render(stage);
   142     renderer.render(stage);
   122 }
   143 }
   123 
   144 
   124 function addNoteInContainer(note, startTime, duration, velocity, pixelsPerSecond, container, prHeight){
   145 function addNoteInContainer(note, startTime, duration, velocity, pixelsPerSecond, container, prHeight, canal){
   125     //console.log("coucou 1", note, timeFromZero, ts, velocity, pixelsPerSecond, container, prHeight);
   146     //console.log("coucou 1", note, timeFromZero, ts, velocity, pixelsPerSecond, container, prHeight);
   126     var beginX = (offsetMusic + startTime) * pixelsPerSecond / 1000;
   147     var beginX = (offsetMusic + startTime) * pixelsPerSecond / 1000;
   127     var width = duration * pixelsPerSecond / 1000;
   148     var width = duration * pixelsPerSecond / 1000;
   128     // We draw the rectangle
   149     // We draw the rectangle
   129     var graphics = new PIXI.Graphics();
   150     var graphics = new PIXI.Graphics();
   130     graphics.beginFill(noteColor, (velocity / 128));
   151     graphics.beginFill(noteColor[canal], (velocity / 128));
   131     var y = (128-note) * prHeight / 128; // (128-note) because y = 0 is for note = 128 and y = 128 for note = 0
   152     var y = (128-note) * prHeight / 128; // (128-note) because y = 0 is for note = 128 and y = 128 for note = 0
   132     graphics.drawRect(beginX, Math.floor(y - (noteHeight/2) + ((prHeight / 128)/2)), width, noteHeight);
   153     graphics.drawRect(beginX, Math.floor(y - (noteHeight/2) + ((prHeight / 128)/2)), width, noteHeight);
   133     graphics.endFill();
   154     graphics.endFill();
   134     container.addChild(graphics);
   155     container.addChild(graphics);
   135 }
   156 }
   144         //console.log("start: ", timePageLoaded, ", now: ", now, ", timeBetweenNowAndStart = ", timeBetweenNowAndStart, ", offsetMusic = ", offsetMusic);
   165         //console.log("start: ", timePageLoaded, ", now: ", now, ", timeBetweenNowAndStart = ", timeBetweenNowAndStart, ", offsetMusic = ", offsetMusic);
   145     }
   166     }
   146     var note = data.content[3];
   167     var note = data.content[3];
   147     var velocity = data.content[4];
   168     var velocity = data.content[4];
   148     if(velocity===0){
   169     if(velocity===0){
   149         if(note in noteDict){
   170         if(typeof noteDict[data.content[2]][note]!=='undefined'){
   150             // We close the note in container one
   171             // We close the note in container one
   151             //console.log("coucou 2", data);
   172             //console.log("coucou 2", data);
   152             var duration = data.content[1] - noteDict[note].ts;
   173             var duration = data.content[1] - noteDict[data.content[2]][note].ts;
   153             addNoteInContainer(note, noteDict[note].ts, duration, noteDict[note].velocity, pixelsPerSecond1, container1, prHeight1);
   174             addNoteInContainer(note, noteDict[data.content[2]][note].ts, duration, noteDict[data.content[2]][note].velocity, pixelsPerSecond1, container1, prHeight1, data.content[2]);
   154             addNoteInContainer(note, noteDict[note].ts, duration, noteDict[note].velocity, pixelsPerSecond2, container2, prHeight2);
   175             addNoteInContainer(note, noteDict[data.content[2]][note].ts, duration, noteDict[data.content[2]][note].velocity, pixelsPerSecond2, container2, prHeight2, data.content[2]);
   155             // delete entry
   176             // delete entry
   156             delete noteDict[note];
   177             delete noteDict[data.content[2]][note];
   157         }
   178         }
   158     }
   179     }
   159     else{
   180     else{
   160         noteDict[note] = {ts: data.content[1], velocity:velocity};
   181         if(typeof noteDict[data.content[2]]==='undefined'){
       
   182             noteDict[data.content[2]] = {};
       
   183         }
       
   184         noteDict[data.content[2]][note] = {ts: data.content[1], velocity:velocity};
   161     }
   185     }
   162 }
   186 }
   163 
   187 
   164 // Socket management
   188 // Socket management
   165 var sock = null;
   189 var sock = null;