notations 0.0.46 → 0.0.49

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.
Files changed (113) hide show
  1. package/lib/cjs/beats.d.ts +34 -69
  2. package/lib/cjs/beats.js +178 -439
  3. package/lib/cjs/beats.js.map +1 -1
  4. package/lib/cjs/beatutils.d.ts +3 -0
  5. package/lib/cjs/beatutils.js +64 -0
  6. package/lib/cjs/beatutils.js.map +1 -0
  7. package/lib/cjs/beatview.d.ts +18 -0
  8. package/lib/cjs/beatview.js +62 -0
  9. package/lib/cjs/beatview.js.map +1 -0
  10. package/lib/cjs/carnatic/LineView.d.ts +2 -7
  11. package/lib/cjs/carnatic/LineView.js +13 -31
  12. package/lib/cjs/carnatic/LineView.js.map +1 -1
  13. package/lib/cjs/carnatic/NotationView.d.ts +8 -7
  14. package/lib/cjs/carnatic/NotationView.js +76 -153
  15. package/lib/cjs/carnatic/NotationView.js.map +1 -1
  16. package/lib/cjs/carnatic/atomviews.js +149 -287
  17. package/lib/cjs/carnatic/atomviews.js.map +1 -1
  18. package/lib/cjs/carnatic/beatviews.d.ts +4 -13
  19. package/lib/cjs/carnatic/beatviews.js +23 -118
  20. package/lib/cjs/carnatic/beatviews.js.map +1 -1
  21. package/lib/cjs/carnatic/embelishments.d.ts +1 -1
  22. package/lib/cjs/carnatic/embelishments.js +189 -283
  23. package/lib/cjs/carnatic/embelishments.js.map +1 -1
  24. package/lib/cjs/carnatic/gamakas.js +15 -47
  25. package/lib/cjs/carnatic/gamakas.js.map +1 -1
  26. package/lib/cjs/commands.js +111 -271
  27. package/lib/cjs/commands.js.map +1 -1
  28. package/lib/cjs/core.d.ts +14 -1
  29. package/lib/cjs/core.js +291 -477
  30. package/lib/cjs/core.js.map +1 -1
  31. package/lib/cjs/cycle.js +175 -367
  32. package/lib/cjs/cycle.js.map +1 -1
  33. package/lib/cjs/entity.js +48 -102
  34. package/lib/cjs/entity.js.map +1 -1
  35. package/lib/cjs/grids.d.ts +125 -0
  36. package/lib/cjs/grids.js +550 -0
  37. package/lib/cjs/grids.js.map +1 -0
  38. package/lib/cjs/iterators.js +96 -234
  39. package/lib/cjs/iterators.js.map +1 -1
  40. package/lib/cjs/layouts.d.ts +1 -1
  41. package/lib/cjs/layouts.js +62 -98
  42. package/lib/cjs/layouts.js.map +1 -1
  43. package/lib/cjs/loader.d.ts +2 -2
  44. package/lib/cjs/loader.js +23 -123
  45. package/lib/cjs/loader.js.map +1 -1
  46. package/lib/cjs/notation.d.ts +0 -3
  47. package/lib/cjs/notation.js +139 -241
  48. package/lib/cjs/notation.js.map +1 -1
  49. package/lib/cjs/parser.d.ts +2 -0
  50. package/lib/cjs/parser.js +225 -214
  51. package/lib/cjs/parser.js.map +1 -1
  52. package/lib/cjs/shapes.js +149 -283
  53. package/lib/cjs/shapes.js.map +1 -1
  54. package/lib/cjs/utils.d.ts +8 -0
  55. package/lib/cjs/utils.js +60 -55
  56. package/lib/cjs/utils.js.map +1 -1
  57. package/lib/esm/beats.d.ts +34 -69
  58. package/lib/esm/beats.js +172 -438
  59. package/lib/esm/beats.js.map +1 -1
  60. package/lib/esm/beatutils.d.ts +3 -0
  61. package/lib/esm/beatutils.js +37 -0
  62. package/lib/esm/beatutils.js.map +1 -0
  63. package/lib/esm/beatview.d.ts +18 -0
  64. package/lib/esm/beatview.js +35 -0
  65. package/lib/esm/beatview.js.map +1 -0
  66. package/lib/esm/carnatic/LineView.d.ts +2 -7
  67. package/lib/esm/carnatic/LineView.js +12 -31
  68. package/lib/esm/carnatic/LineView.js.map +1 -1
  69. package/lib/esm/carnatic/NotationView.d.ts +8 -7
  70. package/lib/esm/carnatic/NotationView.js +74 -152
  71. package/lib/esm/carnatic/NotationView.js.map +1 -1
  72. package/lib/esm/carnatic/atomviews.js +144 -284
  73. package/lib/esm/carnatic/atomviews.js.map +1 -1
  74. package/lib/esm/carnatic/beatviews.d.ts +4 -13
  75. package/lib/esm/carnatic/beatviews.js +21 -94
  76. package/lib/esm/carnatic/beatviews.js.map +1 -1
  77. package/lib/esm/carnatic/embelishments.d.ts +1 -1
  78. package/lib/esm/carnatic/embelishments.js +187 -296
  79. package/lib/esm/carnatic/embelishments.js.map +1 -1
  80. package/lib/esm/carnatic/gamakas.js +14 -48
  81. package/lib/esm/carnatic/gamakas.js.map +1 -1
  82. package/lib/esm/commands.js +100 -271
  83. package/lib/esm/commands.js.map +1 -1
  84. package/lib/esm/core.d.ts +14 -1
  85. package/lib/esm/core.js +287 -484
  86. package/lib/esm/core.js.map +1 -1
  87. package/lib/esm/cycle.js +172 -367
  88. package/lib/esm/cycle.js.map +1 -1
  89. package/lib/esm/entity.js +48 -104
  90. package/lib/esm/entity.js.map +1 -1
  91. package/lib/esm/grids.d.ts +125 -0
  92. package/lib/esm/grids.js +517 -0
  93. package/lib/esm/grids.js.map +1 -0
  94. package/lib/esm/iterators.js +93 -235
  95. package/lib/esm/iterators.js.map +1 -1
  96. package/lib/esm/layouts.d.ts +1 -1
  97. package/lib/esm/layouts.js +60 -97
  98. package/lib/esm/layouts.js.map +1 -1
  99. package/lib/esm/loader.d.ts +2 -2
  100. package/lib/esm/loader.js +20 -120
  101. package/lib/esm/loader.js.map +1 -1
  102. package/lib/esm/notation.d.ts +0 -3
  103. package/lib/esm/notation.js +135 -242
  104. package/lib/esm/notation.js.map +1 -1
  105. package/lib/esm/parser.d.ts +2 -0
  106. package/lib/esm/parser.js +220 -210
  107. package/lib/esm/parser.js.map +1 -1
  108. package/lib/esm/shapes.js +148 -288
  109. package/lib/esm/shapes.js.map +1 -1
  110. package/lib/esm/utils.d.ts +8 -0
  111. package/lib/esm/utils.js +55 -51
  112. package/lib/esm/utils.js.map +1 -1
  113. package/package.json +18 -17
