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.
- package/lib/cjs/beats.d.ts +34 -69
- package/lib/cjs/beats.js +178 -439
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/beatutils.d.ts +3 -0
- package/lib/cjs/beatutils.js +64 -0
- package/lib/cjs/beatutils.js.map +1 -0
- package/lib/cjs/beatview.d.ts +18 -0
- package/lib/cjs/beatview.js +62 -0
- package/lib/cjs/beatview.js.map +1 -0
- package/lib/cjs/carnatic/LineView.d.ts +2 -7
- package/lib/cjs/carnatic/LineView.js +13 -31
- package/lib/cjs/carnatic/LineView.js.map +1 -1
- package/lib/cjs/carnatic/NotationView.d.ts +8 -7
- package/lib/cjs/carnatic/NotationView.js +76 -153
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/carnatic/atomviews.js +149 -287
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/beatviews.d.ts +4 -13
- package/lib/cjs/carnatic/beatviews.js +23 -118
- package/lib/cjs/carnatic/beatviews.js.map +1 -1
- package/lib/cjs/carnatic/embelishments.d.ts +1 -1
- package/lib/cjs/carnatic/embelishments.js +189 -283
- package/lib/cjs/carnatic/embelishments.js.map +1 -1
- package/lib/cjs/carnatic/gamakas.js +15 -47
- package/lib/cjs/carnatic/gamakas.js.map +1 -1
- package/lib/cjs/commands.js +111 -271
- package/lib/cjs/commands.js.map +1 -1
- package/lib/cjs/core.d.ts +14 -1
- package/lib/cjs/core.js +291 -477
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/cycle.js +175 -367
- package/lib/cjs/cycle.js.map +1 -1
- package/lib/cjs/entity.js +48 -102
- package/lib/cjs/entity.js.map +1 -1
- package/lib/cjs/grids.d.ts +125 -0
- package/lib/cjs/grids.js +550 -0
- package/lib/cjs/grids.js.map +1 -0
- package/lib/cjs/iterators.js +96 -234
- package/lib/cjs/iterators.js.map +1 -1
- package/lib/cjs/layouts.d.ts +1 -1
- package/lib/cjs/layouts.js +62 -98
- package/lib/cjs/layouts.js.map +1 -1
- package/lib/cjs/loader.d.ts +2 -2
- package/lib/cjs/loader.js +23 -123
- package/lib/cjs/loader.js.map +1 -1
- package/lib/cjs/notation.d.ts +0 -3
- package/lib/cjs/notation.js +139 -241
- package/lib/cjs/notation.js.map +1 -1
- package/lib/cjs/parser.d.ts +2 -0
- package/lib/cjs/parser.js +225 -214
- package/lib/cjs/parser.js.map +1 -1
- package/lib/cjs/shapes.js +149 -283
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/cjs/utils.d.ts +8 -0
- package/lib/cjs/utils.js +60 -55
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/beats.d.ts +34 -69
- package/lib/esm/beats.js +172 -438
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/beatutils.d.ts +3 -0
- package/lib/esm/beatutils.js +37 -0
- package/lib/esm/beatutils.js.map +1 -0
- package/lib/esm/beatview.d.ts +18 -0
- package/lib/esm/beatview.js +35 -0
- package/lib/esm/beatview.js.map +1 -0
- package/lib/esm/carnatic/LineView.d.ts +2 -7
- package/lib/esm/carnatic/LineView.js +12 -31
- package/lib/esm/carnatic/LineView.js.map +1 -1
- package/lib/esm/carnatic/NotationView.d.ts +8 -7
- package/lib/esm/carnatic/NotationView.js +74 -152
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/carnatic/atomviews.js +144 -284
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/beatviews.d.ts +4 -13
- package/lib/esm/carnatic/beatviews.js +21 -94
- package/lib/esm/carnatic/beatviews.js.map +1 -1
- package/lib/esm/carnatic/embelishments.d.ts +1 -1
- package/lib/esm/carnatic/embelishments.js +187 -296
- package/lib/esm/carnatic/embelishments.js.map +1 -1
- package/lib/esm/carnatic/gamakas.js +14 -48
- package/lib/esm/carnatic/gamakas.js.map +1 -1
- package/lib/esm/commands.js +100 -271
- package/lib/esm/commands.js.map +1 -1
- package/lib/esm/core.d.ts +14 -1
- package/lib/esm/core.js +287 -484
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/cycle.js +172 -367
- package/lib/esm/cycle.js.map +1 -1
- package/lib/esm/entity.js +48 -104
- package/lib/esm/entity.js.map +1 -1
- package/lib/esm/grids.d.ts +125 -0
- package/lib/esm/grids.js +517 -0
- package/lib/esm/grids.js.map +1 -0
- package/lib/esm/iterators.js +93 -235
- package/lib/esm/iterators.js.map +1 -1
- package/lib/esm/layouts.d.ts +1 -1
- package/lib/esm/layouts.js +60 -97
- package/lib/esm/layouts.js.map +1 -1
- package/lib/esm/loader.d.ts +2 -2
- package/lib/esm/loader.js +20 -120
- package/lib/esm/loader.js.map +1 -1
- package/lib/esm/notation.d.ts +0 -3
- package/lib/esm/notation.js +135 -242
- package/lib/esm/notation.js.map +1 -1
- package/lib/esm/parser.d.ts +2 -0
- package/lib/esm/parser.js +220 -210
- package/lib/esm/parser.js.map +1 -1
- package/lib/esm/shapes.js +148 -288
- package/lib/esm/shapes.js.map +1 -1
- package/lib/esm/utils.d.ts +8 -0
- package/lib/esm/utils.js +55 -51
- package/lib/esm/utils.js.map +1 -1
- 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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
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
|
-
|
|
215
|
-
|
|
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 (
|
|
222
|
-
|
|
97
|
+
while (this.beatCounts.length < this.beatLengths.length) {
|
|
98
|
+
this.beatCounts.push(1);
|
|
223
99
|
}
|
|
224
|
-
return _this;
|
|
225
100
|
}
|
|
226
|
-
|
|
227
|
-
return
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (!
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
247
|
-
|
|
120
|
+
}
|
|
121
|
+
copyTo(another) {
|
|
122
|
+
super.copyTo(another);
|
|
248
123
|
another.name = this.name;
|
|
249
|
-
another.beatLengths =
|
|
250
|
-
another.beatCounts =
|
|
251
|
-
}
|
|
252
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
302
|
-
return
|
|
303
|
-
}
|
|
304
|
-
|
|
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
|
-
|
|
308
|
-
if (!
|
|
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 (
|
|
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
|
-
|
|
320
|
-
|
|
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
|
-
|
|
330
|
-
for (
|
|
331
|
-
|
|
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 (
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
|
|
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
|
-
|
|
370
|
-
for (
|
|
371
|
-
|
|
372
|
-
|
|
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 (
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
for (
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
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
|