notations 0.0.48 → 0.0.51

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 +36 -71
  2. package/lib/cjs/beats.js +225 -432
  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 +9 -7
  14. package/lib/cjs/carnatic/NotationView.js +90 -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 +18 -10
  19. package/lib/cjs/carnatic/beatviews.js +59 -91
  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 +6 -1
  29. package/lib/cjs/core.js +288 -493
  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 +124 -1
  36. package/lib/cjs/grids.js +546 -6
  37. package/lib/cjs/grids.js.map +1 -1
  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 +222 -219
  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 +36 -71
  58. package/lib/esm/beats.js +218 -430
  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 +9 -7
  70. package/lib/esm/carnatic/NotationView.js +88 -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 +18 -10
  75. package/lib/esm/carnatic/beatviews.js +53 -87
  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 +6 -1
  85. package/lib/esm/core.js +286 -502
  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 +124 -1
  92. package/lib/esm/grids.js +515 -5
  93. package/lib/esm/grids.js.map +1 -1
  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 +216 -214
  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 +2 -1
package/lib/cjs/beats.js CHANGED
@@ -22,51 +22,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __values = (this && this.__values) || function(o) {
26
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
27
- if (m) return m.call(o);
28
- if (o && typeof o.length === "number") return {
29
- next: function () {
30
- if (o && i >= o.length) o = void 0;
31
- return { value: o && o[i++], done: !o };
32
- }
33
- };
34
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
35
- };
36
- var __read = (this && this.__read) || function (o, n) {
37
- var m = typeof Symbol === "function" && o[Symbol.iterator];
38
- if (!m) return o;
39
- var i = m.call(o), r, ar = [], e;
40
- try {
41
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
42
- }
43
- catch (error) { e = { error: error }; }
44
- finally {
45
- try {
46
- if (r && !r.done && (m = i["return"])) m.call(i);
47
- }
48
- finally { if (e) throw e.error; }
49
- }
50
- return ar;
51
- };
52
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
53
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
54
- if (ar || !(i in from)) {
55
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
56
- ar[i] = from[i];
57
- }
58
- }
59
- return to.concat(ar || Array.prototype.slice.call(from));
60
- };
61
25
  Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.BeatsBuilder = exports.BeatColumn = exports.BeatRow = exports.BeatLayout = exports.Beat = void 0;