@@ -1,147 +1,53 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __assign = (this && this.__assign) || function () {
17
- __assign = Object.assign || function(t) {
18
- for (var s, i = 1, n = arguments.length; i < n; i++) {
19
- s = arguments[i];
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
- t[p] = s[p];
22
- }
23
- return t;
24
- };
25
- return __assign.apply(this, arguments);
26
- };
27
- var __read = (this && this.__read) || function (o, n) {
28
- var m = typeof Symbol === "function" && o[Symbol.iterator];
29
- if (!m) return o;
30
- var i = m.call(o), r, ar = [], e;
31
- try {
32
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
33
- }
34
- catch (error) { e = { error: error }; }
35
- finally {
36
- try {
37
- if (r && !r.done && (m = i["return"])) m.call(i);
38
- }
39
- finally { if (e) throw e.error; }
40
- }
41
- return ar;
42
- };
43
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
45
- if (ar || !(i in from)) {
46
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
47
- ar[i] = from[i];
48
- }
49
- }
50
- return to.concat(ar || Array.prototype.slice.call(from));
51
- };
52
- var __values = (this && this.__values) || function(o) {
53
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
54
- if (m) return m.call(o);
55
- if (o && typeof o.length === "number") return {
56
- next: function () {
57
- if (o && i >= o.length) o = void 0;
58
- return { value: o && o[i++], done: !o };
59
- }
60
- };
61
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
62
- };
63
1
  import * as TSU from "@panyam/tsutils";
64
2
  import { TimedEntity } from "./entity";
65
3
  import { Space, AtomType } from "./core";
