notations 0.0.48 → 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 +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 +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 +217 -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 +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 +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 +211 -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/cycle.js CHANGED
@@ -1,297 +1,154 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
28
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
29
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
30
- function verb(n) { return function (v) { return step([n, v]); }; }
31
- function step(op) {
32
- if (f) throw new TypeError("Generator is already executing.");
33
- while (_) try {
34
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
35
- if (y = 0, t) op = [op[0] & 2, t.value];
36
- switch (op[0]) {
37
- case 0: case 1: t = op; break;
38
- case 4: _.label++; return { value: op[1], done: false };
39
- case 5: _.label++; y = op[1]; op = [0]; continue;
40
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
41
- default:
42
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
43
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
44
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
45
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
46
- if (t[2]) _.ops.pop();
47
- _.trys.pop(); continue;
48
- }
49
- op = body.call(thisArg, _);
50
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
51
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
52
- }
53
- };
54
- var __values = (this && this.__values) || function(o) {
55
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
56
- if (m) return m.call(o);
57
- if (o && typeof o.length === "number") return {
58
- next: function () {
59
- if (o && i >= o.length) o = void 0;
60
- return { value: o && o[i++], done: !o };
61
- }
62
- };
63
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
64
- };
65
- var __read = (this && this.__read) || function (o, n) {
66
- var m = typeof Symbol === "function" && o[Symbol.iterator];
67
- if (!m) return o;
68
- var i = m.call(o), r, ar = [], e;
69
- try {
70
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
71
- }
72
- catch (error) { e = { error: error }; }
73
- finally {
74
- try {
75
- if (r && !r.done && (m = i["return"])) m.call(i);
76
- }
77
- finally { if (e) throw e.error; }
78
- }
79
- return ar;
80
- };
81
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
82
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
83
- if (ar || !(i in from)) {
84
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
85
- ar[i] = from[i];
86
- }
87
- }
88
- return to.concat(ar || Array.prototype.slice.call(from));
89
- };
90
1
  import * as TSU from "@panyam/tsutils";
91
2
  import { TimedEntity } from "./entity";
