notations 0.0.47 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/beats.d.ts +34 -69
- package/lib/cjs/beats.js +178 -439
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/beatutils.d.ts +3 -0
- package/lib/cjs/beatutils.js +64 -0
- package/lib/cjs/beatutils.js.map +1 -0
- package/lib/cjs/beatview.d.ts +18 -0
- package/lib/cjs/beatview.js +62 -0
- package/lib/cjs/beatview.js.map +1 -0
- package/lib/cjs/carnatic/LineView.d.ts +2 -7
- package/lib/cjs/carnatic/LineView.js +13 -31
- package/lib/cjs/carnatic/LineView.js.map +1 -1
- package/lib/cjs/carnatic/NotationView.d.ts +8 -7
- package/lib/cjs/carnatic/NotationView.js +73 -153
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/carnatic/atomviews.js +149 -287
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/beatviews.d.ts +4 -13
- package/lib/cjs/carnatic/beatviews.js +23 -118
- package/lib/cjs/carnatic/beatviews.js.map +1 -1
- package/lib/cjs/carnatic/embelishments.d.ts +1 -1
- package/lib/cjs/carnatic/embelishments.js +189 -283
- package/lib/cjs/carnatic/embelishments.js.map +1 -1
- package/lib/cjs/carnatic/gamakas.js +15 -47
- package/lib/cjs/carnatic/gamakas.js.map +1 -1
- package/lib/cjs/commands.js +111 -271
- package/lib/cjs/commands.js.map +1 -1
- package/lib/cjs/core.d.ts +14 -1
- package/lib/cjs/core.js +291 -477
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/cycle.js +175 -367
- package/lib/cjs/cycle.js.map +1 -1
- package/lib/cjs/entity.js +48 -102
- package/lib/cjs/entity.js.map +1 -1
- package/lib/cjs/grids.d.ts +125 -0
- package/lib/cjs/grids.js +550 -0
- package/lib/cjs/grids.js.map +1 -0
- package/lib/cjs/iterators.js +96 -234
- package/lib/cjs/iterators.js.map +1 -1
- package/lib/cjs/layouts.d.ts +1 -1
- package/lib/cjs/layouts.js +62 -98
- package/lib/cjs/layouts.js.map +1 -1
- package/lib/cjs/loader.d.ts +2 -2
- package/lib/cjs/loader.js +23 -123
- package/lib/cjs/loader.js.map +1 -1
- package/lib/cjs/notation.d.ts +0 -3
- package/lib/cjs/notation.js +139 -241
- package/lib/cjs/notation.js.map +1 -1
- package/lib/cjs/parser.d.ts +2 -0
- package/lib/cjs/parser.js +230 -214
- package/lib/cjs/parser.js.map +1 -1
- package/lib/cjs/shapes.js +149 -283
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/cjs/utils.d.ts +8 -0
- package/lib/cjs/utils.js +60 -55
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/beats.d.ts +34 -69
- package/lib/esm/beats.js +172 -438
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/beatutils.d.ts +3 -0
- package/lib/esm/beatutils.js +37 -0
- package/lib/esm/beatutils.js.map +1 -0
- package/lib/esm/beatview.d.ts +18 -0
- package/lib/esm/beatview.js +35 -0
- package/lib/esm/beatview.js.map +1 -0
- package/lib/esm/carnatic/LineView.d.ts +2 -7
- package/lib/esm/carnatic/LineView.js +12 -31
- package/lib/esm/carnatic/LineView.js.map +1 -1
- package/lib/esm/carnatic/NotationView.d.ts +8 -7
- package/lib/esm/carnatic/NotationView.js +71 -152
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/carnatic/atomviews.js +144 -284
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/beatviews.d.ts +4 -13
- package/lib/esm/carnatic/beatviews.js +21 -94
- package/lib/esm/carnatic/beatviews.js.map +1 -1
- package/lib/esm/carnatic/embelishments.d.ts +1 -1
- package/lib/esm/carnatic/embelishments.js +187 -296
- package/lib/esm/carnatic/embelishments.js.map +1 -1
- package/lib/esm/carnatic/gamakas.js +14 -48
- package/lib/esm/carnatic/gamakas.js.map +1 -1
- package/lib/esm/commands.js +100 -271
- package/lib/esm/commands.js.map +1 -1
- package/lib/esm/core.d.ts +14 -1
- package/lib/esm/core.js +287 -484
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/cycle.js +172 -367
- package/lib/esm/cycle.js.map +1 -1
- package/lib/esm/entity.js +48 -104
- package/lib/esm/entity.js.map +1 -1
- package/lib/esm/grids.d.ts +125 -0
- package/lib/esm/grids.js +517 -0
- package/lib/esm/grids.js.map +1 -0
- package/lib/esm/iterators.js +93 -235
- package/lib/esm/iterators.js.map +1 -1
- package/lib/esm/layouts.d.ts +1 -1
- package/lib/esm/layouts.js +60 -97
- package/lib/esm/layouts.js.map +1 -1
- package/lib/esm/loader.d.ts +2 -2
- package/lib/esm/loader.js +20 -120
- package/lib/esm/loader.js.map +1 -1
- package/lib/esm/notation.d.ts +0 -3
- package/lib/esm/notation.js +135 -242
- package/lib/esm/notation.js.map +1 -1
- package/lib/esm/parser.d.ts +2 -0
- package/lib/esm/parser.js +225 -210
- package/lib/esm/parser.js.map +1 -1
- package/lib/esm/shapes.js +148 -288
- package/lib/esm/shapes.js.map +1 -1
- package/lib/esm/utils.d.ts +8 -0
- package/lib/esm/utils.js +55 -51
- package/lib/esm/utils.js.map +1 -1
- package/package.json +18 -17
package/lib/cjs/iterators.js
CHANGED
|
@@ -1,30 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
3
|
if (k2 === undefined) k2 = k;
|
|
30
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -48,126 +22,59 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
48
22
|
__setModuleDefault(result, mod);
|
|
49
23
|
return result;
|
|
50
24
|
};
|
|
51
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
52
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
53
|
-
if (!m) return o;
|
|
54
|
-
var i = m.call(o), r, ar = [], e;
|
|
55
|
-
try {
|
|
56
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
57
|
-
}
|
|
58
|
-
catch (error) { e = { error: error }; }
|
|
59
|
-
finally {
|
|
60
|
-
try {
|
|
61
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
62
|
-
}
|
|
63
|
-
finally { if (e) throw e.error; }
|
|
64
|
-
}
|
|
65
|
-
return ar;
|
|
66
|
-
};
|
|
67
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
68
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
69
|
-
if (ar || !(i in from)) {
|
|
70
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
71
|
-
ar[i] = from[i];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
75
|
-
};
|
|
76
|
-
var __values = (this && this.__values) || function(o) {
|
|
77
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
78
|
-
if (m) return m.call(o);
|
|
79
|
-
if (o && typeof o.length === "number") return {
|
|
80
|
-
next: function () {
|
|
81
|
-
if (o && i >= o.length) o = void 0;
|
|
82
|
-
return { value: o && o[i++], done: !o };
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
86
|
-
};
|
|
87
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
88
26
|
exports.DurationIterator = exports.WindowIterator = exports.AtomIterator = exports.FlatAtom = void 0;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return
|
|
27
|
+
const TSU = __importStar(require("@panyam/tsutils"));
|
|
28
|
+
const entity_1 = require("./entity");
|
|
29
|
+
const core_1 = require("./core");
|
|
30
|
+
class FlatAtom extends entity_1.TimedEntity {
|
|
31
|
+
constructor(atom, config = null) {
|
|
32
|
+
super((config = config || {}));
|
|
33
|
+
this.atom = atom;
|
|
34
|
+
this.depth = config.depth || 0;
|
|
35
|
+
this.duration = config.duration || atom.duration;
|
|
36
|
+
this.offset = config.offset || TSU.Num.Fraction.ZERO;
|
|
37
|
+
this.isContinuation = "isContinuation" in config ? config.isContinuation : false;
|
|
38
|
+
}
|
|
39
|
+
get type() {
|
|
40
|
+
return "FlatAtom";
|
|
103
41
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
configurable: true
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(FlatAtom.prototype, "endOffset", {
|
|
112
|
-
get: function () {
|
|
113
|
-
return this.offset.plus(this.duration);
|
|
114
|
-
},
|
|
115
|
-
enumerable: false,
|
|
116
|
-
configurable: true
|
|
117
|
-
});
|
|
118
|
-
FlatAtom.prototype.debugValue = function () {
|
|
119
|
-
var out = __assign(__assign({}, _super.prototype.debugValue.call(this)), { atom: this.atom.debugValue(), duration: this.duration.toString(), offset: this.offset.toString(), depth: this.depth });
|
|
42
|
+
get endOffset() {
|
|
43
|
+
return this.offset.plus(this.duration);
|
|
44
|
+
}
|
|
45
|
+
debugValue() {
|
|
46
|
+
const out = Object.assign(Object.assign({}, super.debugValue()), { atom: this.atom.debugValue(), duration: this.duration.toString(), offset: this.offset.toString(), depth: this.depth });
|
|
120
47
|
if (this.isContinuation)
|
|
121
48
|
out.isContinuation = true;
|
|
122
49
|
return out;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}(entity_1.TimedEntity));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
126
52
|
exports.FlatAtom = FlatAtom;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
var atoms = [];
|
|
130
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
131
|
-
atoms[_i] = arguments[_i];
|
|
132
|
-
}
|
|
53
|
+
class AtomIterator {
|
|
54
|
+
constructor(...atoms) {
|
|
133
55
|
this.atomQueue = new TSU.Lists.List();
|
|
134
56
|
this.currOffset = TSU.Num.Fraction.ZERO;
|
|
135
57
|
this.peeked = null;
|
|
136
|
-
this.push
|
|
58
|
+
this.push(...atoms);
|
|
137
59
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
142
|
-
atoms[_i] = arguments[_i];
|
|
143
|
-
}
|
|
144
|
-
try {
|
|
145
|
-
for (var atoms_1 = __values(atoms), atoms_1_1 = atoms_1.next(); !atoms_1_1.done; atoms_1_1 = atoms_1.next()) {
|
|
146
|
-
var atom = atoms_1_1.value;
|
|
147
|
-
this.atomQueue.add([atom, 0, atom.duration]);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
151
|
-
finally {
|
|
152
|
-
try {
|
|
153
|
-
if (atoms_1_1 && !atoms_1_1.done && (_a = atoms_1.return)) _a.call(atoms_1);
|
|
154
|
-
}
|
|
155
|
-
finally { if (e_1) throw e_1.error; }
|
|
60
|
+
push(...atoms) {
|
|
61
|
+
for (const atom of atoms) {
|
|
62
|
+
this.atomQueue.add([atom, 0, atom.duration]);
|
|
156
63
|
}
|
|
157
64
|
return this;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
65
|
+
}
|
|
66
|
+
next() {
|
|
67
|
+
const out = this.peek();
|
|
161
68
|
this.peeked = null;
|
|
162
69
|
if (out != null) {
|
|
163
70
|
this.currOffset = this.currOffset.plus(out.duration).factorized;
|
|
164
71
|
}
|
|
165
72
|
return out;
|
|
166
|
-
}
|
|
167
|
-
|
|
73
|
+
}
|
|
74
|
+
peek() {
|
|
168
75
|
if (this.peeked == null) {
|
|
169
76
|
if (this.hasNext) {
|
|
170
|
-
|
|
77
|
+
const [nextAtom, nextDepth, nextDuration] = this.atomQueue.popFront();
|
|
171
78
|
this.peeked = new FlatAtom(nextAtom, {
|
|
172
79
|
depth: nextDepth,
|
|
173
80
|
offset: this.currOffset,
|
|
@@ -176,47 +83,32 @@ var AtomIterator = (function () {
|
|
|
176
83
|
}
|
|
177
84
|
}
|
|
178
85
|
return this.peeked;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
child,
|
|
196
|
-
nextDepth + 1,
|
|
197
|
-
nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,
|
|
198
|
-
]);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
202
|
-
finally {
|
|
203
|
-
try {
|
|
204
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
205
|
-
}
|
|
206
|
-
finally { if (e_2) throw e_2.error; }
|
|
207
|
-
}
|
|
86
|
+
}
|
|
87
|
+
get hasNext() {
|
|
88
|
+
while (this.atomQueue.first != null) {
|
|
89
|
+
const [nextAtom, nextDepth, nextDuration] = this.atomQueue.first.value;
|
|
90
|
+
if (nextAtom.type != core_1.AtomType.GROUP) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.atomQueue.popFront();
|
|
95
|
+
const group = nextAtom;
|
|
96
|
+
for (const child of group.atoms.reversedValues()) {
|
|
97
|
+
this.atomQueue.pushFront([
|
|
98
|
+
child,
|
|
99
|
+
nextDepth + 1,
|
|
100
|
+
nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,
|
|
101
|
+
]);
|
|
208
102
|
}
|
|
209
103
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
for (var ri = 0; ri < iterators.length; ri++) {
|
|
219
|
-
var flatAtom = iterators[ri].peek();
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
static getMin(iterators) {
|
|
108
|
+
let currRole = -1;
|
|
109
|
+
let currAtom = null;
|
|
110
|
+
for (let ri = 0; ri < iterators.length; ri++) {
|
|
111
|
+
const flatAtom = iterators[ri].peek();
|
|
220
112
|
if (flatAtom != null) {
|
|
221
113
|
if (currAtom == null || flatAtom.offset.cmp(currAtom.offset) < 0) {
|
|
222
114
|
currRole = ri;
|
|
@@ -228,102 +120,73 @@ var AtomIterator = (function () {
|
|
|
228
120
|
iterators[currRole].next();
|
|
229
121
|
}
|
|
230
122
|
return [currRole, currAtom];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
}());
|
|
123
|
+
}
|
|
124
|
+
}
|
|
234
125
|
exports.AtomIterator = AtomIterator;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
var atoms = [];
|
|
238
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
239
|
-
atoms[_i] = arguments[_i];
|
|
240
|
-
}
|
|
126
|
+
class WindowIterator {
|
|
127
|
+
constructor(...atoms) {
|
|
241
128
|
this.atomQueue = new TSU.Lists.List();
|
|
242
129
|
this.currOffset = TSU.Num.Fraction.ZERO;
|
|
243
130
|
this.peeked = null;
|
|
244
|
-
this.push
|
|
131
|
+
this.push(...atoms);
|
|
245
132
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
250
|
-
atoms[_i] = arguments[_i];
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
for (var atoms_2 = __values(atoms), atoms_2_1 = atoms_2.next(); !atoms_2_1.done; atoms_2_1 = atoms_2.next()) {
|
|
254
|
-
var atom = atoms_2_1.value;
|
|
255
|
-
this.atomQueue.add(atom);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
259
|
-
finally {
|
|
260
|
-
try {
|
|
261
|
-
if (atoms_2_1 && !atoms_2_1.done && (_a = atoms_2.return)) _a.call(atoms_2);
|
|
262
|
-
}
|
|
263
|
-
finally { if (e_3) throw e_3.error; }
|
|
133
|
+
push(...atoms) {
|
|
134
|
+
for (const atom of atoms) {
|
|
135
|
+
this.atomQueue.add(atom);
|
|
264
136
|
}
|
|
265
137
|
return this;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
138
|
+
}
|
|
139
|
+
next() {
|
|
140
|
+
const out = this.peek();
|
|
269
141
|
this.peeked = null;
|
|
270
142
|
if (out != null) {
|
|
271
143
|
this.currOffset = this.currOffset.plus(out.duration, true);
|
|
272
144
|
}
|
|
273
145
|
return out;
|
|
274
|
-
}
|
|
275
|
-
|
|
146
|
+
}
|
|
147
|
+
peek() {
|
|
276
148
|
if (this.peeked == null && this.hasMore) {
|
|
277
149
|
this.peeked = this.atomQueue.popFront();
|
|
278
150
|
}
|
|
279
151
|
return this.peeked;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
});
|
|
288
|
-
WindowIterator.prototype.get = function (duration) {
|
|
289
|
-
var out = [];
|
|
290
|
-
var remaining = duration;
|
|
152
|
+
}
|
|
153
|
+
get hasMore() {
|
|
154
|
+
return !this.atomQueue.isEmpty;
|
|
155
|
+
}
|
|
156
|
+
get(duration) {
|
|
157
|
+
const out = [];
|
|
158
|
+
let remaining = duration;
|
|
291
159
|
while (remaining.isGTNum(0) && this.hasMore) {
|
|
292
|
-
|
|
160
|
+
const next = this.next();
|
|
293
161
|
TSU.assert(next != null, "Next cannot be null here");
|
|
294
162
|
out.push(next);
|
|
295
|
-
|
|
163
|
+
const spillOver = next.splitAt(remaining);
|
|
296
164
|
remaining = remaining.minus(next.duration);
|
|
297
165
|
if (spillOver != null) {
|
|
298
166
|
this.atomQueue.pushFront(spillOver);
|
|
299
167
|
}
|
|
300
168
|
}
|
|
301
169
|
return [out, remaining.isZero];
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
}());
|
|
170
|
+
}
|
|
171
|
+
}
|
|
305
172
|
exports.WindowIterator = WindowIterator;
|
|
306
|
-
|
|
307
|
-
|
|
173
|
+
class DurationIterator {
|
|
174
|
+
constructor(atomIterator) {
|
|
308
175
|
this.spillOver = null;
|
|
309
176
|
this.atomIterator = atomIterator;
|
|
310
177
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
DurationIterator.prototype.get = function (duration) {
|
|
322
|
-
var iter = this.atomIterator;
|
|
323
|
-
var out = [];
|
|
324
|
-
var remaining = duration;
|
|
178
|
+
get hasMore() {
|
|
179
|
+
if (this.spillOver != null) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
return this.atomIterator.hasNext;
|
|
183
|
+
}
|
|
184
|
+
get(duration) {
|
|
185
|
+
const iter = this.atomIterator;
|
|
186
|
+
const out = [];
|
|
187
|
+
let remaining = duration;
|
|
325
188
|
while (remaining.isGTNum(0)) {
|
|
326
|
-
|
|
189
|
+
const next = this.spillOver == null ? iter.next() : this.spillOver;
|
|
327
190
|
this.spillOver = null;
|
|
328
191
|
if (next == null) {
|
|
329
192
|
break;
|
|
@@ -341,8 +204,7 @@ var DurationIterator = (function () {
|
|
|
341
204
|
}
|
|
342
205
|
}
|
|
343
206
|
return [out, remaining.isZero];
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
}());
|
|
207
|
+
}
|
|
208
|
+
}
|
|
347
209
|
exports.DurationIterator = DurationIterator;
|
|
348
210
|
//# sourceMappingURL=iterators.js.map
|
package/lib/cjs/iterators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/iterators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,mCAAuC;AACvC,+BAAgE;AAMhE;IAA8B,4BAAW;IAMvC,kBAAmB,IAAc,EAAE,MAAkB;QAAlB,uBAAA,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IACjC,CAAC;IACH,uBAAC;AAAD,CAAC,AA/CD,IA+CC;AA/CY,4CAAgB","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { TimedEntity } from \"./entity\";\nimport { Atom, LeafAtom, Space, Group, AtomType } from \"./core\";\n\ntype Fraction = TSU.Num.Fraction;\n\ntype FlatAtom2 = [atom: Atom, duration: TSU.Num.Fraction, offset: TSU.Num.Fraction];\n\nexport class FlatAtom extends TimedEntity {\n depth: number;\n duration: TSU.Num.Fraction;\n offset: TSU.Num.Fraction;\n private isContinuation: boolean;\n\n constructor(public atom: LeafAtom, config: any = null) {\n super((config = config || {}));\n this.depth = config.depth || 0;\n this.duration = config.duration || atom.duration;\n this.offset = config.offset || TSU.Num.Fraction.ZERO;\n this.isContinuation = \"isContinuation\" in config ? config.isContinuation : false;\n }\n\n /**\n * Returns the type of this Entity.\n */\n get type(): unknown {\n return \"FlatAtom\";\n }\n\n get endOffset(): TSU.Num.Fraction {\n return this.offset.plus(this.duration);\n }\n\n debugValue(): any {\n const out = {\n ...super.debugValue(),\n atom: this.atom.debugValue(),\n duration: this.duration.toString(),\n offset: this.offset.toString(),\n depth: this.depth,\n };\n if (this.isContinuation) out.isContinuation = true;\n return out;\n }\n}\n\n/**\n * A nested atom iterator that returns one atom at a time at the leaf-most level.\n * If we have a Group (or nested Groups) only the leaf atoms are returned as if\n * in an in order traversal thus ensuring time order of atoms.\n */\nexport class AtomIterator {\n private atomQueue = new TSU.Lists.List<[Atom, number, Fraction]>();\n private currOffset = TSU.Num.Fraction.ZERO;\n private peeked: TSU.Nullable<FlatAtom> = null;\n\n constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add([atom, 0, atom.duration]);\n }\n return this;\n }\n\n next(): TSU.Nullable<FlatAtom> {\n const out = this.peek();\n this.peeked = null;\n if (out != null) {\n this.currOffset = this.currOffset.plus(out.duration).factorized;\n }\n return out;\n }\n\n peek(): TSU.Nullable<FlatAtom> {\n if (this.peeked == null) {\n if (this.hasNext) {\n const [nextAtom, nextDepth, nextDuration] = this.atomQueue.popFront();\n this.peeked = new FlatAtom(nextAtom as LeafAtom, {\n depth: nextDepth,\n offset: this.currOffset,\n duration: nextDuration,\n });\n }\n }\n return this.peeked;\n }\n\n get hasNext(): boolean {\n while (this.atomQueue.first != null) {\n // Get from front of queue\n const [nextAtom, nextDepth, nextDuration] = this.atomQueue.first.value;\n if (nextAtom.type != AtomType.GROUP) {\n return true;\n } else {\n this.atomQueue.popFront();\n const group = nextAtom as Group;\n for (const child of group.atoms.reversedValues()) {\n this.atomQueue.pushFront([\n child,\n nextDepth + 1,\n nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,\n ]);\n }\n }\n }\n return false;\n }\n\n static getMin(iterators: AtomIterator[]): [number, FlatAtom] {\n let currRole = -1;\n let currAtom: TSU.Nullable<FlatAtom> = null;\n for (let ri = 0; ri < iterators.length; ri++) {\n const flatAtom = iterators[ri].peek();\n if (flatAtom != null) {\n if (currAtom == null || flatAtom.offset.cmp(currAtom.offset) < 0) {\n currRole = ri;\n currAtom = flatAtom;\n }\n }\n }\n if (currRole >= 0) {\n iterators[currRole].next();\n }\n return [currRole, currAtom!];\n }\n}\n\nexport class WindowIterator {\n private atomQueue = new TSU.Lists.List<Atom>();\n private currOffset = TSU.Num.Fraction.ZERO;\n private peeked: TSU.Nullable<Atom> = null;\n\n constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add(atom);\n }\n return this;\n }\n\n next(): TSU.Nullable<Atom> {\n const out = this.peek();\n this.peeked = null;\n if (out != null) {\n this.currOffset = this.currOffset.plus(out.duration, true);\n }\n return out;\n }\n\n peek(): TSU.Nullable<Atom> {\n if (this.peeked == null && this.hasMore) {\n this.peeked = this.atomQueue.popFront();\n }\n return this.peeked;\n }\n\n get hasMore(): boolean {\n return !this.atomQueue.isEmpty;\n }\n\n /**\n * Gets the atoms to cover the given duration.\n *\n * If the number of atoms left in the iterator is 0 then an empty list\n * is returned. Otherwise the duration of atoms returned will cover\n * the given duration even if padding with Space atoms is necessary.\n */\n get(duration: TSU.Num.Fraction): [Atom[], boolean] {\n const out: Atom[] = [];\n let remaining = duration;\n while (remaining.isGTNum(0) && this.hasMore) {\n const next = this.next();\n TSU.assert(next != null, \"Next cannot be null here\");\n out.push(next);\n const spillOver = next.splitAt(remaining);\n remaining = remaining.minus(next.duration);\n if (spillOver != null) {\n // push the spill over to the front of the queue to be\n // picked up on the next \"get\" call\n this.atomQueue.pushFront(spillOver);\n }\n }\n return [out, remaining.isZero];\n }\n}\n\n/**\n * Duration Iterators take a tree of Atoms and return atoms in given windowed\n * durations. This also ensures that a leaf atom can be further split if it is\n * larger than the required duration.\n */\nexport class DurationIterator {\n private atomIterator: AtomIterator;\n private spillOver: TSU.Nullable<FlatAtom> = null;\n\n constructor(atomIterator: AtomIterator) {\n this.atomIterator = atomIterator;\n }\n\n get hasMore(): boolean {\n if (this.spillOver != null) {\n return true;\n }\n return this.atomIterator.hasNext;\n }\n\n /**\n * Gets the atoms to cover the given duration.\n *\n * If the number of atoms left in the iterator is 0 then an empty list\n * is returned. Otherwise the duration of atoms returned will cover\n * the given duration even if padding with Space atoms is necessary.\n */\n get(duration: TSU.Num.Fraction): [FlatAtom[], boolean] {\n const iter = this.atomIterator;\n const out: FlatAtom[] = [];\n let remaining = duration;\n while (remaining.isGTNum(0)) {\n const next = this.spillOver == null ? iter.next() : this.spillOver;\n this.spillOver = null;\n if (next == null) {\n // stop here\n break;\n } else {\n out.push(next);\n if (next.duration.cmp(remaining) <= 0) {\n remaining = remaining.minus(next.duration);\n } else {\n // Next leaf atm is > duration\n // so split it into two\n this.spillOver = new FlatAtom(new Space(next.duration.minus(remaining)));\n next.duration = remaining;\n remaining = TSU.Num.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AC,CAAC,EAAE;YAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;YACnE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,IAAI,IAAI,IAAI,EAAE;gBAEhB,MAAM;aACP;iBAAM;gBACL,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACf,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;oBACrC,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;iBAC5C;qBAAM;oBAGL,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,IAAI,YAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;oBACzE,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;oBAC1B,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;iBACnC;aACF;SACF;QACD,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACF;AA/CD,4CA+CC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { TimedEntity } from \"./entity\";\nimport { Atom, LeafAtom, Space, Group, AtomType } from \"./core\";\n\ntype Fraction = TSU.Num.Fraction;\n\ntype FlatAtom2 = [atom: Atom, duration: TSU.Num.Fraction, offset: TSU.Num.Fraction];\n\nexport class FlatAtom extends TimedEntity {\n depth: number;\n duration: TSU.Num.Fraction;\n offset: TSU.Num.Fraction;\n private isContinuation: boolean;\n\n constructor(public atom: LeafAtom, config: any = null) {\n super((config = config || {}));\n this.depth = config.depth || 0;\n this.duration = config.duration || atom.duration;\n this.offset = config.offset || TSU.Num.Fraction.ZERO;\n this.isContinuation = \"isContinuation\" in config ? config.isContinuation : false;\n }\n\n /**\n * Returns the type of this Entity.\n */\n get type(): unknown {\n return \"FlatAtom\";\n }\n\n get endOffset(): TSU.Num.Fraction {\n return this.offset.plus(this.duration);\n }\n\n debugValue(): any {\n const out = {\n ...super.debugValue(),\n atom: this.atom.debugValue(),\n duration: this.duration.toString(),\n offset: this.offset.toString(),\n depth: this.depth,\n };\n if (this.isContinuation) out.isContinuation = true;\n return out;\n }\n}\n\n/**\n * A nested atom iterator that returns one atom at a time at the leaf-most level.\n * If we have a Group (or nested Groups) only the leaf atoms are returned as if\n * in an in order traversal thus ensuring time order of atoms.\n */\nexport class AtomIterator {\n private atomQueue = new TSU.Lists.List<[Atom, number, Fraction]>();\n private currOffset = TSU.Num.Fraction.ZERO;\n private peeked: TSU.Nullable<FlatAtom> = null;\n\n constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add([atom, 0, atom.duration]);\n }\n return this;\n }\n\n next(): TSU.Nullable<FlatAtom> {\n const out = this.peek();\n this.peeked = null;\n if (out != null) {\n this.currOffset = this.currOffset.plus(out.duration).factorized;\n }\n return out;\n }\n\n peek(): TSU.Nullable<FlatAtom> {\n if (this.peeked == null) {\n if (this.hasNext) {\n const [nextAtom, nextDepth, nextDuration] = this.atomQueue.popFront();\n this.peeked = new FlatAtom(nextAtom as LeafAtom, {\n depth: nextDepth,\n offset: this.currOffset,\n duration: nextDuration,\n });\n }\n }\n return this.peeked;\n }\n\n get hasNext(): boolean {\n while (this.atomQueue.first != null) {\n // Get from front of queue\n const [nextAtom, nextDepth, nextDuration] = this.atomQueue.first.value;\n if (nextAtom.type != AtomType.GROUP) {\n return true;\n } else {\n this.atomQueue.popFront();\n const group = nextAtom as Group;\n for (const child of group.atoms.reversedValues()) {\n this.atomQueue.pushFront([\n child,\n nextDepth + 1,\n nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,\n ]);\n }\n }\n }\n return false;\n }\n\n static getMin(iterators: AtomIterator[]): [number, FlatAtom] {\n let currRole = -1;\n let currAtom: TSU.Nullable<FlatAtom> = null;\n for (let ri = 0; ri < iterators.length; ri++) {\n const flatAtom = iterators[ri].peek();\n if (flatAtom != null) {\n if (currAtom == null || flatAtom.offset.cmp(currAtom.offset) < 0) {\n currRole = ri;\n currAtom = flatAtom;\n }\n }\n }\n if (currRole >= 0) {\n iterators[currRole].next();\n }\n return [currRole, currAtom!];\n }\n}\n\nexport class WindowIterator {\n private atomQueue = new TSU.Lists.List<Atom>();\n private currOffset = TSU.Num.Fraction.ZERO;\n private peeked: TSU.Nullable<Atom> = null;\n\n constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add(atom);\n }\n return this;\n }\n\n next(): TSU.Nullable<Atom> {\n const out = this.peek();\n this.peeked = null;\n if (out != null) {\n this.currOffset = this.currOffset.plus(out.duration, true);\n }\n return out;\n }\n\n peek(): TSU.Nullable<Atom> {\n if (this.peeked == null && this.hasMore) {\n this.peeked = this.atomQueue.popFront();\n }\n return this.peeked;\n }\n\n get hasMore(): boolean {\n return !this.atomQueue.isEmpty;\n }\n\n /**\n * Gets the atoms to cover the given duration.\n *\n * If the number of atoms left in the iterator is 0 then an empty list\n * is returned. Otherwise the duration of atoms returned will cover\n * the given duration even if padding with Space atoms is necessary.\n */\n get(duration: TSU.Num.Fraction): [Atom[], boolean] {\n const out: Atom[] = [];\n let remaining = duration;\n while (remaining.isGTNum(0) && this.hasMore) {\n const next = this.next();\n TSU.assert(next != null, \"Next cannot be null here\");\n out.push(next);\n const spillOver = next.splitAt(remaining);\n remaining = remaining.minus(next.duration);\n if (spillOver != null) {\n // push the spill over to the front of the queue to be\n // picked up on the next \"get\" call\n this.atomQueue.pushFront(spillOver);\n }\n }\n return [out, remaining.isZero];\n }\n}\n\n/**\n * Duration Iterators take a tree of Atoms and return atoms in given windowed\n * durations. This also ensures that a leaf atom can be further split if it is\n * larger than the required duration.\n */\nexport class DurationIterator {\n private atomIterator: AtomIterator;\n private spillOver: TSU.Nullable<FlatAtom> = null;\n\n constructor(atomIterator: AtomIterator) {\n this.atomIterator = atomIterator;\n }\n\n get hasMore(): boolean {\n if (this.spillOver != null) {\n return true;\n }\n return this.atomIterator.hasNext;\n }\n\n /**\n * Gets the atoms to cover the given duration.\n *\n * If the number of atoms left in the iterator is 0 then an empty list\n * is returned. Otherwise the duration of atoms returned will cover\n * the given duration even if padding with Space atoms is necessary.\n */\n get(duration: TSU.Num.Fraction): [FlatAtom[], boolean] {\n const iter = this.atomIterator;\n const out: FlatAtom[] = [];\n let remaining = duration;\n while (remaining.isGTNum(0)) {\n const next = this.spillOver == null ? iter.next() : this.spillOver;\n this.spillOver = null;\n if (next == null) {\n // stop here\n break;\n } else {\n out.push(next);\n if (next.duration.cmp(remaining) <= 0) {\n remaining = remaining.minus(next.duration);\n } else {\n // Next leaf atm is > duration\n // so split it into two\n this.spillOver = new FlatAtom(new Space(next.duration.minus(remaining)));\n next.duration = remaining;\n remaining = TSU.Num.Fraction.ZERO;\n }\n }\n }\n return [out, remaining.isZero];\n }\n}\n"]}
|
package/lib/cjs/layouts.d.ts
CHANGED
|
@@ -25,9 +25,9 @@ export declare class LayoutParams {
|
|
|
25
25
|
}): [number, number, Fraction];
|
|
26
26
|
get lineBreaks(): number[];
|
|
27
27
|
set lineBreaks(val: number[]);
|
|
28
|
-
refreshLayout(): void;
|
|
29
28
|
get beatLayouts(): ReadonlyArray<ReadonlyArray<[CyclePosition, Fraction]>>;
|
|
30
29
|
get totalBeats(): number;
|
|
31
30
|
get totalLayoutDuration(): Fraction;
|
|
31
|
+
protected refreshLayout(): void;
|
|
32
32
|
}
|
|
33
33
|
export {};
|