66
- var FlatAtom = (function (_super) {
67
- __extends(FlatAtom, _super);
68
- function FlatAtom(atom, config) {
69
- if (config === void 0) { config = null; }
70
- var _this = _super.call(this, (config = config || {})) || this;
71
- _this.atom = atom;
72
- _this.depth = config.depth || 0;
73
- _this.duration = config.duration || atom.duration;
74
- _this.offset = config.offset || TSU.Num.Fraction.ZERO;
75
- _this.isContinuation = "isContinuation" in config ? config.isContinuation : false;
76
- return _this;
4
+ export class FlatAtom extends TimedEntity {
5
+ constructor(atom, config = null) {
6
+ super((config = config || {}));
7
+ this.atom = atom;
8
+ this.depth = config.depth || 0;
9
+ this.duration = config.duration || atom.duration;
10
+ this.offset = config.offset || TSU.Num.Fraction.ZERO;
11
+ this.isContinuation = "isContinuation" in config ? config.isContinuation : false;
12
+ }
13
+ get type() {
14
+ return "FlatAtom";
15
+ }
16
+ get endOffset() {
17
+ return this.offset.plus(this.duration);
77
18
  }
78
- Object.defineProperty(FlatAtom.prototype, "type", {
79
- get: function () {
80
- return "FlatAtom";
81
- },
82
- enumerable: false,
83
- configurable: true
84
- });
85
- Object.defineProperty(FlatAtom.prototype, "endOffset", {
86
- get: function () {
87
- return this.offset.plus(this.duration);
88
- },
89
- enumerable: false,
90
- configurable: true
91
- });
92
- FlatAtom.prototype.debugValue = function () {
93
- var out = __assign(__assign({}, _super.prototype.debugValue.call(this)), { atom: this.atom.debugValue(), duration: this.duration.toString(), offset: this.offset.toString(), depth: this.depth });
19
+ debugValue() {
20
+ const out = Object.assign(Object.assign({}, super.debugValue()), { atom: this.atom.debugValue(), duration: this.duration.toString(), offset: this.offset.toString(), depth: this.depth });
94
21
  if (this.isContinuation)
95
22
  out.isContinuation = true;
96
23
  return out;
97
- };
98
- return FlatAtom;
99
- }(TimedEntity));
100
- export { FlatAtom };
101
- var AtomIterator = (function () {
102
- function AtomIterator() {
103
- var atoms = [];
104
- for (var _i = 0; _i < arguments.length; _i++) {
105
- atoms[_i] = arguments[_i];
106
- }
24
+ }
25
+ }
26
+ export class AtomIterator {
27
+ constructor(...atoms) {
107
28
  this.atomQueue = new TSU.Lists.List();
108
29
  this.currOffset = TSU.Num.Fraction.ZERO;
109
30
  this.peeked = null;
110
- this.push.apply(this, __spreadArray([], __read(atoms), false));
31
+ this.push(...atoms);
111
32
  }
112
- AtomIterator.prototype.push = function () {
113
- var e_1, _a;
114
- var atoms = [];
115
- for (var _i = 0; _i < arguments.length; _i++) {
116
- atoms[_i] = arguments[_i];
117
- }
118
- try {
119
- for (var atoms_1 = __values(atoms), atoms_1_1 = atoms_1.next(); !atoms_1_1.done; atoms_1_1 = atoms_1.next()) {
120
- var atom = atoms_1_1.value;
121
- this.atomQueue.add([atom, 0, atom.duration]);
122
- }
123
- }
124
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
125
- finally {
126
- try {
127
- if (atoms_1_1 && !atoms_1_1.done && (_a = atoms_1.return)) _a.call(atoms_1);
128
- }
129
- finally { if (e_1) throw e_1.error; }
33
+ push(...atoms) {
34
+ for (const atom of atoms) {
35
+ this.atomQueue.add([atom, 0, atom.duration]);
130
36
  }
131
37
  return this;
132
- };
133
- AtomIterator.prototype.next = function () {
134
- var out = this.peek();
38
+ }
39
+ next() {
40
+ const out = this.peek();
135
41
  this.peeked = null;
136
42
  if (out != null) {
137
43
  this.currOffset = this.currOffset.plus(out.duration).factorized;
138
44
  }
139
45
  return out;
140
- };
141
- AtomIterator.prototype.peek = function () {
46
+ }
47
+ peek() {
142
48
  if (this.peeked == null) {
143
49
  if (this.hasNext) {
144
- var _a = __read(this.atomQueue.popFront(), 3), nextAtom = _a[0], nextDepth = _a[1], nextDuration = _a[2];
50
+ const [nextAtom, nextDepth, nextDuration] = this.atomQueue.popFront();
145
51
  this.peeked = new FlatAtom(nextAtom, {
146
52
  depth: nextDepth,
147
53
  offset: this.currOffset,
@@ -150,47 +56,32 @@ var AtomIterator = (function () {
150
56
  }
151
57
  }
152
58
  return this.peeked;
153
- };
154
- Object.defineProperty(AtomIterator.prototype, "hasNext", {
155
- get: function () {
156
- var e_2, _a;
157
- while (this.atomQueue.first != null) {
158
- var _b = __read(this.atomQueue.first.value, 3), nextAtom = _b[0], nextDepth = _b[1], nextDuration = _b[2];
159
- if (nextAtom.type != AtomType.GROUP) {
160
- return true;
161
- }
162
- else {
163
- this.atomQueue.popFront();
164
- var group = nextAtom;
165
- try {
166
- for (var _c = (e_2 = void 0, __values(group.atoms.reversedValues())), _d = _c.next(); !_d.done; _d = _c.next()) {
167
- var child = _d.value;
168
- this.atomQueue.pushFront([
169
- child,
170
- nextDepth + 1,
171
- nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,
172
- ]);
173
- }
174
- }
175
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
176
- finally {
177
- try {
178
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
179
- }
180
- finally { if (e_2) throw e_2.error; }
181
- }
59
+ }
60
+ get hasNext() {
61
+ while (this.atomQueue.first != null) {
62
+ const [nextAtom, nextDepth, nextDuration] = this.atomQueue.first.value;
63
+ if (nextAtom.type != AtomType.GROUP) {
64
+ return true;
65
+ }
66
+ else {
67
+ this.atomQueue.popFront();
68
+ const group = nextAtom;
69
+ for (const child of group.atoms.reversedValues()) {
70
+ this.atomQueue.pushFront([
71
+ child,
72
+ nextDepth + 1,
73
+ nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,
74
+ ]);
182
75
  }
183
76
  }
184
- return false;
185
- },
186
- enumerable: false,
187
- configurable: true
188
- });
189
- AtomIterator.getMin = function (iterators) {
190
- var currRole = -1;
191
- var currAtom = null;
192
- for (var ri = 0; ri < iterators.length; ri++) {
193
- var flatAtom = iterators[ri].peek();
77
+ }
78
+ return false;
79
+ }
80
+ static getMin(iterators) {
81
+ let currRole = -1;
82
+ let currAtom = null;
83
+ for (let ri = 0; ri < iterators.length; ri++) {
84
+ const flatAtom = iterators[ri].peek();
194
85
  if (flatAtom != null) {
195
86
  if (currAtom == null || flatAtom.offset.cmp(currAtom.offset) < 0) {
196
87
  currRole = ri;
@@ -202,102 +93,71 @@ var AtomIterator = (function () {
202
93
  iterators[currRole].next();
203
94
  }
204
95
  return [currRole, currAtom];
205
- };
206
- return AtomIterator;
207
- }());
208
- export { AtomIterator };
209
- var WindowIterator = (function () {
210
- function WindowIterator() {
211
- var atoms = [];
212
- for (var _i = 0; _i < arguments.length; _i++) {
213
- atoms[_i] = arguments[_i];
214
- }
96
+ }
97
+ }
98
+ export class WindowIterator {
99
+ constructor(...atoms) {
215
100
  this.atomQueue = new TSU.Lists.List();
216
101
  this.currOffset = TSU.Num.Fraction.ZERO;
217
102
  this.peeked = null;
218
- this.push.apply(this, __spreadArray([], __read(atoms), false));
103
+ this.push(...atoms);
219
104
  }
220
- WindowIterator.prototype.push = function () {
221
- var e_3, _a;
222
- var atoms = [];
223
- for (var _i = 0; _i < arguments.length; _i++) {
224
- atoms[_i] = arguments[_i];
225
- }
226
- try {
227
- for (var atoms_2 = __values(atoms), atoms_2_1 = atoms_2.next(); !atoms_2_1.done; atoms_2_1 = atoms_2.next()) {
228
- var atom = atoms_2_1.value;
229
- this.atomQueue.add(atom);
230
- }
231
- }
232
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
233
- finally {
234
- try {
235
- if (atoms_2_1 && !atoms_2_1.done && (_a = atoms_2.return)) _a.call(atoms_2);
236
- }
237
- finally { if (e_3) throw e_3.error; }
105
+ push(...atoms) {
106
+ for (const atom of atoms) {
107
+ this.atomQueue.add(atom);
238
108
  }
239
109
  return this;
240
- };
241
- WindowIterator.prototype.next = function () {
242
- var out = this.peek();
110
+ }
111
+ next() {
112
+ const out = this.peek();
243
113
  this.peeked = null;
244
114
  if (out != null) {
245
115
  this.currOffset = this.currOffset.plus(out.duration, true);
246
116
  }
247
117
  return out;
248
- };
249
- WindowIterator.prototype.peek = function () {
118
+ }
119
+ peek() {
250
120
  if (this.peeked == null && this.hasMore) {
251
121
  this.peeked = this.atomQueue.popFront();
252
122
  }
253
123
  return this.peeked;
254
- };
255
- Object.defineProperty(WindowIterator.prototype, "hasMore", {
256
- get: function () {
257
- return !this.atomQueue.isEmpty;
258
- },
259
- enumerable: false,
260
- configurable: true
261
- });
262
- WindowIterator.prototype.get = function (duration) {
263
- var out = [];
264
- var remaining = duration;
124
+ }
125
+ get hasMore() {
126
+ return !this.atomQueue.isEmpty;
127
+ }
128
+ get(duration) {
129
+ const out = [];
130
+ let remaining = duration;
265
131
  while (remaining.isGTNum(0) && this.hasMore) {
266
- var next = this.next();
132
+ const next = this.next();
267
133
  TSU.assert(next != null, "Next cannot be null here");
268
134
  out.push(next);
269
- var spillOver = next.splitAt(remaining);
135
+ const spillOver = next.splitAt(remaining);
270
136
  remaining = remaining.minus(next.duration);
271
137
  if (spillOver != null) {
272
138
  this.atomQueue.pushFront(spillOver);
273
139
  }
274
140
  }
275
141
  return [out, remaining.isZero];
276
- };
277
- return WindowIterator;
278
- }());
279
- export { WindowIterator };
280
- var DurationIterator = (function () {
281
- function DurationIterator(atomIterator) {
142
+ }
143
+ }
144
+ export class DurationIterator {
145
+ constructor(atomIterator) {
282
146
  this.spillOver = null;
283
147
  this.atomIterator = atomIterator;
284
148
  }
285
- Object.defineProperty(DurationIterator.prototype, "hasMore", {
286
- get: function () {
287
- if (this.spillOver != null) {
288
- return true;
289
- }
290
- return this.atomIterator.hasNext;
291
- },
292
- enumerable: false,
293
- configurable: true
294
- });
295
- DurationIterator.prototype.get = function (duration) {
296
- var iter = this.atomIterator;
297
- var out = [];
298
- var remaining = duration;
149
+ get hasMore() {
150
+ if (this.spillOver != null) {
151
+ return true;
152
+ }
153
+ return this.atomIterator.hasNext;
154
+ }
155
+ get(duration) {
156
+ const iter = this.atomIterator;
157
+ const out = [];
158
+ let remaining = duration;
299
159
  while (remaining.isGTNum(0)) {
300
- var next = this.spillOver == null ? iter.next() : this.spillOver;
160
+ const next = this.spillOver == null ? iter.next() : this.spillOver;
301
161
  this.spillOver = null;
302
162
  if (next == null) {
303
163
  break;
@@ -315,8 +175,6 @@ var DurationIterator = (function () {
315
175
  }
316
176
  }
317
177
  return [out, remaining.isZero];
318
- };
319
- return DurationIterator;
320
- }());
321
- export { DurationIterator };
178
+ }
179
+ }
322
180
  //# sourceMappingURL=iterators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/iterators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAkB,KAAK,EAAS,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAMhE;IAA8B,4BAAW;IAMvC,kBAAmB,IAAc,EAAE,MAAkB;QAAlB,uBAAA,EAAA,aAAkB;QAArD,YACE,kBAAM,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,SAK/B;QANkB,UAAI,GAAJ,IAAI,CAAU;QAE/B,KAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;QAC/B,KAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;QACjD,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrD,KAAI,CAAC,cAAc,GAAG,gBAAgB,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC;;IACnF,CAAC;IAKD,sBAAI,0BAAI;aAAR;YACE,OAAO,UAAU,CAAC;QACpB,CAAC;;;OAAA;IAED,sBAAI,+BAAS;aAAb;YACE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,C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AAC,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,KAAK,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;IACH,uBAAC;AAAD,CAAC,AA/CD,IA+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"]}
1
+ {"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/iterators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAkB,KAAK,EAAS,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAMhE,MAAM,OAAO,QAAS,SAAQ,WAAW;IAMvC,YAAmB,IAAc,EAAE,SAAc,IAAI;QACnD,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QADd,SAAI,GAAJ,IAAI,CAAU;QAE/B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrD,IAAI,CAAC,c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G,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;iBACnC;aACF;SACF;QACD,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACF","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"]}
@@ -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 {};