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.
- 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 +73 -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 +6 -1
- package/lib/cjs/core.js +288 -493
- 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 +124 -1
- package/lib/cjs/grids.js +546 -6
- package/lib/cjs/grids.js.map +1 -1
- 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 +217 -219
- 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 +71 -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 +6 -1
- package/lib/esm/core.js +286 -502
- 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 +124 -1
- package/lib/esm/grids.js +515 -5
- package/lib/esm/grids.js.map +1 -1
- 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 +211 -214
- 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 +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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
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
|
-
|
|
189
|
-
|
|
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 (
|
|
196
|
-
|
|
70
|
+
while (this.beatCounts.length < this.beatLengths.length) {
|
|
71
|
+
this.beatCounts.push(1);
|
|
197
72
|
}
|
|
198
|
-
return _this;
|
|
199
73
|
}
|
|
200
|
-
|
|
201
|
-
return
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (!
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
221
|
-
|
|
93
|
+
}
|
|
94
|
+
copyTo(another) {
|
|
95
|
+
super.copyTo(another);
|
|
222
96
|
another.name = this.name;
|
|
223
|
-
another.beatLengths =
|
|
224
|
-
another.beatCounts =
|
|
225
|
-
}
|
|
226
|
-
|
|
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
|
-
|
|
276
|
-
return
|
|
277
|
-
}
|
|
278
|
-
|
|
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
|
-
|
|
282
|
-
if (!
|
|
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 (
|
|
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
|
-
|
|
294
|
-
|
|
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
|
-
|
|
304
|
-
for (
|
|
305
|
-
|
|
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 (
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
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
|
-
|
|
344
|
-
for (
|
|
345
|
-
|
|
346
|
-
|
|
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 (
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
for (
|
|
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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|