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/core.js CHANGED
@@ -1,30 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
3
  if (k2 === undefined) k2 = k;
30
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -48,48 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
48
22
  __setModuleDefault(result, mod);
49
23
  return result;
50
24
  };
51
- var __read = (this && this.__read) || function (o, n) {
52
- var m = typeof Symbol === "function" && o[Symbol.iterator];
53
- if (!m) return o;
54
- var i = m.call(o), r, ar = [], e;
55
- try {
56
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
57
- }
58
- catch (error) { e = { error: error }; }
59
- finally {
60
- try {
61
- if (r && !r.done && (m = i["return"])) m.call(i);
62
- }
63
- finally { if (e) throw e.error; }
64
- }
65
- return ar;
66
- };
67
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
68
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
69
- if (ar || !(i in from)) {
70
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
71
- ar[i] = from[i];
72
- }
73
- }
74
- return to.concat(ar || Array.prototype.slice.call(from));
75
- };
76
- var __values = (this && this.__values) || function(o) {
77
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
78
- if (m) return m.call(o);
79
- if (o && typeof o.length === "number") return {
80
- next: function () {
81
- if (o && i >= o.length) o = void 0;
82
- return { value: o && o[i++], done: !o };
83
- }
84
- };
85
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
86
- };
87
25
  Object.defineProperty(exports, "__esModule", { value: true });
88
26
  exports.Role = exports.Line = exports.Group = exports.Note = exports.Syllable = exports.Literal = exports.Space = exports.Rest = exports.Marker = exports.LeafAtom = exports.Atom = exports.AtomType = void 0;
89
- var TSU = __importStar(require("@panyam/tsutils"));
90
- var entity_1 = require("./entity");
91
- var ZERO = TSU.Num.Fraction.ZERO;
92
- var ONE = TSU.Num.Fraction.ONE;
27
+ const TSU = __importStar(require("@panyam/tsutils"));
28
+ const entity_1 = require("./entity");
29
+ const ZERO = TSU.Num.Fraction.ZERO;
30
+ const ONE = TSU.Num.Fraction.ONE;
93
31
  var AtomType;
94
32
  (function (AtomType) {
95
33
  AtomType["NOTE"] = "Note";
@@ -101,289 +39,245 @@ var AtomType;
101
39
  AtomType["REST"] = "Rest";
102
40
  AtomType["MARKER"] = "Marker";
103
41
  })(AtomType = exports.AtomType || (exports.AtomType = {}));
104
- var Atom = (function (_super) {
105
- __extends(Atom, _super);
106
- function Atom(duration) {
107
- if (duration === void 0) { duration = ONE; }
108
- var _this = _super.call(this) || this;
109
- _this.nextSibling = null;
110
- _this.prevSibling = null;
111
- _this.parentGroup = null;
112
- _this.isContinuation = false;
113
- _this._duration = duration || ONE;
114
- return _this;
115
- }
116
- Atom.prototype.debugValue = function () {
117
- var out = _super.prototype.debugValue.call(this);
42
+ class Atom extends entity_1.TimedEntity {
43
+ constructor(duration = ONE) {
44
+ super();
45
+ this.nextSibling = null;
46
+ this.prevSibling = null;
47
+ this.parentGroup = null;
48
+ this.isContinuation = false;
49
+ this._duration = duration || ONE;
50
+ }
51
+ debugValue() {
52
+ const out = super.debugValue();
118
53
  if (!this.duration.isOne) {
119
54
  out.duration = this.duration.factorized.toString();
120
55
  }
121
56
  if (this.isContinuation) {
122
57
  out.isContinuation = true;
123
58
  }
59
+ if ((this.markersBefore || []).length > 0) {
60
+ out.mbef = this.markersBefore.map((m) => m.debugValue());
61
+ }
62
+ if ((this.markersAfter || []).length > 0) {
63
+ out.maft = this.markersAfter.map((m) => m.debugValue());
64
+ }
124
65
  return out;
125
- };
126
- Atom.prototype.copyTo = function (another) {
127
- _super.prototype.copyTo.call(this, another);
66
+ }
67
+ copyTo(another) {
68
+ super.copyTo(another);
128
69
  another._duration = new TSU.Num.Fraction(this.duration.num, this.duration.den);
129
- };
130
- Object.defineProperty(Atom.prototype, "duration", {
131
- get: function () {
132
- return this._duration;
133
- },
134
- set: function (d) {
135
- this._duration = d;
136
- },
137
- enumerable: false,
138
- configurable: true
139
- });
140
- return Atom;
141
- }(entity_1.TimedEntity));
70
+ }
71
+ get duration() {
72
+ return this._duration;
73
+ }
74
+ set duration(d) {
75
+ this._duration = d;
76
+ }
77
+ }
142
78
  exports.Atom = Atom;
