notations 0.0.47 → 0.0.50

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