notations 0.0.46 → 0.0.49

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