143
- var LeafAtom = (function (_super) {
144
- __extends(LeafAtom, _super);
145
- function LeafAtom() {
146
- var _this = _super !== null && _super.apply(this, arguments) || this;
147
- _this.beforeRest = false;
148
- return _this;
149
- }
150
- LeafAtom.prototype.splitAt = function (duration) {
79
+ class LeafAtom extends Atom {
80
+ constructor() {
81
+ super(...arguments);
82
+ this.beforeRest = false;
83
+ }
84
+ splitAt(duration) {
151
85
  if (this.duration.cmp(duration) > 0) {
152
- var spillOver = this.createSpilloverSpace(this.duration.minus(duration));
86
+ const spillOver = this.createSpilloverSpace(this.duration.minus(duration));
153
87
  spillOver.isContinuation = true;
154
88
  this.duration = duration;
155
89
  return spillOver;
156
90
  }
157
91
  return null;
158
- };
159
- LeafAtom.prototype.createSpilloverSpace = function (duration) {
92
+ }
93
+ createSpilloverSpace(duration) {
160
94
  return new Space(duration);
161
- };
162
- LeafAtom.prototype.debugValue = function () {
163
- return this.beforeRest ? __assign(__assign({}, _super.prototype.debugValue.call(this)), { beforeRest: true }) : _super.prototype.debugValue.call(this);
164
- };
165
- return LeafAtom;
166
- }(Atom));
95
+ }
96
+ debugValue() {
97
+ return this.beforeRest ? Object.assign(Object.assign({}, super.debugValue()), { beforeRest: true }) : super.debugValue();
98
+ }
99
+ }
167
100
  exports.LeafAtom = LeafAtom;
168
- var Marker = (function (_super) {
169
- __extends(Marker, _super);
170
- function Marker(text, isBefore) {
171
- if (isBefore === void 0) { isBefore = true; }
172
- var _this = _super.call(this, ZERO) || this;
173
- _this.text = text;
174
- _this.isBefore = isBefore;
175
- return _this;
176
- }
177
- Marker.prototype.debugValue = function () {
178
- return __assign(__assign({}, _super.prototype.debugValue.call(this)), { text: this.text, before: this.isBefore });
179
- };
180
- Marker.prototype.toString = function () {
181
- return "Marker(".concat(this.text, "-").concat(this.isBefore, ")");
182
- };
183
- return Marker;
184
- }(LeafAtom));
101
+ class Marker extends entity_1.Entity {
102
+ constructor(text, isBefore = true) {
103
+ super();
104
+ this.text = text;
105
+ this.isBefore = isBefore;
106
+ }
107
+ debugValue() {
108
+ return Object.assign(Object.assign({}, super.debugValue()), { text: this.text, before: this.isBefore });
109
+ }
110
+ toString() {
111
+ return `Marker(${this.text}-${this.isBefore})`;
112
+ }
113
+ }
185
114
  exports.Marker = Marker;
