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