client/annotviz/app/js/doubleroll.js
author rougeronj
Mon, 13 Apr 2015 17:11:47 +0200
changeset 146 192d7d7f7bb4
parent 145 a8052f8ab19c
child 147 4902992b2783
permissions -rw-r--r--
Add dynamicRange option. Adapt rescaleScene to be able to increase the scale (new note is added) or decrease the scale (a note is deleted).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
/**
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
* scripts/doubleroll.js
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
*
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
* This is the starting point for your application.
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
* Take a look at http://browserify.org/ for more info
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
*/
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
'use strict';
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
var PIXI = require('pixi');
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
var _ = require('lodash');
131
0bb70072a56f some quick cleaning
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    13
var PianoRoll = require('./pianoroll');
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
var defaultConfig = {
95
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
    16
    orientation: 'horizontal',
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
    17
    logger: undefined,
104
685c5ebc59d0 update resolution screen
rougeronj
parents: 100
diff changeset
    18
    sceneWidth: 1024,
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    pianorolls : [
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
      {
145
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    21
        height: 384,
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
        timeWidth: 10,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
        lineInterval: 5000,
145
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    24
        noteHeight: undefined,
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    25
        range: {
146
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
    26
    		bottom: 50,
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
    27
    		top: 90,
145
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    28
        },
146
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
    29
        dynamicRange: true,
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
      },
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
      {
145
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    32
        height: 384,
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        timeWidth: 60,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
        lineInterval: 5000,
145
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    35
        noteHeight: undefined,
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    36
        range:{
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    37
    		bottom: 0,
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    38
    		top: 128,
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
    39
        },
146
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
    40
        dynamicRange: false,
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
      },
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    ],
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    framerate: 25,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    offsetMusic: false,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    sceneBgColor: 0xFFFFFF,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    lineColor: 0x444444,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    lineFillColor: 0xFFFF00,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    noteColors: [0xB90000, 0x4BDD71, 0xAF931E, 0x1C28BA, 0x536991],
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    noteHeight: undefined,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    zeroShift: 0.9,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    timeWidth: 60,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    lineInterval: 5000,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
//    wsUri: undefined,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
//    eventCode: undefined
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
};
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
function DoubleRoll(options) {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    var _this = this;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    var opts = _(options).defaults(defaultConfig).value();
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
95
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
    63
    var orientation = opts.orientation;
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
    64
    var isHorizontal = (orientation !== 'vertical');
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
    65
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
    this.logger = opts.logger;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
    this.lineColor = opts.lineColor;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
    this.lineFillColor = opts.lineFillColor;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
    this.framerate = opts.framerate;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
    this.offsetMusic = opts.offsetMusic;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    this.noteColors = opts.noteColors;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    var noteHeight = opts.noteHeight;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    var sceneHeight = opts.sceneHeight || _(opts.pianorolls).reduce(function(s,p) { return s + p.height; }, 0);
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    var timeWidth = opts.timeWidth;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    var lineInterval = opts.lineInterval;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    var offsetMusic = opts.offsetMusic;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
    var sceneWidth = opts.sceneWidth;
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
    80
    var stageView = opts.stageView;
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
    var zeroShift = opts.zeroShift;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
    84
    var ws = opts.ws;
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
    var colorsReg = {};
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
    88
    this.container = new PIXI.DisplayObjectContainer();
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
    89
    this.container.x = Math.floor(sceneWidth*zeroShift);
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
    90
    this.container.y = 0;
131
0bb70072a56f some quick cleaning
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    91
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
    92
    stageView.registerComponent(this);
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
    var pianorollList = [];
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
    var pianorollOptions = {
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
    97
        parentContainer: this.container,
95
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
    98
        orientation: orientation,
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
        xInit: 0,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        width: sceneWidth,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
        noteColors: this.noteColors,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
        colorsReg: colorsReg,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
        lineColor: this.lineColor,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
        lineInterval: lineInterval,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        offsetMusic: offsetMusic,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
    };
146
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   107
    
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   108
    var lineGraphics = new PIXI.Graphics()
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   109
	    .beginFill(this.lineFillColor)
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   110
	    .lineStyle(1, this.lineColor)
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   111
	    .moveTo(Math.floor(sceneWidth*zeroShift), 0)
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   112
	    .lineTo(-sceneWidth - Math.floor(sceneWidth*zeroShift), 0)
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   113
	    .endFill();
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   114
	this.container.addChild(lineGraphics);
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 104
diff changeset
   116
    var yInit = opts.yInit || 0;
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
    var linesDown = true;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
    _(opts.pianorolls).forEach(function(prDef, i) {
146
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   119
        var prNoteHeight = noteHeight || prDef.noteHeight || prDef.height / (prDef.range.top - prDef.range.bottom + 1);
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
        var prTimeWidth = prDef.timeWidth || timeWidth;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
        pianorollList.push(new PianoRoll(_({
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
            yInit: yInit,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
            height: prDef.height,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
            linesDown: linesDown,
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
            pixelsPerSecond: Math.floor(sceneWidth / prTimeWidth),
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
            noteHeight: prNoteHeight,
145
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
   127
            lineInterval: prDef.lineInterval,
a8052f8ab19c add range options to scale the scene depending on this range. Add rescale function to rescale the scene when a note is out of this range
rougeronj
parents: 131
diff changeset
   128
            range: prDef.range,
146
192d7d7f7bb4 Add dynamicRange option.
rougeronj
parents: 145
diff changeset
   129
            dynamicRange: prDef.dynamicRange,
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
        }).defaults(pianorollOptions).value()));
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
        yInit += prDef.height;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
        linesDown = !linesDown;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
        if(i<(opts.pianorolls.length-1)) {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
            var lineGraphics = new PIXI.Graphics()
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
                .beginFill(_this.lineFillColor)
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
                .lineStyle(1, _this.lineColor)
95
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
   138
                .moveTo(Math.floor(sceneWidth*zeroShift), yInit)
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
   139
                .lineTo(-sceneWidth - Math.floor(sceneWidth*zeroShift), yInit)
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
                .endFill();
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
   141
            _this.container.addChild(lineGraphics);
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
        }
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
    });
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
95
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
   145
    if(!isHorizontal) {
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
   146
        this.container.rotation = Math.PI/2;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
   147
        this.container.y = sceneHeight;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
   148
        this.container.x = sceneWidth;
95
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
   149
    }
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
   150
806739a26858 add vertical version for pianoroll
ymh <ymh.work@gmail.com>
parents: 94
diff changeset
   151
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
    this.init = function() {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
   154
    	ws.message(function(data) {
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
   155
            _this.addNotes(data);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
   156
        });
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
    };
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
    this.addNotes = function(data) {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
        pianorollList.forEach(function(c) {
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
   164
            c.addNoteRaw(data);
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
        });
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
    };
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 98
diff changeset
   168
    this.refresh = function() {
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
        pianorollList.forEach(function(c) {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
            c.move();
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
        });
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
    };
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
    // Init page and intervals
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
    var startTs;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
    this.start = function() {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
        startTs = Date.now();
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
        pianorollList.forEach(function(c) {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
            c.start();
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
        });
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
    };
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
    this.stop = function() {
131
0bb70072a56f some quick cleaning
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   186
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
        pianorollList.forEach(function(c) {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
            c.stop();
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
        });
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
    };
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
    this.log = function(m) {
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
   194
        if(this.logger) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
   195
            this.logger.log(m);
94
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
        }
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
    };
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
    return this;
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
}
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
module.exports = {
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
    DoubleRoll: DoubleRoll
e0e514c5470f create doubleroll component and modularize app
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
};