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.
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 +73 -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 +230 -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 +71 -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 +225 -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
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,12 @@ var Beat = (function () {
76
41
  this.instance = instance;
77
42
  this.prevBeat = prevBeat;
78
43
  this.nextBeat = nextBeat;
44
+ this.uuid = Beat.idCounter++;
79
45
  this.layoutLine = -1;
80
46
  this.layoutColumn = -1;
81
- this.uuid = Beat.idCounter++;
82
47
  this.atomIsPlaceholder = false;
83
48
  }
84
- Beat.prototype.debugValue = function () {
49
+ debugValue() {
85
50
  return {
86
51
  index: this.index,
87
52
  role: this.role.name,
@@ -92,29 +57,17 @@ var Beat = (function () {
92
57
  instance: this.instance,
93
58
  atom: this.atom.debugValue(),
94
59
  };
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) {
60
+ }
61
+ get endOffset() {
62
+ return this.offset.plus(this.duration);
63
+ }
64
+ get filled() {
65
+ return this.remaining.isZero;
66
+ }
67
+ get remaining() {
68
+ return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;
69
+ }
70
+ add(atom) {
118
71
  if (this.remaining.cmp(atom.duration) < 0) {
119
72
  return false;
120
73
  }
@@ -129,399 +82,185 @@ var Beat = (function () {
129
82
  this.atom.addAtoms(true, atom);
130
83
  }
131
84
  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
- }());
85
+ }
86
+ }
171
87
  exports.Beat = Beat;
172
- var BeatLayout = (function () {
173
- function BeatLayout(layoutParams) {
88
+ Beat.idCounter = 0;
89
+ class BeatsBuilder {
90
+ constructor(role, layoutParams, startOffset = ZERO, ...atoms) {
91
+ this.role = role;
174
92
  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;
93
+ this.startOffset = startOffset;
94
+ this.beats = [];
95
+ const [, [bar, beat, instance], beatOffset, index] = layoutParams.cycle.getPosition(startOffset);
96
+ this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);
97
+ this.windowIter = new iterators_1.WindowIterator();
98
+ this.beatOffset = beatOffset;
99
+ this.startIndex = index;
100
+ this.addAtoms(...atoms);
182
101
  }
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);
192
- }
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
- }
102
+ addAtoms(...atoms) {
103
+ this.windowIter.push(...atoms);
104
+ while (this.windowIter.hasMore) {
105
+ let currBeat = this.beats[this.beats.length - 1];
106
+ if (this.beats.length == 0 || currBeat.filled) {
107
+ currBeat = this.addBeat();
213
108
  }
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
- }
109
+ const [remAtoms, filled] = this.windowIter.get(currBeat.remaining);
110
+ TSU.assert(remAtoms.length > 0, "Atleast one element should have been available here");
111
+ for (const atom of remAtoms) {
112
+ TSU.assert(currBeat.add(atom), "Should return true as we are already using a duration iterator here");
113
+ if (this.onAtomAdded)
114
+ this.onAtomAdded(atom, currBeat);
251
115
  }
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);
116
+ if (currBeat.filled) {
117
+ if (this.onBeatFilled)
118
+ this.onBeatFilled(currBeat);
257
119
  }
258
- finally { if (e_2) throw e_2.error; }
259
120
  }
260
- 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;
121
+ }
122
+ addBeat() {
123
+ const numBeats = this.beats.length;
124
+ const lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];
125
+ const nextCP = this.cycleIter.next().value;
126
+ const apb = this.layoutParams.beatDuration;
127
+ 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);
128
+ if (lastBeat == null && this.beatOffset.isGT(ZERO)) {
129
+ newBeat.add(new _1.Space(this.beatOffset.timesNum(apb)));
306
130
  }
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 = [];
131
+ if (lastBeat)
132
+ lastBeat.nextBeat = newBeat;
133
+ this.beats.push(newBeat);
134
+ if (this.onBeatAdded)
135
+ this.onBeatAdded(newBeat);
136
+ return newBeat;
357
137
  }
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) {
138
+ }
139
+ exports.BeatsBuilder = BeatsBuilder;
140
+ class BeatColumn extends grids_1.ColAlign {
141
+ constructor(offset, endOffset, markerType) {
142
+ super();
378
143
  this.offset = offset;
379
- this.duration = duration;
380
- this._x = 0;
381
- this._maxWidth = 0;
382
- this.needsLayout = false;
144
+ this.endOffset = endOffset;
145
+ this.markerType = markerType;
383
146
  this.atomSpacing = 5;
384
- this.paddingLeft = 15;
385
- this.paddingRight = 15;
386
- this.beats = [];
387
147
  offset = offset.factorized;
388
- duration = duration.factorized;
148
+ endOffset = endOffset.factorized;
149
+ this.key = BeatColumn.keyFor(offset, endOffset, markerType);
389
150
  }
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;
406
- }
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; }
151
+ static keyFor(offset, endOffset, markerType = 0) {
152
+ offset = offset.factorized;
153
+ endOffset = endOffset.factorized;
154
+ if (markerType < 0) {
155
+ return ":" + offset.toString();
414
156
  }
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;
157
+ else if (markerType > 0) {
158
+ return endOffset.toString() + ":";
426
159
  }
427
- if (right >= 0) {
428
- this.paddingRight = right;
160
+ else {
161
+ return offset.toString() + ":" + endOffset.toString();
429
162
  }
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;
163
+ }
164
+ }
165
+ exports.BeatColumn = BeatColumn;
166
+ class BeatColDAG {
167
+ constructor(layoutGroup) {
168
+ this.layoutGroup = layoutGroup;
169
+ this.beatColumns = new Map();
170
+ }
171
+ getBeatColumn(offset, endOffset, markerType = 0) {
172
+ const [bcol, newcreated] = this.ensureBeatColumn(offset, endOffset, markerType);
173
+ if (newcreated) {
174
+ if (markerType == 0) {
175
+ const [prevcol] = this.ensureBeatColumn(offset, endOffset, -1);
176
+ const [nextcol] = this.ensureBeatColumn(offset, endOffset, 1);
177
+ prevcol.addSuccessor(bcol);
178
+ bcol.addSuccessor(nextcol);
179
+ for (const other of this.beatColumns.values()) {
180
+ if (other.markerType == -1 && endOffset.equals(other.offset)) {
181
+ nextcol.addSuccessor(other);
182
+ }
183
+ else if (other.markerType == 1 && other.endOffset.equals(offset)) {
184
+ other.addSuccessor(prevcol);
185
+ }
441
186
  }
442
187
  }
443
188
  }
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);
448
- }
449
- finally { if (e_6) throw e_6.error; }
189
+ return bcol;
190
+ }
191
+ ensureBeatColumn(offset, endOffset, markerType = 0) {
192
+ const key = BeatColumn.keyFor(offset, endOffset, markerType);
193
+ let bcol = this.beatColumns.get(key) || null;
194
+ const newcreated = bcol == null;
195
+ if (!bcol) {
196
+ bcol = new BeatColumn(offset, endOffset, markerType);
197
+ this.beatColumns.set(key, bcol);
450
198
  }
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; }
463
- this.role = role;
464
- this.layoutParams = layoutParams;
465
- this.startOffset = startOffset;
466
- 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];
468
- this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);
469
- this.windowIter = new iterators_1.WindowIterator();
470
- this.beatOffset = beatOffset;
471
- this.startIndex = index;
199
+ return [bcol, newcreated];
472
200
  }
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);
479
- if (lastBeat == null && this.beatOffset.isGT(ZERO)) {
480
- newBeat.add(new _1.Space(this.beatOffset.timesNum(apb)));
201
+ }
202
+ exports.BeatColDAG = BeatColDAG;
203
+ class GlobalBeatLayout {
204
+ constructor() {
205
+ this.gridModelsForLine = new Map();
206
+ this.roleBeatsForLine = new Map();
207
+ this.beatColDAGsByLP = new Map();
208
+ this.gridLayoutGroup = new grids_1.GridLayoutGroup();
209
+ }
210
+ getGridModelForLine(lineid) {
211
+ let out = this.gridModelsForLine.get(lineid) || null;
212
+ if (!out) {
213
+ out = new grids_1.GridModel();
214
+ this.gridLayoutGroup.addGridModel(out);
215
+ this.gridModelsForLine.set(lineid, out);
481
216
  }
482
- if (lastBeat)
483
- lastBeat.nextBeat = newBeat;
484
- this.beats.push(newBeat);
485
- if (this.onBeatAdded)
486
- this.onBeatAdded(newBeat);
487
- 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];
217
+ return out;
218
+ }
219
+ beatColDAGForLP(lpid) {
220
+ let out = this.beatColDAGsByLP.get(lpid) || null;
221
+ if (!out) {
222
+ out = new BeatColDAG(this.gridLayoutGroup);
223
+ this.beatColDAGsByLP.set(lpid, out);
494
224
  }
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);
515
- }
516
- finally { if (e_7) throw e_7.error; }
517
- }
518
- if (currBeat.filled) {
519
- if (this.onBeatFilled)
520
- this.onBeatFilled(currBeat);
225
+ return out;
226
+ }
227
+ addLine(line) {
228
+ var _a, _b;
229
+ const gridModel = this.getGridModelForLine(line.uuid);
230
+ (_a = gridModel.eventHub) === null || _a === void 0 ? void 0 : _a.startBatchMode();
231
+ this.lineToRoleBeats(line, gridModel);
232
+ (_b = gridModel.eventHub) === null || _b === void 0 ? void 0 : _b.commitBatch();
233
+ }
234
+ lineToRoleBeats(line, gridModel) {
235
+ const lp = line.layoutParams;
236
+ const roleBeats = [];
237
+ this.roleBeatsForLine.set(line.uuid, roleBeats);
238
+ const lineOffset = line.offset.divbyNum(lp.beatDuration);
239
+ for (const role of line.roles) {
240
+ const bb = new BeatsBuilder(role, lp, lineOffset, ...role.atoms);
241
+ roleBeats.push(bb.beats);
242
+ for (const beat of bb.beats) {
243
+ this.addBeat(beat, gridModel);
521
244
  }
522
245
  }
523
- };
524
- return BeatsBuilder;
525
- }());
526
- exports.BeatsBuilder = BeatsBuilder;
246
+ return roleBeats;
247
+ }
248
+ addBeat(beat, gridModel) {
249
+ const line = beat.role.line;
250
+ const lp = line.layoutParams;
251
+ const beatColDAG = this.beatColDAGForLP(lp.uuid);
252
+ const [layoutLine, layoutColumn, rowOffset] = lp.getBeatLocation(beat);
253
+ const colEnd = rowOffset.plus(beat.duration, true);
254
+ const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);
255
+ const roleIndex = beat.role.line.indexOfRole(beat.role.name);
256
+ const realRow = line.roles.length * (layoutLine + Math.floor(beat.index / lp.totalBeats)) + roleIndex;
257
+ const realCol = layoutColumn * 3;
258
+ return gridModel.setValue(realRow, realCol, beat, (gridRow, col) => {
259
+ const cell = new grids_1.GridCell(gridRow, col);
260
+ cell.colAlign = bcol;
261
+ return cell;
262
+ });
263
+ }
264
+ }
265
+ exports.GlobalBeatLayout = GlobalBeatLayout;
527
266
  //# sourceMappingURL=beats.js.map