notations 0.0.47 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +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 +230 -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 +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 +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 +225 -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/esm/notation.js
CHANGED
|
@@ -1,301 +1,197 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
1
|
import { Entity } from "./entity";
|
|
39
2
|
import { Cycle } from "./cycle";
|
|
40
3
|
import { Line } from "./core";
|
|
41
4
|
import { LayoutParams } from "./layouts";
|
|
42
|
-
|
|
43
|
-
|
|
5
|
+
export class RoleDef {
|
|
6
|
+
constructor() {
|
|
44
7
|
this.name = "";
|
|
45
8
|
this.notesOnly = false;
|
|
46
9
|
this.index = 0;
|
|
47
10
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return this.constructor.name;
|
|
69
|
-
},
|
|
70
|
-
enumerable: false,
|
|
71
|
-
configurable: true
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(Command.prototype, "type", {
|
|
74
|
-
get: function () {
|
|
75
|
-
return "Command";
|
|
76
|
-
},
|
|
77
|
-
enumerable: false,
|
|
78
|
-
configurable: true
|
|
79
|
-
});
|
|
80
|
-
Command.prototype.debugValue = function () {
|
|
11
|
+
}
|
|
12
|
+
export class Command extends Entity {
|
|
13
|
+
constructor(params = []) {
|
|
14
|
+
super();
|
|
15
|
+
this.autoGenerated = false;
|
|
16
|
+
this.prevSibling = null;
|
|
17
|
+
this.nextSibling = null;
|
|
18
|
+
this.params = params;
|
|
19
|
+
this.index = 0;
|
|
20
|
+
this.validateParams();
|
|
21
|
+
}
|
|
22
|
+
validateParams() {
|
|
23
|
+
}
|
|
24
|
+
get name() {
|
|
25
|
+
return this.constructor.name;
|
|
26
|
+
}
|
|
27
|
+
get type() {
|
|
28
|
+
return "Command";
|
|
29
|
+
}
|
|
30
|
+
debugValue() {
|
|
81
31
|
return { name: this.name, index: this.index, params: this.params };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var param = _c.value;
|
|
88
|
-
if (param.key == name)
|
|
89
|
-
return param.value;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
93
|
-
finally {
|
|
94
|
-
try {
|
|
95
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
96
|
-
}
|
|
97
|
-
finally { if (e_1) throw e_1.error; }
|
|
32
|
+
}
|
|
33
|
+
getParam(name) {
|
|
34
|
+
for (const param of this.params) {
|
|
35
|
+
if (param.key == name)
|
|
36
|
+
return param.value;
|
|
98
37
|
}
|
|
99
38
|
return null;
|
|
100
|
-
}
|
|
101
|
-
|
|
39
|
+
}
|
|
40
|
+
getParamAt(index) {
|
|
102
41
|
return index < this.params.length ? this.params[index].value : null;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return __assign(__assign({}, _super.prototype.debugValue.call(this)), { content: this.content, contentType: this.contentType });
|
|
118
|
-
};
|
|
119
|
-
return RawBlock;
|
|
120
|
-
}(Entity));
|
|
121
|
-
export { RawBlock };
|
|
122
|
-
var MetaData = (function () {
|
|
123
|
-
function MetaData(key, value, params) {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class RawBlock extends Entity {
|
|
45
|
+
constructor(content, contentType = "md") {
|
|
46
|
+
super();
|
|
47
|
+
this.content = content;
|
|
48
|
+
this.contentType = contentType;
|
|
49
|
+
}
|
|
50
|
+
debugValue() {
|
|
51
|
+
return Object.assign(Object.assign({}, super.debugValue()), { content: this.content, contentType: this.contentType });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export class MetaData {
|
|
55
|
+
constructor(key, value, params) {
|
|
124
56
|
this.key = key;
|
|
125
57
|
this.value = value;
|
|
126
58
|
this.params = params;
|
|
127
59
|
params = params || {};
|
|
128
60
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
157
|
-
Object.defineProperty(Notation.prototype, "unnamedLayoutParams", {
|
|
158
|
-
get: function () {
|
|
159
|
-
return this._unnamedLayoutParams;
|
|
160
|
-
},
|
|
161
|
-
enumerable: false,
|
|
162
|
-
configurable: true
|
|
163
|
-
});
|
|
164
|
-
Object.defineProperty(Notation.prototype, "namedLayoutParams", {
|
|
165
|
-
get: function () {
|
|
166
|
-
return this._namedLayoutParams;
|
|
167
|
-
},
|
|
168
|
-
enumerable: false,
|
|
169
|
-
configurable: true
|
|
170
|
-
});
|
|
171
|
-
Object.defineProperty(Notation.prototype, "type", {
|
|
172
|
-
get: function () {
|
|
173
|
-
return "Notation";
|
|
174
|
-
},
|
|
175
|
-
enumerable: false,
|
|
176
|
-
configurable: true
|
|
177
|
-
});
|
|
178
|
-
Notation.prototype.addLine = function (line) {
|
|
61
|
+
}
|
|
62
|
+
export class Notation extends Entity {
|
|
63
|
+
constructor() {
|
|
64
|
+
super(...arguments);
|
|
65
|
+
this._unnamedLayoutParams = [];
|
|
66
|
+
this._namedLayoutParams = new Map();
|
|
67
|
+
this._currRoleDef = null;
|
|
68
|
+
this.roles = [];
|
|
69
|
+
this.blocks = [];
|
|
70
|
+
this.currentAPB = 1;
|
|
71
|
+
this.currentCycle = Cycle.DEFAULT;
|
|
72
|
+
this.currentBreaks = [];
|
|
73
|
+
this.metadata = new Map();
|
|
74
|
+
this.onMissingRole = (name) => this.newRoleDef(name, name == "sw");
|
|
75
|
+
this._currentLine = null;
|
|
76
|
+
this._layoutParams = null;
|
|
77
|
+
}
|
|
78
|
+
get unnamedLayoutParams() {
|
|
79
|
+
return this._unnamedLayoutParams;
|
|
80
|
+
}
|
|
81
|
+
get namedLayoutParams() {
|
|
82
|
+
return this._namedLayoutParams;
|
|
83
|
+
}
|
|
84
|
+
get type() {
|
|
85
|
+
return "Notation";
|
|
86
|
+
}
|
|
87
|
+
addLine(line) {
|
|
179
88
|
this.blocks.push(line);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
89
|
+
}
|
|
90
|
+
removeLine(line) {
|
|
91
|
+
const index = this.blocks.findIndex((l) => l == line);
|
|
183
92
|
if (index >= 0) {
|
|
184
93
|
this.blocks.splice(index, 1);
|
|
185
94
|
}
|
|
186
95
|
return index;
|
|
187
|
-
}
|
|
188
|
-
|
|
96
|
+
}
|
|
97
|
+
addRawBlock(raw) {
|
|
189
98
|
this.blocks.push(raw);
|
|
190
99
|
this.resetLine();
|
|
191
|
-
}
|
|
192
|
-
|
|
100
|
+
}
|
|
101
|
+
addMetaData(meta) {
|
|
193
102
|
if (!this.metadata.has(meta.key)) {
|
|
194
|
-
|
|
103
|
+
const raw = new RawBlock(meta.key, "metadata");
|
|
195
104
|
this.addRawBlock(raw);
|
|
196
105
|
}
|
|
197
106
|
this.metadata.set(meta.key, meta);
|
|
198
|
-
}
|
|
199
|
-
|
|
107
|
+
}
|
|
108
|
+
debugValue() {
|
|
200
109
|
var _a;
|
|
201
|
-
return
|
|
202
|
-
}
|
|
203
|
-
|
|
110
|
+
return Object.assign(Object.assign({}, super.debugValue), { roles: this.roles, blocks: this.blocks.map((b) => b.debugValue()), currentAPB: this.currentAPB, currentCycle: (_a = this.currentCycle) === null || _a === void 0 ? void 0 : _a.uuid, currentBreaks: this.currentBreaks });
|
|
111
|
+
}
|
|
112
|
+
getRoleDef(name) {
|
|
204
113
|
name = name.trim().toLowerCase();
|
|
205
114
|
if (name == "") {
|
|
206
115
|
return this.roles[this.roles.length - 1] || null;
|
|
207
116
|
}
|
|
208
|
-
for (
|
|
209
|
-
|
|
117
|
+
for (let i = 0; i < this.roles.length; i++) {
|
|
118
|
+
const rd = this.roles[i];
|
|
210
119
|
if (name == rd.name)
|
|
211
120
|
return rd;
|
|
212
121
|
}
|
|
213
122
|
return null;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (notesOnly === void 0) { notesOnly = false; }
|
|
123
|
+
}
|
|
124
|
+
newRoleDef(name, notesOnly = false) {
|
|
217
125
|
name = name.trim().toLowerCase();
|
|
218
126
|
if (name.trim() == "") {
|
|
219
127
|
throw new Error("Role name cannot be empty");
|
|
220
128
|
}
|
|
221
|
-
|
|
129
|
+
const roleDef = this.getRoleDef(name);
|
|
222
130
|
if (roleDef != null) {
|
|
223
131
|
throw new Error("Role already exists");
|
|
224
132
|
}
|
|
225
|
-
|
|
133
|
+
const rd = new RoleDef();
|
|
226
134
|
rd.name = name;
|
|
227
135
|
rd.notesOnly = notesOnly;
|
|
228
136
|
rd.index = this.roles.length;
|
|
229
137
|
this.roles.push(rd);
|
|
230
138
|
return rd;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (this.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this._currRoleDef = this.roles[this.roles.length - 1];
|
|
240
|
-
}
|
|
139
|
+
}
|
|
140
|
+
get currRoleDef() {
|
|
141
|
+
if (this._currRoleDef == null) {
|
|
142
|
+
if (this.roles.length == 0) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this._currRoleDef = this.roles[this.roles.length - 1];
|
|
241
147
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
});
|
|
247
|
-
Notation.prototype.setCurrRole = function (name) {
|
|
148
|
+
}
|
|
149
|
+
return this._currRoleDef;
|
|
150
|
+
}
|
|
151
|
+
setCurrRole(name) {
|
|
248
152
|
name = name.trim().toLowerCase();
|
|
249
153
|
if (name.trim() == "") {
|
|
250
154
|
throw new Error("Role name cannot be empty");
|
|
251
155
|
}
|
|
252
|
-
|
|
156
|
+
const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);
|
|
253
157
|
if (roleDef == null) {
|
|
254
158
|
throw new Error("Role not found: " + name);
|
|
255
159
|
}
|
|
256
160
|
this._currRoleDef = roleDef;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
enumerable: false,
|
|
266
|
-
configurable: true
|
|
267
|
-
});
|
|
268
|
-
Notation.prototype.resetLine = function () {
|
|
161
|
+
}
|
|
162
|
+
get currentLine() {
|
|
163
|
+
if (this._currentLine == null) {
|
|
164
|
+
return this.newLine();
|
|
165
|
+
}
|
|
166
|
+
return this._currentLine;
|
|
167
|
+
}
|
|
168
|
+
resetLine() {
|
|
269
169
|
this._currentLine = null;
|
|
270
|
-
}
|
|
271
|
-
|
|
170
|
+
}
|
|
171
|
+
newLine() {
|
|
272
172
|
if (this._currentLine && this._currentLine.isEmpty) {
|
|
273
173
|
this.removeLine(this._currentLine);
|
|
274
174
|
}
|
|
275
175
|
this._currentLine = new Line();
|
|
276
176
|
this.addLine(this._currentLine);
|
|
277
177
|
return this._currentLine;
|
|
278
|
-
}
|
|
279
|
-
|
|
178
|
+
}
|
|
179
|
+
resetLayoutParams() {
|
|
280
180
|
this._layoutParams = null;
|
|
281
181
|
this.resetLine();
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
182
|
+
}
|
|
183
|
+
get layoutParams() {
|
|
184
|
+
if (this._layoutParams == null) {
|
|
185
|
+
this._layoutParams = this.findUnnamedLayoutParams();
|
|
285
186
|
if (this._layoutParams == null) {
|
|
286
|
-
this._layoutParams = this.
|
|
287
|
-
|
|
288
|
-
this._layoutParams = this.snapshotLayoutParams();
|
|
289
|
-
this._unnamedLayoutParams.push(this._layoutParams);
|
|
290
|
-
}
|
|
187
|
+
this._layoutParams = this.snapshotLayoutParams();
|
|
188
|
+
this._unnamedLayoutParams.push(this._layoutParams);
|
|
291
189
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
Notation.prototype.ensureNamedLayoutParams = function (name) {
|
|
298
|
-
var lp = this._namedLayoutParams.get(name) || null;
|
|
190
|
+
}
|
|
191
|
+
return this._layoutParams;
|
|
192
|
+
}
|
|
193
|
+
ensureNamedLayoutParams(name) {
|
|
194
|
+
let lp = this._namedLayoutParams.get(name) || null;
|
|
299
195
|
if (lp == null || this._layoutParams != lp) {
|
|
300
196
|
if (lp == null) {
|
|
301
197
|
lp = this.snapshotLayoutParams();
|
|
@@ -310,23 +206,20 @@ var Notation = (function (_super) {
|
|
|
310
206
|
this.resetLine();
|
|
311
207
|
}
|
|
312
208
|
return this._layoutParams;
|
|
313
|
-
}
|
|
314
|
-
|
|
209
|
+
}
|
|
210
|
+
snapshotLayoutParams() {
|
|
315
211
|
return new LayoutParams({
|
|
316
212
|
cycle: this.currentCycle,
|
|
317
213
|
beatDuration: this.currentAPB,
|
|
318
214
|
layout: this.currentBreaks,
|
|
319
215
|
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
lp.lineBreaksEqual(_this.currentBreaks));
|
|
216
|
+
}
|
|
217
|
+
findUnnamedLayoutParams() {
|
|
218
|
+
return (this._unnamedLayoutParams.find((lp) => {
|
|
219
|
+
return (lp.beatDuration == this.currentAPB &&
|
|
220
|
+
this.currentCycle.equals(lp.cycle) &&
|
|
221
|
+
lp.lineBreaksEqual(this.currentBreaks));
|
|
327
222
|
}) || null);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
}(Entity));
|
|
331
|
-
export { Notation };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
332
225
|
//# sourceMappingURL=notation.js.map
|
package/lib/esm/notation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9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U;gBAClC,KAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;gBAClC,EAAE,CAAC,eAAe,CAAC,KAAI,CAAC,aAAa,CAAC,CACvC,CAAC;QACJ,CAAC,CAAC,IAAI,IAAI,CACX,CAAC;IACJ,CAAC;IACH,eAAC;AAAD,CAAC,AAtND,CAA8B,MAAM,GAsNnC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\n\nexport class RoleDef {\n name = \"\";\n notesOnly = false;\n index = 0;\n}\n\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\nexport abstract class Command extends Entity {\n // Commands that are auto generated are usually created by other commands\n autoGenerated = false;\n prevSibling: null | Command = null;\n nextSibling: null | Command = null;\n params: CmdParam[];\n index: number;\n\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * called to validate parameters.\n */\n validateParams(): void {\n //\n }\n\n get name(): string {\n return this.constructor.name;\n }\n\n get type(): string {\n return \"Command\";\n }\n\n debugValue(): any {\n return { name: this.name, index: this.index, params: this.params };\n }\n\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n abstract applyToNotation(notebook: Notation): void;\n}\n\nexport class RawBlock extends Entity {\n constructor(public content: string, public contentType: string = \"md\") {\n super();\n }\n\n debugValue(): any {\n return { ...super.debugValue(), content: this.content, contentType: this.contentType };\n }\n}\n\nexport class MetaData {\n constructor(public readonly key: string, public readonly value: string, public readonly params?: any) {\n params = params || {};\n }\n}\n\nexport class Notation extends Entity {\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _currRoleDef: TSU.Nullable<RoleDef> = null;\n roles: RoleDef[] = [];\n blocks: (Line | RawBlock)[] = [];\n private lpsForLine = new Map<number, LayoutParams>();\n currentAPB = 1;\n currentCycle: Cycle = Cycle.DEFAULT;\n currentBreaks: number[] = [];\n metadata = new Map<string, MetaData>();\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n layoutParamsForLine(line: Line): null | LayoutParams {\n return this.lpsForLine.get(line.uuid) || null;\n }\n\n setLayoutParamsForLine(line: Line, layoutParams: LayoutParams): void {\n this.lpsForLine.set(line.uuid, layoutParams);\n }\n\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n get type(): unknown {\n return \"Notation\";\n }\n\n addLine(line: Line): void {\n this.blocks.push(line);\n }\n\n removeLine(line: Line): number {\n const index = this.blocks.findIndex((l) => l == line);\n if (index >= 0) {\n this.blocks.splice(index, 1);\n }\n return index;\n }\n\n addRawBlock(raw: RawBlock): void {\n this.blocks.push(raw);\n this.resetLine();\n }\n\n addMetaData(meta: MetaData): void {\n if (!this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n debugValue(): any {\n return {\n ...super.debugValue,\n roles: this.roles,\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentCycle: this.currentCycle?.uuid,\n currentBreaks: this.currentBreaks,\n };\n }\n\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name == \"\") {\n return this.roles[this.roles.length - 1] || null;\n }\n for (let i = 0; i < this.roles.length; i++) {\n const rd = this.roles[i];\n if (name == rd.name) return rd;\n }\n return null;\n }\n\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name);\n if (roleDef != null) {\n throw new Error(\"Role already exists\");\n // roleDef.notesOnly = notesOnly;\n // return roleDef;\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.roles.length;\n this.roles.push(rd);\n\n return rd;\n }\n\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n if (this.roles.length == 0) {\n return null;\n } else {\n this._currRoleDef = this.roles[this.roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n // Gets the current line, creating it if needed\n private _currentLine: Line | null = null;\n get currentLine(): Line {\n if (this._currentLine == null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n resetLine(): void {\n this._currentLine = null;\n }\n\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n\n private _layoutParams: LayoutParams | null = null;\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\n this._layoutParams = this.findUnnamedLayoutParams();\n if (this._layoutParams == null) {\n this._layoutParams = this.snapshotLayoutParams();\n this._unnamedLayoutParams.push(this._layoutParams);\n }\n }\n return this._layoutParams;\n }\n\n ensureNamedLayoutParams(name: string): LayoutParams {\n let lp = this._namedLayoutParams.get(name) || null;\n if (lp == null || this._layoutParams != lp) {\n // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Find a layout params that is currently _unnamed but matches one\n * by current set of layout attributes.\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,OAAO,OAAO;IAApB;QACE,SAAI,GAAG,EAAE,CAAC;QACV,cAAS,GAAG,KAAK,CAAC;QAClB,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA;AAGD,MAAM,OAAgB,OAAQ,SAAQ,MAAM;IAQ1C,YAAY,SAAqB,EAAE;QACjC,KAAK,EAAE,CAAC;QAPV,kBAAa,GAAG,KAAK,CAAC;QACtB,gBAAW,GAAmB,IAAI,CAAC;QACnC,gBAAW,GAAmB,IAAI,CAAC;QAMjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,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AM,CAAC,EAAE,CAAC,KAAK,CAAC;gBAClC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CACvC,CAAC;QACJ,CAAC,CAAC,IAAI,IAAI,CACX,CAAC;IACJ,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\n\nexport class RoleDef {\n name = \"\";\n notesOnly = false;\n index = 0;\n}\n\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\nexport abstract class Command extends Entity {\n // Commands that are auto generated are usually created by other commands\n autoGenerated = false;\n prevSibling: null | Command = null;\n nextSibling: null | Command = null;\n params: CmdParam[];\n index: number;\n\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * called to validate parameters.\n */\n validateParams(): void {\n //\n }\n\n get name(): string {\n return this.constructor.name;\n }\n\n get type(): string {\n return \"Command\";\n }\n\n debugValue(): any {\n return { name: this.name, index: this.index, params: this.params };\n }\n\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n abstract applyToNotation(notebook: Notation): void;\n}\n\nexport class RawBlock extends Entity {\n constructor(public content: string, public contentType: string = \"md\") {\n super();\n }\n\n debugValue(): any {\n return { ...super.debugValue(), content: this.content, contentType: this.contentType };\n }\n}\n\nexport class MetaData {\n constructor(public readonly key: string, public readonly value: string, public readonly params?: any) {\n params = params || {};\n }\n}\n\nexport class Notation extends Entity {\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _currRoleDef: TSU.Nullable<RoleDef> = null;\n roles: RoleDef[] = [];\n blocks: (Line | RawBlock)[] = [];\n currentAPB = 1;\n currentCycle: Cycle = Cycle.DEFAULT;\n currentBreaks: number[] = [];\n metadata = new Map<string, MetaData>();\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n get type(): unknown {\n return \"Notation\";\n }\n\n addLine(line: Line): void {\n this.blocks.push(line);\n }\n\n removeLine(line: Line): number {\n const index = this.blocks.findIndex((l) => l == line);\n if (index >= 0) {\n this.blocks.splice(index, 1);\n }\n return index;\n }\n\n addRawBlock(raw: RawBlock): void {\n this.blocks.push(raw);\n this.resetLine();\n }\n\n addMetaData(meta: MetaData): void {\n if (!this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n debugValue(): any {\n return {\n ...super.debugValue,\n roles: this.roles,\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentCycle: this.currentCycle?.uuid,\n currentBreaks: this.currentBreaks,\n };\n }\n\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name == \"\") {\n return this.roles[this.roles.length - 1] || null;\n }\n for (let i = 0; i < this.roles.length; i++) {\n const rd = this.roles[i];\n if (name == rd.name) return rd;\n }\n return null;\n }\n\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name);\n if (roleDef != null) {\n throw new Error(\"Role already exists\");\n // roleDef.notesOnly = notesOnly;\n // return roleDef;\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.roles.length;\n this.roles.push(rd);\n\n return rd;\n }\n\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n if (this.roles.length == 0) {\n return null;\n } else {\n this._currRoleDef = this.roles[this.roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n // Gets the current line, creating it if needed\n private _currentLine: Line | null = null;\n get currentLine(): Line {\n if (this._currentLine == null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n resetLine(): void {\n this._currentLine = null;\n }\n\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n\n private _layoutParams: LayoutParams | null = null;\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\n this._layoutParams = this.findUnnamedLayoutParams();\n if (this._layoutParams == null) {\n this._layoutParams = this.snapshotLayoutParams();\n this._unnamedLayoutParams.push(this._layoutParams);\n }\n }\n return this._layoutParams;\n }\n\n ensureNamedLayoutParams(name: string): LayoutParams {\n let lp = this._namedLayoutParams.get(name) || null;\n if (lp == null || this._layoutParams != lp) {\n // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Find a layout params that is currently _unnamed but matches one\n * by current set of layout attributes.\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n}\n"]}
|
package/lib/esm/parser.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export declare class Parser {
|
|
|
18
18
|
newRest: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Rest;
|
|
19
19
|
newDoubleSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Space;
|
|
20
20
|
newSilentSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Space;
|
|
21
|
+
applyPreMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
|
|
22
|
+
applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
|
|
21
23
|
applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
|
|
22
24
|
newArray: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any[];
|
|
23
25
|
concatAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
|