63
- var TSU = __importStar(require("@panyam/tsutils"));
64
- var _1 = require("./");
65
- var iterators_1 = require("./iterators");
66
- var ZERO = TSU.Num.Fraction.ZERO;
67
- var ONE = TSU.Num.Fraction.ONE;
68
- var Beat = (function () {
69
- function Beat(index, role, offset, duration, barIndex, beatIndex, instance, prevBeat, nextBeat) {
26
+ exports.GlobalBeatLayout = exports.BeatColDAG = exports.BeatColumn = exports.BeatsBuilder = exports.Beat = void 0;
27
+ const TSU = __importStar(require("@panyam/tsutils"));
28
+ const _1 = require("./");
29
+ const iterators_1 = require("./iterators");
30
+ const grids_1 = require("./grids");
31
+ const ZERO = TSU.Num.Fraction.ZERO;
32
+ const ONE = TSU.Num.Fraction.ONE;
33
+ class Beat {
34
+ constructor(index, role, offset, duration, barIndex, beatIndex, instance, prevBeat, nextBeat) {
70
35
  this.index = index;
71
36
  this.role = role;
72
37
  this.offset = offset;
@@ -76,12 +41,10 @@ var Beat = (function () {
76
41
  this.instance = instance;
77
42
  this.prevBeat = prevBeat;
78
43
  this.nextBeat = nextBeat;
79
- this.layoutLine = -1;
80
- this.layoutColumn = -1;
81
44
  this.uuid = Beat.idCounter++;
82
45
  this.atomIsPlaceholder = false;
83
46
  }
84
- Beat.prototype.debugValue = function () {
47
+ debugValue() {
85
48
  return {
86
49
  index: this.index,
87
50
  role: this.role.name,
@@ -92,29 +55,17 @@ var Beat = (function () {
92
55
  instance: this.instance,
93
56
  atom: this.atom.debugValue(),
94
57
  };
95
- };
96
- Object.defineProperty(Beat.prototype, "endOffset", {
97
- get: function () {
98
- return this.offset.plus(this.duration);
99
- },
100
- enumerable: false,
101
- configurable: true
102
- });
103
- Object.defineProperty(Beat.prototype, "filled", {
104
- get: function () {
105
- return this.remaining.isZero;
106
- },
107
- enumerable: false,
108
- configurable: true
109
- });
110
- Object.defineProperty(Beat.prototype, "remaining", {
111
- get: function () {
112
- return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;
113
- },
114
- enumerable: false,
115
- configurable: true
116
- });
117
- Beat.prototype.add = function (atom) {
58
+ }
59
+ get endOffset() {
60
+ return this.offset.plus(this.duration);
61
+ }
62
+ get filled() {
63
+ return this.remaining.isZero;
64
+ }
65
+ get remaining() {
66
+ return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;
67
+ }
68
+ add(atom) {
118
69
  if (this.remaining.cmp(atom.duration) < 0) {
119
70
  return false;
120
71
  }
@@ -129,353 +80,79 @@ var Beat = (function () {
129
80
  this.atom.addAtoms(true, atom);
130
81
  }
131
82
  return true;
132
- };
133
- Beat.prototype.ensureUniformSpaces = function (atoms, slotsPerBeat) {
134
- if (slotsPerBeat === void 0) { slotsPerBeat = 1; }
135
- var lcm = 1;
136
- var gcd = 0;
137
- atoms.forEach(function (a, index) {
138
- a.duration = a.duration.factorized;
139
- var currDen = a.duration.den;
140
- if (currDen != 1) {
141
- lcm *= currDen;
142
- if (gcd == 0) {
143
- gcd = a.duration.den;
144
- }
145
- else {
146
- gcd = TSU.Num.gcdof(gcd, currDen);
147
- lcm /= gcd;
148
- }
149
- }
150
- });
151
- var baseDur = new TSU.Num.Fraction(1, lcm);
152
- var currOffset = this.offset;
153
- for (var i = 0; i < atoms.length;) {
154
- var fa = atoms[i];
155
- var numSpaces = lcm == 1 ? fa.duration.num - 1 : lcm / fa.duration.den - 1;
156
- fa.duration = baseDur;
157
- currOffset = currOffset.plus(baseDur);
158
- i++;
159
- for (var j = 0; j < numSpaces; j++, i++) {
160
- var space = new _1.Space(baseDur);
161
- space.isContinuation = true;
162
- atoms.splice(i, 0, new iterators_1.FlatAtom(space));
163
- atoms.splice(i, 0, new iterators_1.FlatAtom(space));
164
- currOffset = currOffset.plus(baseDur);
165
- }
166
- }
167
- };
168
- Beat.idCounter = 0;
169
- return Beat;
170
- }());
171
- exports.Beat = Beat;
172
- var BeatLayout = (function () {
173
- function BeatLayout(layoutParams) {
174
- this.layoutParams = layoutParams;
175
- this.bcolNextList = new Map();
176
- this.beatColumns = new Map();
177
- this.startingColumns = [];
178
- this.columnForBeat = new Map();
179
- this.DEBUG = false;
180
- this.roleSpacing = 10;
181
- this.rowSpacing = 15;
182
83
  }
183
- BeatLayout.prototype.getBeatColumn = function (offset, duration) {
184
- var e_1, _a;
185
- var key = BeatLayout.keyFor(offset, duration);
186
- var bcol = this.beatColumns.get(key) || null;
187
- if (!bcol) {
188
- bcol = new BeatColumn(offset, duration);
189
- this.beatColumns.set(key, bcol);
190
- if (bcol.offset.isZero) {
191
- this.startingColumns.push(bcol);
84
+ get preMarkers() {
85
+ const out = [];
86
+ let curr = this.atom;
87
+ while (curr != null) {
88
+ for (const marker of curr.markersBefore || []) {
89
+ out.push(marker);
192
90
  }
193
- else {
194
- var endOffset = offset.plus(duration);
195
- try {
196
- for (var _b = __values(this.beatColumns.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
197
- var other = _c.value;
198
- if (other.offset.plus(other.duration).equals(offset)) {
199
- this.addSuccessor(other, bcol);
200
- }
201
- else if (other.offset.equals(endOffset)) {
202
- this.addSuccessor(bcol, other);
203
- }
204
- }
205
- }
206
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
207
- finally {
208
- try {
209
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
210
- }
211
- finally { if (e_1) throw e_1.error; }
212
- }
213
- }
214
- }
215
- return bcol;
216
- };
217
- BeatLayout.keyFor = function (offset, duration) {
218
- return offset.factorized.toString() + ":" + duration.factorized.toString();
219
- };
220
- BeatLayout.prototype.addSuccessor = function (prev, next) {
221
- TSU.assert(prev.offset.plus(prev.duration).equals(next.offset), "BeatColumns are not adjacent to each other");
222
- var prevKey = BeatLayout.keyFor(prev.offset, prev.duration);
223
- var nextKey = BeatLayout.keyFor(next.offset, next.duration);
224
- var nextset = this.bcolNextList.get(prevKey) || null;
225
- if (!nextset) {
226
- nextset = new Set();
227
- this.bcolNextList.set(prevKey, nextset);
228
- }
229
- nextset.add(nextKey);
230
- };
231
- BeatLayout.prototype.addBeat = function (beat) {
232
- var lp = this.layoutParams;
233
- var _a = __read(lp.getBeatLocation(beat), 3), layoutLine = _a[0], layoutColumn = _a[1], rowOffset = _a[2];
234
- var bcol = this.getBeatColumn(rowOffset, beat.duration);
235
- bcol.add(beat);
236
- this.columnForBeat.set(beat.uuid, bcol);
237
- beat.layoutLine = layoutLine;
238
- beat.layoutColumn = layoutColumn;
239
- return bcol;
240
- };
241
- BeatLayout.prototype.neighborsOf = function (beatColumn) {
242
- var e_2, _a;
243
- var out = [];
244
- var endOffset = beatColumn.offset.plus(beatColumn.duration);
245
- try {
246
- for (var _b = __values(this.beatColumns.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
247
- var other = _c.value;
248
- if (endOffset.equals(other.offset)) {
249
- out.push(other);
250
- }
91
+ if (curr.type == _1.AtomType.GROUP) {
92
+ curr = curr.atoms.first;
251
93
  }
252
- }
253
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
254
- finally {
255
- try {
256
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
94
+ else {
95
+ curr = null;
257
96
  }
258
- finally { if (e_2) throw e_2.error; }
259
97
  }
260
98
  return out;
261
- };
262
- BeatLayout.prototype.evalColumnSizes = function (beatViewDelegate) {
263
- var e_3, _a, e_4, _b;
264
- var queue = __spreadArray([], __read(this.startingColumns), false);
265
- var xForOffsets = {};
266
- while (queue.length > 0) {
267
- var nextQueue = [];
268
- try {
269
- for (var queue_1 = (e_3 = void 0, __values(queue)), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
270
- var bcol = queue_1_1.value;
271
- var offset = bcol.offset.factorized;
272
- var colWidth = bcol.evalMaxWidth(beatViewDelegate);
273
- var currX = 0;
274
- if (!bcol.offset.isZero) {
275
- TSU.assert(offset.toString() in xForOffsets, "Cannot find x for given offset");
276
- currX = xForOffsets[offset.toString()];
277
- }
278
- bcol.setX(currX, beatViewDelegate);
279
- var endOffset = offset.plus(bcol.duration, true);
280
- xForOffsets[endOffset.toString()] = Math.max(xForOffsets[endOffset.toString()] || 0, currX + colWidth + bcol.paddingLeft + bcol.paddingRight);
281
- try {
282
- for (var _c = (e_4 = void 0, __values(this.beatColumns.values())), _d = _c.next(); !_d.done; _d = _c.next()) {
283
- var other = _d.value;
284
- if (endOffset.equals(other.offset)) {
285
- nextQueue.push(other);
286
- }
287
- }
288
- }
289
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
290
- finally {
291
- try {
292
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
293
- }
294
- finally { if (e_4) throw e_4.error; }
295
- }
296
- }
297
- }
298
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
299
- finally {
300
- try {
301
- if (queue_1_1 && !queue_1_1.done && (_a = queue_1.return)) _a.call(queue_1);
302
- }
303
- finally { if (e_3) throw e_3.error; }
304
- }
305
- queue = nextQueue;
306
- }
307
- };
308
- BeatLayout.prototype.layoutBeatsForLine = function (line, allRoleBeats, beatViewDelegate) {
309
- var lp = this.layoutParams;
310
- var currBeats = line.roles.map(function (l, index) { return allRoleBeats[index][0]; });
311
- var currY = this.roleSpacing;
312
- var numDone = 0;
313
- do {
314
- numDone = 0;
315
- for (var currRole = 0; currRole < currBeats.length; currRole++) {
316
- var currBeat = currBeats[currRole];
317
- if (currBeat) {
318
- var temp = currBeat;
319
- var numBeatsInRow = lp.lineBreaks[currBeat.layoutLine];
320
- var maxHeight = 0;
321
- var currX = 15;
322
- for (var i = currBeat.layoutColumn; i < numBeatsInRow && currBeat; i++, currBeat = currBeat.nextBeat, numDone++) {
323
- var beatView = beatViewDelegate.viewForBeat(currBeat);
324
- beatView.y = currY;
325
- if (this.DEBUG) {
326
- beatView.x = currX;
327
- beatView.refreshLayout();
328
- currX += beatView.width;
329
- }
330
- maxHeight = Math.max(maxHeight, beatView.minSize.height);
331
- }
332
- currBeat = temp;
333
- for (var i = currBeat.layoutColumn; i < numBeatsInRow && currBeat; i++, currBeat = currBeat.nextBeat, numDone++) {
334
- var beatView = beatViewDelegate.viewForBeat(currBeat);
335
- beatView.height = maxHeight;
336
- }
337
- currY += maxHeight;
338
- currY += this.roleSpacing;
339
- }
340
- currBeats[currRole] = currBeat;
341
- }
342
- currY += this.rowSpacing;
343
- } while (numDone > 0);
344
- };
345
- return BeatLayout;
346
- }());
347
- exports.BeatLayout = BeatLayout;
348
- var BeatRow = (function () {
349
- function BeatRow(layoutLine, rowIndex) {
350
- this.layoutLine = layoutLine;
351
- this.rowIndex = rowIndex;
352
- this._y = 0;
353
- this._maxHeight = 0;
354
- this.needsLayout = false;
355
- this.rowSpacing = 5;
356
- this.beats = [];
357
- }
358
- Object.defineProperty(BeatRow.prototype, "y", {
359
- get: function () {
360
- return this._y;
361
- },
362
- set: function (val) {
363
- this._y = val;
364
- this.needsLayout = true;
365
- },
366
- enumerable: false,
367
- configurable: true
368
- });
369
- BeatRow.prototype.add = function (beat) {
370
- this.beats.push(beat);
371
- this.needsLayout = true;
372
- };
373
- return BeatRow;
374
- }());
375
- exports.BeatRow = BeatRow;
376
- var BeatColumn = (function () {
377
- function BeatColumn(offset, duration) {
378
- this.offset = offset;
379
- this.duration = duration;
380
- this._x = 0;
381
- this._maxWidth = 0;
382
- this.needsLayout = false;
383
- this.atomSpacing = 5;
384
- this.paddingLeft = 15;
385
- this.paddingRight = 15;
386
- this.beats = [];
387
- offset = offset.factorized;
388
- duration = duration.factorized;
389
99
  }
390
- Object.defineProperty(BeatColumn.prototype, "x", {
391
- get: function () {
392
- return this._x;
393
- },
394
- enumerable: false,
395
- configurable: true
396
- });
397
- BeatColumn.prototype.setX = function (val, beatViewDelegate) {
398
- var e_5, _a;
399
- this._x = val;
400
- try {
401
- for (var _b = __values(this.beats), _c = _b.next(); !_c.done; _c = _b.next()) {
402
- var beat = _c.value;
403
- var beatView = beatViewDelegate.viewForBeat(beat);
404
- beatView.x = val + this.paddingLeft;
405
- beatView.width = this._maxWidth;
100
+ get postMarkers() {
101
+ const out = [];
102
+ let curr = this.atom;
103
+ while (curr != null) {
104
+ out.splice(0, 0, ...(curr.markersAfter || []));
105
+ if (curr.type == _1.AtomType.GROUP) {
106
+ curr = curr.atoms.last;
406
107
  }
407
- }
408
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
409
- finally {
410
- try {
411
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
412
- }
413
- finally { if (e_5) throw e_5.error; }
414
- }
415
- };
416
- Object.defineProperty(BeatColumn.prototype, "maxWidth", {
417
- get: function () {
418
- return this._maxWidth + this.paddingLeft + this.paddingRight;
419
- },
420
- enumerable: false,
421
- configurable: true
422
- });
423
- BeatColumn.prototype.setPadding = function (left, right) {
424
- if (left >= 0) {
425
- this.paddingLeft = left;
426
- }
427
- if (right >= 0) {
428
- this.paddingRight = right;
429
- }
430
- };
431
- BeatColumn.prototype.evalMaxWidth = function (beatViewDelegate) {
432
- var e_6, _a;
433
- this._maxWidth = 0;
434
- try {
435
- for (var _b = __values(this.beats), _c = _b.next(); !_c.done; _c = _b.next()) {
436
- var beat = _c.value;
437
- var beatView = beatViewDelegate.viewForBeat(beat);
438
- var minSize = beatView.minSize;
439
- if (minSize.width > this._maxWidth) {
440
- this._maxWidth = minSize.width;
441
- }
442
- }
443
- }
444
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
445
- finally {
446
- try {
447
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
108
+ else {
109
+ curr = null;
448
110
  }
449
- finally { if (e_6) throw e_6.error; }
450
111
  }
451
- return this._maxWidth;
452
- };
453
- BeatColumn.prototype.add = function (beat) {
454
- this.beats.push(beat);
455
- this.needsLayout = true;
456
- };
457
- return BeatColumn;
458
- }());
459
- exports.BeatColumn = BeatColumn;
460
- var BeatsBuilder = (function () {
461
- function BeatsBuilder(role, layoutParams, startOffset) {
462
- if (startOffset === void 0) { startOffset = ZERO; }
112
+ return out;
113
+ }
114
+ }
115
+ exports.Beat = Beat;
116
+ Beat.idCounter = 0;
117
+ class BeatsBuilder {
118
+ constructor(role, layoutParams, startOffset = ZERO, ...atoms) {
463
119
  this.role = role;
464
120
  this.layoutParams = layoutParams;
465
121
  this.startOffset = startOffset;
466
122
  this.beats = [];
467
- var _a = __read(layoutParams.cycle.getPosition(startOffset), 4), _b = __read(_a[1], 3), bar = _b[0], beat = _b[1], instance = _b[2], beatOffset = _a[2], index = _a[3];
123
+ const [, [bar, beat, instance], beatOffset, index] = layoutParams.cycle.getPosition(startOffset);
468
124
  this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);
469
125
  this.windowIter = new iterators_1.WindowIterator();
470
126
  this.beatOffset = beatOffset;
471
127
  this.startIndex = index;
128
+ this.addAtoms(...atoms);
129
+ }
130
+ addAtoms(...atoms) {
131
+ this.windowIter.push(...atoms);
132
+ while (this.windowIter.hasMore) {
133
+ let currBeat = this.beats[this.beats.length - 1];
134
+ if (this.beats.length == 0 || currBeat.filled) {
135
+ currBeat = this.addBeat();
136
+ }
137
+ const [remAtoms, filled] = this.windowIter.get(currBeat.remaining);
138
+ TSU.assert(remAtoms.length > 0, "Atleast one element should have been available here");
139
+ for (const atom of remAtoms) {
140
+ TSU.assert(currBeat.add(atom), "Should return true as we are already using a duration iterator here");
141
+ if (this.onAtomAdded)
142
+ this.onAtomAdded(atom, currBeat);
143
+ }
144
+ if (currBeat.filled) {
145
+ if (this.onBeatFilled)
146
+ this.onBeatFilled(currBeat);
147
+ }
148
+ }
472
149
  }
473
- BeatsBuilder.prototype.addBeat = function () {
474
- var numBeats = this.beats.length;
475
- var lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];
476
- var nextCP = this.cycleIter.next().value;
477
- var apb = this.layoutParams.beatDuration;
478
- var newBeat = new Beat(lastBeat == null ? this.startIndex : lastBeat.index + 1, this.role, lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset, nextCP[1].timesNum(apb), nextCP[0][0], nextCP[0][1], nextCP[0][2], lastBeat, null);
150
+ addBeat() {
151
+ const numBeats = this.beats.length;
152
+ const lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];
153
+ const nextCP = this.cycleIter.next().value;
154
+ const apb = this.layoutParams.beatDuration;
155
+ const newBeat = new Beat(lastBeat == null ? this.startIndex : lastBeat.index + 1, this.role, lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset, nextCP[1].timesNum(apb), nextCP[0][0], nextCP[0][1], nextCP[0][2], lastBeat, null);
479
156
  if (lastBeat == null && this.beatOffset.isGT(ZERO)) {
480
157
  newBeat.add(new _1.Space(this.beatOffset.timesNum(apb)));
481
158
  }
@@ -485,43 +162,159 @@ var BeatsBuilder = (function () {
485
162
  if (this.onBeatAdded)
486
163
  this.onBeatAdded(newBeat);
487
164
  return newBeat;
488
- };
489
- BeatsBuilder.prototype.addAtoms = function () {
490
- var _a, e_7, _b;
491
- var atoms = [];
492
- for (var _i = 0; _i < arguments.length; _i++) {
493
- atoms[_i] = arguments[_i];
165
+ }
166
+ }
167
+ exports.BeatsBuilder = BeatsBuilder;
168
+ class BeatColumn extends grids_1.ColAlign {
169
+ constructor(offset, endOffset, markerType) {
170
+ super();
171
+ this.offset = offset;
172
+ this.endOffset = endOffset;
173
+ this.markerType = markerType;
174
+ this.atomSpacing = 5;
175
+ offset = offset.factorized;
176
+ endOffset = endOffset.factorized;
177
+ this.key = BeatColumn.keyFor(offset, endOffset, markerType);
178
+ }
179
+ static keyFor(offset, endOffset, markerType = 0) {
180
+ offset = offset.factorized;
181
+ endOffset = endOffset.factorized;
182
+ if (markerType < 0) {
183
+ return ":" + offset.toString();
494
184
  }
495
- (_a = this.windowIter).push.apply(_a, __spreadArray([], __read(atoms), false));
496
- while (this.windowIter.hasMore) {
497
- var currBeat = this.beats[this.beats.length - 1];
498
- if (this.beats.length == 0 || currBeat.filled) {
499
- currBeat = this.addBeat();
500
- }
501
- var _c = __read(this.windowIter.get(currBeat.remaining), 2), remAtoms = _c[0], filled = _c[1];
502
- TSU.assert(remAtoms.length > 0, "Atleast one element should have been available here");
503
- try {
504
- for (var remAtoms_1 = (e_7 = void 0, __values(remAtoms)), remAtoms_1_1 = remAtoms_1.next(); !remAtoms_1_1.done; remAtoms_1_1 = remAtoms_1.next()) {
505
- var atom = remAtoms_1_1.value;
506
- TSU.assert(currBeat.add(atom), "Should return true as we are already using a duration iterator here");
507
- if (this.onAtomAdded)
508
- this.onAtomAdded(atom, currBeat);
509
- }
510
- }
511
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
512
- finally {
513
- try {
514
- if (remAtoms_1_1 && !remAtoms_1_1.done && (_b = remAtoms_1.return)) _b.call(remAtoms_1);
185
+ else if (markerType > 0) {
186
+ return endOffset.toString() + ":";
187
+ }
188
+ else {
189
+ return offset.toString() + ":" + endOffset.toString();
190
+ }
191
+ }
192
+ }
193
+ exports.BeatColumn = BeatColumn;
194
+ class BeatColDAG {
195
+ constructor(layoutGroup) {
196
+ this.layoutGroup = layoutGroup;
197
+ this.beatColumns = new Map();
198
+ }
199
+ getBeatColumn(offset, endOffset, markerType = 0) {
200
+ const [bcol, newcreated] = this.ensureBeatColumn(offset, endOffset, markerType);
201
+ if (newcreated) {
202
+ if (markerType == 0) {
203
+ const [prevcol] = this.ensureBeatColumn(offset, endOffset, -1);
204
+ const [nextcol] = this.ensureBeatColumn(offset, endOffset, 1);
205
+ prevcol.addSuccessor(bcol);
206
+ bcol.addSuccessor(nextcol);
207
+ for (const other of this.beatColumns.values()) {
208
+ if (other.markerType == -1 && endOffset.equals(other.offset)) {
209
+ nextcol.addSuccessor(other);
210
+ }
211
+ else if (other.markerType == 1 && other.endOffset.equals(offset)) {
212
+ other.addSuccessor(prevcol);
213
+ }
515
214
  }
516
- finally { if (e_7) throw e_7.error; }
517
215
  }
518
- if (currBeat.filled) {
519
- if (this.onBeatFilled)
520
- this.onBeatFilled(currBeat);
216
+ }
217
+ return bcol;
218
+ }
219
+ ensureBeatColumn(offset, endOffset, markerType = 0) {
220
+ const key = BeatColumn.keyFor(offset, endOffset, markerType);
221
+ let bcol = this.beatColumns.get(key) || null;
222
+ const newcreated = bcol == null;
223
+ if (!bcol) {
224
+ bcol = new BeatColumn(offset, endOffset, markerType);
225
+ this.beatColumns.set(key, bcol);
226
+ }
227
+ return [bcol, newcreated];
228
+ }
229
+ }
230
+ exports.BeatColDAG = BeatColDAG;
231
+ class GlobalBeatLayout {
232
+ constructor() {
233
+ this.gridModelsForLine = new Map();
234
+ this.roleBeatsForLine = new Map();
235
+ this.beatColDAGsByLP = new Map();
236
+ this.gridLayoutGroup = new grids_1.GridLayoutGroup();
237
+ }
238
+ getGridModelForLine(lineid) {
239
+ let out = this.gridModelsForLine.get(lineid) || null;
240
+ if (!out) {
241
+ out = new grids_1.GridModel();
242
+ this.gridLayoutGroup.addGridModel(out);
243
+ this.gridModelsForLine.set(lineid, out);
244
+ }
245
+ return out;
246
+ }
247
+ beatColDAGForLP(lpid) {
248
+ let out = this.beatColDAGsByLP.get(lpid) || null;
249
+ if (!out) {
250
+ out = new BeatColDAG(this.gridLayoutGroup);
251
+ this.beatColDAGsByLP.set(lpid, out);
252
+ }
253
+ return out;
254
+ }
255
+ addLine(line) {
256
+ var _a, _b;
257
+ const gridModel = this.getGridModelForLine(line.uuid);
258
+ (_a = gridModel.eventHub) === null || _a === void 0 ? void 0 : _a.startBatchMode();
259
+ this.lineToRoleBeats(line, gridModel);
260
+ (_b = gridModel.eventHub) === null || _b === void 0 ? void 0 : _b.commitBatch();
261
+ }
262
+ lineToRoleBeats(line, gridModel) {
263
+ const lp = line.layoutParams;
264
+ const roleBeats = [];
265
+ this.roleBeatsForLine.set(line.uuid, roleBeats);
266
+ const lineOffset = line.offset.divbyNum(lp.beatDuration);
267
+ for (const role of line.roles) {
268
+ const bb = new BeatsBuilder(role, lp, lineOffset, ...role.atoms);
269
+ roleBeats.push(bb.beats);
270
+ for (const beat of bb.beats) {
271
+ this.addBeat(beat, gridModel);
521
272
  }
522
273
  }
523
- };
524
- return BeatsBuilder;
525
- }());
526
- exports.BeatsBuilder = BeatsBuilder;
274
+ return roleBeats;
275
+ }
276
+ addBeat(beat, gridModel) {
277
+ const line = beat.role.line;
278
+ const lp = line.layoutParams;
279
+ const beatColDAG = this.beatColDAGForLP(lp.uuid);
280
+ const [layoutLine, layoutColumn, rowOffset] = lp.getBeatLocation(beat);
281
+ const colEnd = rowOffset.plus(beat.duration, true);
282
+ const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);
283
+ const roleIndex = beat.role.line.indexOfRole(beat.role.name);
284
+ const realRow = line.roles.length * (layoutLine + Math.floor(beat.index / lp.totalBeats)) + roleIndex;
285
+ const realCol = 1 + layoutColumn * 3;
286
+ const preMarkers = beat.preMarkers;
287
+ if (preMarkers.length > 0) {
288
+ const val = {
289
+ beat: beat,
290
+ markers: preMarkers,
291
+ };
292
+ const precol = beatColDAG.getBeatColumn(rowOffset, colEnd, -1);
293
+ gridModel.setValue(realRow, realCol - 1, val, (gridRow, col) => {
294
+ const cell = new grids_1.GridCell(gridRow, col);
295
+ cell.colAlign = precol;
296
+ return cell;
297
+ });
298
+ }
299
+ const postMarkers = beat.postMarkers;
300
+ if (postMarkers.length > 0) {
301
+ const val = {
302
+ beat: beat,
303
+ markers: postMarkers,
304
+ };
305
+ const postcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 1);
306
+ gridModel.setValue(realRow, realCol + 1, val, (gridRow, col) => {
307
+ const cell = new grids_1.GridCell(gridRow, col);
308
+ cell.colAlign = postcol;
309
+ return cell;
310
+ });
311
+ }
312
+ return gridModel.setValue(realRow, realCol, beat, (gridRow, col) => {
313
+ const cell = new grids_1.GridCell(gridRow, col);
314
+ cell.colAlign = bcol;
315
+ return cell;
316
+ });
317
+ }
318
+ }
319
+ exports.GlobalBeatLayout = GlobalBeatLayout;
527
320
  //# sourceMappingURL=beats.js.map