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/cjs/layouts.js
CHANGED
|
@@ -22,29 +22,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
-
if (!m) return o;
|
|
28
|
-
var i = m.call(o), r, ar = [], e;
|
|
29
|
-
try {
|
|
30
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
-
}
|
|
32
|
-
catch (error) { e = { error: error }; }
|
|
33
|
-
finally {
|
|
34
|
-
try {
|
|
35
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
-
}
|
|
37
|
-
finally { if (e) throw e.error; }
|
|
38
|
-
}
|
|
39
|
-
return ar;
|
|
40
|
-
};
|
|
41
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
26
|
exports.LayoutParams = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
const TSU = __importStar(require("@panyam/tsutils"));
|
|
28
|
+
const cycle_1 = require("./cycle");
|
|
29
|
+
const ZERO = TSU.Num.Fraction.ZERO;
|
|
30
|
+
class LayoutParams {
|
|
31
|
+
constructor(config) {
|
|
48
32
|
this.uuid = LayoutParams.counter++;
|
|
49
33
|
config = config || {};
|
|
50
34
|
this.beatDuration = config.beatDuration || 1;
|
|
@@ -61,35 +45,33 @@ var LayoutParams = (function () {
|
|
|
61
45
|
this._beatLayouts = [];
|
|
62
46
|
this.lineBreaks = config.lineBreaks || config.layout || [];
|
|
63
47
|
}
|
|
64
|
-
|
|
48
|
+
equals(another) {
|
|
65
49
|
return (this.beatDuration == another.beatDuration &&
|
|
66
50
|
this.cycle.equals(another.cycle) &&
|
|
67
51
|
this.lineBreaksEqual(another._lineBreaks));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this._lineBreaks.length == another.length && this._lineBreaks.every(
|
|
71
|
-
}
|
|
72
|
-
|
|
52
|
+
}
|
|
53
|
+
lineBreaksEqual(another) {
|
|
54
|
+
return this._lineBreaks.length == another.length && this._lineBreaks.every((x, i) => x == another[i]);
|
|
55
|
+
}
|
|
56
|
+
debugValue() {
|
|
73
57
|
var _a;
|
|
74
58
|
return {
|
|
75
59
|
cycle: (_a = this.cycle) === null || _a === void 0 ? void 0 : _a.debugValue(),
|
|
76
60
|
beatDuration: this.beatDuration,
|
|
77
61
|
lineBreaks: this._lineBreaks,
|
|
78
62
|
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
for (var i = 0; i < this._lineBreaks.length; i++) {
|
|
63
|
+
}
|
|
64
|
+
getBeatLocation(beat) {
|
|
65
|
+
const modIndex = beat.index % this.totalBeats;
|
|
66
|
+
let total = 0;
|
|
67
|
+
for (let i = 0; i < this._lineBreaks.length; i++) {
|
|
85
68
|
if (modIndex < total + this._lineBreaks[i]) {
|
|
86
|
-
|
|
87
|
-
var startBeat = beat;
|
|
69
|
+
let offset = ZERO;
|
|
88
70
|
if (modIndex > total) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (
|
|
92
|
-
|
|
71
|
+
const cursor = new cycle_1.CycleCursor(this.cycle, beat.barIndex, beat.beatIndex, beat.instance);
|
|
72
|
+
let [, duration] = cursor.prev;
|
|
73
|
+
for (let i = total; i < modIndex; i++) {
|
|
74
|
+
[, duration] = cursor.prev;
|
|
93
75
|
offset = offset.plus(duration.timesNum(this.beatDuration));
|
|
94
76
|
}
|
|
95
77
|
}
|
|
@@ -99,72 +81,54 @@ var LayoutParams = (function () {
|
|
|
99
81
|
}
|
|
100
82
|
throw new Error("Invalid beat index: " + beat.index);
|
|
101
83
|
return [-1, -1, ZERO];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
84
|
+
}
|
|
85
|
+
get lineBreaks() {
|
|
86
|
+
if (!this._lineBreaks || this._lineBreaks.length == 0) {
|
|
87
|
+
this.lineBreaks = [this.cycle.beatCount];
|
|
88
|
+
}
|
|
89
|
+
return this._lineBreaks;
|
|
90
|
+
}
|
|
91
|
+
set lineBreaks(val) {
|
|
92
|
+
this._lineBreaks = val;
|
|
93
|
+
this.refreshLayout();
|
|
94
|
+
}
|
|
95
|
+
get beatLayouts() {
|
|
96
|
+
if (!this._beatLayouts || this._beatLayouts.length < this.lineBreaks.length) {
|
|
112
97
|
this.refreshLayout();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
98
|
+
}
|
|
99
|
+
return this._beatLayouts;
|
|
100
|
+
}
|
|
101
|
+
get totalBeats() {
|
|
102
|
+
this.beatLayouts;
|
|
103
|
+
return this._totalBeats;
|
|
104
|
+
}
|
|
105
|
+
get totalLayoutDuration() {
|
|
106
|
+
this.beatLayouts;
|
|
107
|
+
return this._totalLayoutDuration;
|
|
108
|
+
}
|
|
109
|
+
refreshLayout() {
|
|
110
|
+
const cycleIter = this.cycle.iterateBeats();
|
|
111
|
+
const akb = this.beatDuration;
|
|
112
|
+
this._beatLayouts = this.lineBreaks.map((numBeats, index) => {
|
|
113
|
+
const beats = [];
|
|
114
|
+
for (let i = 0; i < numBeats; i++) {
|
|
115
|
+
const nextCP = cycleIter.next().value;
|
|
125
116
|
nextCP[1] = nextCP[1].timesNum(akb);
|
|
126
117
|
beats.push(nextCP);
|
|
127
118
|
}
|
|
128
119
|
return beats;
|
|
129
120
|
});
|
|
130
|
-
this._totalBeats = this.lineBreaks.reduce(
|
|
131
|
-
this._rowDurations = this._beatLayouts.map(
|
|
132
|
-
this._rowDurations.forEach(
|
|
133
|
-
|
|
121
|
+
this._totalBeats = this.lineBreaks.reduce((a, b) => a + b, 0);
|
|
122
|
+
this._rowDurations = this._beatLayouts.map((beats) => beats.reduce((x, y) => x.plus(y[1]), ZERO));
|
|
123
|
+
this._rowDurations.forEach((rd, index) => {
|
|
124
|
+
this._rowStartOffsets[index] = index == 0 ? ZERO : this._rowStartOffsets[index - 1].plus(rd);
|
|
134
125
|
});
|
|
135
|
-
this._rowEndOffsets = this._rowDurations.map(
|
|
136
|
-
return
|
|
126
|
+
this._rowEndOffsets = this._rowDurations.map((rd, index) => {
|
|
127
|
+
return this._rowStartOffsets[index].plus(rd);
|
|
137
128
|
});
|
|
138
|
-
this._totalLayoutDuration = this._rowDurations.reduce(
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
get: function () {
|
|
142
|
-
if (!this._beatLayouts || this._beatLayouts.length < this.lineBreaks.length) {
|
|
143
|
-
this.refreshLayout();
|
|
144
|
-
}
|
|
145
|
-
return this._beatLayouts;
|
|
146
|
-
},
|
|
147
|
-
enumerable: false,
|
|
148
|
-
configurable: true
|
|
149
|
-
});
|
|
150
|
-
Object.defineProperty(LayoutParams.prototype, "totalBeats", {
|
|
151
|
-
get: function () {
|
|
152
|
-
this.beatLayouts;
|
|
153
|
-
return this._totalBeats;
|
|
154
|
-
},
|
|
155
|
-
enumerable: false,
|
|
156
|
-
configurable: true
|
|
157
|
-
});
|
|
158
|
-
Object.defineProperty(LayoutParams.prototype, "totalLayoutDuration", {
|
|
159
|
-
get: function () {
|
|
160
|
-
this.beatLayouts;
|
|
161
|
-
return this._totalLayoutDuration;
|
|
162
|
-
},
|
|
163
|
-
enumerable: false,
|
|
164
|
-
configurable: true
|
|
165
|
-
});
|
|
166
|
-
LayoutParams.counter = 0;
|
|
167
|
-
return LayoutParams;
|
|
168
|
-
}());
|
|
129
|
+
this._totalLayoutDuration = this._rowDurations.reduce((x, y) => x.plus(y), ZERO);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
169
132
|
exports.LayoutParams = LayoutParams;
|
|
133
|
+
LayoutParams.counter = 0;
|
|
170
134
|
//# sourceMappingURL=layouts.js.map
|
package/lib/cjs/layouts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layouts.js","sourceRoot":"","sources":["../../src/layouts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,iCAA4D;AAG5D,IAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AAEnC;IAaE,sBAAY,MAAY;QAXf,SAAI,GAAG,YAAY,CA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,EAAE;gBAC3E,IAAI,CAAC,aAAa,EAAE,CAAC;aACtB;YACD,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;;;OAAA;IAKD,sBAAI,oCAAU;aAAd;YACE,IAAI,CAAC,WAAW,CAAC;YACjB,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;;;OAAA;IAKD,sBAAI,6CAAmB;aAAvB;YACE,IAAI,CAAC,WAAW,CAAC;YACjB,OAAO,IAAI,CAAC,oBAAoB,CAAC;QACnC,CAAC;;;OAAA;IAjLc,oBAAO,GAAG,CAAC,CAAC;IA+M7B,mBAAC;CAAA,AAhND,IAgNC;AAhNY,oCAAY","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Cycle, CyclePosition, CycleCursor } from \"./cycle\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\n\nexport class LayoutParams {\n private static counter = 0;\n readonly uuid = LayoutParams.counter++;\n beatDuration: number;\n cycle: Cycle;\n protected _lineBreaks: number[];\n private _rowStartOffsets: Fraction[];\n private _rowEndOffsets: Fraction[];\n private _rowDurations: Fraction[];\n private _totalLayoutDuration;\n private _beatLayouts: [CyclePosition, Fraction][][];\n private _totalBeats: number;\n\n constructor(config?: any) {\n config = config || {};\n this.beatDuration = config.beatDuration || 1;\n if (\"cycle\" in config) this.cycle = config.cycle;\n if (!this.cycle || this.cycle.duration.isZero) {\n this.cycle = Cycle.DEFAULT;\n }\n\n this._rowStartOffsets = [];\n this._rowEndOffsets = [];\n this._rowDurations = [];\n this._totalLayoutDuration = ZERO;\n this._totalBeats = 0;\n this._beatLayouts = [];\n this.lineBreaks = config.lineBreaks || config.layout || [];\n }\n\n equals(another: this): boolean {\n return (\n // super.equals(another) &&\n this.beatDuration == another.beatDuration &&\n this.cycle.equals(another.cycle) &&\n this.lineBreaksEqual(another._lineBreaks)\n );\n }\n\n lineBreaksEqual(another: number[]): boolean {\n return this._lineBreaks.length == another.length && this._lineBreaks.every((x, i) => x == another[i]);\n }\n\n debugValue(): any {\n return {\n // ...super.debugValue(),\n cycle: this.cycle?.debugValue(),\n beatDuration: this.beatDuration,\n lineBreaks: this._lineBreaks,\n };\n }\n\n /**\n * Returns the \"location\" of a beat within a layout.\n *\n * Lines are broken into beats of notes (which can be changed) and those beats\n * are aligned as per the specs in the LayoutParams (breaks).\n *\n * This methods returns the triple: [layoutLine, layoutColumn, rowOffset]\n * where\n *\n * layoutLine: The particular line in the layout break spec this index falls in. Note\n * that since lines can start with negative offsets, we can even return a\n * layoutLine that is towards the end and then go back to 0, eg 4, 0, 1, 2, 3, 4 ...\n * layoutColumn: The column within the layoutLine line where this beat falls.\n * rowOffset: The note offset of the beat from the start of the row/line\n * (not from the start of the cycle).\n *\n * Note the beatIndex can also be negative so we can return a beat starting from before\n * the cycle starting point.\n *\n * To calculate the \"real\" line globally simply do:\n *\n * realLine = [Math.floor(beatIndex / this.totalBeats) + layoutLine;\n */\n getBeatLocation(beat: {\n index: number;\n barIndex: number;\n beatIndex: number;\n instance: number;\n }): [number, number, Fraction] {\n const modIndex = beat.index % this.totalBeats;\n let total = 0;\n for (let i = 0; i < this._lineBreaks.length; i++) {\n if (modIndex < total + this._lineBreaks[i]) {\n // TODO: What is the right offset here?\n let offset = ZERO;\n const startBeat = beat;\n if (modIndex > total) {\n const cursor = new CycleCursor(this.cycle, beat.barIndex, beat.beatIndex, beat.instance);\n let [pos, duration] = cursor.prev;\n for (let i = total; i < modIndex; i++) {\n [pos, duration] = cursor.prev;\n offset = offset.plus(duration.timesNum(this.beatDuration));\n }\n }\n return [i, modIndex - total, offset];\n }\n total += this._lineBreaks[i];\n }\n throw new Error(\"Invalid beat index: \" + beat.index);\n return [-1, -1, ZERO];\n }\n\n /**\n * Return the line layout - ie number of beats in each line - as a\n * repeating pattern.\n *\n * For example 4,2,4 indicates that the notes in our song should be\n * laid out 4 beats in line 1, 2 beats in line 2, 4 beats in line 3 and\n * 4 beats in line 4 and so on as long as there are more notes available\n * in this line.\n */\n get lineBreaks(): number[] {\n if (!this._lineBreaks || this._lineBreaks.length == 0) {\n // trigger a refresh\n this.lineBreaks = [this.cycle.beatCount];\n }\n return this._lineBreaks;\n }\n\n /**\n * Sets the line layout pattern.\n */\n set lineBreaks(val: number[]) {\n this._lineBreaks = val;\n this.refreshLayout();\n }\n\n refreshLayout(): void {\n const cycleIter = this.cycle.iterateBeats();\n const akb = this.beatDuration;\n this._beatLayouts = this.lineBreaks.map((numBeats, index) => {\n const beats: [CyclePosition, Fraction][] = [];\n // see what the beat lengths are here\n for (let i = 0; i < numBeats; i++) {\n const nextCP = cycleIter.next().value;\n nextCP[1] = nextCP[1].timesNum(akb);\n beats.push(nextCP);\n }\n return beats;\n });\n this._totalBeats = this.lineBreaks.reduce((a, b) => a + b, 0);\n this._rowDurations = this._beatLayouts.map((beats) => beats.reduce((x, y) => x.plus(y[1]), ZERO));\n this._rowDurations.forEach((rd, index) => {\n this._rowStartOffsets[index] = index == 0 ? ZERO : this._rowStartOffsets[index - 1].plus(rd);\n });\n this._rowEndOffsets = this._rowDurations.map((rd, index) => {\n return this._rowStartOffsets[index].plus(rd);\n });\n this._totalLayoutDuration = this._rowDurations.reduce((x, y) => x.plus(y), ZERO);\n }\n\n /**\n * Returns the number of beats in each line based on the line layout\n * after taking beatDuration into account.\n */\n get beatLayouts(): ReadonlyArray<ReadonlyArray<[CyclePosition, Fraction]>> {\n if (!this._beatLayouts || this._beatLayouts.length < this.lineBreaks.length) {\n this.refreshLayout();\n }\n return this._beatLayouts;\n }\n\n /**\n * Total duration of all beats across all lines in our line layout.\n */\n get totalBeats(): number {\n this.beatLayouts;\n return this._totalBeats;\n }\n\n /**\n * Total duration of all beats across all lines in our line layout.\n */\n get totalLayoutDuration(): Fraction {\n this.beatLayouts;\n return this._totalLayoutDuration;\n }\n\n /*\n layoutOffsetsFor(offset: Fraction, layoutLine = -1): [number, Fraction] {\n const m1 = offset.mod(this.totalLayoutDuration);\n\n // layoutLine = L such that layout[L].startOffset <= atom.offset % totalLayoutDuration < layout[L].endOffset\n // calculate layoutLine if not provided\n if (layoutLine < 0) {\n // this.beatLayouts should kick off eval of all row offsets, durations etc\n for (let i = 0; i < this.beatLayouts.length; i++) {\n let cmp = this._rowStartOffsets[i].cmp(m1);\n if (cmp >= 0) {\n cmp = m1.cmp(this._rowEndOffsets[i]);\n if (cmp < 0) {\n layoutLine = i;\n break;\n }\n }\n }\n }\n if (layoutLine < 0) {\n throw new Error(\"Atom offset falls outside beat layout range: \" + offset.toString());\n }\n\n // offset = atom.offset % totalLayoutDuration - rowOffset[layoutLine]\n const layoutOffset = m1.minus(this._rowStartOffsets[layoutLine]);\n return [layoutLine, layoutOffset];\n }\n */\n}\n"]}
|
|
1
|
+
{"version":3,"file":"layouts.js","sourceRoot":"","sources":["../../src/layouts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,mCAA4D;AAG5D,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AAEnC,MAAa,YAAY;IAavB,YAAY,MAAY;QAXf,SAAI,GAAG,YAAY,CAAC,OAAO,EAAE,CAAC;QAYrC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC;QAC7C,IAAI,OAAO,IAAI,MAAM;YAAE,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QACjD,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE;YAC7C,IAAI,CAAC,KAAK,GAAG,aAAK,CAAC,OAAO,CAAC;SAC5B;QAED,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACx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C,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;QAClG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACvC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/F,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACzD,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACnF,CAAC;;AAzMH,oCA0MC;AAzMgB,oBAAO,GAAG,CAAC,CAAC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Cycle, CyclePosition, CycleCursor } from \"./cycle\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\n\nexport class LayoutParams {\n private static counter = 0;\n readonly uuid = LayoutParams.counter++;\n beatDuration: number;\n cycle: Cycle;\n protected _lineBreaks: number[];\n private _rowStartOffsets: Fraction[];\n private _rowEndOffsets: Fraction[];\n private _rowDurations: Fraction[];\n private _totalLayoutDuration;\n private _beatLayouts: [CyclePosition, Fraction][][];\n private _totalBeats: number;\n\n constructor(config?: any) {\n config = config || {};\n this.beatDuration = config.beatDuration || 1;\n if (\"cycle\" in config) this.cycle = config.cycle;\n if (!this.cycle || this.cycle.duration.isZero) {\n this.cycle = Cycle.DEFAULT;\n }\n\n this._rowStartOffsets = [];\n this._rowEndOffsets = [];\n this._rowDurations = [];\n this._totalLayoutDuration = ZERO;\n this._totalBeats = 0;\n this._beatLayouts = [];\n this.lineBreaks = config.lineBreaks || config.layout || [];\n }\n\n equals(another: this): boolean {\n return (\n // super.equals(another) &&\n this.beatDuration == another.beatDuration &&\n this.cycle.equals(another.cycle) &&\n this.lineBreaksEqual(another._lineBreaks)\n );\n }\n\n lineBreaksEqual(another: number[]): boolean {\n return this._lineBreaks.length == another.length && this._lineBreaks.every((x, i) => x == another[i]);\n }\n\n debugValue(): any {\n return {\n // ...super.debugValue(),\n cycle: this.cycle?.debugValue(),\n beatDuration: this.beatDuration,\n lineBreaks: this._lineBreaks,\n };\n }\n\n /**\n * Returns the \"location\" of a beat within a layout.\n *\n * Lines are broken into beats of notes and those beats are aligned as per\n * the specs in the LayoutParams (breaks). For example if the breaks param\n * stipulates [5, 5, 4] then we have 5 beats in the first 2 lines and 4 in\n * the last line.\n *\n * If a line contains say 50 beats (B1 - B50), then it is laid out as:\n *\n * C1 C2 C3 C4 C5\n * ---------------------\n * L1 | B1 B2 B3 B4 B5\n * L1 | B6 B7 B8 B9 B10\n * L1 | B11 B12 B13 B14\n * L2 | B15 B16 B17 B18 B19\n * L2 | B20 B21 B22 B23 B24\n * L2 | B25 B26 B27 B28\n * L3 | B29 B30 B31 B32 B33\n * L3 | B34 B35 B36 B37 B38\n * L3 | B39 B40 B41 B42\n * L4 | B43 B44 B45 B46 B47\n * L4 | B48 B49 B50\n *\n * This methods returns the triple: [layoutLine, layoutColumn, rowOffset]\n * where\n *\n * layoutLine: The particular line in the layout break spec this index falls in.\n * *Note*: Since lines can start with negative offsets, we can\n * even return a layoutLine that is towards the end and then go\n * back to 0, eg 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 ...\n * (eg returns L1 or L2 ... Ln)\n * layoutColumn: The column within the layoutLine line where this beat falls.\n * (eg C1 - C5 above - or depending on how many columns exist\n * in the particular layout line).\n * rowOffset: The note offset of the beat from the start of the row/line\n * (not from the start of the cycle).\n *\n * Note the beatIndex can also be negative so we can return a beat\n * starting from before the cycle starting point.\n *\n * To calculate the \"real\" line globally simply do:\n *\n * realLine = [Math.floor(beatIndex / this.totalBeats) + layoutLine;\n *\n * Some examples here are (using B1-B50 above):\n */\n getBeatLocation(beat: {\n index: number;\n barIndex: number;\n beatIndex: number;\n instance: number;\n }): [number, number, Fraction] {\n const modIndex = beat.index % this.totalBeats;\n let total = 0;\n for (let i = 0; i < this._lineBreaks.length; i++) {\n if (modIndex < total + this._lineBreaks[i]) {\n // TODO: What is the right offset here?\n let offset = ZERO;\n if (modIndex > total) {\n const cursor = new CycleCursor(this.cycle, beat.barIndex, beat.beatIndex, beat.instance);\n let [, duration] = cursor.prev;\n for (let i = total; i < modIndex; i++) {\n [, duration] = cursor.prev;\n offset = offset.plus(duration.timesNum(this.beatDuration));\n }\n }\n return [i, modIndex - total, offset];\n }\n total += this._lineBreaks[i];\n }\n throw new Error(\"Invalid beat index: \" + beat.index);\n return [-1, -1, ZERO];\n }\n\n /**\n * Return the line layout - ie number of beats in each line - as a\n * repeating pattern.\n *\n * For example 4,2,4 indicates that the notes in our song should be\n * laid out 4 beats in line 1, 2 beats in line 2, 4 beats in line 3 and\n * 4 beats in line 4 and so on as long as there are more notes available\n * in this line.\n */\n get lineBreaks(): number[] {\n if (!this._lineBreaks || this._lineBreaks.length == 0) {\n // trigger a refresh\n this.lineBreaks = [this.cycle.beatCount];\n }\n return this._lineBreaks;\n }\n\n /**\n * Sets the line layout pattern.\n */\n set lineBreaks(val: number[]) {\n this._lineBreaks = val;\n this.refreshLayout();\n }\n\n /**\n * Returns the number of beats in each line based on the line layout\n * after taking beatDuration into account.\n */\n get beatLayouts(): ReadonlyArray<ReadonlyArray<[CyclePosition, Fraction]>> {\n if (!this._beatLayouts || this._beatLayouts.length < this.lineBreaks.length) {\n this.refreshLayout();\n }\n return this._beatLayouts;\n }\n\n /**\n * Total duration of all beats across all lines in our line layout.\n */\n get totalBeats(): number {\n this.beatLayouts;\n return this._totalBeats;\n }\n\n /**\n * Total duration of all beats across all lines in our line layout.\n */\n get totalLayoutDuration(): Fraction {\n this.beatLayouts;\n return this._totalLayoutDuration;\n }\n\n protected refreshLayout(): void {\n const cycleIter = this.cycle.iterateBeats();\n const akb = this.beatDuration;\n this._beatLayouts = this.lineBreaks.map((numBeats, index) => {\n const beats: [CyclePosition, Fraction][] = [];\n // see what the beat lengths are here\n for (let i = 0; i < numBeats; i++) {\n const nextCP = cycleIter.next().value;\n nextCP[1] = nextCP[1].timesNum(akb);\n beats.push(nextCP);\n }\n return beats;\n });\n this._totalBeats = this.lineBreaks.reduce((a, b) => a + b, 0);\n this._rowDurations = this._beatLayouts.map((beats) => beats.reduce((x, y) => x.plus(y[1]), ZERO));\n this._rowDurations.forEach((rd, index) => {\n this._rowStartOffsets[index] = index == 0 ? ZERO : this._rowStartOffsets[index - 1].plus(rd);\n });\n this._rowEndOffsets = this._rowDurations.map((rd, index) => {\n return this._rowStartOffsets[index].plus(rd);\n });\n this._totalLayoutDuration = this._rowDurations.reduce((x, y) => x.plus(y), ZERO);\n }\n}\n"]}
|
package/lib/cjs/loader.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
2
|
import * as G from "galore";
|
|
3
|
-
import {
|
|
3
|
+
import { GlobalBeatLayout } from "./beats";
|
|
4
4
|
import { Notation } from "./notation";
|
|
5
5
|
export declare function parse(input: string): [Notation, G.ParseError[]];
|
|
6
|
-
export declare function load(codeText: string, config?: any): [Notation,
|
|
6
|
+
export declare function load(codeText: string, config?: any): [Notation, GlobalBeatLayout, G.ParseError[], TSU.StringMap<number>];
|
package/lib/cjs/loader.js
CHANGED
|
@@ -22,142 +22,42 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
-
if (!m) return o;
|
|
28
|
-
var i = m.call(o), r, ar = [], e;
|
|
29
|
-
try {
|
|
30
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
-
}
|
|
32
|
-
catch (error) { e = { error: error }; }
|
|
33
|
-
finally {
|
|
34
|
-
try {
|
|
35
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
-
}
|
|
37
|
-
finally { if (e) throw e.error; }
|
|
38
|
-
}
|
|
39
|
-
return ar;
|
|
40
|
-
};
|
|
41
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
42
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
43
|
-
if (ar || !(i in from)) {
|
|
44
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
45
|
-
ar[i] = from[i];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
49
|
-
};
|
|
50
|
-
var __values = (this && this.__values) || function(o) {
|
|
51
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
52
|
-
if (m) return m.call(o);
|
|
53
|
-
if (o && typeof o.length === "number") return {
|
|
54
|
-
next: function () {
|
|
55
|
-
if (o && i >= o.length) o = void 0;
|
|
56
|
-
return { value: o && o[i++], done: !o };
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
60
|
-
};
|
|
61
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
26
|
exports.load = exports.parse = void 0;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
27
|
+
const TSU = __importStar(require("@panyam/tsutils"));
|
|
28
|
+
const beats_1 = require("./beats");
|
|
29
|
+
const parser_1 = require("./parser");
|
|
30
|
+
const notation_1 = require("./notation");
|
|
67
31
|
function parse(input) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var errors = [];
|
|
32
|
+
const notation = new notation_1.Notation();
|
|
33
|
+
const parser = new parser_1.Parser();
|
|
34
|
+
const errors = [];
|
|
72
35
|
parser.parse(input);
|
|
73
|
-
errors.push
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var cmd = _c.value;
|
|
77
|
-
cmd.applyToNotation(notation);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
81
|
-
finally {
|
|
82
|
-
try {
|
|
83
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
84
|
-
}
|
|
85
|
-
finally { if (e_1) throw e_1.error; }
|
|
86
|
-
}
|
|
36
|
+
errors.push(...parser.errors);
|
|
37
|
+
for (const cmd of parser.commands)
|
|
38
|
+
cmd.applyToNotation(notation);
|
|
87
39
|
return [notation, errors];
|
|
88
40
|
}
|
|
89
41
|
exports.parse = parse;
|
|
90
|
-
function load(codeText, config) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var block = _f.value;
|
|
101
|
-
if (block.type == "Line") {
|
|
102
|
-
var line = block;
|
|
103
|
-
var layoutParams = notation.layoutParamsForLine(line) || null;
|
|
104
|
-
if (!line.isEmpty) {
|
|
105
|
-
TSU.assert(layoutParams != null, "Layout params for a non empty line *should* exist");
|
|
106
|
-
var beatLayout = beatLayouts.get(layoutParams.uuid) || null;
|
|
107
|
-
if (beatLayout == null) {
|
|
108
|
-
beatLayout = new beats_1.BeatLayout(layoutParams);
|
|
109
|
-
beatLayouts.set(layoutParams.uuid, beatLayout);
|
|
110
|
-
}
|
|
111
|
-
var roleBeats = [];
|
|
112
|
-
beatsByLineRole.set(line.uuid, roleBeats);
|
|
113
|
-
var lineOffset = line.offset.divbyNum(layoutParams.beatDuration);
|
|
114
|
-
try {
|
|
115
|
-
for (var _g = (e_3 = void 0, __values(line.roles)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
116
|
-
var role = _h.value;
|
|
117
|
-
var bb = new beats_1.BeatsBuilder(role, layoutParams, lineOffset);
|
|
118
|
-
bb.addAtoms.apply(bb, __spreadArray([], __read(role.atoms), false));
|
|
119
|
-
roleBeats.push(bb.beats);
|
|
120
|
-
try {
|
|
121
|
-
for (var _j = (e_4 = void 0, __values(bb.beats)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
122
|
-
var beat = _k.value;
|
|
123
|
-
beatLayout.addBeat(beat);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
127
|
-
finally {
|
|
128
|
-
try {
|
|
129
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
130
|
-
}
|
|
131
|
-
finally { if (e_4) throw e_4.error; }
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
136
|
-
finally {
|
|
137
|
-
try {
|
|
138
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
139
|
-
}
|
|
140
|
-
finally { if (e_3) throw e_3.error; }
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
147
|
-
finally {
|
|
148
|
-
try {
|
|
149
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
42
|
+
function load(codeText, config = {}) {
|
|
43
|
+
const beatLayout = new beats_1.GlobalBeatLayout();
|
|
44
|
+
const startTime = performance.now();
|
|
45
|
+
const [notation, errors] = parse(codeText);
|
|
46
|
+
const parseTime = performance.now();
|
|
47
|
+
for (const block of notation.blocks) {
|
|
48
|
+
if (block.type == "Line" && !block.isEmpty) {
|
|
49
|
+
const line = block;
|
|
50
|
+
TSU.assert(line.layoutParams != null, "Layout params for a non empty line *SHOULD* exist");
|
|
51
|
+
beatLayout.addLine(line);
|
|
150
52
|
}
|
|
151
|
-
finally { if (e_2) throw e_2.error; }
|
|
152
53
|
}
|
|
153
|
-
|
|
54
|
+
const buildTime = performance.now();
|
|
154
55
|
if (config.log) {
|
|
155
|
-
console.log(
|
|
56
|
+
console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);
|
|
156
57
|
}
|
|
157
58
|
return [
|
|
158
59
|
notation,
|
|
159
|
-
|
|
160
|
-
beatLayouts,
|
|
60
|
+
beatLayout,
|
|
161
61
|
errors,
|
|
162
62
|
{
|
|
163
63
|
parseTime: parseTime - startTime,
|
package/lib/cjs/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAGvC,mCAA2C;AAC3C,qCAAkC;AAClC,yCAAsC;AAEtC,SAAgB,KAAK,CAAC,KAAa;IACjC,MAAM,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAmB,EAAE,CAAC;IAClC,MAAM,C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;AAjCD,oBAiCC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport { Line } from \"./core\";\nimport { GlobalBeatLayout } from \"./beats\";\nimport { Parser } from \"./parser\";\nimport { Notation } from \"./notation\";\n\nexport function parse(input: string): [Notation, G.ParseError[]] {\n const notation = new Notation();\n const parser = new Parser();\n const errors: G.ParseError[] = [];\n parser.parse(input);\n errors.push(...parser.errors);\n for (const cmd of parser.commands) cmd.applyToNotation(notation);\n return [notation, errors];\n}\n\nexport function load(\n codeText: string,\n config: any = {},\n): [Notation, GlobalBeatLayout, G.ParseError[], TSU.StringMap<number>] {\n const beatLayout = new GlobalBeatLayout();\n const startTime = performance.now();\n const [notation, errors] = parse(codeText);\n const parseTime = performance.now();\n\n // Create Line Beats\n for (const block of notation.blocks) {\n if (block.type == \"Line\" && !(block as Line).isEmpty) {\n const line = block as Line;\n // LP should exist by now\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(line.layoutParams != null, \"Layout params for a non empty line *SHOULD* exist\");\n beatLayout.addLine(line);\n }\n }\n\n const buildTime = performance.now();\n if (config.log) {\n console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);\n }\n return [\n notation,\n beatLayout,\n errors,\n {\n parseTime: parseTime - startTime,\n buildTime: buildTime - parseTime,\n },\n ];\n}\n"]}
|
package/lib/cjs/notation.d.ts
CHANGED
|
@@ -45,14 +45,11 @@ export declare class Notation extends Entity {
|
|
|
45
45
|
private _currRoleDef;
|
|
46
46
|
roles: RoleDef[];
|
|
47
47
|
blocks: (Line | RawBlock)[];
|
|
48
|
-
private lpsForLine;
|
|
49
48
|
currentAPB: number;
|
|
50
49
|
currentCycle: Cycle;
|
|
51
50
|
currentBreaks: number[];
|
|
52
51
|
metadata: Map<string, MetaData>;
|
|
53
52
|
onMissingRole: (name: string) => RoleDef | null;
|
|
54
|
-
layoutParamsForLine(line: Line): null | LayoutParams;
|
|
55
|
-
setLayoutParamsForLine(line: Line, layoutParams: LayoutParams): void;
|
|
56
53
|
get unnamedLayoutParams(): ReadonlyArray<LayoutParams>;
|
|
57
54
|
get namedLayoutParams(): ReadonlyMap<string, LayoutParams>;
|
|
58
55
|
get type(): unknown;
|