186
- var Rest = (function (_super) {
187
- __extends(Rest, _super);
188
- function Rest() {
189
- return _super.call(this, ZERO) || this;
115
+ class Rest extends LeafAtom {
116
+ constructor() {
117
+ super(ZERO);
190
118
  }
191
- return Rest;
192
- }(LeafAtom));
119
+ }
193
120
  exports.Rest = Rest;
194
- var Space = (function (_super) {
195
- __extends(Space, _super);
196
- function Space(duration, isSilent) {
197
- if (duration === void 0) { duration = ONE; }
198
- if (isSilent === void 0) { isSilent = false; }
199
- var _this = _super.call(this, duration) || this;
200
- _this.isSilent = false;
201
- _this.isSilent = isSilent;
202
- return _this;
203
- }
204
- Space.prototype.debugValue = function () {
205
- return __assign(__assign({}, _super.prototype.debugValue.call(this)), { isSilent: this.isSilent });
206
- };
207
- Space.prototype.toString = function () {
208
- return "Space(".concat(this.duration, "-").concat(this.isSilent, ")");
209
- };
210
- Space.prototype.copyTo = function (another) {
211
- _super.prototype.copyTo.call(this, another);
121
+ class Space extends LeafAtom {
122
+ constructor(duration = ONE, isSilent = false) {
123
+ super(duration);
124
+ this.isSilent = false;
125
+ this.isSilent = isSilent;
126
+ }
127
+ debugValue() {
128
+ return Object.assign(Object.assign({}, super.debugValue()), { isSilent: this.isSilent });
129
+ }
130
+ toString() {
131
+ return `Space(${this.duration}-${this.isSilent})`;
132
+ }
133
+ copyTo(another) {
134
+ super.copyTo(another);
212
135
  another.isSilent = this.isSilent;
213
- };
214
- Space.prototype.equals = function (another) {
215
- return _super.prototype.equals.call(this, another) && this.isSilent == another.isSilent;
216
- };
217
- Space.prototype.createSpilloverSpace = function (duration) {
218
- var out = _super.prototype.createSpilloverSpace.call(this, duration);
136
+ }
137
+ equals(another) {
138
+ return super.equals(another) && this.isSilent == another.isSilent;
139
+ }
140
+ createSpilloverSpace(duration) {
141
+ const out = super.createSpilloverSpace(duration);
219
142
  out.isSilent = this.isSilent;
220
143
  return out;
221
- };
222
- return Space;
223
- }(LeafAtom));
144
+ }
145
+ }
224
146
  exports.Space = Space;
225
- var Literal = (function (_super) {
226
- __extends(Literal, _super);
227
- function Literal(value, duration) {
228
- if (duration === void 0) { duration = ONE; }
229
- var _this = _super.call(this, duration) || this;
230
- _this.value = value;
231
- _this.embelishments = [];
232
- return _this;
233
- }
234
- Literal.prototype.debugValue = function () {
235
- var out = __assign(__assign({}, _super.prototype.debugValue.call(this)), { value: this.value });
147
+ class Literal extends LeafAtom {
148
+ constructor(value, duration = ONE) {
149
+ super(duration);
150
+ this.value = value;
151
+ this.embelishments = [];
152
+ }
153
+ debugValue() {
154
+ const out = Object.assign(Object.assign({}, super.debugValue()), { value: this.value });
236
155
  if (this.embelishments.length > 0) {
237
- out.embs = this.embelishments.map(function (e) { return ("debugValue" in e ? e.debugValue() : e); });
156
+ out.embs = this.embelishments.map((e) => ("debugValue" in e ? e.debugValue() : e));
238
157
  }
239
158
  return out;
240
- };
241
- Literal.prototype.toString = function () {
242
- return "Lit(".concat(this.duration, "-").concat(this.value, ")");
243
- };
244
- Literal.prototype.equals = function (another) {
245
- return _super.prototype.equals.call(this, another) && this.value == another.value;
246
- };
247
- Literal.prototype.copyTo = function (another) {
248
- _super.prototype.copyTo.call(this, another);
159
+ }
160
+ toString() {
161
+ return `Lit(${this.duration}-${this.value})`;
162
+ }
163
+ equals(another) {
164
+ return super.equals(another) && this.value == another.value;
165
+ }
166
+ copyTo(another) {
167
+ super.copyTo(another);
249
168
  another.value = this.value;
250
- };
251
- return Literal;
252
- }(LeafAtom));
253
- exports.Literal = Literal;
254
- var Syllable = (function (_super) {
255
- __extends(Syllable, _super);
256
- function Syllable() {
257
- return _super !== null && _super.apply(this, arguments) || this;
258
169
  }
259
- Syllable.fromLit = function (lit) {
170
+ }
171
+ exports.Literal = Literal;
172
+ class Syllable extends Literal {
173
+ static fromLit(lit) {
260
174
  if (lit.type == AtomType.SYLLABLE)
261
175
  return lit;
262
- var out = new Syllable(lit.value, lit.duration);
176
+ const out = new Syllable(lit.value, lit.duration);
263
177
  out.embelishments = lit.embelishments;
264
178
  out.beforeRest = lit.beforeRest;
265
179
  return out;
266
- };
267
- Syllable.prototype.toString = function () {
268
- return "Syll(".concat(this.duration, "-").concat(this.value, ")");
269
- };
270
- return Syllable;
271
- }(Literal));
180
+ }
181
+ toString() {
182
+ return `Syll(${this.duration}-${this.value})`;
183
+ }
184
+ }
272
185
  exports.Syllable = Syllable;
273
- var Note = (function (_super) {
274
- __extends(Note, _super);
275
- function Note(value, duration, octave, shift) {
276
- if (duration === void 0) { duration = ONE; }
277
- if (octave === void 0) { octave = 0; }
278
- if (shift === void 0) { shift = 0; }
279
- var _this = _super.call(this, value, duration) || this;
280
- _this.octave = 0;
281
- _this.shift = 0;
282
- _this.octave = octave;
283
- _this.shift = shift;
284
- return _this;
285
- }
286
- Note.fromLit = function (lit) {
186
+ class Note extends Literal {
187
+ constructor(value, duration = ONE, octave = 0, shift = 0) {
188
+ super(value, duration);
189
+ this.octave = 0;
190
+ this.shift = 0;
191
+ this.octave = octave;
192
+ this.shift = shift;
193
+ }
194
+ static fromLit(lit) {
287
195
  if (lit.type == AtomType.NOTE)
288
196
  return lit;
289
- var out = new Note(lit.value, lit.duration);
197
+ const out = new Note(lit.value, lit.duration);
290
198
  out.embelishments = lit.embelishments;
291
199
  out.beforeRest = lit.beforeRest;
292
200
  return out;
293
- };
294
- Note.prototype.debugValue = function () {
295
- var out = __assign({}, _super.prototype.debugValue.call(this));
201
+ }
202
+ debugValue() {
203
+ const out = Object.assign({}, super.debugValue());
296
204
  if (this.octave != 0)
297
205
  out.octave = this.octave;
298
206
  if (this.shift != 0)
299
207
  out.shift = this.shift;
300
208
  return out;
301
- };
302
- Note.prototype.toString = function () {
303
- return "Note(".concat(this.duration, "-").concat(this.value, "-").concat(this.octave, ")");
304
- };
305
- Note.prototype.equals = function (another) {
306
- return _super.prototype.equals.call(this, another) && this.octave == another.octave && this.shift == another.shift;
307
- };
308
- Note.prototype.copyTo = function (another) {
309
- _super.prototype.copyTo.call(this, another);
209
+ }
210
+ toString() {
211
+ return `Note(${this.duration}-${this.value}-${this.octave})`;
212
+ }
213
+ equals(another) {
214
+ return super.equals(another) && this.octave == another.octave && this.shift == another.shift;
215
+ }
216
+ copyTo(another) {
217
+ super.copyTo(another);
310
218
  another.octave = this.octave;
311
219
  another.shift = this.shift;
312
- };
313
- return Note;
314
- }(Literal));
220
+ }
221
+ }
315
222
  exports.Note = Note;
316
- var Group = (function (_super) {
317
- __extends(Group, _super);
318
- function Group() {
319
- var atoms = [];
320
- for (var _i = 0; _i < arguments.length; _i++) {
321
- atoms[_i] = arguments[_i];
322
- }
323
- var _this = _super.call(this, atoms.length == 0 ? ZERO : ONE) || this;
324
- _this.durationIsMultiplier = false;
325
- _this.atoms = new TSU.Lists.ValueList();
326
- _this.addAtoms.apply(_this, __spreadArray([false], __read(atoms), false));
327
- return _this;
328
- }
329
- Group.prototype.equals = function (another, expect) {
330
- if (expect === void 0) { expect = false; }
331
- if (!_super.prototype.equals.call(this, another))
223
+ class Group extends Atom {
224
+ constructor(...atoms) {
225
+ super(atoms.length == 0 ? ZERO : ONE);
226
+ this.durationIsMultiplier = false;
227
+ this.atoms = new TSU.Lists.ValueList();
228
+ this.addAtoms(false, ...atoms);
229
+ }
230
+ equals(another, expect = false) {
231
+ if (!super.equals(another))
332
232
  return false;
333
- return this.atoms.equals(another.atoms, function (a1, a2) { return a1.equals(a2); });
334
- };
335
- Group.prototype.copyTo = function (another) {
336
- _super.prototype.copyTo.call(this, another);
233
+ return this.atoms.equals(another.atoms, (a1, a2) => a1.equals(a2));
234
+ }
235
+ copyTo(another) {
236
+ super.copyTo(another);
337
237
  another.durationIsMultiplier = this.durationIsMultiplier;
338
- this.atoms.forEach(function (atom) { return another.atoms.add(atom.clone()); });
339
- };
340
- Object.defineProperty(Group.prototype, "duration", {
341
- get: function () {
342
- if (this.durationIsMultiplier) {
343
- return this.totalChildDuration.divby(this._duration);
344
- }
345
- else {
346
- return this._duration;
347
- }
348
- },
349
- enumerable: false,
350
- configurable: true
351
- });
352
- Group.prototype.setDurationAsMultiplier = function (asMultiplier) {
353
- if (asMultiplier === void 0) { asMultiplier = true; }
238
+ this.atoms.forEach((atom) => another.atoms.add(atom.clone()));
239
+ }
240
+ get duration() {
241
+ if (this.durationIsMultiplier) {
242
+ return this.totalChildDuration.divby(this._duration);
243
+ }
244
+ else {
245
+ return this._duration;
246
+ }
247
+ }
248
+ setDurationAsMultiplier(asMultiplier = true) {
354
249
  this.durationIsMultiplier = asMultiplier;
355
250
  return this;
356
- };
357
- Group.prototype.setDuration = function (d, asMultiplier) {
358
- if (asMultiplier === void 0) { asMultiplier = false; }
251
+ }
252
+ setDuration(d, asMultiplier = false) {
359
253
  this._duration = d;
360
254
  this.durationIsMultiplier = asMultiplier;
361
255
  return this;
362
- };
363
- Group.prototype.debugValue = function () {
364
- var out = __assign(__assign({}, _super.prototype.debugValue.call(this)), { atoms: Array.from(this.atoms.values(), function (a) { return a.debugValue(); }) });
256
+ }
257
+ debugValue() {
258
+ const out = Object.assign(Object.assign({}, super.debugValue()), { atoms: Array.from(this.atoms.values(), (a) => a.debugValue()) });
365
259
  if (this.durationIsMultiplier)
366
260
  out.durationIsMultiplier = true;
367
261
  return out;
368
- };
369
- Group.prototype.splitAt = function (requiredDuration) {
262
+ }
263
+ splitAt(requiredDuration) {
370
264
  if (this.duration.isLTE(requiredDuration) || requiredDuration.isLTE(ZERO)) {
371
265
  return null;
372
266
  }
373
- var targetGroup = new Group();
267
+ const targetGroup = new Group();
374
268
  if (this.durationIsMultiplier) {
375
269
  targetGroup.durationIsMultiplier = true;
376
270
  targetGroup._duration = this._duration;
377
271
  }
378
- var remainingDur = this.duration;
379
- var totalChildDuration = this.totalChildDuration;
380
- var durationFactor = this.durationIsMultiplier
272
+ let remainingDur = this.duration;
273
+ const totalChildDuration = this.totalChildDuration;
274
+ const durationFactor = this.durationIsMultiplier
381
275
  ? ONE.divby(this._duration)
382
276
  : this._duration.divby(totalChildDuration, true);
383
277
  while (remainingDur.isGT(requiredDuration) && this.atoms.last) {
384
- var lastChild = this.atoms.last;
385
- var childDuration = lastChild.duration.times(durationFactor);
386
- var newDuration = remainingDur.minus(childDuration);
278
+ const lastChild = this.atoms.last;
279
+ const childDuration = lastChild.duration.times(durationFactor);
280
+ const newDuration = remainingDur.minus(childDuration);
387
281
  if (newDuration.isGTE(requiredDuration)) {
388
282
  this.removeAtoms(true, lastChild);
389
283
  targetGroup.insertAtomsAt(targetGroup.atoms.first, true, lastChild);
@@ -392,8 +286,8 @@ var Group = (function (_super) {
392
286
  }
393
287
  }
394
288
  else {
395
- var newRequiredDur = requiredDuration.minus(newDuration, true).divby(durationFactor, true);
396
- var spillOver = lastChild.splitAt(newRequiredDur);
289
+ const newRequiredDur = requiredDuration.minus(newDuration, true).divby(durationFactor, true);
290
+ const spillOver = lastChild.splitAt(newRequiredDur);
397
291
  if (spillOver == null) {
398
292
  throw new Error("Spill over cannot be null here");
399
293
  }
@@ -411,52 +305,32 @@ var Group = (function (_super) {
411
305
  remainingDur = newDuration;
412
306
  }
413
307
  return targetGroup;
414
- };
415
- Object.defineProperty(Group.prototype, "totalChildDuration", {
416
- get: function () {
417
- var out = ZERO;
418
- this.atoms.forEach(function (atom) { return (out = out.plus(atom.duration)); });
419
- return out;
420
- },
421
- enumerable: false,
422
- configurable: true
423
- });
424
- Group.prototype.insertAtomsAt = function (beforeAtom, adjustDuration) {
425
- var e_1, _a;
426
- if (adjustDuration === void 0) { adjustDuration = false; }
427
- var atoms = [];
428
- for (var _i = 2; _i < arguments.length; _i++) {
429
- atoms[_i - 2] = arguments[_i];
430
- }
308
+ }
309
+ get totalChildDuration() {
310
+ let out = ZERO;
311
+ this.atoms.forEach((atom) => (out = out.plus(atom.duration)));
312
+ return out;
313
+ }
314
+ insertAtomsAt(beforeAtom, adjustDuration = false, ...atoms) {
431
315
  adjustDuration = adjustDuration && !this.durationIsMultiplier;
432
- var oldChildDuration = adjustDuration ? this.totalChildDuration : ONE;
433
- try {
434
- for (var atoms_1 = __values(atoms), atoms_1_1 = atoms_1.next(); !atoms_1_1.done; atoms_1_1 = atoms_1.next()) {
435
- var atom = atoms_1_1.value;
436
- if (atom.parentGroup != null) {
437
- if (atom.parentGroup != this) {
438
- throw new Error("Atom belongs to another parent. Remove it first");
439
- }
440
- atom.parentGroup.removeAtoms(false, atom);
316
+ const oldChildDuration = adjustDuration ? this.totalChildDuration : ONE;
317
+ for (const atom of atoms) {
318
+ if (atom.parentGroup != null) {
319
+ if (atom.parentGroup != this) {
320
+ throw new Error("Atom belongs to another parent. Remove it first");
441
321
  }
442
- if (atom.type == AtomType.REST) {
443
- var last = this.atoms.last;
444
- if (last && last.type != AtomType.GROUP && last.type != AtomType.LABEL) {
445
- last.beforeRest = true;
446
- }
447
- }
448
- else {
449
- atom.parentGroup = this;
450
- this.atoms.add(atom, beforeAtom);
322
+ atom.parentGroup.removeAtoms(false, atom);
323
+ }
324
+ if (atom.type == AtomType.REST) {
325
+ const last = this.atoms.last;
326
+ if (last && last.type != AtomType.GROUP && last.type != AtomType.LABEL) {
327
+ last.beforeRest = true;
451
328
  }
452
329
  }
453
- }
454
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
455
- finally {
456
- try {
457
- if (atoms_1_1 && !atoms_1_1.done && (_a = atoms_1.return)) _a.call(atoms_1);
330
+ else {
331
+ atom.parentGroup = this;
332
+ this.atoms.add(atom, beforeAtom);
458
333
  }
459
- finally { if (e_1) throw e_1.error; }
460
334
  }
461
335
  if (adjustDuration) {
462
336
  if (this._duration.isZero) {
@@ -465,47 +339,26 @@ var Group = (function (_super) {
465
339
  this._duration = this.totalChildDuration;
466
340
  }
467
341
  else {
468
- var scaleFactor = this.totalChildDuration.divby(oldChildDuration);
342
+ const scaleFactor = this.totalChildDuration.divby(oldChildDuration);
469
343
  this._duration = this._duration.times(scaleFactor, true);
470
344
  }
471
345
  }
472
346
  return this;
473
- };
474
- Group.prototype.addAtoms = function (adjustDuration) {
475
- if (adjustDuration === void 0) { adjustDuration = false; }
476
- var atoms = [];
477
- for (var _i = 1; _i < arguments.length; _i++) {
478
- atoms[_i - 1] = arguments[_i];
479
- }
480
- return this.insertAtomsAt.apply(this, __spreadArray([null, adjustDuration], __read(atoms), false));
481
- };
482
- Group.prototype.removeAtoms = function (adjustDuration) {
483
- var e_2, _a;
484
- if (adjustDuration === void 0) { adjustDuration = false; }
485
- var atoms = [];
486
- for (var _i = 1; _i < arguments.length; _i++) {
487
- atoms[_i - 1] = arguments[_i];
488
- }
347
+ }
348
+ addAtoms(adjustDuration = false, ...atoms) {
349
+ return this.insertAtomsAt(null, adjustDuration, ...atoms);
350
+ }
351
+ removeAtoms(adjustDuration = false, ...atoms) {
489
352
  adjustDuration = adjustDuration && !this.durationIsMultiplier;
490
- var oldChildDuration = adjustDuration ? this.totalChildDuration : ONE;
491
- try {
492
- for (var atoms_2 = __values(atoms), atoms_2_1 = atoms_2.next(); !atoms_2_1.done; atoms_2_1 = atoms_2.next()) {
493
- var atom = atoms_2_1.value;
494
- if (atom.parentGroup == this) {
495
- this.atoms.remove(atom);
496
- atom.parentGroup = null;
497
- }
498
- else if (atom.parentGroup != null) {
499
- throw new Error("Atom cannot be removed as it does not belong to this group");
500
- }
353
+ const oldChildDuration = adjustDuration ? this.totalChildDuration : ONE;
354
+ for (const atom of atoms) {
355
+ if (atom.parentGroup == this) {
356
+ this.atoms.remove(atom);
357
+ atom.parentGroup = null;
501
358
  }
502
- }
503
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
504
- finally {
505
- try {
506
- if (atoms_2_1 && !atoms_2_1.done && (_a = atoms_2.return)) _a.call(atoms_2);
359
+ else if (atom.parentGroup != null) {
360
+ throw new Error("Atom cannot be removed as it does not belong to this group");
507
361
  }
508
- finally { if (e_2) throw e_2.error; }
509
362
  }
510
363
  if (adjustDuration) {
511
364
  if (this._duration.isZero) {
@@ -514,161 +367,103 @@ var Group = (function (_super) {
514
367
  this._duration = this.totalChildDuration;
515
368
  }
516
369
  else {
517
- var scaleFactor = this.totalChildDuration.divby(oldChildDuration);
370
+ const scaleFactor = this.totalChildDuration.divby(oldChildDuration);
518
371
  this._duration = this._duration.times(scaleFactor, true);
519
372
  }
520
373
  }
521
374
  return this;
522
- };
523
- return Group;
524
- }(Atom));
375
+ }
376
+ }
525
377
  exports.Group = Group;
526
- var Line = (function (_super) {
527
- __extends(Line, _super);
528
- function Line() {
529
- var _this = _super !== null && _super.apply(this, arguments) || this;
530
- _this.offset = ZERO;
531
- _this.roles = [];
532
- _this.marginText = "";
533
- return _this;
534
- }
535
- Object.defineProperty(Line.prototype, "isEmpty", {
536
- get: function () {
537
- var e_3, _a;
538
- try {
539
- for (var _b = __values(this.roles), _c = _b.next(); !_c.done; _c = _b.next()) {
540
- var r = _c.value;
541
- if (!r.isEmpty)
542
- return false;
543
- }
544
- }
545
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
546
- finally {
547
- try {
548
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
549
- }
550
- finally { if (e_3) throw e_3.error; }
551
- }
552
- return true;
553
- },
554
- enumerable: false,
555
- configurable: true
556
- });
557
- Line.prototype.debugValue = function () {
558
- var out = __assign(__assign({}, _super.prototype.debugValue.call(this)), { roles: this.roles.map(function (r) { return r.debugValue(); }) });
378
+ class Line extends entity_1.Entity {
379
+ constructor() {
380
+ super(...arguments);
381
+ this.offset = ZERO;
382
+ this.roles = [];
383
+ this.marginText = "";
384
+ }
385
+ indexOfRole(name) {
386
+ for (let i = 0; i < this.roles.length; i++) {
387
+ if (this.roles[i].name == name)
388
+ return i;
389
+ }
390
+ return -1;
391
+ }
392
+ get isEmpty() {
393
+ for (const r of this.roles)
394
+ if (!r.isEmpty)
395
+ return false;
396
+ return true;
397
+ }
398
+ debugValue() {
399
+ const out = Object.assign(Object.assign({}, super.debugValue()), { roles: this.roles.map((r) => r.debugValue()) });
559
400
  if (!this.offset.isZero) {
560
401
  out.offset = this.offset.toString();
561
402
  }
562
403
  return out;
563
- };
564
- Line.prototype.copyTo = function (another) {
565
- _super.prototype.copyTo.call(this, another);
566
- another.roles = this.roles.map(function (r) { return r.clone(); });
567
- };
568
- Line.prototype.addAtoms = function (roleName, defaultToNotes) {
569
- var atoms = [];
570
- for (var _i = 2; _i < arguments.length; _i++) {
571
- atoms[_i - 2] = arguments[_i];
572
- }
573
- var role = this.ensureRole(roleName, defaultToNotes);
574
- role.addAtoms.apply(role, __spreadArray([], __read(atoms), false));
404
+ }
405
+ copyTo(another) {
406
+ super.copyTo(another);
407
+ another.roles = this.roles.map((r) => r.clone());
408
+ }
409
+ addAtoms(roleName, defaultToNotes, ...atoms) {
410
+ const role = this.ensureRole(roleName, defaultToNotes);
411
+ role.addAtoms(...atoms);
575
412
  return this;
576
- };
577
- Line.prototype.ensureRole = function (roleName, defaultToNotes) {
578
- var ri = this.roles.findIndex(function (r) { return r.name == roleName; });
413
+ }
414
+ ensureRole(roleName, defaultToNotes) {
415
+ let ri = this.roles.findIndex((r) => r.name == roleName);
579
416
  if (ri < 0) {
580
417
  ri = this.roles.length;
581
- var role = new Role(this, roleName);
418
+ const role = new Role(this, roleName);
582
419
  role.defaultToNotes = defaultToNotes;
583
420
  this.roles.push(role);
584
421
  }
585
422
  return this.roles[ri];
586
- };
587
- Object.defineProperty(Line.prototype, "duration", {
588
- get: function () {
589
- var e_4, _a;
590
- var max = ZERO;
591
- try {
592
- for (var _b = __values(this.roles), _c = _b.next(); !_c.done; _c = _b.next()) {
593
- var role = _c.value;
594
- max = TSU.Num.Fraction.max(role.duration, max);
595
- }
596
- }
597
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
598
- finally {
599
- try {
600
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
601
- }
602
- finally { if (e_4) throw e_4.error; }
603
- }
604
- return max;
605
- },
606
- enumerable: false,
607
- configurable: true
608
- });
609
- return Line;
610
- }(entity_1.Entity));
611
- exports.Line = Line;
612
- var Role = (function (_super) {
613
- __extends(Role, _super);
614
- function Role(line, name) {
615
- var _this = _super.call(this) || this;
616
- _this.line = line;
617
- _this.name = name;
618
- _this.defaultToNotes = true;
619
- _this.atoms = [];
620
- return _this;
621
- }
622
- Object.defineProperty(Role.prototype, "isEmpty", {
623
- get: function () {
624
- return this.atoms.length == 0;
625
- },
626
- enumerable: false,
627
- configurable: true
628
- });
629
- Role.prototype.debugValue = function () {
630
- return { name: this.name, atoms: this.atoms.map(function (a) { return a.debugValue(); }) };
631
- };
632
- Role.prototype.addAtoms = function () {
633
- var e_5, _a;
634
- var atoms = [];
635
- for (var _i = 0; _i < arguments.length; _i++) {
636
- atoms[_i] = arguments[_i];
423
+ }
424
+ get duration() {
425
+ let max = ZERO;
426
+ for (const role of this.roles) {
427
+ max = TSU.Num.Fraction.max(role.duration, max);
637
428
  }
638
- var last = null;
639
- try {
640
- for (var atoms_3 = __values(atoms), atoms_3_1 = atoms_3.next(); !atoms_3_1.done; atoms_3_1 = atoms_3.next()) {
641
- var atom = atoms_3_1.value;
642
- if (atom.type == AtomType.REST) {
643
- if (last && last.type != AtomType.GROUP && last.type != AtomType.LABEL) {
644
- last.beforeRest = true;
645
- }
646
- }
647
- else {
648
- this.atoms.push(atom);
429
+ return max;
430
+ }
431
+ }
432
+ exports.Line = Line;
433
+ class Role extends entity_1.Entity {
434
+ constructor(line, name) {
435
+ super();
436
+ this.line = line;
437
+ this.name = name;
438
+ this.defaultToNotes = true;
439
+ this.atoms = [];
440
+ }
441
+ get isEmpty() {
442
+ return this.atoms.length == 0;
443
+ }
444
+ debugValue() {
445
+ return { name: this.name, atoms: this.atoms.map((a) => a.debugValue()) };
446
+ }
447
+ addAtoms(...atoms) {
448
+ let last = null;
449
+ for (const atom of atoms) {
450
+ if (atom.type == AtomType.REST) {
451
+ if (last && last.type != AtomType.GROUP && last.type != AtomType.LABEL) {
452
+ last.beforeRest = true;
649
453
  }
650
- last = atom;
651
454
  }
652
- }
653
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
654
- finally {
655
- try {
656
- if (atoms_3_1 && !atoms_3_1.done && (_a = atoms_3.return)) _a.call(atoms_3);
455
+ else {
456
+ this.atoms.push(atom);
657
457
  }
658
- finally { if (e_5) throw e_5.error; }
458
+ last = atom;
659
459
  }
660
- };
661
- Role.prototype.copyTo = function (another) {
662
- another.addAtoms.apply(another, __spreadArray([], __read(this.atoms), false));
663
- };
664
- Object.defineProperty(Role.prototype, "duration", {
665
- get: function () {
666
- return this.atoms.reduce(function (a, b) { return a.plus(b.duration); }, ZERO);
667
- },
668
- enumerable: false,
669
- configurable: true
670
- });
671
- return Role;
672
- }(entity_1.Entity));
460
+ }
461
+ copyTo(another) {
462
+ another.addAtoms(...this.atoms);
463
+ }
464
+ get duration() {
465
+ return this.atoms.reduce((a, b) => a.plus(b.duration), ZERO);
466
+ }
467
+ }
673
468
  exports.Role = Role;
674
469
  //# sourceMappingURL=core.js.map