-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathobjects.js
69 lines (61 loc) · 1.99 KB
/
objects.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
// Public: A module that exposes {BMSObjects}.
/* module */
module.exports = BMSObjects
// Public: A BMSObjects holds a collection of objects inside a BMS notechart.
/* class BMSObjects */
// Public: Constructs an empty BMSObjects.
function BMSObjects () {
this._objects = []
}
// Public: Adds a new object to this collection.
//
// If an object already exists on the same channel and position,
// the object is replaced (except for autokeysound tracks).
//
// * `object` {BMSObject} to add
//
BMSObjects.prototype.add = function (object) {
if (object.channel !== '01') {
for (var i = 0; i < this._objects.length; i++) {
var test = this._objects[i]
if (test.channel === object.channel &&
test.measure === object.measure &&
test.fraction === object.fraction) {
this._objects[i] = object
return
}
}
}
this._objects.push(object)
}
// Public: Returns an array of all objects.
//
// Returns an {Array} of {BMSObject} objects
//
BMSObjects.prototype.all = function () {
return this._objects.slice()
}
// Public: Returns a sorted array of all objects.
//
// Returns an {Array} of {BMSObject} objects
//
BMSObjects.prototype.allSorted = function () {
var list = this.all()
list.sort(function (a, b) {
return (a.measure + a.fraction) - (b.measure + b.fraction)
})
return list
}
// Public: A BMSObject data structure represents an object inside a {BMSChart}.
//
// It is a plain object with the following fields:
//
// * `channel` A {String} representing the raw two-character BMS channel of this object
// * `measure` A {Number} representing the measure number, starting at 0 (corresponds to `#000`)
// * `fraction` A {Number} representing the fractional position inside the measure,
// ranging from 0 (inclusive) to 1 (exclusive).
// 0 means that the object is at the start of the measure,
// whereas 1 means that the object is at the end of the measure.
// * `value` A {String} representing the raw value of the BMS object.
//
/* data BMSObject */