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