92
- var ZERO = TSU.Num.Fraction.ZERO;
93
- var ONE = TSU.Num.Fraction.ONE;
94
- var CycleCursor = (function () {
95
- function CycleCursor(cycle, barIndex, beatIndex, instance) {
96
- if (barIndex === void 0) { barIndex = 0; }
97
- if (beatIndex === void 0) { beatIndex = 0; }
98
- if (instance === void 0) { instance = 0; }
3
+ const ZERO = TSU.Num.Fraction.ZERO;
4
+ const ONE = TSU.Num.Fraction.ONE;
5
+ export class CycleCursor {
6
+ constructor(cycle, barIndex = 0, beatIndex = 0, instance = 0) {
99
7
  this.cycle = cycle;
100
8
  this.barIndex = barIndex;
101
9
  this.beatIndex = beatIndex;
102
10
  this.instance = instance;
103
11
  }
104
- Object.defineProperty(CycleCursor.prototype, "next", {
105
- get: function () {
106
- var currBar = this.cycle.bars[this.barIndex];
107
- var result = [
108
- [this.barIndex, this.beatIndex, this.instance],
109
- currBar.beatLengths[this.beatIndex],
110
- ];
111
- this.instance++;
112
- if (!currBar.beatCounts[this.beatIndex] || this.instance >= currBar.beatCounts[this.beatIndex]) {
113
- this.instance = 0;
114
- this.beatIndex++;
115
- if (this.beatIndex >= currBar.beatLengths.length) {
116
- this.beatIndex = 0;
117
- this.barIndex++;
118
- if (this.barIndex >= this.cycle.bars.length) {
119
- this.barIndex = 0;
120
- }
121
- }
122
- }
123
- return result;
124
- },
125
- enumerable: false,
126
- configurable: true
127
- });
128
- Object.defineProperty(CycleCursor.prototype, "prev", {
129
- get: function () {
130
- var currBar = this.cycle.bars[this.barIndex];
131
- var result = [
132
- [this.barIndex, this.beatIndex, this.instance],
133
- currBar.beatLengths[this.beatIndex],
134
- ];
135
- this.instance--;
136
- if (this.instance < 0) {
137
- this.beatIndex--;
138
- if (this.beatIndex < 0) {
139
- this.barIndex--;
140
- if (this.barIndex < 0) {
141
- this.barIndex = this.cycle.bars.length - 1;
142
- }
143
- this.beatIndex = this.cycle.bars[this.barIndex].beatCount - 1;
12
+ get next() {
13
+ const currBar = this.cycle.bars[this.barIndex];
14
+ const result = [
15
+ [this.barIndex, this.beatIndex, this.instance],
16
+ currBar.beatLengths[this.beatIndex],
17
+ ];
18
+ this.instance++;
19
+ if (!currBar.beatCounts[this.beatIndex] || this.instance >= currBar.beatCounts[this.beatIndex]) {
20
+ this.instance = 0;
21
+ this.beatIndex++;
22
+ if (this.beatIndex >= currBar.beatLengths.length) {
23
+ this.beatIndex = 0;
24
+ this.barIndex++;
25
+ if (this.barIndex >= this.cycle.bars.length) {
26
+ this.barIndex = 0;
144
27
  }
145
- this.instance = (this.cycle.bars[this.barIndex].beatCounts[this.beatIndex] || 1) - 1;
146
28
  }
147
- return result;
148
- },
149
- enumerable: false,
150
- configurable: true
151
- });
152
- return CycleCursor;
153
- }());
154
- export { CycleCursor };
155
- var Bar = (function (_super) {
156
- __extends(Bar, _super);
157
- function Bar(config) {
158
- var e_1, _a, e_2, _b;
159
- if (config === void 0) { config = null; }
160
- var _this = _super.call(this, (config = config || {})) || this;
161
- _this.beatLengths = [];
162
- _this.beatCounts = [];
163
- _this.name = config.name || "";
164
- try {
165
- for (var _c = __values(config.beatLengths || []), _d = _c.next(); !_d.done; _d = _c.next()) {
166
- var bl = _d.value;
167
- if (typeof bl === "number") {
168
- _this.beatLengths.push(TSU.Num.Frac(bl));
169
- }
170
- else {
171
- _this.beatLengths.push(bl);
29
+ }
30
+ return result;
31
+ }
32
+ get prev() {
33
+ const currBar = this.cycle.bars[this.barIndex];
34
+ const result = [
35
+ [this.barIndex, this.beatIndex, this.instance],
36
+ currBar.beatLengths[this.beatIndex],
37
+ ];
38
+ this.instance--;
39
+ if (this.instance < 0) {
40
+ this.beatIndex--;
41
+ if (this.beatIndex < 0) {
42
+ this.barIndex--;
43
+ if (this.barIndex < 0) {
44
+ this.barIndex = this.cycle.bars.length - 1;
172
45
  }
46
+ this.beatIndex = this.cycle.bars[this.barIndex].beatCount - 1;
173
47
  }
48
+ this.instance = (this.cycle.bars[this.barIndex].beatCounts[this.beatIndex] || 1) - 1;
174
49
  }
175
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
176
- finally {
177
- try {
178
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
50
+ return result;
51
+ }
52
+ }
53
+ export class Bar extends TimedEntity {
54
+ constructor(config = null) {
55
+ super((config = config || {}));
56
+ this.beatLengths = [];
57
+ this.beatCounts = [];
58
+ this.name = config.name || "";
59
+ for (const bl of config.beatLengths || []) {
60
+ if (typeof bl === "number") {
61
+ this.beatLengths.push(TSU.Num.Frac(bl));
179
62
  }
180
- finally { if (e_1) throw e_1.error; }
181
- }
182
- try {
183
- for (var _e = __values(config.beatCounts || []), _f = _e.next(); !_f.done; _f = _e.next()) {
184
- var bc = _f.value;
185
- _this.beatCounts.push(bc);
63
+ else {
64
+ this.beatLengths.push(bl);
186
65
  }
187
66
  }
188
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
189
- finally {
190
- try {
191
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
192
- }
193
- finally { if (e_2) throw e_2.error; }
67
+ for (const bc of config.beatCounts || []) {
68
+ this.beatCounts.push(bc);
194
69
  }
195
- while (_this.beatCounts.length < _this.beatLengths.length) {
196
- _this.beatCounts.push(1);
70
+ while (this.beatCounts.length < this.beatLengths.length) {
71
+ this.beatCounts.push(1);
197
72
  }
198
- return _this;
199
73
  }
200
- Bar.prototype.debugValue = function () {
201
- return __assign(__assign({}, _super.prototype.debugValue.call(this)), { name: name, beatLengths: this.beatLengths });
202
- };
203
- Bar.prototype.equals = function (another) {
204
- if (!_super.prototype.equals.call(this, another))
74
+ debugValue() {
75
+ return Object.assign(Object.assign({}, super.debugValue()), { name: name, beatLengths: this.beatLengths });
76
+ }
77
+ equals(another) {
78
+ if (!super.equals(another))
205
79
  return false;
206
80
  if (this.beatLengths.length != another.beatLengths.length)
207
81
  return false;
208
82
  if (this.beatCounts.length != another.beatCounts.length)
209
83
  return false;
210
- for (var i = 0; i < this.beatLengths.length; i++) {
84
+ for (let i = 0; i < this.beatLengths.length; i++) {
211
85
  if (!this.beatLengths[i].equals(another.beatLengths[i]))
212
86
  return false;
213
87
  }
214
- for (var i = 0; i < this.beatCounts.length; i++) {
88
+ for (let i = 0; i < this.beatCounts.length; i++) {
215
89
  if (this.beatCounts[i] != another.beatCounts[i])
216
90
  return false;
217
91
  }
218
92
  return true;
219
- };
220
- Bar.prototype.copyTo = function (another) {
221
- _super.prototype.copyTo.call(this, another);
93
+ }
94
+ copyTo(another) {
95
+ super.copyTo(another);
222
96
  another.name = this.name;
223
- another.beatLengths = __spreadArray([], __read(this.beatLengths), false);
224
- another.beatCounts = __spreadArray([], __read(this.beatCounts), false);
225
- };
226
- Bar.prototype.instanceCount = function (beatIndex) {
97
+ another.beatLengths = [...this.beatLengths];
98
+ another.beatCounts = [...this.beatCounts];
99
+ }
100
+ instanceCount(beatIndex) {
227
101
  if (beatIndex > this.beatCounts.length) {
228
102
  return 1;
229
103
  }
230
104
  else {
231
105
  return this.beatCounts[beatIndex];
232
106
  }
233
- };
234
- Object.defineProperty(Bar.prototype, "beatCount", {
235
- get: function () {
236
- return this.beatLengths.length;
237
- },
238
- enumerable: false,
239
- configurable: true
240
- });
241
- Object.defineProperty(Bar.prototype, "totalBeatCount", {
242
- get: function () {
243
- var out = 0;
244
- for (var i = 0; i < this.beatLengths.length; i++) {
245
- out += this.beatCounts[i] || 1;
246
- }
247
- return out;
248
- },
249
- enumerable: false,
250
- configurable: true
251
- });
252
- Object.defineProperty(Bar.prototype, "duration", {
253
- get: function () {
254
- var total = ZERO;
255
- for (var i = 0; i < this.beatLengths.length; i++) {
256
- total = total.plus(this.beatLengths[i].timesNum(this.beatCounts[i] || 1));
257
- }
258
- return total;
259
- },
260
- enumerable: false,
261
- configurable: true
262
- });
263
- return Bar;
264
- }(TimedEntity));
265
- export { Bar };
266
- var Cycle = (function (_super) {
267
- __extends(Cycle, _super);
268
- function Cycle(config) {
269
- if (config === void 0) { config = null; }
270
- var _this = _super.call(this, (config = config || {})) || this;
271
- _this.name = config.name || "";
272
- _this.bars = config.bars || [];
273
- return _this;
274
107
  }
275
- Cycle.prototype.debugValue = function () {
276
- return __assign(__assign({}, _super.prototype.debugValue.call(this)), { name: name, bars: this.bars.map(function (p) { return p.debugValue(); }) });
277
- };
278
- Cycle.prototype.children = function () {
108
+ get beatCount() {
109
+ return this.beatLengths.length;
110
+ }
111
+ get totalBeatCount() {
112
+ let out = 0;
113
+ for (let i = 0; i < this.beatLengths.length; i++) {
114
+ out += this.beatCounts[i] || 1;
115
+ }
116
+ return out;
117
+ }
118
+ get duration() {
119
+ let total = ZERO;
120
+ for (let i = 0; i < this.beatLengths.length; i++) {
121
+ total = total.plus(this.beatLengths[i].timesNum(this.beatCounts[i] || 1));
122
+ }
123
+ return total;
124
+ }
125
+ }
126
+ export class Cycle extends TimedEntity {
127
+ constructor(config = null) {
128
+ super((config = config || {}));
129
+ this.name = config.name || "";
130
+ this.bars = config.bars || [];
131
+ }
132
+ debugValue() {
133
+ return Object.assign(Object.assign({}, super.debugValue()), { name: name, bars: this.bars.map((p) => p.debugValue()) });
134
+ }
135
+ children() {
279
136
  return this.bars;
280
- };
281
- Cycle.prototype.equals = function (another) {
282
- if (!_super.prototype.equals.call(this, another)) {
137
+ }
138
+ equals(another) {
139
+ if (!super.equals(another)) {
283
140
  return false;
284
141
  }
285
142
  if (this.bars.length != another.bars.length)
286
143
  return false;
287
- for (var i = 0; i < this.bars.length; i++) {
144
+ for (let i = 0; i < this.bars.length; i++) {
288
145
  if (!this.bars[i].equals(another.bars[i]))
289
146
  return false;
290
147
  }
291
148
  return true;
292
- };
293
- Cycle.prototype.getAtIndex = function (globalIndex) {
294
- var cycle = 0;
149
+ }
150
+ getAtIndex(globalIndex) {
151
+ let cycle = 0;
295
152
  while (globalIndex < 0) {
296
153
  globalIndex += this.totalBeatCount;
297
154
  cycle--;
@@ -300,33 +157,33 @@ var Cycle = (function (_super) {
300
157
  cycle = Math.floor(globalIndex / this.totalBeatCount);
301
158
  }
302
159
  globalIndex = globalIndex % this.totalBeatCount;
303
- var offset = ZERO;
304
- for (var barIndex = 0; barIndex < this.bars.length; barIndex++) {
305
- var bar = this.bars[barIndex];
160
+ let offset = ZERO;
161
+ for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {
162
+ const bar = this.bars[barIndex];
306
163
  if (globalIndex >= bar.totalBeatCount) {
307
164
  globalIndex -= bar.totalBeatCount;
308
165
  offset = offset.plus(bar.duration);
309
166
  }
310
167
  else {
311
- for (var beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {
312
- var beatLength = bar.beatLengths[beatIndex];
313
- var beatCount = bar.beatCounts[beatIndex] || 1;
168
+ for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {
169
+ const beatLength = bar.beatLengths[beatIndex];
170
+ const beatCount = bar.beatCounts[beatIndex] || 1;
314
171
  if (globalIndex >= beatCount) {
315
172
  globalIndex -= beatCount;
316
173
  offset = offset.plus(beatLength.timesNum(beatCount));
317
174
  }
318
175
  else {
319
- var instance = globalIndex;
176
+ const instance = globalIndex;
320
177
  return [cycle, [barIndex, beatIndex, instance], offset.plus(beatLength.timesNum(instance))];
321
178
  }
322
179
  }
323
180
  }
324
181
  }
325
182
  throw new Error("Should not be here!");
326
- };
327
- Cycle.prototype.getPosition = function (globalOffset) {
328
- var duration = this.duration;
329
- var cycleNum = 0;
183
+ }
184
+ getPosition(globalOffset) {
185
+ const duration = this.duration;
186
+ let cycleNum = 0;
330
187
  if (globalOffset.isLT(ZERO)) {
331
188
  while (globalOffset.isLT(ZERO)) {
332
189
  cycleNum--;
@@ -334,24 +191,24 @@ var Cycle = (function (_super) {
334
191
  }
335
192
  }
336
193
  else if (globalOffset.isGTE(duration)) {
337
- var realOffset = globalOffset.mod(duration);
194
+ const realOffset = globalOffset.mod(duration);
338
195
  globalOffset = globalOffset.minus(realOffset).divby(duration);
339
196
  TSU.assert(globalOffset.isWhole);
340
197
  cycleNum = globalOffset.floor;
341
198
  globalOffset = realOffset;
342
199
  }
343
- var globalIndex = 0;
344
- for (var barIndex = 0; barIndex < this.bars.length; barIndex++) {
345
- var bar = this.bars[barIndex];
346
- var barDuration = bar.duration;
200
+ let globalIndex = 0;
201
+ for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {
202
+ const bar = this.bars[barIndex];
203
+ const barDuration = bar.duration;
347
204
  if (globalOffset.isGTE(barDuration)) {
348
205
  globalOffset = globalOffset.minus(barDuration);
349
206
  }
350
207
  else {
351
- for (var beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {
352
- var beatLength = bar.beatLengths[beatIndex];
353
- var beatCount = bar.beatCounts[beatIndex] || 1;
354
- for (var instance = 0; instance < beatCount; instance++, globalIndex++) {
208
+ for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {
209
+ const beatLength = bar.beatLengths[beatIndex];
210
+ const beatCount = bar.beatCounts[beatIndex] || 1;
211
+ for (let instance = 0; instance < beatCount; instance++, globalIndex++) {
355
212
  if (globalOffset.isGTE(beatLength)) {
356
213
  globalOffset = globalOffset.minus(beatLength);
357
214
  }
@@ -364,107 +221,55 @@ var Cycle = (function (_super) {
364
221
  globalIndex += bar.totalBeatCount;
365
222
  }
366
223
  throw new Error("Should not be here!");
367
- };
368
- Cycle.prototype.iterateBeats = function (startBar, startBeat, startInstance) {
369
- var barIndex, beatIndex, instanceIndex, currBar;
370
- if (startBar === void 0) { startBar = 0; }
371
- if (startBeat === void 0) { startBeat = 0; }
372
- if (startInstance === void 0) { startInstance = 0; }
373
- return __generator(this, function (_a) {
374
- switch (_a.label) {
375
- case 0:
376
- barIndex = startBar;
377
- beatIndex = startBeat;
378
- instanceIndex = startInstance;
379
- _a.label = 1;
380
- case 1:
381
- if (!true) return [3, 3];
382
- currBar = this.bars[barIndex];
383
- return [4, [[barIndex, beatIndex, instanceIndex], currBar.beatLengths[beatIndex]]];
384
- case 2:
385
- _a.sent();
386
- instanceIndex++;
387
- if (!currBar.beatCounts[beatIndex] || instanceIndex >= currBar.beatCounts[beatIndex]) {
388
- instanceIndex = 0;
389
- beatIndex++;
390
- if (beatIndex >= currBar.beatLengths.length) {
391
- beatIndex = 0;
392
- barIndex++;
393
- if (barIndex >= this.bars.length) {
394
- barIndex = 0;
395
- }
396
- }
224
+ }
225
+ *iterateBeats(startBar = 0, startBeat = 0, startInstance = 0) {
226
+ let barIndex = startBar;
227
+ let beatIndex = startBeat;
228
+ let instanceIndex = startInstance;
229
+ while (true) {
230
+ const currBar = this.bars[barIndex];
231
+ yield [[barIndex, beatIndex, instanceIndex], currBar.beatLengths[beatIndex]];
232
+ instanceIndex++;
233
+ if (!currBar.beatCounts[beatIndex] || instanceIndex >= currBar.beatCounts[beatIndex]) {
234
+ instanceIndex = 0;
235
+ beatIndex++;
236
+ if (beatIndex >= currBar.beatLengths.length) {
237
+ beatIndex = 0;
238
+ barIndex++;
239
+ if (barIndex >= this.bars.length) {
240
+ barIndex = 0;
397
241
  }
398
- return [3, 1];
399
- case 3: return [2];
400
- }
401
- });
402
- };
403
- Cycle.prototype.copyTo = function (another) {
404
- _super.prototype.copyTo.call(this, another);
405
- another.name = this.name;
406
- another.bars = this.bars.map(function (x) { return x.clone(); });
407
- };
408
- Object.defineProperty(Cycle.prototype, "beatCount", {
409
- get: function () {
410
- var e_3, _a;
411
- var out = 0;
412
- try {
413
- for (var _b = __values(this.bars), _c = _b.next(); !_c.done; _c = _b.next()) {
414
- var bar = _c.value;
415
- out += bar.beatCount;
416
242
  }
417
243
  }
418
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
419
- finally {
420
- try {
421
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
422
- }
423
- finally { if (e_3) throw e_3.error; }
424
- }
425
- return out;
426
- },
427
- enumerable: false,
428
- configurable: true
429
- });
430
- Object.defineProperty(Cycle.prototype, "totalBeatCount", {
431
- get: function () {
432
- var e_4, _a;
433
- var out = 0;
434
- try {
435
- for (var _b = __values(this.bars), _c = _b.next(); !_c.done; _c = _b.next()) {
436
- var bar = _c.value;
437
- out += bar.totalBeatCount;
438
- }
439
- }
440
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
441
- finally {
442
- try {
443
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
444
- }
445
- finally { if (e_4) throw e_4.error; }
446
- }
447
- return out;
448
- },
449
- enumerable: false,
450
- configurable: true
451
- });
452
- Object.defineProperty(Cycle.prototype, "duration", {
453
- get: function () {
454
- return this.bars.reduce(function (x, y) { return x.plus(y.duration); }, ZERO);
455
- },
456
- enumerable: false,
457
- configurable: true
458
- });
459
- Cycle.DEFAULT = new Cycle({
460
- name: "Adi Thalam",
461
- bars: [
462
- new Bar({ name: "Laghu", beatLengths: [1, 1, 1, 1] }),
463
- new Bar({ name: "Dhrutam", beatLengths: [1, 1] }),
464
- new Bar({ name: "Dhrutam", beatLengths: [1, 1] }),
465
- ],
466
- });
467
- return Cycle;
468
- }(TimedEntity));
469
- export { Cycle };
244
+ }
245
+ }
246
+ copyTo(another) {
247
+ super.copyTo(another);
248
+ another.name = this.name;
249
+ another.bars = this.bars.map((x) => x.clone());
250
+ }
251
+ get beatCount() {
252
+ let out = 0;
253
+ for (const bar of this.bars)
254
+ out += bar.beatCount;
255
+ return out;
256
+ }
257
+ get totalBeatCount() {
258
+ let out = 0;
259
+ for (const bar of this.bars)
260
+ out += bar.totalBeatCount;
261
+ return out;
262
+ }
263
+ get duration() {
264
+ return this.bars.reduce((x, y) => x.plus(y.duration), ZERO);
265
+ }
266
+ }
267
+ Cycle.DEFAULT = new Cycle({
268
+ name: "Adi Thalam",
269
+ bars: [
270
+ new Bar({ name: "Laghu", beatLengths: [1, 1, 1, 1] }),
271
+ new Bar({ name: "Dhrutam", beatLengths: [1, 1] }),
272
+ new Bar({ name: "Dhrutam", beatLengths: [1, 1] }),
273
+ ],
274
+ });
470
275
  //# sourceMappingURL=cycle.js.map