Repository navigation
Expand file tree
/
Copy pathmodule.js
More file actions
98 lines (76 loc) · 2.33 KB
/
Copy pathmodule.js
File metadata and controls
98 lines (76 loc) · 2.33 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
export { default as Event } from './modules/event.js';
import Event from './modules/event.js';
import Sequence from './modules/sequence.js';
import parse from './modules/parse/parse-sequence.js';
import { VERSION } from './modules/record/serialise.js';
import { toRecord, toATProtoRecord, fromRecord } from './modules/record.js';
const assign = Object.assign;
// The Sequence() constructor delegates to Sequence.from() to recursively
// instantiate nested sequences, so Sequence.from() must be overridden to
// provide deserialisation of nested records' events.
const fromData = Sequence.from;
Sequence.from = function from(data) {
// events is a Uint8Array
return data.events && data.events instanceof Uint8Array ? fromRecord(data) :
// events is an ATProto bytes object
data.events && typeof data.events.$bytes === 'string' ? fromRecord(data) :
// events is something else
fromData(data) ;
};
assign(Sequence, {
/**
Sequence.version
Version number for the revision of the sequence spec this Sequence object
implements.
**/
version: VERSION,
/**
Sequence.parse(string);
**/
parse,
/**
Sequence.toRecord(sequence);
**/
toRecord,
toATProtoRecord,
/**
Sequence.fromRecord(record);
**/
fromRecord
});
assign(Sequence.prototype, {
/**
.toRecord()
**/
toRecord: function() {
return toRecord(this);
},
/**
.toString()
**/
toString: function() {
// Top-level sequence header (only if named)
let string = this.id || this.name ?
`#${ this.id || '' } ${ this.name || '' }` :
'' ;
// Top-level sequence events
let event, beat, duration;
for (event of this.events) {
if (event[0] >= beat + duration) string += '\n';
while (event[0] >= beat + duration) beat += duration;
if (Event.isMeter(event)) {
beat = event.beat;
duration = event.duration;
}
string += '\n' + event.toString();
}
// Sub-sequences
let sequence;
if (this.sequences) for (sequence of this.sequences) {
string += '\n' + sequence.toString();
}
return string;
},
});
export default Sequence;
export { Sequence };