-
Notifications
You must be signed in to change notification settings - Fork 0
/
mom.js
72 lines (65 loc) · 1.35 KB
/
mom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"use strict";
function Score(){
this.data = [];
}
Score.prototype = {
removeAllNodes: function() {
this.data = [];
},
appendNode: function(mel) {
var i,l, o;
if (mel instanceof Array) {
for(i = 0, l = mel.length; i < l; i++) {
o = mel[i];
o.scoreIndex = this.data.length-1
this.data.push(o);
mel.scoreIndex = this.data.length-1;
}
} else {
this.data.push(mel);
mel.scoreIndex = this.data.length-1;
}
},
getLastElementByType: function(type) {
var i = 0, l = this.data.length;
var mel;
for (i = 0; i < l; i++) {
mel = this.data[l-i];
if (mel && mel.type === type) {
return mel;
}
}
},
getNextElementByType: function(type) {
var i = 0, l = this.data.length;
var mel;
for (i = 0; i < l; i++) {
mel = this.data[i];
if (mel && mel.type === type) {
return mel;
}
}
}
};
var score = new Score();
Score.prototype.find = function(mel) {
var i = -1;
if (mel.scoreIndex) {
i = mel.scoreIndex;
} else {
var j = 0;
var l = this.data.length;
var o;
for (j = 0; j < l; j++) {
if (mel == this.data[j]) {
mel.scoreIndex = j;
i = j;
break;
}
}
}
return i;
};
Score.prototype.get = function(scoreIndex) {
return (this.data[scoreIndex]);
}