notations 0.0.50 → 0.0.51
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 +3 -3
- package/lib/cjs/beats.js +57 -3
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/beatview.js +2 -2
- package/lib/cjs/beatview.js.map +1 -1
- package/lib/cjs/carnatic/NotationView.d.ts +4 -3
- package/lib/cjs/carnatic/NotationView.js +26 -9
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/carnatic/beatviews.d.ts +17 -0
- package/lib/cjs/carnatic/beatviews.js +64 -1
- package/lib/cjs/carnatic/beatviews.js.map +1 -1
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/esm/beats.d.ts +3 -3
- package/lib/esm/beats.js +58 -4
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/beatview.js +2 -2
- package/lib/esm/beatview.js.map +1 -1
- package/lib/esm/carnatic/NotationView.d.ts +4 -3
- package/lib/esm/carnatic/NotationView.js +27 -10
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/carnatic/beatviews.d.ts +17 -0
- package/lib/esm/carnatic/beatviews.js +39 -0
- package/lib/esm/carnatic/beatviews.js.map +1 -1
- package/lib/esm/shapes.js.map +1 -1
- package/package.json +1 -1
package/lib/cjs/beats.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
|
-
import { Line, Atom, Role } from "./";
|
|
2
|
+
import { Marker, Line, Atom, Role } from "./";
|
|
3
3
|
import { CycleIterator } from "./cycle";
|
|
4
4
|
import { WindowIterator } from "./iterators";
|
|
5
5
|
import { LayoutParams } from "./layouts";
|
|
@@ -17,8 +17,6 @@ export declare class Beat {
|
|
|
17
17
|
nextBeat: null | Beat;
|
|
18
18
|
private static idCounter;
|
|
19
19
|
readonly uuid: number;
|
|
20
|
-
layoutLine: number;
|
|
21
|
-
layoutColumn: number;
|
|
22
20
|
atom: Atom;
|
|
23
21
|
protected atomIsPlaceholder: boolean;
|
|
24
22
|
constructor(index: number, role: Role, offset: Fraction, duration: Fraction, barIndex: number, beatIndex: number, instance: number, prevBeat: null | Beat, nextBeat: null | Beat);
|
|
@@ -27,6 +25,8 @@ export declare class Beat {
|
|
|
27
25
|
get filled(): boolean;
|
|
28
26
|
get remaining(): Fraction;
|
|
29
27
|
add(atom: Atom): boolean;
|
|
28
|
+
get preMarkers(): Marker[];
|
|
29
|
+
get postMarkers(): Marker[];
|
|
30
30
|
}
|
|
31
31
|
export declare class BeatsBuilder {
|
|
32
32
|
readonly role: Role;
|
package/lib/cjs/beats.js
CHANGED
|
@@ -42,8 +42,6 @@ class Beat {
|
|
|
42
42
|
this.prevBeat = prevBeat;
|
|
43
43
|
this.nextBeat = nextBeat;
|
|
44
44
|
this.uuid = Beat.idCounter++;
|
|
45
|
-
this.layoutLine = -1;
|
|
46
|
-
this.layoutColumn = -1;
|
|
47
45
|
this.atomIsPlaceholder = false;
|
|
48
46
|
}
|
|
49
47
|
debugValue() {
|
|
@@ -83,6 +81,36 @@ class Beat {
|
|
|
83
81
|
}
|
|
84
82
|
return true;
|
|
85
83
|
}
|
|
84
|
+
get preMarkers() {
|
|
85
|
+
const out = [];
|
|
86
|
+
let curr = this.atom;
|
|
87
|
+
while (curr != null) {
|
|
88
|
+
for (const marker of curr.markersBefore || []) {
|
|
89
|
+
out.push(marker);
|
|
90
|
+
}
|
|
91
|
+
if (curr.type == _1.AtomType.GROUP) {
|
|
92
|
+
curr = curr.atoms.first;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
curr = null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
get postMarkers() {
|
|
101
|
+
const out = [];
|
|
102
|
+
let curr = this.atom;
|
|
103
|
+
while (curr != null) {
|
|
104
|
+
out.splice(0, 0, ...(curr.markersAfter || []));
|
|
105
|
+
if (curr.type == _1.AtomType.GROUP) {
|
|
106
|
+
curr = curr.atoms.last;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
curr = null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
86
114
|
}
|
|
87
115
|
exports.Beat = Beat;
|
|
88
116
|
Beat.idCounter = 0;
|
|
@@ -254,7 +282,33 @@ class GlobalBeatLayout {
|
|
|
254
282
|
const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);
|
|
255
283
|
const roleIndex = beat.role.line.indexOfRole(beat.role.name);
|
|
256
284
|
const realRow = line.roles.length * (layoutLine + Math.floor(beat.index / lp.totalBeats)) + roleIndex;
|
|
257
|
-
const realCol = layoutColumn * 3;
|
|
285
|
+
const realCol = 1 + layoutColumn * 3;
|
|
286
|
+
const preMarkers = beat.preMarkers;
|
|
287
|
+
if (preMarkers.length > 0) {
|
|
288
|
+
const val = {
|
|
289
|
+
beat: beat,
|
|
290
|
+
markers: preMarkers,
|
|
291
|
+
};
|
|
292
|
+
const precol = beatColDAG.getBeatColumn(rowOffset, colEnd, -1);
|
|
293
|
+
gridModel.setValue(realRow, realCol - 1, val, (gridRow, col) => {
|
|
294
|
+
const cell = new grids_1.GridCell(gridRow, col);
|
|
295
|
+
cell.colAlign = precol;
|
|
296
|
+
return cell;
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const postMarkers = beat.postMarkers;
|
|
300
|
+
if (postMarkers.length > 0) {
|
|
301
|
+
const val = {
|
|
302
|
+
beat: beat,
|
|
303
|
+
markers: postMarkers,
|
|
304
|
+
};
|
|
305
|
+
const postcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 1);
|
|
306
|
+
gridModel.setValue(realRow, realCol + 1, val, (gridRow, col) => {
|
|
307
|
+
const cell = new grids_1.GridCell(gridRow, col);
|
|
308
|
+
cell.colAlign = postcol;
|
|
309
|
+
return cell;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
258
312
|
return gridModel.setValue(realRow, realCol, beat, (gridRow, col) => {
|
|
259
313
|
const cell = new grids_1.GridCell(gridRow, col);
|
|
260
314
|
cell.colAlign = bcol;
|
package/lib/cjs/beats.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beats.js","sourceRoot":"","sources":["../../src/beats.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,yBAAoD;AAEpD,2CAA6C;AAE7C,mCAAkF;AAGlF,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAEjC,MAAa,IAAI;IASf,YACkB,KAAa,EACb,IAAU,EACV,MAAgB,EAChB,QAAkB,EAClB,QAAgB,EAChB,SAAiB,EACjB,QAAgB,EAChB,QAAqB,EAC9B,QAAqB;QARZ,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAM;QACV,WAAM,GAAN,MAAM,CAAU;QAChB,aAAQ,GAAR,QAAQ,CAAU;QAClB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAa;QAC9B,aAAQ,GAAR,QAAQ,CAAa;QAhBrB,SAAI,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QACjC,eAAU,GAAG,CAAC,CAAC,CAAC;QAChB,iBAAY,GAAG,CAAC,CAAC,CAAC;QAIR,sBAAiB,GAAG,KAAK,CAAC;IAWjC,CAAC;IAEJ,UAAU;QACR,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;YACpB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,QAA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AAI,GAAG,IAAI,gBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvFD,4CAuFC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Group, Line, Atom, Space, Role } from \"./\";\nimport { CycleIterator, CyclePosition } from \"./cycle\";\nimport { WindowIterator } from \"./iterators\";\nimport { LayoutParams } from \"./layouts\";\nimport { GridModel, GridRow, GridCell, ColAlign, GridLayoutGroup } from \"./grids\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\nexport class Beat {\n private static idCounter = 0;\n readonly uuid = Beat.idCounter++;\n layoutLine = -1;\n layoutColumn = -1;\n // Should this be as flat Atoms or should we keep it as atoms and breakdown\n // later?\n atom: Atom;\n protected atomIsPlaceholder = false;\n constructor(\n public readonly index: number,\n public readonly role: Role,\n public readonly offset: Fraction,\n public readonly duration: Fraction,\n public readonly barIndex: number,\n public readonly beatIndex: number,\n public readonly instance: number,\n public readonly prevBeat: null | Beat,\n public nextBeat: null | Beat,\n ) {}\n\n debugValue(): any {\n return {\n index: this.index,\n role: this.role.name,\n offset: this.offset.toString(),\n duration: this.duration.toString(),\n barIndex: this.barIndex,\n beatIndex: this.beatIndex,\n instance: this.instance,\n atom: this.atom.debugValue(),\n };\n }\n\n get endOffset(): Fraction {\n return this.offset.plus(this.duration);\n }\n get filled(): boolean {\n return this.remaining.isZero;\n }\n\n get remaining(): Fraction {\n return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;\n }\n\n add(atom: Atom): boolean {\n if (this.remaining.cmp(atom.duration) < 0) {\n return false;\n }\n if (!this.atom) {\n this.atom = atom;\n } else {\n if (!this.atomIsPlaceholder) {\n this.atomIsPlaceholder = true;\n this.atom = new Group(this.atom).setDuration(ONE, true);\n }\n (this.atom as Group).addAtoms(true, atom);\n }\n return true;\n }\n}\n\nexport class BeatsBuilder {\n // All atoms divided into beats\n readonly beats: Beat[] = [];\n readonly startIndex: number;\n readonly beatOffset: Fraction;\n cycleIter: CycleIterator;\n windowIter: WindowIterator;\n\n // Callback for when an atom is added to this role.\n onAtomAdded: (atom: Atom, beat: Beat) => void;\n\n // Callback for when a new beat is added\n onBeatAdded: (beat: Beat) => void;\n // Callback for when a beat has been filled\n onBeatFilled: (beat: Beat) => void;\n\n constructor(\n public readonly role: Role,\n public readonly layoutParams: LayoutParams,\n public readonly startOffset: Fraction = ZERO,\n ...atoms: Atom[]\n ) {\n const [, [bar, beat, instance], beatOffset, index] = layoutParams.cycle.getPosition(startOffset);\n this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);\n this.windowIter = new WindowIterator();\n this.beatOffset = beatOffset;\n\n // evaluate the start beatindex - typically it would be 0 if things start\n // at beginning of a cycle. But if the start offset is < 0 then the\n // startIndex should also shift accordingly\n this.startIndex = index;\n this.addAtoms(...atoms);\n }\n\n addAtoms(...atoms: Atom[]): void {\n // First add all atoms to the atom Iterator so we can\n // fetch them as FlatAtoms. This is needed because atoms\n // passed here could be unflatted (via groups) or much larger\n // than what can fit in the given role/bar etc. So this\n // flattening and windowing is needed before we add them\n // to the views - and this is done by the durationIterators.\n this.windowIter.push(...atoms);\n while (this.windowIter.hasMore) {\n // get the last/current row and add a new one if it is full\n let currBeat = this.beats[this.beats.length - 1];\n\n // First add a row if last row is filled\n if (this.beats.length == 0 || currBeat.filled) {\n // what should be the beatlengths be here?\n currBeat = this.addBeat();\n }\n\n // For this beat get symbols in all roles\n const [remAtoms, filled] = this.windowIter.get(currBeat.remaining);\n TSU.assert(remAtoms.length > 0, \"Atleast one element should have been available here\");\n // render the atoms now\n for (const atom of remAtoms) {\n // console.log(\"Adding FA: \", flatAtom.debugValue(), flatAtom.atom);\n TSU.assert(currBeat.add(atom), \"Should return true as we are already using a duration iterator here\");\n if (this.onAtomAdded) this.onAtomAdded(atom, currBeat);\n }\n if (currBeat.filled) {\n if (this.onBeatFilled) this.onBeatFilled(currBeat);\n }\n }\n }\n\n protected addBeat(): Beat {\n const numBeats = this.beats.length;\n const lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];\n const nextCP: [CyclePosition, Fraction] = this.cycleIter.next().value;\n const apb = this.layoutParams.beatDuration;\n const newBeat = new Beat(\n lastBeat == null ? this.startIndex : lastBeat.index + 1,\n this.role,\n lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset,\n nextCP[1].timesNum(apb),\n nextCP[0][0],\n nextCP[0][1],\n nextCP[0][2],\n lastBeat,\n null,\n );\n if (lastBeat == null && this.beatOffset.isGT(ZERO)) {\n // Add spaces to fill up empty beats\n newBeat.add(new Space(this.beatOffset.timesNum(apb)));\n }\n if (lastBeat) lastBeat.nextBeat = newBeat;\n this.beats.push(newBeat);\n if (this.onBeatAdded) this.onBeatAdded(newBeat);\n return newBeat;\n }\n}\n\nexport class BeatColumn extends ColAlign {\n atomSpacing = 5;\n readonly key: string;\n constructor(\n public readonly offset: Fraction,\n public readonly endOffset: Fraction,\n public readonly markerType: number,\n ) {\n super();\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n this.key = BeatColumn.keyFor(offset, endOffset, markerType);\n }\n\n static keyFor(offset: Fraction, endOffset: Fraction, markerType = 0): string {\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n if (markerType < 0) {\n // return the column for the marker \"before\" this col\n // int his case only the \"start offset\" is needed and length doesnt matter\n return \":\" + offset.toString();\n } else if (markerType > 0) {\n // return the column for the marker \"after\" this col\n // in this case only thd end offset matters\n return endOffset.toString() + \":\";\n } else {\n return offset.toString() + \":\" + endOffset.toString();\n }\n }\n}\n\n/**\n * Grouping of beats by their column based on the layout params.\n * The confusion is we have beats broken up and saved in columns\n * but we are loosing how a line is supposed to access it in its own way\n * we have beatsByRole for getting all beats for a role (in a line)\n * sequentially we have beatColumns for getting all beats in a particular\n * column across all lines and roles globally.\n *\n * What we want here is for a given line get all roles, their beats\n * in zipped way. eg for a Line with 3 roles and say 10 beats each\n * (with the breaks of 4, 1) we need:\n *\n * R1 B1 R1 B2 R1 B3 R1 B4\n * R2 B1 R2 B2 R2 B3 R2 B4\n * R3 B1 R3 B2 R3 B3 R3 B4\n *\n * R1 B5\n * R2 B5\n * R3 B5\n *\n * R1 B6 R1 B7 R1 B8 R1 B9\n * R2 B6 R2 B7 R2 B8 R2 B9\n * R3 B6 R3 B7 R3 B8 R3 B9\n *\n * R1 B10\n * R2 B10\n * R3 B10\n *\n *\n * Here we have 5 distinct beat columns:\n *\n * 1: R1B1, R2B1, R3B1, R1B6, R2B6, R3B6,\n * 2: R1B2, R2B2, R3B2, R1B7, R2B7, R3B7,\n * 3: R1B3, R2B3, R3B3, R1B8, R2B8, R3B8,\n * 4: R1B4, R2B4, R3B4, R1B9, R2B9, R3B9,\n * 5: R1B5, R2B5, R3B5, R1B10, R2B10, R3B10,\n *\n */\nexport class BeatColDAG {\n beatColumns = new Map<string, BeatColumn>();\n\n constructor(public readonly layoutGroup: GridLayoutGroup) {\n //\n }\n\n /**\n * Gets the beat column of a given duration at the given offset.\n */\n getBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): BeatColumn {\n const [bcol, newcreated] = this.ensureBeatColumn(offset, endOffset, markerType);\n if (newcreated) {\n if (markerType == 0) {\n const [prevcol] = this.ensureBeatColumn(offset, endOffset, -1);\n const [nextcol] = this.ensureBeatColumn(offset, endOffset, 1);\n prevcol.addSuccessor(bcol);\n bcol.addSuccessor(nextcol);\n for (const other of this.beatColumns.values()) {\n // only join the \"marker\" columns\n if (other.markerType == -1 && endOffset.equals(other.offset)) {\n // our next col is a preecessor of other\n nextcol.addSuccessor(other);\n } else if (other.markerType == 1 && other.endOffset.equals(offset)) {\n // our prev col is a predecessor of other\n other.addSuccessor(prevcol);\n }\n }\n }\n }\n return bcol;\n }\n\n protected ensureBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): [BeatColumn, boolean] {\n const key = BeatColumn.keyFor(offset, endOffset, markerType);\n let bcol = this.beatColumns.get(key) || null;\n const newcreated = bcol == null;\n if (!bcol) {\n bcol = new BeatColumn(offset, endOffset, markerType);\n this.beatColumns.set(key, bcol);\n }\n return [bcol, newcreated];\n }\n}\n\n/**\n * Manages the beat layouts for *all* lines in a notation.\n */\ntype LineId = number;\ntype LPID = number;\nexport class GlobalBeatLayout {\n gridModelsForLine = new Map<LineId, GridModel>();\n roleBeatsForLine = new Map<LineId, Beat[][]>();\n beatColDAGsByLP = new Map<LPID, BeatColDAG>();\n readonly gridLayoutGroup = new GridLayoutGroup();\n\n /**\n * Get the GridView associated with a particular line.\n */\n getGridModelForLine(lineid: LineId): GridModel {\n let out = this.gridModelsForLine.get(lineid) || null;\n if (!out) {\n out = new GridModel();\n this.gridLayoutGroup.addGridModel(out);\n this.gridModelsForLine.set(lineid, out);\n }\n return out;\n }\n\n protected beatColDAGForLP(lpid: LPID): BeatColDAG {\n let out = this.beatColDAGsByLP.get(lpid) || null;\n if (!out) {\n out = new BeatColDAG(this.gridLayoutGroup);\n this.beatColDAGsByLP.set(lpid, out);\n }\n return out;\n }\n\n /**\n * First lines are added to the BeatLayout object.\n * This ensures that a line is broken down into beats and added\n * into a dedicated GridModel per line.\n *\n * A line must also be given the layout params by which the beat\n * break down will happen. This LayoutParams object does not have\n * to be unique per line (this non-constraint allows to align\n * beats across lines!).\n */\n addLine(line: Line): void {\n const gridModel = this.getGridModelForLine(line.uuid) as GridModel;\n gridModel.eventHub?.startBatchMode();\n this.lineToRoleBeats(line, gridModel);\n gridModel.eventHub?.commitBatch();\n }\n\n protected lineToRoleBeats(line: Line, gridModel: GridModel): Beat[][] {\n const lp = line.layoutParams;\n const roleBeats = [] as Beat[][];\n this.roleBeatsForLine.set(line.uuid, roleBeats);\n const lineOffset = line.offset.divbyNum(lp.beatDuration);\n for (const role of line.roles) {\n const bb = new BeatsBuilder(role, lp, lineOffset, ...role.atoms);\n roleBeats.push(bb.beats);\n\n // Add these to the beat layout too\n for (const beat of bb.beats) {\n // beat.ensureUniformSpaces(layoutParams.beatDuration);\n this.addBeat(beat, gridModel);\n }\n }\n return roleBeats;\n }\n\n /**\n * Adds the beat to this layout and returns the BeatColumn to which\n * this beat was added.\n */\n protected addBeat(beat: Beat, gridModel: GridModel): GridCell {\n // Get the beat column at this index (and line) and add to it.\n const line = beat.role.line;\n const lp = line.layoutParams;\n const beatColDAG = this.beatColDAGForLP(lp.uuid);\n const [layoutLine, layoutColumn, rowOffset] = lp.getBeatLocation(beat);\n const colEnd = rowOffset.plus(beat.duration, true);\n const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);\n\n // Since a beat's column has a \"pre\" and \"post\" col to, each\n // beat has 3 columns for it\n const roleIndex = beat.role.line.indexOfRole(beat.role.name);\n const realRow = line.roles.length * (layoutLine + Math.floor(beat.index / lp.totalBeats)) + roleIndex;\n const realCol = layoutColumn * 3;\n return gridModel.setValue(realRow, realCol, beat, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = bcol;\n return cell;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"beats.js","sourceRoot":"","sources":["../../src/beats.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,yBAAsE;AAEtE,2CAA6C;AAE7C,mCAAkF;AAGlF,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAEjC,MAAa,IAAI;IAOf,YACkB,KAAa,EACb,IAAU,EACV,MAAgB,EAChB,QAAkB,EAClB,QAAgB,EAChB,SAAiB,EACjB,QAAgB,EAChB,QAAqB,EAC9B,QAAqB;QARZ,UAAK,GAAL,KAAK,CAAQ;QACb,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AAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,OAAgB,EAAE,GAAW,EAAE,EAAE;YAClF,MAAM,IAAI,GAAG,IAAI,gBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlHD,4CAkHC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { AtomType, Marker, Group, Line, Atom, Space, Role } from \"./\";\nimport { CycleIterator, CyclePosition } from \"./cycle\";\nimport { WindowIterator } from \"./iterators\";\nimport { LayoutParams } from \"./layouts\";\nimport { GridModel, GridRow, GridCell, ColAlign, GridLayoutGroup } from \"./grids\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\nexport class Beat {\n private static idCounter = 0;\n readonly uuid = Beat.idCounter++;\n // Should this be as flat Atoms or should we keep it as atoms and breakdown\n // later?\n atom: Atom;\n protected atomIsPlaceholder = false;\n constructor(\n public readonly index: number,\n public readonly role: Role,\n public readonly offset: Fraction,\n public readonly duration: Fraction,\n public readonly barIndex: number,\n public readonly beatIndex: number,\n public readonly instance: number,\n public readonly prevBeat: null | Beat,\n public nextBeat: null | Beat,\n ) {}\n\n debugValue(): any {\n return {\n index: this.index,\n role: this.role.name,\n offset: this.offset.toString(),\n duration: this.duration.toString(),\n barIndex: this.barIndex,\n beatIndex: this.beatIndex,\n instance: this.instance,\n atom: this.atom.debugValue(),\n };\n }\n\n get endOffset(): Fraction {\n return this.offset.plus(this.duration);\n }\n get filled(): boolean {\n return this.remaining.isZero;\n }\n\n get remaining(): Fraction {\n return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;\n }\n\n add(atom: Atom): boolean {\n if (this.remaining.cmp(atom.duration) < 0) {\n return false;\n }\n if (!this.atom) {\n this.atom = atom;\n } else {\n if (!this.atomIsPlaceholder) {\n this.atomIsPlaceholder = true;\n this.atom = new Group(this.atom).setDuration(ONE, true);\n }\n (this.atom as Group).addAtoms(true, atom);\n }\n return true;\n }\n\n get preMarkers(): Marker[] {\n const out = [] as Marker[];\n let curr: Atom | null = this.atom;\n while (curr != null) {\n for (const marker of curr.markersBefore || []) {\n out.push(marker);\n }\n if (curr.type == AtomType.GROUP) {\n curr = (curr as Group).atoms.first;\n } else {\n curr = null;\n }\n }\n return out;\n }\n\n get postMarkers(): Marker[] {\n const out = [] as Marker[];\n let curr: Atom | null = this.atom;\n while (curr != null) {\n out.splice(0, 0, ...(curr.markersAfter || []));\n if (curr.type == AtomType.GROUP) {\n curr = (curr as Group).atoms.last;\n } else {\n curr = null;\n }\n }\n return out;\n }\n}\n\nexport class BeatsBuilder {\n // All atoms divided into beats\n readonly beats: Beat[] = [];\n readonly startIndex: number;\n readonly beatOffset: Fraction;\n cycleIter: CycleIterator;\n windowIter: WindowIterator;\n\n // Callback for when an atom is added to this role.\n onAtomAdded: (atom: Atom, beat: Beat) => void;\n\n // Callback for when a new beat is added\n onBeatAdded: (beat: Beat) => void;\n // Callback for when a beat has been filled\n onBeatFilled: (beat: Beat) => void;\n\n constructor(\n public readonly role: Role,\n public readonly layoutParams: LayoutParams,\n public readonly startOffset: Fraction = ZERO,\n ...atoms: Atom[]\n ) {\n const [, [bar, beat, instance], beatOffset, index] = layoutParams.cycle.getPosition(startOffset);\n this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);\n this.windowIter = new WindowIterator();\n this.beatOffset = beatOffset;\n\n // evaluate the start beatindex - typically it would be 0 if things start\n // at beginning of a cycle. But if the start offset is < 0 then the\n // startIndex should also shift accordingly\n this.startIndex = index;\n this.addAtoms(...atoms);\n }\n\n addAtoms(...atoms: Atom[]): void {\n // First add all atoms to the atom Iterator so we can\n // fetch them as FlatAtoms. This is needed because atoms\n // passed here could be unflatted (via groups) or much larger\n // than what can fit in the given role/bar etc. So this\n // flattening and windowing is needed before we add them\n // to the views - and this is done by the durationIterators.\n this.windowIter.push(...atoms);\n while (this.windowIter.hasMore) {\n // get the last/current row and add a new one if it is full\n let currBeat = this.beats[this.beats.length - 1];\n\n // First add a row if last row is filled\n if (this.beats.length == 0 || currBeat.filled) {\n // what should be the beatlengths be here?\n currBeat = this.addBeat();\n }\n\n // For this beat get symbols in all roles\n const [remAtoms, filled] = this.windowIter.get(currBeat.remaining);\n TSU.assert(remAtoms.length > 0, \"Atleast one element should have been available here\");\n // render the atoms now\n for (const atom of remAtoms) {\n // console.log(\"Adding FA: \", flatAtom.debugValue(), flatAtom.atom);\n TSU.assert(currBeat.add(atom), \"Should return true as we are already using a duration iterator here\");\n if (this.onAtomAdded) this.onAtomAdded(atom, currBeat);\n }\n if (currBeat.filled) {\n if (this.onBeatFilled) this.onBeatFilled(currBeat);\n }\n }\n }\n\n protected addBeat(): Beat {\n const numBeats = this.beats.length;\n const lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];\n const nextCP: [CyclePosition, Fraction] = this.cycleIter.next().value;\n const apb = this.layoutParams.beatDuration;\n const newBeat = new Beat(\n lastBeat == null ? this.startIndex : lastBeat.index + 1,\n this.role,\n lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset,\n nextCP[1].timesNum(apb),\n nextCP[0][0],\n nextCP[0][1],\n nextCP[0][2],\n lastBeat,\n null,\n );\n if (lastBeat == null && this.beatOffset.isGT(ZERO)) {\n // Add spaces to fill up empty beats\n newBeat.add(new Space(this.beatOffset.timesNum(apb)));\n }\n if (lastBeat) lastBeat.nextBeat = newBeat;\n this.beats.push(newBeat);\n if (this.onBeatAdded) this.onBeatAdded(newBeat);\n return newBeat;\n }\n}\n\nexport class BeatColumn extends ColAlign {\n atomSpacing = 5;\n readonly key: string;\n constructor(\n public readonly offset: Fraction,\n public readonly endOffset: Fraction,\n public readonly markerType: number,\n ) {\n super();\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n this.key = BeatColumn.keyFor(offset, endOffset, markerType);\n }\n\n static keyFor(offset: Fraction, endOffset: Fraction, markerType = 0): string {\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n if (markerType < 0) {\n // return the column for the marker \"before\" this col\n // int his case only the \"start offset\" is needed and length doesnt matter\n return \":\" + offset.toString();\n } else if (markerType > 0) {\n // return the column for the marker \"after\" this col\n // in this case only thd end offset matters\n return endOffset.toString() + \":\";\n } else {\n return offset.toString() + \":\" + endOffset.toString();\n }\n }\n}\n\n/**\n * Grouping of beats by their column based on the layout params.\n * The confusion is we have beats broken up and saved in columns\n * but we are loosing how a line is supposed to access it in its own way\n * we have beatsByRole for getting all beats for a role (in a line)\n * sequentially we have beatColumns for getting all beats in a particular\n * column across all lines and roles globally.\n *\n * What we want here is for a given line get all roles, their beats\n * in zipped way. eg for a Line with 3 roles and say 10 beats each\n * (with the breaks of 4, 1) we need:\n *\n * R1 B1 R1 B2 R1 B3 R1 B4\n * R2 B1 R2 B2 R2 B3 R2 B4\n * R3 B1 R3 B2 R3 B3 R3 B4\n *\n * R1 B5\n * R2 B5\n * R3 B5\n *\n * R1 B6 R1 B7 R1 B8 R1 B9\n * R2 B6 R2 B7 R2 B8 R2 B9\n * R3 B6 R3 B7 R3 B8 R3 B9\n *\n * R1 B10\n * R2 B10\n * R3 B10\n *\n *\n * Here we have 5 distinct beat columns:\n *\n * 1: R1B1, R2B1, R3B1, R1B6, R2B6, R3B6,\n * 2: R1B2, R2B2, R3B2, R1B7, R2B7, R3B7,\n * 3: R1B3, R2B3, R3B3, R1B8, R2B8, R3B8,\n * 4: R1B4, R2B4, R3B4, R1B9, R2B9, R3B9,\n * 5: R1B5, R2B5, R3B5, R1B10, R2B10, R3B10,\n *\n */\nexport class BeatColDAG {\n beatColumns = new Map<string, BeatColumn>();\n\n constructor(public readonly layoutGroup: GridLayoutGroup) {\n //\n }\n\n /**\n * Gets the beat column of a given duration at the given offset.\n */\n getBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): BeatColumn {\n const [bcol, newcreated] = this.ensureBeatColumn(offset, endOffset, markerType);\n if (newcreated) {\n if (markerType == 0) {\n const [prevcol] = this.ensureBeatColumn(offset, endOffset, -1);\n const [nextcol] = this.ensureBeatColumn(offset, endOffset, 1);\n prevcol.addSuccessor(bcol);\n bcol.addSuccessor(nextcol);\n for (const other of this.beatColumns.values()) {\n // only join the \"marker\" columns\n if (other.markerType == -1 && endOffset.equals(other.offset)) {\n // our next col is a preecessor of other\n nextcol.addSuccessor(other);\n } else if (other.markerType == 1 && other.endOffset.equals(offset)) {\n // our prev col is a predecessor of other\n other.addSuccessor(prevcol);\n }\n }\n }\n }\n return bcol;\n }\n\n protected ensureBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): [BeatColumn, boolean] {\n const key = BeatColumn.keyFor(offset, endOffset, markerType);\n let bcol = this.beatColumns.get(key) || null;\n const newcreated = bcol == null;\n if (!bcol) {\n bcol = new BeatColumn(offset, endOffset, markerType);\n this.beatColumns.set(key, bcol);\n }\n return [bcol, newcreated];\n }\n}\n\n/**\n * Manages the beat layouts for *all* lines in a notation.\n */\ntype LineId = number;\ntype LPID = number;\nexport class GlobalBeatLayout {\n gridModelsForLine = new Map<LineId, GridModel>();\n roleBeatsForLine = new Map<LineId, Beat[][]>();\n beatColDAGsByLP = new Map<LPID, BeatColDAG>();\n readonly gridLayoutGroup = new GridLayoutGroup();\n\n /**\n * Get the GridView associated with a particular line.\n */\n getGridModelForLine(lineid: LineId): GridModel {\n let out = this.gridModelsForLine.get(lineid) || null;\n if (!out) {\n out = new GridModel();\n this.gridLayoutGroup.addGridModel(out);\n this.gridModelsForLine.set(lineid, out);\n }\n return out;\n }\n\n protected beatColDAGForLP(lpid: LPID): BeatColDAG {\n let out = this.beatColDAGsByLP.get(lpid) || null;\n if (!out) {\n out = new BeatColDAG(this.gridLayoutGroup);\n this.beatColDAGsByLP.set(lpid, out);\n }\n return out;\n }\n\n /**\n * First lines are added to the BeatLayout object.\n * This ensures that a line is broken down into beats and added\n * into a dedicated GridModel per line.\n *\n * A line must also be given the layout params by which the beat\n * break down will happen. This LayoutParams object does not have\n * to be unique per line (this non-constraint allows to align\n * beats across lines!).\n */\n addLine(line: Line): void {\n const gridModel = this.getGridModelForLine(line.uuid) as GridModel;\n gridModel.eventHub?.startBatchMode();\n this.lineToRoleBeats(line, gridModel);\n gridModel.eventHub?.commitBatch();\n }\n\n protected lineToRoleBeats(line: Line, gridModel: GridModel): Beat[][] {\n const lp = line.layoutParams;\n const roleBeats = [] as Beat[][];\n this.roleBeatsForLine.set(line.uuid, roleBeats);\n const lineOffset = line.offset.divbyNum(lp.beatDuration);\n for (const role of line.roles) {\n const bb = new BeatsBuilder(role, lp, lineOffset, ...role.atoms);\n roleBeats.push(bb.beats);\n\n // Add these to the beat layout too\n for (const beat of bb.beats) {\n // beat.ensureUniformSpaces(layoutParams.beatDuration);\n this.addBeat(beat, gridModel);\n }\n }\n return roleBeats;\n }\n\n /**\n * Adds the beat to this layout and returns the BeatColumn to which\n * this beat was added.\n */\n protected addBeat(beat: Beat, gridModel: GridModel): GridCell {\n // Get the beat column at this index (and line) and add to it.\n const line = beat.role.line;\n const lp = line.layoutParams;\n const beatColDAG = this.beatColDAGForLP(lp.uuid);\n const [layoutLine, layoutColumn, rowOffset] = lp.getBeatLocation(beat);\n const colEnd = rowOffset.plus(beat.duration, true);\n const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);\n\n // Since a beat's column has a \"pre\" and \"post\" col to, each\n // beat has 3 columns for it\n const roleIndex = beat.role.line.indexOfRole(beat.role.name);\n const realRow = line.roles.length * (layoutLine + Math.floor(beat.index / lp.totalBeats)) + roleIndex;\n // pre marker goes on realCol - 1, post marker goes on realCol + 1\n const realCol = 1 + layoutColumn * 3;\n const preMarkers = beat.preMarkers;\n if (preMarkers.length > 0) {\n const val = {\n beat: beat,\n markers: preMarkers,\n };\n const precol = beatColDAG.getBeatColumn(rowOffset, colEnd, -1);\n gridModel.setValue(realRow, realCol - 1, val, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = precol;\n return cell;\n });\n }\n const postMarkers = beat.postMarkers;\n if (postMarkers.length > 0) {\n const val = {\n beat: beat,\n markers: postMarkers,\n };\n const postcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 1);\n gridModel.setValue(realRow, realCol + 1, val, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = postcol;\n return cell;\n });\n }\n return gridModel.setValue(realRow, realCol, beat, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = bcol;\n return cell;\n });\n }\n}\n"]}
|
package/lib/cjs/beatview.js
CHANGED
|
@@ -35,9 +35,9 @@ class BeatView extends shapes_1.ElementShape {
|
|
|
35
35
|
beatId: "" + beat.uuid,
|
|
36
36
|
id: "" + beat.uuid,
|
|
37
37
|
roleName: beat.role.name,
|
|
38
|
-
layoutLine: "" + beat.layoutLine,
|
|
39
|
-
layoutColumn: "" + beat.layoutColumn,
|
|
40
38
|
beatIndex: "" + beat.index,
|
|
39
|
+
gridRow: cell.rowIndex,
|
|
40
|
+
gridCol: cell.colIndex,
|
|
41
41
|
},
|
|
42
42
|
}));
|
|
43
43
|
this.cell = cell;
|
package/lib/cjs/beatview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beatview.js","sourceRoot":"","sources":["../../src/beatview.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,qCAAgE;AAKhE,MAAsB,QAAS,SAAQ,qBAAyB;IAI9D,YACkB,IAAc,EACd,IAAU,EACV,WAA+B,EAC/B,KAAY,EAC5B,MAAY;QAEZ,KAAK,CACH,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE;YACzB,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE;gBACL,KAAK,EAAE,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AE,CAAC;SAClD;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,SAAS,CAAC,MAAW;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CAIF;AA1CD,4BA0CC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { AtomView, Embelishment, ElementShape } from \"./shapes\";\nimport { GridCell, GridCellView } from \"./grids\";\nimport { Cycle } from \"./cycle\";\nimport { Beat } from \"./beats\";\n\nexport abstract class BeatView extends ElementShape<SVGGElement> implements GridCellView {\n private _embelishments: Embelishment[];\n atomView: AtomView;\n needsLayout = true;\n constructor(\n public readonly cell: GridCell,\n public readonly beat: Beat,\n public readonly rootElement: SVGGraphicsElement,\n public readonly cycle: Cycle,\n config?: any,\n ) {\n super(\n TSU.DOM.createSVGNode(\"g\", {\n parent: rootElement,\n attrs: {\n class: \"beatView\",\n beatId: \"\" + beat.uuid,\n id: \"\" + beat.uuid,\n roleName: beat.role.name,\n beatIndex: \"\" + beat.index,\n gridRow: cell.rowIndex,\n gridCol: cell.colIndex,\n },\n }),\n );\n this.atomView = this.createAtomView();\n this.atomView.refreshLayout();\n }\n\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n setStyles(config: any): void {\n this.needsLayout = true;\n }\n\n protected abstract createEmbelishments(): Embelishment[];\n protected abstract createAtomView(): AtomView;\n}\n"]}
|
|
@@ -2,9 +2,9 @@ import * as TSU from "@panyam/tsutils";
|
|
|
2
2
|
import { LineView } from "./LineView";
|
|
3
3
|
import { Notation, RawBlock } from "../notation";
|
|
4
4
|
import { GlobalBeatLayout } from "../beats";
|
|
5
|
-
import { GridCell } from "../grids";
|
|
5
|
+
import { GridCell, GridCellView } from "../grids";
|
|
6
6
|
import { Line } from "../core";
|
|
7
|
-
import { BeatView } from "./beatviews";
|
|
7
|
+
import { BeatView, MarkerView } from "./beatviews";
|
|
8
8
|
export declare class NotationView {
|
|
9
9
|
readonly rootElement: HTMLElement;
|
|
10
10
|
readonly config?: any;
|
|
@@ -28,5 +28,6 @@ export declare class NotationView {
|
|
|
28
28
|
refreshLayout(): void;
|
|
29
29
|
renderBlock(raw: RawBlock): void;
|
|
30
30
|
beatViews: Map<number, BeatView>;
|
|
31
|
-
|
|
31
|
+
markerViews: Map<string, MarkerView>;
|
|
32
|
+
viewForBeat(cell: GridCell): GridCellView;
|
|
32
33
|
}
|
|
@@ -34,6 +34,7 @@ class NotationView {
|
|
|
34
34
|
this.lineViews = [];
|
|
35
35
|
this.currentSVGElement = null;
|
|
36
36
|
this.beatViews = new Map();
|
|
37
|
+
this.markerViews = new Map();
|
|
37
38
|
this.loadChildViews();
|
|
38
39
|
}
|
|
39
40
|
get beatLayout() {
|
|
@@ -161,16 +162,32 @@ class NotationView {
|
|
|
161
162
|
this.currentSVGElement = null;
|
|
162
163
|
}
|
|
163
164
|
viewForBeat(cell) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
165
|
+
if (cell.colIndex % 3 == 1) {
|
|
166
|
+
const beat = cell.value;
|
|
167
|
+
let curr = this.beatViews.get(beat.uuid) || null;
|
|
168
|
+
if (curr == null) {
|
|
169
|
+
const line = beat.role.line;
|
|
170
|
+
const lineView = this.ensureLineView(line);
|
|
171
|
+
const lp = line.layoutParams;
|
|
172
|
+
curr = new beatviews_1.BeatView(cell, beat, lineView.gElem, lp.cycle);
|
|
173
|
+
this.beatViews.set(beat.uuid, curr);
|
|
174
|
+
}
|
|
175
|
+
return curr;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const marker = cell.value;
|
|
179
|
+
const beat = marker.beat;
|
|
180
|
+
let curr = this.markerViews.get("pre:" + beat.uuid) || null;
|
|
181
|
+
if (curr == null) {
|
|
182
|
+
const line = beat.role.line;
|
|
183
|
+
const lineView = this.ensureLineView(line);
|
|
184
|
+
const lp = line.layoutParams;
|
|
185
|
+
const isPreMarker = cell.colIndex % 3 == 0;
|
|
186
|
+
curr = new beatviews_1.MarkerView(cell, beat, marker.markers, isPreMarker, lineView.gElem);
|
|
187
|
+
this.markerViews.set("pre:" + beat.uuid, curr);
|
|
188
|
+
}
|
|
189
|
+
return curr;
|
|
172
190
|
}
|
|
173
|
-
return curr;
|
|
174
191
|
}
|
|
175
192
|
}
|
|
176
193
|
exports.NotationView = NotationView;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,yCAAsC;AAKtC,2CAAuC;AAEvC,MAAa,YAAY;IAUvB,YAA4B,WAAwB,EAAkB,MAAY;QAAtD,gBAAW,GAAX,WAAW,CAAa;QAAkB,WAAM,GAAN,MAAM,CAAM;QAPlF,cAAS,GAAe,EAAE,CAAC;QAE3B,sBAAiB,GAAyB,IAAI,CAAC;QA+J/C,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QAzJtC,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU,CAAC,UAA4B;QACzC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,UAAU,CAAC,eAAe,CAAC,WAAW,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5E,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE;YAC9C,MAAM,EAAE,IAAI,CAAC,WAAW;YACxB,KAAK,EAAE;gBACL,KAAK,EAAE,2BAA2B;aACnC;SACF,CAAqB,CAAC;IACzB,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,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlLD,oCAkLC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { LineView } from \"./LineView\";\nimport { Notation, RawBlock } from \"../notation\";\nimport { GlobalBeatLayout } from \"../beats\";\nimport { GridCell } from \"../grids\";\nimport { Line } from \"../core\";\nimport { BeatView } from \"./beatviews\";\n\nexport class NotationView {\n headerElement: HTMLDivElement;\n notation: Notation;\n lineViews: LineView[] = [];\n // Mapping from line id -> list of beats in each of its roles\n currentSVGElement: SVGSVGElement | null = null;\n tableElement: HTMLTableElement;\n markdownParser: (contents: string) => string;\n _beatLayout: GlobalBeatLayout;\n\n constructor(public readonly rootElement: HTMLElement, public readonly config?: any) {\n this.loadChildViews();\n }\n\n get beatLayout(): GlobalBeatLayout {\n return this._beatLayout;\n }\n\n set beatLayout(beatLayout: GlobalBeatLayout) {\n this._beatLayout = beatLayout;\n beatLayout.gridLayoutGroup.getCellView = (cell) => this.viewForBeat(cell);\n }\n\n loadChildViews(): void {\n this.tableElement = TSU.DOM.createNode(\"table\", {\n parent: this.rootElement,\n attrs: {\n class: \"notationsContentRootTable\",\n },\n }) as HTMLTableElement;\n }\n\n public addNewRow(id: string, prefix: string, withAnnotation = true): [HTMLElement, HTMLElement] {\n const tr = TSU.DOM.createNode(\"tr\", {\n parent: this.tableElement, // parent,\n attrs: {\n class: prefix + \"Row\",\n id: prefix + \"Row\" + id,\n },\n });\n let td1: HTMLElement | null = null;\n if (withAnnotation) {\n td1 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"AnnotationCell\",\n id: prefix + \"Annotation\" + id,\n },\n }) as HTMLElement;\n }\n const td2 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"ContentCell\",\n id: prefix + \"Content\" + id,\n colspan: withAnnotation ? 1 : 2,\n },\n }) as HTMLElement;\n return [td1!, td2];\n }\n\n public newLineRoot(parent: Element, line: Line): SVGSVGElement {\n const [td1, td2] = this.addNewRow(line.uuid + \"\", \"line\");\n // Hacky solution to \"line headings\"\n if (line.marginText) {\n td1.innerHTML = line.marginText;\n }\n return TSU.DOM.createSVGNode(\"svg\", {\n parent: td2, // parent\n attrs: {\n style: \"margin-bottom: 10px\",\n class: \"lineRootSVG\",\n },\n }) as SVGSVGElement;\n }\n\n ensureLineView(line: Line): LineView {\n let lineView = this.getLineView(line);\n if (lineView == null) {\n const layoutParams = line.layoutParams || null;\n const svgElem = this.newLineRoot(this.tableElement, line);\n lineView = new LineView(svgElem, line, {\n layoutParams: layoutParams,\n } as any);\n if (!line.isEmpty) {\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(layoutParams != null, \"Layout params for a non empty line *should* exist\");\n lineView.gridModel = this.beatLayout!.getGridModelForLine(line.uuid);\n }\n this.lineViews.push(lineView);\n }\n return lineView;\n }\n\n getLineView(line: Line): TSU.Nullable<LineView> {\n return this.lineViews.find((l) => l.line == line) || null;\n }\n\n get currentLineView(): LineView {\n return this.lineViews[this.lineViews.length - 1];\n }\n\n clear(): void {\n this.lineViews = [];\n // Mapping from line id -> list of beats in each of its roles\n this.currentSVGElement = null;\n this.tableElement.innerHTML = \"\";\n this.beatViews = new Map<number, BeatView>();\n }\n\n /**\n * Layout all the blocks in the Notation along with their corresponding blocks.\n * Key thing is here is an opportunity to perform any batch rendering as needed.\n */\n refreshLayout(): void {\n const lines = [] as Line[];\n const lineViews = [] as LineView[];\n for (const block of this.notation.blocks) {\n if (block.type == \"RawBlock\") {\n // Add the markdown here\n this.renderBlock(block as RawBlock);\n } else {\n lines.push(block as Line);\n const lineView = this.ensureLineView(block as Line);\n lineViews.push(lineView);\n }\n }\n\n const now = performance.now();\n for (const lineView of lineViews) {\n lineView.gridModel.lastUpdatedAt = now;\n }\n\n this.beatLayout.gridLayoutGroup.refreshLayout();\n\n for (const lineView of lineViews) {\n lineView.wrapToSize();\n }\n\n // now that all spacing has been calculated\n // go through all\n // for (const beatView of this.beatViews.values()) { beatView.refreshLayout(); }\n }\n\n renderBlock(raw: RawBlock): void {\n const [, td2] = this.addNewRow(raw.uuid + \"\", \"rawBlock\", false);\n if (raw.contentType == \"metadata\") {\n // we have a metadata block\n const meta = this.notation.metadata.get(raw.content);\n if (meta) {\n // For now ignore metadata with \":\" in the key\n if (meta.key.toLowerCase().indexOf(\":\") < 0) {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n const html = `<span class = \"${meta.key.toLowerCase()}\"><strong>${meta.key}</strong>: ${meta.value}</span>`;\n div.innerHTML = html;\n }\n }\n } else {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n div.innerHTML = this.markdownParser(raw.content.trim());\n }\n this.currentSVGElement = null;\n }\n\n beatViews = new Map<number, BeatView>();\n viewForBeat(cell: GridCell): BeatView {\n const beat = cell.value;\n let curr = this.beatViews.get(beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n // how to get the bar and beat index for a given beat in a given row?\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n curr = new BeatView(cell, beat, lineView.gElem, lp.cycle);\n this.beatViews.set(beat.uuid, curr);\n }\n return curr;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,yCAAsC;AAKtC,2CAAmD;AAEnD,MAAa,YAAY;IAUvB,YAA4B,WAAwB,EAAkB,MAAY;QAAtD,gBAAW,GAAX,WAAW,CAAa;QAAkB,WAAM,GAAN,MAAM,CAAM;QAPlF,cAAS,GAAe,EAAE,CAAC;QAE3B,sBAAiB,GAAyB,IAAI,CAAC;QA+J/C,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QACxC,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;QA1J1C,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AAE,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAC/E,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aAChD;YACD,OAAO,IAAI,CAAC;SACb;IACH,CAAC;CACF;AApMD,oCAoMC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { LineView } from \"./LineView\";\nimport { Notation, RawBlock } from \"../notation\";\nimport { Beat, GlobalBeatLayout } from \"../beats\";\nimport { GridCell, GridCellView } from \"../grids\";\nimport { Line } from \"../core\";\nimport { BeatView, MarkerView } from \"./beatviews\";\n\nexport class NotationView {\n headerElement: HTMLDivElement;\n notation: Notation;\n lineViews: LineView[] = [];\n // Mapping from line id -> list of beats in each of its roles\n currentSVGElement: SVGSVGElement | null = null;\n tableElement: HTMLTableElement;\n markdownParser: (contents: string) => string;\n _beatLayout: GlobalBeatLayout;\n\n constructor(public readonly rootElement: HTMLElement, public readonly config?: any) {\n this.loadChildViews();\n }\n\n get beatLayout(): GlobalBeatLayout {\n return this._beatLayout;\n }\n\n set beatLayout(beatLayout: GlobalBeatLayout) {\n this._beatLayout = beatLayout;\n beatLayout.gridLayoutGroup.getCellView = (cell) => this.viewForBeat(cell);\n }\n\n loadChildViews(): void {\n this.tableElement = TSU.DOM.createNode(\"table\", {\n parent: this.rootElement,\n attrs: {\n class: \"notationsContentRootTable\",\n },\n }) as HTMLTableElement;\n }\n\n public addNewRow(id: string, prefix: string, withAnnotation = true): [HTMLElement, HTMLElement] {\n const tr = TSU.DOM.createNode(\"tr\", {\n parent: this.tableElement, // parent,\n attrs: {\n class: prefix + \"Row\",\n id: prefix + \"Row\" + id,\n },\n });\n let td1: HTMLElement | null = null;\n if (withAnnotation) {\n td1 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"AnnotationCell\",\n id: prefix + \"Annotation\" + id,\n },\n }) as HTMLElement;\n }\n const td2 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"ContentCell\",\n id: prefix + \"Content\" + id,\n colspan: withAnnotation ? 1 : 2,\n },\n }) as HTMLElement;\n return [td1!, td2];\n }\n\n public newLineRoot(parent: Element, line: Line): SVGSVGElement {\n const [td1, td2] = this.addNewRow(line.uuid + \"\", \"line\");\n // Hacky solution to \"line headings\"\n if (line.marginText) {\n td1.innerHTML = line.marginText;\n }\n return TSU.DOM.createSVGNode(\"svg\", {\n parent: td2, // parent\n attrs: {\n style: \"margin-bottom: 10px\",\n class: \"lineRootSVG\",\n },\n }) as SVGSVGElement;\n }\n\n ensureLineView(line: Line): LineView {\n let lineView = this.getLineView(line);\n if (lineView == null) {\n const layoutParams = line.layoutParams || null;\n const svgElem = this.newLineRoot(this.tableElement, line);\n lineView = new LineView(svgElem, line, {\n layoutParams: layoutParams,\n } as any);\n if (!line.isEmpty) {\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(layoutParams != null, \"Layout params for a non empty line *should* exist\");\n lineView.gridModel = this.beatLayout!.getGridModelForLine(line.uuid);\n }\n this.lineViews.push(lineView);\n }\n return lineView;\n }\n\n getLineView(line: Line): TSU.Nullable<LineView> {\n return this.lineViews.find((l) => l.line == line) || null;\n }\n\n get currentLineView(): LineView {\n return this.lineViews[this.lineViews.length - 1];\n }\n\n clear(): void {\n this.lineViews = [];\n // Mapping from line id -> list of beats in each of its roles\n this.currentSVGElement = null;\n this.tableElement.innerHTML = \"\";\n this.beatViews = new Map<number, BeatView>();\n }\n\n /**\n * Layout all the blocks in the Notation along with their corresponding blocks.\n * Key thing is here is an opportunity to perform any batch rendering as needed.\n */\n refreshLayout(): void {\n const lines = [] as Line[];\n const lineViews = [] as LineView[];\n for (const block of this.notation.blocks) {\n if (block.type == \"RawBlock\") {\n // Add the markdown here\n this.renderBlock(block as RawBlock);\n } else {\n lines.push(block as Line);\n const lineView = this.ensureLineView(block as Line);\n lineViews.push(lineView);\n }\n }\n\n const now = performance.now();\n for (const lineView of lineViews) {\n lineView.gridModel.lastUpdatedAt = now;\n }\n\n this.beatLayout.gridLayoutGroup.refreshLayout();\n\n for (const lineView of lineViews) {\n lineView.wrapToSize();\n }\n\n // now that all spacing has been calculated\n // go through all\n // for (const beatView of this.beatViews.values()) { beatView.refreshLayout(); }\n }\n\n renderBlock(raw: RawBlock): void {\n const [, td2] = this.addNewRow(raw.uuid + \"\", \"rawBlock\", false);\n if (raw.contentType == \"metadata\") {\n // we have a metadata block\n const meta = this.notation.metadata.get(raw.content);\n if (meta) {\n // For now ignore metadata with \":\" in the key\n if (meta.key.toLowerCase().indexOf(\":\") < 0) {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n const html = `<span class = \"${meta.key.toLowerCase()}\"><strong>${meta.key}</strong>: ${meta.value}</span>`;\n div.innerHTML = html;\n }\n }\n } else {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n div.innerHTML = this.markdownParser(raw.content.trim());\n }\n this.currentSVGElement = null;\n }\n\n beatViews = new Map<number, BeatView>();\n markerViews = new Map<string, MarkerView>();\n viewForBeat(cell: GridCell): GridCellView {\n if (cell.colIndex % 3 == 1) {\n // beat view needed\n const beat = cell.value;\n let curr = this.beatViews.get(beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n // how to get the bar and beat index for a given beat in a given row?\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n curr = new BeatView(cell, beat, lineView.gElem, lp.cycle);\n this.beatViews.set(beat.uuid, curr);\n }\n return curr;\n } else {\n // markers view\n const marker = cell.value;\n const beat = marker.beat as Beat;\n let curr = this.markerViews.get(\"pre:\" + beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n const isPreMarker = cell.colIndex % 3 == 0;\n curr = new MarkerView(cell, beat, marker.markers, isPreMarker, lineView.gElem);\n this.markerViews.set(\"pre:\" + beat.uuid, curr);\n }\n return curr;\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { Embelishment } from "../shapes";
|
|
2
|
+
import { GridCell, GridCellView } from "../grids";
|
|
3
|
+
import { ElementShape } from "../shapes";
|
|
4
|
+
import { Marker } from "../core";
|
|
5
|
+
import { Beat } from "../beats";
|
|
2
6
|
import { BeatView as BeatViewBase } from "../beatview";
|
|
7
|
+
export declare class MarkerView extends ElementShape<SVGGElement> implements GridCellView {
|
|
8
|
+
readonly cell: GridCell;
|
|
9
|
+
readonly beat: Beat;
|
|
10
|
+
readonly markers: Marker[];
|
|
11
|
+
readonly isPreMarker: boolean;
|
|
12
|
+
readonly rootElement: SVGGraphicsElement;
|
|
13
|
+
needsLayout: boolean;
|
|
14
|
+
rootGroup: SVGGElement;
|
|
15
|
+
textElement: SVGTextElement;
|
|
16
|
+
constructor(cell: GridCell, beat: Beat, markers: Marker[], isPreMarker: boolean, rootElement: SVGGraphicsElement, config?: any);
|
|
17
|
+
refreshLayout(): void;
|
|
18
|
+
protected updateBounds(x: null | number, y: null | number, w: null | number, h: null | number): [number | null, number | null, number | null, number | null];
|
|
19
|
+
}
|
|
3
20
|
export declare class BeatView extends BeatViewBase {
|
|
4
21
|
createAtomView(): import("../shapes").AtomView;
|
|
5
22
|
refreshLayout(): void;
|
|
@@ -1,9 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BeatView = void 0;
|
|
26
|
+
exports.BeatView = exports.MarkerView = void 0;
|
|
27
|
+
const TSU = __importStar(require("@panyam/tsutils"));
|
|
28
|
+
const shapes_1 = require("../shapes");
|
|
4
29
|
const atomviews_1 = require("./atomviews");
|
|
5
30
|
const beatview_1 = require("../beatview");
|
|
6
31
|
const embelishments_1 = require("./embelishments");
|
|
32
|
+
class MarkerView extends shapes_1.ElementShape {
|
|
33
|
+
constructor(cell, beat, markers, isPreMarker, rootElement, config) {
|
|
34
|
+
const rootGroup = TSU.DOM.createSVGNode("g", {
|
|
35
|
+
parent: rootElement,
|
|
36
|
+
attrs: {
|
|
37
|
+
class: "markerView",
|
|
38
|
+
pre: isPreMarker,
|
|
39
|
+
roleName: beat.role.name,
|
|
40
|
+
beatIndex: "" + beat.index,
|
|
41
|
+
gridRow: cell.rowIndex,
|
|
42
|
+
gridCol: cell.colIndex,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
super(rootGroup);
|
|
46
|
+
this.cell = cell;
|
|
47
|
+
this.beat = beat;
|
|
48
|
+
this.markers = markers;
|
|
49
|
+
this.isPreMarker = isPreMarker;
|
|
50
|
+
this.rootElement = rootElement;
|
|
51
|
+
this.needsLayout = true;
|
|
52
|
+
this.rootGroup = rootGroup;
|
|
53
|
+
this.textElement = TSU.DOM.createSVGNode("text", {
|
|
54
|
+
parent: rootGroup,
|
|
55
|
+
attrs: {
|
|
56
|
+
class: "markerText",
|
|
57
|
+
pre: isPreMarker,
|
|
58
|
+
},
|
|
59
|
+
text: this.markers[0].text,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
refreshLayout() {
|
|
63
|
+
this.rootGroup.setAttribute("transform", "translate(" + this.x + "," + this.y + ")");
|
|
64
|
+
}
|
|
65
|
+
updateBounds(x, y, w, h) {
|
|
66
|
+
return [x, y, NaN, NaN];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.MarkerView = MarkerView;
|
|
7
70
|
class BeatView extends beatview_1.BeatView {
|
|
8
71
|
createAtomView() {
|
|
9
72
|
return (0, atomviews_1.createAtomView)(this.element, this.beat.atom, this.beat.role.defaultToNotes);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beatviews.js","sourceRoot":"","sources":["../../../src/carnatic/beatviews.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"beatviews.js","sourceRoot":"","sources":["../../../src/carnatic/beatviews.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAGvC,sCAAyC;AACzC,2CAA6C;AAG7C,0CAAuD;AACvD,mDAA+D;AAE/D,MAAa,UAAW,SAAQ,qBAAyB;IAIvD,YACkB,IAAc,EACd,IAAU,EACV,OAAiB,EACjB,WAAoB,EACpB,WAA+B,EAC/C,MAAY;QAEZ,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE;YAC3C,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE;gBACL,KAAK,EAAE,YAAY;gBACnB,GAAG,EAAE,WAAW;gBAChB,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;gBAC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AI,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;wBAE1C,MAAM,GAAG,GAAG,IAAI,4BAAY,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;wBACnD,aAAa,GAAG,CAAC,GAAG,CAAC,CAAC;qBACvB;yBAAM;wBAEL,MAAM,GAAG,GAAG,IAAI,4BAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;wBAChD,aAAa,GAAG,CAAC,GAAG,CAAC,CAAC;qBACvB;iBACF;aACF;SACF;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AA7CD,4BA6CC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Embelishment } from \"../shapes\";\nimport { GridCell, GridCellView } from \"../grids\";\nimport { ElementShape } from \"../shapes\";\nimport { createAtomView } from \"./atomviews\";\nimport { Marker } from \"../core\";\nimport { Beat } from \"../beats\";\nimport { BeatView as BeatViewBase } from \"../beatview\";\nimport { BeatStartLines, BeatEndLines } from \"./embelishments\";\n\nexport class MarkerView extends ElementShape<SVGGElement> implements GridCellView {\n needsLayout = true;\n rootGroup: SVGGElement;\n textElement: SVGTextElement;\n constructor(\n public readonly cell: GridCell,\n public readonly beat: Beat,\n public readonly markers: Marker[],\n public readonly isPreMarker: boolean,\n public readonly rootElement: SVGGraphicsElement,\n config?: any,\n ) {\n const rootGroup = TSU.DOM.createSVGNode(\"g\", {\n parent: rootElement,\n attrs: {\n class: \"markerView\",\n pre: isPreMarker,\n roleName: beat.role.name,\n beatIndex: \"\" + beat.index,\n gridRow: cell.rowIndex,\n gridCol: cell.colIndex,\n },\n });\n super(rootGroup);\n this.rootGroup = rootGroup as SVGGElement;\n this.textElement = TSU.DOM.createSVGNode(\"text\", {\n parent: rootGroup,\n attrs: {\n class: \"markerText\",\n pre: isPreMarker,\n },\n text: this.markers[0].text,\n });\n }\n\n refreshLayout(): void {\n // TODO - move this code out to refreshLayout?\n // set the glyphs Y first so we can layout others\n this.rootGroup.setAttribute(\"transform\", \"translate(\" + this.x + \",\" + this.y + \")\");\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, NaN, NaN];\n }\n}\n\nexport class BeatView extends BeatViewBase {\n createAtomView() {\n return createAtomView(this.element, this.beat.atom, this.beat.role.defaultToNotes);\n }\n\n refreshLayout(): void {\n const newX = this.hasX ? this._x : 0;\n const newY = this.hasY ? this._y : 0;\n this.element.setAttribute(\"transform\", \"translate(\" + newX + \",\" + newY + \")\");\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n protected createEmbelishments(): Embelishment[] {\n let embelishments: Embelishment[] = [];\n const beat = this.beat;\n // TODO - Should this be the group's parent element?\n const rootElement = this.rootElement;\n if (beat.beatIndex == 0 && beat.barIndex == 0 && beat.instance == 0) {\n // first beat in bar - Do a BarStart\n const emb = new BeatStartLines(this, rootElement);\n embelishments = [emb];\n } else {\n const cycle = this.cycle;\n const bar = cycle.bars[beat.barIndex];\n if (beat.beatIndex == bar.beatCount - 1) {\n // It is important that we are not just looking at the last beat of the bar\n // but also in the last \"instance\" of the beat in this bar to account for\n // kalais\n if (beat.instance == bar.instanceCount(beat.beatIndex) - 1) {\n if (beat.barIndex == cycle.bars.length - 1) {\n // last beat in last bar so - do a thalam end (2 lines)\n const emb = new BeatEndLines(this, rootElement, 2);\n embelishments = [emb];\n } else {\n // end of a bar so single line end\n const emb = new BeatEndLines(this, rootElement);\n embelishments = [emb];\n }\n }\n }\n }\n return embelishments;\n }\n}\n"]}
|
package/lib/cjs/shapes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AASvC,MAAsB,KAAK;IAA3B;QAEW,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,GAAG,GAAG,CAAC;QAC3D,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,EAAE;YACxB,SAAS,IAAI,SAAS,GAAG,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC;SACjD;QACD,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAOvD,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,KAAK,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACnC,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAC7C,KAAK,IAAI,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,aAAa;YAAE,CAAC,CAAC,aAAa,EAAE,CAAC;QACtD,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;SAClD;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAES,mBAAmB;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,SAAS,CAAC,MAAW;QACnB,IAAI,aAAa,IAAI,MAAM;YAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACnE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CACF;AAtGD,8BAsGC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Atom, LeafAtom, Group } from \"./core\";\n\n/**\n * Base class of all renderable objects for caching things like bounding boxes etc.\n * We do this since a lot of the property setters dont change bounding boxes but\n * bounding box reads are a bit slow in general. This also allows us to test\n * layouts, positioning etc without having to worry about implementation details.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n /**\n * Note that x and y coordinates are not always the x and y coordinates\n * of the bounding box.\n * Eg a circle's x and y coordinates are its center point and not the\n * top left corner.\n * These \"main\" coordinates are referred as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n children: Shape[] = [];\n\n get bbox(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox();\n }\n return this._bbox;\n }\n\n /**\n * Sizes can have a minimum size.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n }\n return this._minSize;\n }\n\n /**\n * refreshBBox is called by the Shape when it knows the bbox it is tracking\n * cannot be trusted and has to be refreshed by calling native methods.\n */\n protected abstract refreshBBox(): TSU.Geom.Rect;\n protected abstract refreshMinSize(): TSU.Geom.Size;\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n invalidateBounds(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n\n /**\n * Sets the x or y coordinate of this shape in coordinate system within its\n * parent.\n *\n * Note that null and NaN are valid values and mean the following:\n * null - Dont change the value. Passed to \"ignore\" effects.\n * NaN - Ensure the value is set to null so that the bounding box specific coord is used going forward.\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n get hasHeight(): boolean {\n return this._height != null && !isNaN(this._height);\n }\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n return this._x || 0;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * This is called when bounds or other properties of a shape have changed to\n * give the shape an opportunity to layout the children. For shapes\n * with no children this is a no-op. It is expected the Shape will keep track\n * of all changes so it can apply them all in in one go in this method - A\n * form of \"commit\"ing the layout transaction.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\nexport abstract class Embelishment extends Shape {}\n\nexport class ElementShape<T extends SVGGraphicsElement = SVGGraphicsElement> extends Shape {\n constructor(public readonly element: T) {\n super();\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n if (this.hasX) this.element.setAttribute(\"x\", \"\" + this._x);\n if (this.hasY) this.element.setAttribute(\"y\", \"\" + this._y);\n }\n}\n\nexport abstract class AtomView extends Shape {\n depth = 0;\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n baseline: number;\n ascent: number;\n descent: number;\n capHeight: number;\n leading: number;\n\n abstract isLeaf(): boolean;\n\n /**\n * Creates views needed for this AtomView.\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n}\n\nexport abstract class LeafAtomView extends AtomView {\n constructor(public leafAtom: LeafAtom) {\n super();\n }\n\n isLeaf(): boolean {\n return true;\n }\n\n get viewId(): number {\n return this.leafAtom.uuid;\n }\n\n /*\n embRoot(): SVGGraphicsElement {\n let rootElem = this.glyph.element.parentElement as any as SVGGraphicsElement;\n while (rootElem && (rootElem.tagName == \"tspan\" || rootElem.tagName == \"text\")) {\n rootElem = rootElem.parentElement as any as SVGGraphicsElement;\n }\n return rootElem;\n }\n */\n}\n\n/**\n * An GroupView that contains a collection of AtomViews.\n */\nexport abstract class GroupView extends AtomView {\n protected atomSpacing: number;\n protected groupElement: SVGGElement;\n protected atomViews: AtomView[] = [];\n private _embelishments: Embelishment[];\n defaultToNotes = true;\n needsLayout = true;\n scaleFactor = 1.0;\n constructor(public group: Group, config?: any) {\n super();\n this.atomSpacing = 5;\n this.setStyles(config || {});\n }\n\n /**\n * Creates views needed for this AtomView.\n */\n createElements(parent: SVGGraphicsElement): void {\n this.groupElement = TSU.DOM.createSVGNode(\"g\", {\n parent: parent,\n attrs: {\n class: \"groupViewRoot\",\n id: \"groupViewRoot\" + this.group.uuid,\n },\n });\n\n // now create child atom views for each atom in this Group\n for (const atom of this.group.atoms.values()) {\n const atomView = this.createAtomView(atom);\n this.atomViews.push(atomView);\n }\n this.invalidateBounds();\n }\n\n isLeaf(): boolean {\n return false;\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.groupElement);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n let totalWidth = 0;\n let maxHeight = 0;\n this.atomViews.forEach((av, index) => {\n const ms = av.minSize;\n totalWidth += ms.width + this.atomSpacing;\n maxHeight = Math.max(maxHeight, ms.height);\n });\n return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);\n }\n\n abstract createAtomView(atom: Atom): AtomView;\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n let transform = \"translate(\" + this.x + \",\" + this.y + \")\";\n if (this.scaleFactor < 1) {\n transform += \" scale(\" + this.scaleFactor + \")\";\n }\n this.groupElement.setAttribute(\"transform\", transform);\n // if (this.widthChanged) {\n // All our atoms have to be laid out between startX and endX\n // old way of doing where we just set dx between atom views\n // this worked when atomviews were single glyphs. But\n // as atomViews can be complex (eg with accents and pre/post\n // spaces etc) explicitly setting x/y may be important\n let currX = 0;\n const currY = 0; // null; // this.y; // + 10;\n this.atomViews.forEach((av, index) => {\n av.setBounds(currX, currY, null, null, true);\n currX += this.atomSpacing + av.minSize.width;\n });\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n protected createEmbelishments(): Embelishment[] {\n return [];\n }\n\n setStyles(config: any): void {\n if (\"atomSpacing\" in config) this.atomSpacing = config.atomSpacing;\n this.needsLayout = true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AASvC,MAAsB,KAAK;IAA3B;QAEW,YAAO,GAAW,KAAK,CAAC,SAAS,EAAE,CAAC;QAQnC,OAAE,GAAkB,IAAI,CAAC;QACzB,OAAE,GAAkB,IAAI,CAAC;QACzB,WAAM,GAAkB,IAAI,CAAC;QAC7B,YAAO,GAAkB,IAAI,CAAC;QAG9B,gBAAW,GAAiB,IAAI,CAAC;QAC3C,aAAQ,GAAY,EAAE,CAAC;IA+LzB,CAAC;IA7LC,IAAI,IAAI;QACN,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;SACjC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAMD,IAAI,OAAO;QACT,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;SACvC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAeD,gBAAgB;QACd,IAAI,CAAC,QAAQ,GAAG,IAAgC,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG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D,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;SAClD;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAES,mBAAmB;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,SAAS,CAAC,MAAW;QACnB,IAAI,aAAa,IAAI,MAAM;YAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACnE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CACF;AAtGD,8BAsGC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Atom, LeafAtom, Group } from \"./core\";\n\n/**\n * Base class of all renderable objects for caching things like bounding boxes etc.\n * We do this since a lot of the property setters dont change bounding boxes but\n * bounding box reads are a bit slow in general. This also allows us to test\n * layouts, positioning etc without having to worry about implementation details.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n /**\n * Note that x and y coordinates are not always the x and y coordinates\n * of the bounding box.\n * Eg a circle's x and y coordinates are its center point and not the\n * top left corner.\n * These \"main\" coordinates are referred as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n children: Shape[] = [];\n\n get bbox(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox();\n }\n return this._bbox;\n }\n\n /**\n * Sizes can have a minimum size.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n }\n return this._minSize;\n }\n\n /**\n * refreshBBox is called by the Shape when it knows the bbox it is tracking\n * cannot be trusted and has to be refreshed by calling native methods.\n */\n protected abstract refreshBBox(): TSU.Geom.Rect;\n protected abstract refreshMinSize(): TSU.Geom.Size;\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n invalidateBounds(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n\n /**\n * Sets the x or y coordinate of this shape in coordinate system within its\n * parent.\n *\n * Note that null and NaN are valid values and mean the following:\n * null - Dont change the value. Passed to \"ignore\" effects.\n * NaN - Ensure the value is set to null so that the bounding box specific coord is used going forward.\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n get hasHeight(): boolean {\n return this._height != null && !isNaN(this._height);\n }\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n return this._x || 0;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * This is called when bounds or other properties of a shape have changed to\n * give the shape an opportunity to layout the children. For shapes\n * with no children this is a no-op. It is expected the Shape will keep track\n * of all changes so it can apply them all in in one go in this method - A\n * form of \"commit\"ing the layout transaction.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\nexport abstract class Embelishment extends Shape {}\n\nexport class ElementShape<T extends SVGGraphicsElement = SVGGraphicsElement> extends Shape {\n constructor(public readonly element: T) {\n super();\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n if (this.hasX) this.element.setAttribute(\"x\", \"\" + this._x);\n if (this.hasY) this.element.setAttribute(\"y\", \"\" + this._y);\n }\n}\n\nexport abstract class AtomView extends Shape {\n depth = 0;\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n baseline: number;\n ascent: number;\n descent: number;\n capHeight: number;\n leading: number;\n\n abstract isLeaf(): boolean;\n\n /**\n * Creates views needed for this AtomView.\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n}\n\nexport abstract class LeafAtomView extends AtomView {\n constructor(public leafAtom: LeafAtom) {\n super();\n }\n\n isLeaf(): boolean {\n return true;\n }\n\n get viewId(): number {\n return this.leafAtom.uuid;\n }\n}\n\n/**\n * An GroupView that contains a collection of AtomViews.\n */\nexport abstract class GroupView extends AtomView {\n protected atomSpacing: number;\n protected groupElement: SVGGElement;\n protected atomViews: AtomView[] = [];\n private _embelishments: Embelishment[];\n defaultToNotes = true;\n needsLayout = true;\n scaleFactor = 1.0;\n constructor(public group: Group, config?: any) {\n super();\n this.atomSpacing = 5;\n this.setStyles(config || {});\n }\n\n /**\n * Creates views needed for this AtomView.\n */\n createElements(parent: SVGGraphicsElement): void {\n this.groupElement = TSU.DOM.createSVGNode(\"g\", {\n parent: parent,\n attrs: {\n class: \"groupViewRoot\",\n id: \"groupViewRoot\" + this.group.uuid,\n },\n });\n\n // now create child atom views for each atom in this Group\n for (const atom of this.group.atoms.values()) {\n const atomView = this.createAtomView(atom);\n this.atomViews.push(atomView);\n }\n this.invalidateBounds();\n }\n\n isLeaf(): boolean {\n return false;\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.groupElement);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n let totalWidth = 0;\n let maxHeight = 0;\n this.atomViews.forEach((av, index) => {\n const ms = av.minSize;\n totalWidth += ms.width + this.atomSpacing;\n maxHeight = Math.max(maxHeight, ms.height);\n });\n return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);\n }\n\n abstract createAtomView(atom: Atom): AtomView;\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n let transform = \"translate(\" + this.x + \",\" + this.y + \")\";\n if (this.scaleFactor < 1) {\n transform += \" scale(\" + this.scaleFactor + \")\";\n }\n this.groupElement.setAttribute(\"transform\", transform);\n // if (this.widthChanged) {\n // All our atoms have to be laid out between startX and endX\n // old way of doing where we just set dx between atom views\n // this worked when atomviews were single glyphs. But\n // as atomViews can be complex (eg with accents and pre/post\n // spaces etc) explicitly setting x/y may be important\n let currX = 0;\n const currY = 0; // null; // this.y; // + 10;\n this.atomViews.forEach((av, index) => {\n av.setBounds(currX, currY, null, null, true);\n currX += this.atomSpacing + av.minSize.width;\n });\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n protected createEmbelishments(): Embelishment[] {\n return [];\n }\n\n setStyles(config: any): void {\n if (\"atomSpacing\" in config) this.atomSpacing = config.atomSpacing;\n this.needsLayout = true;\n }\n}\n"]}
|
package/lib/esm/beats.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
|
-
import { Line, Atom, Role } from "./";
|
|
2
|
+
import { Marker, Line, Atom, Role } from "./";
|
|
3
3
|
import { CycleIterator } from "./cycle";
|
|
4
4
|
import { WindowIterator } from "./iterators";
|
|
5
5
|
import { LayoutParams } from "./layouts";
|
|
@@ -17,8 +17,6 @@ export declare class Beat {
|
|
|
17
17
|
nextBeat: null | Beat;
|
|
18
18
|
private static idCounter;
|
|
19
19
|
readonly uuid: number;
|
|
20
|
-
layoutLine: number;
|
|
21
|
-
layoutColumn: number;
|
|
22
20
|
atom: Atom;
|
|
23
21
|
protected atomIsPlaceholder: boolean;
|
|
24
22
|
constructor(index: number, role: Role, offset: Fraction, duration: Fraction, barIndex: number, beatIndex: number, instance: number, prevBeat: null | Beat, nextBeat: null | Beat);
|
|
@@ -27,6 +25,8 @@ export declare class Beat {
|
|
|
27
25
|
get filled(): boolean;
|
|
28
26
|
get remaining(): Fraction;
|
|
29
27
|
add(atom: Atom): boolean;
|
|
28
|
+
get preMarkers(): Marker[];
|
|
29
|
+
get postMarkers(): Marker[];
|
|
30
30
|
}
|
|
31
31
|
export declare class BeatsBuilder {
|
|
32
32
|
readonly role: Role;
|
package/lib/esm/beats.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
|
-
import { Group, Space } from "./";
|
|
2
|
+
import { AtomType, Group, Space } from "./";
|
|
3
3
|
import { WindowIterator } from "./iterators";
|
|
4
4
|
import { GridModel, GridCell, ColAlign, GridLayoutGroup } from "./grids";
|
|
5
5
|
const ZERO = TSU.Num.Fraction.ZERO;
|
|
@@ -16,8 +16,6 @@ export class Beat {
|
|
|
16
16
|
this.prevBeat = prevBeat;
|
|
17
17
|
this.nextBeat = nextBeat;
|
|
18
18
|
this.uuid = Beat.idCounter++;
|
|
19
|
-
this.layoutLine = -1;
|
|
20
|
-
this.layoutColumn = -1;
|
|
21
19
|
this.atomIsPlaceholder = false;
|
|
22
20
|
}
|
|
23
21
|
debugValue() {
|
|
@@ -57,6 +55,36 @@ export class Beat {
|
|
|
57
55
|
}
|
|
58
56
|
return true;
|
|
59
57
|
}
|
|
58
|
+
get preMarkers() {
|
|
59
|
+
const out = [];
|
|
60
|
+
let curr = this.atom;
|
|
61
|
+
while (curr != null) {
|
|
62
|
+
for (const marker of curr.markersBefore || []) {
|
|
63
|
+
out.push(marker);
|
|
64
|
+
}
|
|
65
|
+
if (curr.type == AtomType.GROUP) {
|
|
66
|
+
curr = curr.atoms.first;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
curr = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
get postMarkers() {
|
|
75
|
+
const out = [];
|
|
76
|
+
let curr = this.atom;
|
|
77
|
+
while (curr != null) {
|
|
78
|
+
out.splice(0, 0, ...(curr.markersAfter || []));
|
|
79
|
+
if (curr.type == AtomType.GROUP) {
|
|
80
|
+
curr = curr.atoms.last;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
curr = null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
60
88
|
}
|
|
61
89
|
Beat.idCounter = 0;
|
|
62
90
|
export class BeatsBuilder {
|
|
@@ -224,7 +252,33 @@ export class GlobalBeatLayout {
|
|
|
224
252
|
const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);
|
|
225
253
|
const roleIndex = beat.role.line.indexOfRole(beat.role.name);
|
|
226
254
|
const realRow = line.roles.length * (layoutLine + Math.floor(beat.index / lp.totalBeats)) + roleIndex;
|
|
227
|
-
const realCol = layoutColumn * 3;
|
|
255
|
+
const realCol = 1 + layoutColumn * 3;
|
|
256
|
+
const preMarkers = beat.preMarkers;
|
|
257
|
+
if (preMarkers.length > 0) {
|
|
258
|
+
const val = {
|
|
259
|
+
beat: beat,
|
|
260
|
+
markers: preMarkers,
|
|
261
|
+
};
|
|
262
|
+
const precol = beatColDAG.getBeatColumn(rowOffset, colEnd, -1);
|
|
263
|
+
gridModel.setValue(realRow, realCol - 1, val, (gridRow, col) => {
|
|
264
|
+
const cell = new GridCell(gridRow, col);
|
|
265
|
+
cell.colAlign = precol;
|
|
266
|
+
return cell;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
const postMarkers = beat.postMarkers;
|
|
270
|
+
if (postMarkers.length > 0) {
|
|
271
|
+
const val = {
|
|
272
|
+
beat: beat,
|
|
273
|
+
markers: postMarkers,
|
|
274
|
+
};
|
|
275
|
+
const postcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 1);
|
|
276
|
+
gridModel.setValue(realRow, realCol + 1, val, (gridRow, col) => {
|
|
277
|
+
const cell = new GridCell(gridRow, col);
|
|
278
|
+
cell.colAlign = postcol;
|
|
279
|
+
return cell;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
228
282
|
return gridModel.setValue(realRow, realCol, beat, (gridRow, col) => {
|
|
229
283
|
const cell = new GridCell(gridRow, col);
|
|
230
284
|
cell.colAlign = bcol;
|
package/lib/esm/beats.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beats.js","sourceRoot":"","sources":["../../src/beats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAc,KAAK,EAAQ,MAAM,IAAI,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAW,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGlF,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAEjC,MAAM,OAAO,IAAI;IASf,YACkB,KAAa,EACb,IAAU,EACV,MAAgB,EAChB,QAAkB,EAClB,QAAgB,EAChB,SAAiB,EACjB,QAAgB,EAChB,QAAqB,EAC9B,QAAqB;QARZ,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAM;QACV,WAAM,GAAN,MAAM,CAAU;QAChB,aAAQ,GAAR,QAAQ,CAAU;QAClB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAa;QAC9B,aAAQ,GAAR,QAAQ,CAAa;QAhBrB,SA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IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC;QACtG,MAAM,OAAO,GAAG,YAAY,GAAG,CAAC,CAAC;QACjC,OAAO,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,OAAgB,EAAE,GAAW,EAAE,EAAE;YAClF,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Group, Line, Atom, Space, Role } from \"./\";\nimport { CycleIterator, CyclePosition } from \"./cycle\";\nimport { WindowIterator } from \"./iterators\";\nimport { LayoutParams } from \"./layouts\";\nimport { GridModel, GridRow, GridCell, ColAlign, GridLayoutGroup } from \"./grids\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\nexport class Beat {\n private static idCounter = 0;\n readonly uuid = Beat.idCounter++;\n layoutLine = -1;\n layoutColumn = -1;\n // Should this be as flat Atoms or should we keep it as atoms and breakdown\n // later?\n atom: Atom;\n protected atomIsPlaceholder = false;\n constructor(\n public readonly index: number,\n public readonly role: Role,\n public readonly offset: Fraction,\n public readonly duration: Fraction,\n public readonly barIndex: number,\n public readonly beatIndex: number,\n public readonly instance: number,\n public readonly prevBeat: null | Beat,\n public nextBeat: null | Beat,\n ) {}\n\n debugValue(): any {\n return {\n index: this.index,\n role: this.role.name,\n offset: this.offset.toString(),\n duration: this.duration.toString(),\n barIndex: this.barIndex,\n beatIndex: this.beatIndex,\n instance: this.instance,\n atom: this.atom.debugValue(),\n };\n }\n\n get endOffset(): Fraction {\n return this.offset.plus(this.duration);\n }\n get filled(): boolean {\n return this.remaining.isZero;\n }\n\n get remaining(): Fraction {\n return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;\n }\n\n add(atom: Atom): boolean {\n if (this.remaining.cmp(atom.duration) < 0) {\n return false;\n }\n if (!this.atom) {\n this.atom = atom;\n } else {\n if (!this.atomIsPlaceholder) {\n this.atomIsPlaceholder = true;\n this.atom = new Group(this.atom).setDuration(ONE, true);\n }\n (this.atom as Group).addAtoms(true, atom);\n }\n return true;\n }\n}\n\nexport class BeatsBuilder {\n // All atoms divided into beats\n readonly beats: Beat[] = [];\n readonly startIndex: number;\n readonly beatOffset: Fraction;\n cycleIter: CycleIterator;\n windowIter: WindowIterator;\n\n // Callback for when an atom is added to this role.\n onAtomAdded: (atom: Atom, beat: Beat) => void;\n\n // Callback for when a new beat is added\n onBeatAdded: (beat: Beat) => void;\n // Callback for when a beat has been filled\n onBeatFilled: (beat: Beat) => void;\n\n constructor(\n public readonly role: Role,\n public readonly layoutParams: LayoutParams,\n public readonly startOffset: Fraction = ZERO,\n ...atoms: Atom[]\n ) {\n const [, [bar, beat, instance], beatOffset, index] = layoutParams.cycle.getPosition(startOffset);\n this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);\n this.windowIter = new WindowIterator();\n this.beatOffset = beatOffset;\n\n // evaluate the start beatindex - typically it would be 0 if things start\n // at beginning of a cycle. But if the start offset is < 0 then the\n // startIndex should also shift accordingly\n this.startIndex = index;\n this.addAtoms(...atoms);\n }\n\n addAtoms(...atoms: Atom[]): void {\n // First add all atoms to the atom Iterator so we can\n // fetch them as FlatAtoms. This is needed because atoms\n // passed here could be unflatted (via groups) or much larger\n // than what can fit in the given role/bar etc. So this\n // flattening and windowing is needed before we add them\n // to the views - and this is done by the durationIterators.\n this.windowIter.push(...atoms);\n while (this.windowIter.hasMore) {\n // get the last/current row and add a new one if it is full\n let currBeat = this.beats[this.beats.length - 1];\n\n // First add a row if last row is filled\n if (this.beats.length == 0 || currBeat.filled) {\n // what should be the beatlengths be here?\n currBeat = this.addBeat();\n }\n\n // For this beat get symbols in all roles\n const [remAtoms, filled] = this.windowIter.get(currBeat.remaining);\n TSU.assert(remAtoms.length > 0, \"Atleast one element should have been available here\");\n // render the atoms now\n for (const atom of remAtoms) {\n // console.log(\"Adding FA: \", flatAtom.debugValue(), flatAtom.atom);\n TSU.assert(currBeat.add(atom), \"Should return true as we are already using a duration iterator here\");\n if (this.onAtomAdded) this.onAtomAdded(atom, currBeat);\n }\n if (currBeat.filled) {\n if (this.onBeatFilled) this.onBeatFilled(currBeat);\n }\n }\n }\n\n protected addBeat(): Beat {\n const numBeats = this.beats.length;\n const lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];\n const nextCP: [CyclePosition, Fraction] = this.cycleIter.next().value;\n const apb = this.layoutParams.beatDuration;\n const newBeat = new Beat(\n lastBeat == null ? this.startIndex : lastBeat.index + 1,\n this.role,\n lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset,\n nextCP[1].timesNum(apb),\n nextCP[0][0],\n nextCP[0][1],\n nextCP[0][2],\n lastBeat,\n null,\n );\n if (lastBeat == null && this.beatOffset.isGT(ZERO)) {\n // Add spaces to fill up empty beats\n newBeat.add(new Space(this.beatOffset.timesNum(apb)));\n }\n if (lastBeat) lastBeat.nextBeat = newBeat;\n this.beats.push(newBeat);\n if (this.onBeatAdded) this.onBeatAdded(newBeat);\n return newBeat;\n }\n}\n\nexport class BeatColumn extends ColAlign {\n atomSpacing = 5;\n readonly key: string;\n constructor(\n public readonly offset: Fraction,\n public readonly endOffset: Fraction,\n public readonly markerType: number,\n ) {\n super();\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n this.key = BeatColumn.keyFor(offset, endOffset, markerType);\n }\n\n static keyFor(offset: Fraction, endOffset: Fraction, markerType = 0): string {\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n if (markerType < 0) {\n // return the column for the marker \"before\" this col\n // int his case only the \"start offset\" is needed and length doesnt matter\n return \":\" + offset.toString();\n } else if (markerType > 0) {\n // return the column for the marker \"after\" this col\n // in this case only thd end offset matters\n return endOffset.toString() + \":\";\n } else {\n return offset.toString() + \":\" + endOffset.toString();\n }\n }\n}\n\n/**\n * Grouping of beats by their column based on the layout params.\n * The confusion is we have beats broken up and saved in columns\n * but we are loosing how a line is supposed to access it in its own way\n * we have beatsByRole for getting all beats for a role (in a line)\n * sequentially we have beatColumns for getting all beats in a particular\n * column across all lines and roles globally.\n *\n * What we want here is for a given line get all roles, their beats\n * in zipped way. eg for a Line with 3 roles and say 10 beats each\n * (with the breaks of 4, 1) we need:\n *\n * R1 B1 R1 B2 R1 B3 R1 B4\n * R2 B1 R2 B2 R2 B3 R2 B4\n * R3 B1 R3 B2 R3 B3 R3 B4\n *\n * R1 B5\n * R2 B5\n * R3 B5\n *\n * R1 B6 R1 B7 R1 B8 R1 B9\n * R2 B6 R2 B7 R2 B8 R2 B9\n * R3 B6 R3 B7 R3 B8 R3 B9\n *\n * R1 B10\n * R2 B10\n * R3 B10\n *\n *\n * Here we have 5 distinct beat columns:\n *\n * 1: R1B1, R2B1, R3B1, R1B6, R2B6, R3B6,\n * 2: R1B2, R2B2, R3B2, R1B7, R2B7, R3B7,\n * 3: R1B3, R2B3, R3B3, R1B8, R2B8, R3B8,\n * 4: R1B4, R2B4, R3B4, R1B9, R2B9, R3B9,\n * 5: R1B5, R2B5, R3B5, R1B10, R2B10, R3B10,\n *\n */\nexport class BeatColDAG {\n beatColumns = new Map<string, BeatColumn>();\n\n constructor(public readonly layoutGroup: GridLayoutGroup) {\n //\n }\n\n /**\n * Gets the beat column of a given duration at the given offset.\n */\n getBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): BeatColumn {\n const [bcol, newcreated] = this.ensureBeatColumn(offset, endOffset, markerType);\n if (newcreated) {\n if (markerType == 0) {\n const [prevcol] = this.ensureBeatColumn(offset, endOffset, -1);\n const [nextcol] = this.ensureBeatColumn(offset, endOffset, 1);\n prevcol.addSuccessor(bcol);\n bcol.addSuccessor(nextcol);\n for (const other of this.beatColumns.values()) {\n // only join the \"marker\" columns\n if (other.markerType == -1 && endOffset.equals(other.offset)) {\n // our next col is a preecessor of other\n nextcol.addSuccessor(other);\n } else if (other.markerType == 1 && other.endOffset.equals(offset)) {\n // our prev col is a predecessor of other\n other.addSuccessor(prevcol);\n }\n }\n }\n }\n return bcol;\n }\n\n protected ensureBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): [BeatColumn, boolean] {\n const key = BeatColumn.keyFor(offset, endOffset, markerType);\n let bcol = this.beatColumns.get(key) || null;\n const newcreated = bcol == null;\n if (!bcol) {\n bcol = new BeatColumn(offset, endOffset, markerType);\n this.beatColumns.set(key, bcol);\n }\n return [bcol, newcreated];\n }\n}\n\n/**\n * Manages the beat layouts for *all* lines in a notation.\n */\ntype LineId = number;\ntype LPID = number;\nexport class GlobalBeatLayout {\n gridModelsForLine = new Map<LineId, GridModel>();\n roleBeatsForLine = new Map<LineId, Beat[][]>();\n beatColDAGsByLP = new Map<LPID, BeatColDAG>();\n readonly gridLayoutGroup = new GridLayoutGroup();\n\n /**\n * Get the GridView associated with a particular line.\n */\n getGridModelForLine(lineid: LineId): GridModel {\n let out = this.gridModelsForLine.get(lineid) || null;\n if (!out) {\n out = new GridModel();\n this.gridLayoutGroup.addGridModel(out);\n this.gridModelsForLine.set(lineid, out);\n }\n return out;\n }\n\n protected beatColDAGForLP(lpid: LPID): BeatColDAG {\n let out = this.beatColDAGsByLP.get(lpid) || null;\n if (!out) {\n out = new BeatColDAG(this.gridLayoutGroup);\n this.beatColDAGsByLP.set(lpid, out);\n }\n return out;\n }\n\n /**\n * First lines are added to the BeatLayout object.\n * This ensures that a line is broken down into beats and added\n * into a dedicated GridModel per line.\n *\n * A line must also be given the layout params by which the beat\n * break down will happen. This LayoutParams object does not have\n * to be unique per line (this non-constraint allows to align\n * beats across lines!).\n */\n addLine(line: Line): void {\n const gridModel = this.getGridModelForLine(line.uuid) as GridModel;\n gridModel.eventHub?.startBatchMode();\n this.lineToRoleBeats(line, gridModel);\n gridModel.eventHub?.commitBatch();\n }\n\n protected lineToRoleBeats(line: Line, gridModel: GridModel): Beat[][] {\n const lp = line.layoutParams;\n const roleBeats = [] as Beat[][];\n this.roleBeatsForLine.set(line.uuid, roleBeats);\n const lineOffset = line.offset.divbyNum(lp.beatDuration);\n for (const role of line.roles) {\n const bb = new BeatsBuilder(role, lp, lineOffset, ...role.atoms);\n roleBeats.push(bb.beats);\n\n // Add these to the beat layout too\n for (const beat of bb.beats) {\n // beat.ensureUniformSpaces(layoutParams.beatDuration);\n this.addBeat(beat, gridModel);\n }\n }\n return roleBeats;\n }\n\n /**\n * Adds the beat to this layout and returns the BeatColumn to which\n * this beat was added.\n */\n protected addBeat(beat: Beat, gridModel: GridModel): GridCell {\n // Get the beat column at this index (and line) and add to it.\n const line = beat.role.line;\n const lp = line.layoutParams;\n const beatColDAG = this.beatColDAGForLP(lp.uuid);\n const [layoutLine, layoutColumn, rowOffset] = lp.getBeatLocation(beat);\n const colEnd = rowOffset.plus(beat.duration, true);\n const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);\n\n // Since a beat's column has a \"pre\" and \"post\" col to, each\n // beat has 3 columns for it\n const roleIndex = beat.role.line.indexOfRole(beat.role.name);\n const realRow = line.roles.length * (layoutLine + Math.floor(beat.index / lp.totalBeats)) + roleIndex;\n const realCol = layoutColumn * 3;\n return gridModel.setValue(realRow, realCol, beat, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = bcol;\n return cell;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"beats.js","sourceRoot":"","sources":["../../src/beats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAU,KAAK,EAAc,KAAK,EAAQ,MAAM,IAAI,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,C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UAAU,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAC/D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,OAAgB,EAAE,GAAW,EAAE,EAAE;gBAC9E,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;gBACxC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;gBACxB,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,OAAgB,EAAE,GAAW,EAAE,EAAE;YAClF,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { AtomType, Marker, Group, Line, Atom, Space, Role } from \"./\";\nimport { CycleIterator, CyclePosition } from \"./cycle\";\nimport { WindowIterator } from \"./iterators\";\nimport { LayoutParams } from \"./layouts\";\nimport { GridModel, GridRow, GridCell, ColAlign, GridLayoutGroup } from \"./grids\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\nexport class Beat {\n private static idCounter = 0;\n readonly uuid = Beat.idCounter++;\n // Should this be as flat Atoms or should we keep it as atoms and breakdown\n // later?\n atom: Atom;\n protected atomIsPlaceholder = false;\n constructor(\n public readonly index: number,\n public readonly role: Role,\n public readonly offset: Fraction,\n public readonly duration: Fraction,\n public readonly barIndex: number,\n public readonly beatIndex: number,\n public readonly instance: number,\n public readonly prevBeat: null | Beat,\n public nextBeat: null | Beat,\n ) {}\n\n debugValue(): any {\n return {\n index: this.index,\n role: this.role.name,\n offset: this.offset.toString(),\n duration: this.duration.toString(),\n barIndex: this.barIndex,\n beatIndex: this.beatIndex,\n instance: this.instance,\n atom: this.atom.debugValue(),\n };\n }\n\n get endOffset(): Fraction {\n return this.offset.plus(this.duration);\n }\n get filled(): boolean {\n return this.remaining.isZero;\n }\n\n get remaining(): Fraction {\n return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;\n }\n\n add(atom: Atom): boolean {\n if (this.remaining.cmp(atom.duration) < 0) {\n return false;\n }\n if (!this.atom) {\n this.atom = atom;\n } else {\n if (!this.atomIsPlaceholder) {\n this.atomIsPlaceholder = true;\n this.atom = new Group(this.atom).setDuration(ONE, true);\n }\n (this.atom as Group).addAtoms(true, atom);\n }\n return true;\n }\n\n get preMarkers(): Marker[] {\n const out = [] as Marker[];\n let curr: Atom | null = this.atom;\n while (curr != null) {\n for (const marker of curr.markersBefore || []) {\n out.push(marker);\n }\n if (curr.type == AtomType.GROUP) {\n curr = (curr as Group).atoms.first;\n } else {\n curr = null;\n }\n }\n return out;\n }\n\n get postMarkers(): Marker[] {\n const out = [] as Marker[];\n let curr: Atom | null = this.atom;\n while (curr != null) {\n out.splice(0, 0, ...(curr.markersAfter || []));\n if (curr.type == AtomType.GROUP) {\n curr = (curr as Group).atoms.last;\n } else {\n curr = null;\n }\n }\n return out;\n }\n}\n\nexport class BeatsBuilder {\n // All atoms divided into beats\n readonly beats: Beat[] = [];\n readonly startIndex: number;\n readonly beatOffset: Fraction;\n cycleIter: CycleIterator;\n windowIter: WindowIterator;\n\n // Callback for when an atom is added to this role.\n onAtomAdded: (atom: Atom, beat: Beat) => void;\n\n // Callback for when a new beat is added\n onBeatAdded: (beat: Beat) => void;\n // Callback for when a beat has been filled\n onBeatFilled: (beat: Beat) => void;\n\n constructor(\n public readonly role: Role,\n public readonly layoutParams: LayoutParams,\n public readonly startOffset: Fraction = ZERO,\n ...atoms: Atom[]\n ) {\n const [, [bar, beat, instance], beatOffset, index] = layoutParams.cycle.getPosition(startOffset);\n this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);\n this.windowIter = new WindowIterator();\n this.beatOffset = beatOffset;\n\n // evaluate the start beatindex - typically it would be 0 if things start\n // at beginning of a cycle. But if the start offset is < 0 then the\n // startIndex should also shift accordingly\n this.startIndex = index;\n this.addAtoms(...atoms);\n }\n\n addAtoms(...atoms: Atom[]): void {\n // First add all atoms to the atom Iterator so we can\n // fetch them as FlatAtoms. This is needed because atoms\n // passed here could be unflatted (via groups) or much larger\n // than what can fit in the given role/bar etc. So this\n // flattening and windowing is needed before we add them\n // to the views - and this is done by the durationIterators.\n this.windowIter.push(...atoms);\n while (this.windowIter.hasMore) {\n // get the last/current row and add a new one if it is full\n let currBeat = this.beats[this.beats.length - 1];\n\n // First add a row if last row is filled\n if (this.beats.length == 0 || currBeat.filled) {\n // what should be the beatlengths be here?\n currBeat = this.addBeat();\n }\n\n // For this beat get symbols in all roles\n const [remAtoms, filled] = this.windowIter.get(currBeat.remaining);\n TSU.assert(remAtoms.length > 0, \"Atleast one element should have been available here\");\n // render the atoms now\n for (const atom of remAtoms) {\n // console.log(\"Adding FA: \", flatAtom.debugValue(), flatAtom.atom);\n TSU.assert(currBeat.add(atom), \"Should return true as we are already using a duration iterator here\");\n if (this.onAtomAdded) this.onAtomAdded(atom, currBeat);\n }\n if (currBeat.filled) {\n if (this.onBeatFilled) this.onBeatFilled(currBeat);\n }\n }\n }\n\n protected addBeat(): Beat {\n const numBeats = this.beats.length;\n const lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];\n const nextCP: [CyclePosition, Fraction] = this.cycleIter.next().value;\n const apb = this.layoutParams.beatDuration;\n const newBeat = new Beat(\n lastBeat == null ? this.startIndex : lastBeat.index + 1,\n this.role,\n lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset,\n nextCP[1].timesNum(apb),\n nextCP[0][0],\n nextCP[0][1],\n nextCP[0][2],\n lastBeat,\n null,\n );\n if (lastBeat == null && this.beatOffset.isGT(ZERO)) {\n // Add spaces to fill up empty beats\n newBeat.add(new Space(this.beatOffset.timesNum(apb)));\n }\n if (lastBeat) lastBeat.nextBeat = newBeat;\n this.beats.push(newBeat);\n if (this.onBeatAdded) this.onBeatAdded(newBeat);\n return newBeat;\n }\n}\n\nexport class BeatColumn extends ColAlign {\n atomSpacing = 5;\n readonly key: string;\n constructor(\n public readonly offset: Fraction,\n public readonly endOffset: Fraction,\n public readonly markerType: number,\n ) {\n super();\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n this.key = BeatColumn.keyFor(offset, endOffset, markerType);\n }\n\n static keyFor(offset: Fraction, endOffset: Fraction, markerType = 0): string {\n offset = offset.factorized;\n endOffset = endOffset.factorized;\n if (markerType < 0) {\n // return the column for the marker \"before\" this col\n // int his case only the \"start offset\" is needed and length doesnt matter\n return \":\" + offset.toString();\n } else if (markerType > 0) {\n // return the column for the marker \"after\" this col\n // in this case only thd end offset matters\n return endOffset.toString() + \":\";\n } else {\n return offset.toString() + \":\" + endOffset.toString();\n }\n }\n}\n\n/**\n * Grouping of beats by their column based on the layout params.\n * The confusion is we have beats broken up and saved in columns\n * but we are loosing how a line is supposed to access it in its own way\n * we have beatsByRole for getting all beats for a role (in a line)\n * sequentially we have beatColumns for getting all beats in a particular\n * column across all lines and roles globally.\n *\n * What we want here is for a given line get all roles, their beats\n * in zipped way. eg for a Line with 3 roles and say 10 beats each\n * (with the breaks of 4, 1) we need:\n *\n * R1 B1 R1 B2 R1 B3 R1 B4\n * R2 B1 R2 B2 R2 B3 R2 B4\n * R3 B1 R3 B2 R3 B3 R3 B4\n *\n * R1 B5\n * R2 B5\n * R3 B5\n *\n * R1 B6 R1 B7 R1 B8 R1 B9\n * R2 B6 R2 B7 R2 B8 R2 B9\n * R3 B6 R3 B7 R3 B8 R3 B9\n *\n * R1 B10\n * R2 B10\n * R3 B10\n *\n *\n * Here we have 5 distinct beat columns:\n *\n * 1: R1B1, R2B1, R3B1, R1B6, R2B6, R3B6,\n * 2: R1B2, R2B2, R3B2, R1B7, R2B7, R3B7,\n * 3: R1B3, R2B3, R3B3, R1B8, R2B8, R3B8,\n * 4: R1B4, R2B4, R3B4, R1B9, R2B9, R3B9,\n * 5: R1B5, R2B5, R3B5, R1B10, R2B10, R3B10,\n *\n */\nexport class BeatColDAG {\n beatColumns = new Map<string, BeatColumn>();\n\n constructor(public readonly layoutGroup: GridLayoutGroup) {\n //\n }\n\n /**\n * Gets the beat column of a given duration at the given offset.\n */\n getBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): BeatColumn {\n const [bcol, newcreated] = this.ensureBeatColumn(offset, endOffset, markerType);\n if (newcreated) {\n if (markerType == 0) {\n const [prevcol] = this.ensureBeatColumn(offset, endOffset, -1);\n const [nextcol] = this.ensureBeatColumn(offset, endOffset, 1);\n prevcol.addSuccessor(bcol);\n bcol.addSuccessor(nextcol);\n for (const other of this.beatColumns.values()) {\n // only join the \"marker\" columns\n if (other.markerType == -1 && endOffset.equals(other.offset)) {\n // our next col is a preecessor of other\n nextcol.addSuccessor(other);\n } else if (other.markerType == 1 && other.endOffset.equals(offset)) {\n // our prev col is a predecessor of other\n other.addSuccessor(prevcol);\n }\n }\n }\n }\n return bcol;\n }\n\n protected ensureBeatColumn(offset: Fraction, endOffset: Fraction, markerType = 0): [BeatColumn, boolean] {\n const key = BeatColumn.keyFor(offset, endOffset, markerType);\n let bcol = this.beatColumns.get(key) || null;\n const newcreated = bcol == null;\n if (!bcol) {\n bcol = new BeatColumn(offset, endOffset, markerType);\n this.beatColumns.set(key, bcol);\n }\n return [bcol, newcreated];\n }\n}\n\n/**\n * Manages the beat layouts for *all* lines in a notation.\n */\ntype LineId = number;\ntype LPID = number;\nexport class GlobalBeatLayout {\n gridModelsForLine = new Map<LineId, GridModel>();\n roleBeatsForLine = new Map<LineId, Beat[][]>();\n beatColDAGsByLP = new Map<LPID, BeatColDAG>();\n readonly gridLayoutGroup = new GridLayoutGroup();\n\n /**\n * Get the GridView associated with a particular line.\n */\n getGridModelForLine(lineid: LineId): GridModel {\n let out = this.gridModelsForLine.get(lineid) || null;\n if (!out) {\n out = new GridModel();\n this.gridLayoutGroup.addGridModel(out);\n this.gridModelsForLine.set(lineid, out);\n }\n return out;\n }\n\n protected beatColDAGForLP(lpid: LPID): BeatColDAG {\n let out = this.beatColDAGsByLP.get(lpid) || null;\n if (!out) {\n out = new BeatColDAG(this.gridLayoutGroup);\n this.beatColDAGsByLP.set(lpid, out);\n }\n return out;\n }\n\n /**\n * First lines are added to the BeatLayout object.\n * This ensures that a line is broken down into beats and added\n * into a dedicated GridModel per line.\n *\n * A line must also be given the layout params by which the beat\n * break down will happen. This LayoutParams object does not have\n * to be unique per line (this non-constraint allows to align\n * beats across lines!).\n */\n addLine(line: Line): void {\n const gridModel = this.getGridModelForLine(line.uuid) as GridModel;\n gridModel.eventHub?.startBatchMode();\n this.lineToRoleBeats(line, gridModel);\n gridModel.eventHub?.commitBatch();\n }\n\n protected lineToRoleBeats(line: Line, gridModel: GridModel): Beat[][] {\n const lp = line.layoutParams;\n const roleBeats = [] as Beat[][];\n this.roleBeatsForLine.set(line.uuid, roleBeats);\n const lineOffset = line.offset.divbyNum(lp.beatDuration);\n for (const role of line.roles) {\n const bb = new BeatsBuilder(role, lp, lineOffset, ...role.atoms);\n roleBeats.push(bb.beats);\n\n // Add these to the beat layout too\n for (const beat of bb.beats) {\n // beat.ensureUniformSpaces(layoutParams.beatDuration);\n this.addBeat(beat, gridModel);\n }\n }\n return roleBeats;\n }\n\n /**\n * Adds the beat to this layout and returns the BeatColumn to which\n * this beat was added.\n */\n protected addBeat(beat: Beat, gridModel: GridModel): GridCell {\n // Get the beat column at this index (and line) and add to it.\n const line = beat.role.line;\n const lp = line.layoutParams;\n const beatColDAG = this.beatColDAGForLP(lp.uuid);\n const [layoutLine, layoutColumn, rowOffset] = lp.getBeatLocation(beat);\n const colEnd = rowOffset.plus(beat.duration, true);\n const bcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 0);\n\n // Since a beat's column has a \"pre\" and \"post\" col to, each\n // beat has 3 columns for it\n const roleIndex = beat.role.line.indexOfRole(beat.role.name);\n const realRow = line.roles.length * (layoutLine + Math.floor(beat.index / lp.totalBeats)) + roleIndex;\n // pre marker goes on realCol - 1, post marker goes on realCol + 1\n const realCol = 1 + layoutColumn * 3;\n const preMarkers = beat.preMarkers;\n if (preMarkers.length > 0) {\n const val = {\n beat: beat,\n markers: preMarkers,\n };\n const precol = beatColDAG.getBeatColumn(rowOffset, colEnd, -1);\n gridModel.setValue(realRow, realCol - 1, val, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = precol;\n return cell;\n });\n }\n const postMarkers = beat.postMarkers;\n if (postMarkers.length > 0) {\n const val = {\n beat: beat,\n markers: postMarkers,\n };\n const postcol = beatColDAG.getBeatColumn(rowOffset, colEnd, 1);\n gridModel.setValue(realRow, realCol + 1, val, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = postcol;\n return cell;\n });\n }\n return gridModel.setValue(realRow, realCol, beat, (gridRow: GridRow, col: number) => {\n const cell = new GridCell(gridRow, col);\n cell.colAlign = bcol;\n return cell;\n });\n }\n}\n"]}
|
package/lib/esm/beatview.js
CHANGED
|
@@ -9,9 +9,9 @@ export class BeatView extends ElementShape {
|
|
|
9
9
|
beatId: "" + beat.uuid,
|
|
10
10
|
id: "" + beat.uuid,
|
|
11
11
|
roleName: beat.role.name,
|
|
12
|
-
layoutLine: "" + beat.layoutLine,
|
|
13
|
-
layoutColumn: "" + beat.layoutColumn,
|
|
14
12
|
beatIndex: "" + beat.index,
|
|
13
|
+
gridRow: cell.rowIndex,
|
|
14
|
+
gridCol: cell.colIndex,
|
|
15
15
|
},
|
|
16
16
|
}));
|
|
17
17
|
this.cell = cell;
|
package/lib/esm/beatview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beatview.js","sourceRoot":"","sources":["../../src/beatview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAA0B,YAAY,EAAE,MAAM,UAAU,CAAC;AAKhE,MAAM,OAAgB,QAAS,SAAQ,YAAyB;IAI9D,YACkB,IAAc,EACd,IAAU,EACV,WAA+B,EAC/B,KAAY,EAC5B,MAAY;QAEZ,KAAK,CACH,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE;YACzB,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE;gBACL,KAAK,EAAE,UAAU;gBACjB,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI;gBACtB,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI;gBAClB,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;gBACxB,
|
|
1
|
+
{"version":3,"file":"beatview.js","sourceRoot":"","sources":["../../src/beatview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAA0B,YAAY,EAAE,MAAM,UAAU,CAAC;AAKhE,MAAM,OAAgB,QAAS,SAAQ,YAAyB;IAI9D,YACkB,IAAc,EACd,IAAU,EACV,WAA+B,EAC/B,KAAY,EAC5B,MAAY;QAEZ,KAAK,CACH,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE;YACzB,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE;gBACL,KAAK,EAAE,UAAU;gBACjB,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI;gBACtB,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI;gBAClB,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;gBACxB,SAAS,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK;gBAC1B,OAAO,EAAE,IAAI,CAAC,QAAQ;gBACtB,OAAO,EAAE,IAAI,CAAC,QAAQ;aACvB;SACF,CAAC,CACH,CAAC;QAnBc,SAAI,GAAJ,IAAI,CAAU;QACd,SAAI,GAAJ,IAAI,CAAM;QACV,gBAAW,GAAX,WAAW,CAAoB;QAC/B,UAAK,GAAL,KAAK,CAAO;QAL9B,gBAAW,GAAG,IAAI,CAAC;QAsBjB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACtC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;IAChC,CAAC;IAED,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;SAClD;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,SAAS,CAAC,MAAW;QACnB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CAIF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { AtomView, Embelishment, ElementShape } from \"./shapes\";\nimport { GridCell, GridCellView } from \"./grids\";\nimport { Cycle } from \"./cycle\";\nimport { Beat } from \"./beats\";\n\nexport abstract class BeatView extends ElementShape<SVGGElement> implements GridCellView {\n private _embelishments: Embelishment[];\n atomView: AtomView;\n needsLayout = true;\n constructor(\n public readonly cell: GridCell,\n public readonly beat: Beat,\n public readonly rootElement: SVGGraphicsElement,\n public readonly cycle: Cycle,\n config?: any,\n ) {\n super(\n TSU.DOM.createSVGNode(\"g\", {\n parent: rootElement,\n attrs: {\n class: \"beatView\",\n beatId: \"\" + beat.uuid,\n id: \"\" + beat.uuid,\n roleName: beat.role.name,\n beatIndex: \"\" + beat.index,\n gridRow: cell.rowIndex,\n gridCol: cell.colIndex,\n },\n }),\n );\n this.atomView = this.createAtomView();\n this.atomView.refreshLayout();\n }\n\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n setStyles(config: any): void {\n this.needsLayout = true;\n }\n\n protected abstract createEmbelishments(): Embelishment[];\n protected abstract createAtomView(): AtomView;\n}\n"]}
|
|
@@ -2,9 +2,9 @@ import * as TSU from "@panyam/tsutils";
|
|
|
2
2
|
import { LineView } from "./LineView";
|
|
3
3
|
import { Notation, RawBlock } from "../notation";
|
|
4
4
|
import { GlobalBeatLayout } from "../beats";
|
|
5
|
-
import { GridCell } from "../grids";
|
|
5
|
+
import { GridCell, GridCellView } from "../grids";
|
|
6
6
|
import { Line } from "../core";
|
|
7
|
-
import { BeatView } from "./beatviews";
|
|
7
|
+
import { BeatView, MarkerView } from "./beatviews";
|
|
8
8
|
export declare class NotationView {
|
|
9
9
|
readonly rootElement: HTMLElement;
|
|
10
10
|
readonly config?: any;
|
|
@@ -28,5 +28,6 @@ export declare class NotationView {
|
|
|
28
28
|
refreshLayout(): void;
|
|
29
29
|
renderBlock(raw: RawBlock): void;
|
|
30
30
|
beatViews: Map<number, BeatView>;
|
|
31
|
-
|
|
31
|
+
markerViews: Map<string, MarkerView>;
|
|
32
|
+
viewForBeat(cell: GridCell): GridCellView;
|
|
32
33
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
2
|
import { LineView } from "./LineView";
|
|
3
|
-
import { BeatView } from "./beatviews";
|
|
3
|
+
import { BeatView, MarkerView } from "./beatviews";
|
|
4
4
|
export class NotationView {
|
|
5
5
|
constructor(rootElement, config) {
|
|
6
6
|
this.rootElement = rootElement;
|
|
@@ -8,6 +8,7 @@ export class NotationView {
|
|
|
8
8
|
this.lineViews = [];
|
|
9
9
|
this.currentSVGElement = null;
|
|
10
10
|
this.beatViews = new Map();
|
|
11
|
+
this.markerViews = new Map();
|
|
11
12
|
this.loadChildViews();
|
|
12
13
|
}
|
|
13
14
|
get beatLayout() {
|
|
@@ -135,16 +136,32 @@ export class NotationView {
|
|
|
135
136
|
this.currentSVGElement = null;
|
|
136
137
|
}
|
|
137
138
|
viewForBeat(cell) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
139
|
+
if (cell.colIndex % 3 == 1) {
|
|
140
|
+
const beat = cell.value;
|
|
141
|
+
let curr = this.beatViews.get(beat.uuid) || null;
|
|
142
|
+
if (curr == null) {
|
|
143
|
+
const line = beat.role.line;
|
|
144
|
+
const lineView = this.ensureLineView(line);
|
|
145
|
+
const lp = line.layoutParams;
|
|
146
|
+
curr = new BeatView(cell, beat, lineView.gElem, lp.cycle);
|
|
147
|
+
this.beatViews.set(beat.uuid, curr);
|
|
148
|
+
}
|
|
149
|
+
return curr;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const marker = cell.value;
|
|
153
|
+
const beat = marker.beat;
|
|
154
|
+
let curr = this.markerViews.get("pre:" + beat.uuid) || null;
|
|
155
|
+
if (curr == null) {
|
|
156
|
+
const line = beat.role.line;
|
|
157
|
+
const lineView = this.ensureLineView(line);
|
|
158
|
+
const lp = line.layoutParams;
|
|
159
|
+
const isPreMarker = cell.colIndex % 3 == 0;
|
|
160
|
+
curr = new MarkerView(cell, beat, marker.markers, isPreMarker, lineView.gElem);
|
|
161
|
+
this.markerViews.set("pre:" + beat.uuid, curr);
|
|
162
|
+
}
|
|
163
|
+
return curr;
|
|
146
164
|
}
|
|
147
|
-
return curr;
|
|
148
165
|
}
|
|
149
166
|
}
|
|
150
167
|
//# sourceMappingURL=NotationView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,OAAO,YAAY;IAUvB,Y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KAAK,CAAC,CAAC,CAAC;YACvD,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;SACzD;QACD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAChC,CAAC;IAGD,WAAW,CAAC,IAAc;QACxB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;QACjD,IAAI,IAAI,IAAI,IAAI,EAAE;YAChB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAE5B,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;YAC7B,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;YAC1D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { LineView } from \"./LineView\";\nimport { Notation, RawBlock } from \"../notation\";\nimport { GlobalBeatLayout } from \"../beats\";\nimport { GridCell } from \"../grids\";\nimport { Line } from \"../core\";\nimport { BeatView } from \"./beatviews\";\n\nexport class NotationView {\n headerElement: HTMLDivElement;\n notation: Notation;\n lineViews: LineView[] = [];\n // Mapping from line id -> list of beats in each of its roles\n currentSVGElement: SVGSVGElement | null = null;\n tableElement: HTMLTableElement;\n markdownParser: (contents: string) => string;\n _beatLayout: GlobalBeatLayout;\n\n constructor(public readonly rootElement: HTMLElement, public readonly config?: any) {\n this.loadChildViews();\n }\n\n get beatLayout(): GlobalBeatLayout {\n return this._beatLayout;\n }\n\n set beatLayout(beatLayout: GlobalBeatLayout) {\n this._beatLayout = beatLayout;\n beatLayout.gridLayoutGroup.getCellView = (cell) => this.viewForBeat(cell);\n }\n\n loadChildViews(): void {\n this.tableElement = TSU.DOM.createNode(\"table\", {\n parent: this.rootElement,\n attrs: {\n class: \"notationsContentRootTable\",\n },\n }) as HTMLTableElement;\n }\n\n public addNewRow(id: string, prefix: string, withAnnotation = true): [HTMLElement, HTMLElement] {\n const tr = TSU.DOM.createNode(\"tr\", {\n parent: this.tableElement, // parent,\n attrs: {\n class: prefix + \"Row\",\n id: prefix + \"Row\" + id,\n },\n });\n let td1: HTMLElement | null = null;\n if (withAnnotation) {\n td1 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"AnnotationCell\",\n id: prefix + \"Annotation\" + id,\n },\n }) as HTMLElement;\n }\n const td2 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"ContentCell\",\n id: prefix + \"Content\" + id,\n colspan: withAnnotation ? 1 : 2,\n },\n }) as HTMLElement;\n return [td1!, td2];\n }\n\n public newLineRoot(parent: Element, line: Line): SVGSVGElement {\n const [td1, td2] = this.addNewRow(line.uuid + \"\", \"line\");\n // Hacky solution to \"line headings\"\n if (line.marginText) {\n td1.innerHTML = line.marginText;\n }\n return TSU.DOM.createSVGNode(\"svg\", {\n parent: td2, // parent\n attrs: {\n style: \"margin-bottom: 10px\",\n class: \"lineRootSVG\",\n },\n }) as SVGSVGElement;\n }\n\n ensureLineView(line: Line): LineView {\n let lineView = this.getLineView(line);\n if (lineView == null) {\n const layoutParams = line.layoutParams || null;\n const svgElem = this.newLineRoot(this.tableElement, line);\n lineView = new LineView(svgElem, line, {\n layoutParams: layoutParams,\n } as any);\n if (!line.isEmpty) {\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(layoutParams != null, \"Layout params for a non empty line *should* exist\");\n lineView.gridModel = this.beatLayout!.getGridModelForLine(line.uuid);\n }\n this.lineViews.push(lineView);\n }\n return lineView;\n }\n\n getLineView(line: Line): TSU.Nullable<LineView> {\n return this.lineViews.find((l) => l.line == line) || null;\n }\n\n get currentLineView(): LineView {\n return this.lineViews[this.lineViews.length - 1];\n }\n\n clear(): void {\n this.lineViews = [];\n // Mapping from line id -> list of beats in each of its roles\n this.currentSVGElement = null;\n this.tableElement.innerHTML = \"\";\n this.beatViews = new Map<number, BeatView>();\n }\n\n /**\n * Layout all the blocks in the Notation along with their corresponding blocks.\n * Key thing is here is an opportunity to perform any batch rendering as needed.\n */\n refreshLayout(): void {\n const lines = [] as Line[];\n const lineViews = [] as LineView[];\n for (const block of this.notation.blocks) {\n if (block.type == \"RawBlock\") {\n // Add the markdown here\n this.renderBlock(block as RawBlock);\n } else {\n lines.push(block as Line);\n const lineView = this.ensureLineView(block as Line);\n lineViews.push(lineView);\n }\n }\n\n const now = performance.now();\n for (const lineView of lineViews) {\n lineView.gridModel.lastUpdatedAt = now;\n }\n\n this.beatLayout.gridLayoutGroup.refreshLayout();\n\n for (const lineView of lineViews) {\n lineView.wrapToSize();\n }\n\n // now that all spacing has been calculated\n // go through all\n // for (const beatView of this.beatViews.values()) { beatView.refreshLayout(); }\n }\n\n renderBlock(raw: RawBlock): void {\n const [, td2] = this.addNewRow(raw.uuid + \"\", \"rawBlock\", false);\n if (raw.contentType == \"metadata\") {\n // we have a metadata block\n const meta = this.notation.metadata.get(raw.content);\n if (meta) {\n // For now ignore metadata with \":\" in the key\n if (meta.key.toLowerCase().indexOf(\":\") < 0) {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n const html = `<span class = \"${meta.key.toLowerCase()}\"><strong>${meta.key}</strong>: ${meta.value}</span>`;\n div.innerHTML = html;\n }\n }\n } else {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n div.innerHTML = this.markdownParser(raw.content.trim());\n }\n this.currentSVGElement = null;\n }\n\n beatViews = new Map<number, BeatView>();\n viewForBeat(cell: GridCell): BeatView {\n const beat = cell.value;\n let curr = this.beatViews.get(beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n // how to get the bar and beat index for a given beat in a given row?\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n curr = new BeatView(cell, beat, lineView.gElem, lp.cycle);\n this.beatViews.set(beat.uuid, curr);\n }\n return curr;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKtC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,OAAO,YAAY;IAUvB,YAA4B,WAAwB,EAAkB,MAAY;QAAtD,gBAAW,GAAX,WAAW,CAAa;QAAkB,WAAM,GAAN,MAAM,CAAM;QAPlF,cAAS,GAAe,EAAE,CAAC;QAE3B,sBAAiB,GAAyB,IAAI,CAAC;QA+J/C,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QACxC,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;QA1J1C,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU,CAAC,UAA4B;QACzC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,UAAU,CAAC,eAAe,CAAC,WAAW,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5E,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE;YAC9C,MAAM,EAAE,IAAI,CAAC,WAAW;YACxB,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AI,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBAC1D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aACrC;YACD,OAAO,IAAI,CAAC;SACb;aAAM;YAEL,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;YAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAY,CAAC;YACjC,IAAI,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;YAC5D,IAAI,IAAI,IAAI,IAAI,EAAE;gBAChB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;gBAC7B,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC3C,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAC/E,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aAChD;YACD,OAAO,IAAI,CAAC;SACb;IACH,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { LineView } from \"./LineView\";\nimport { Notation, RawBlock } from \"../notation\";\nimport { Beat, GlobalBeatLayout } from \"../beats\";\nimport { GridCell, GridCellView } from \"../grids\";\nimport { Line } from \"../core\";\nimport { BeatView, MarkerView } from \"./beatviews\";\n\nexport class NotationView {\n headerElement: HTMLDivElement;\n notation: Notation;\n lineViews: LineView[] = [];\n // Mapping from line id -> list of beats in each of its roles\n currentSVGElement: SVGSVGElement | null = null;\n tableElement: HTMLTableElement;\n markdownParser: (contents: string) => string;\n _beatLayout: GlobalBeatLayout;\n\n constructor(public readonly rootElement: HTMLElement, public readonly config?: any) {\n this.loadChildViews();\n }\n\n get beatLayout(): GlobalBeatLayout {\n return this._beatLayout;\n }\n\n set beatLayout(beatLayout: GlobalBeatLayout) {\n this._beatLayout = beatLayout;\n beatLayout.gridLayoutGroup.getCellView = (cell) => this.viewForBeat(cell);\n }\n\n loadChildViews(): void {\n this.tableElement = TSU.DOM.createNode(\"table\", {\n parent: this.rootElement,\n attrs: {\n class: \"notationsContentRootTable\",\n },\n }) as HTMLTableElement;\n }\n\n public addNewRow(id: string, prefix: string, withAnnotation = true): [HTMLElement, HTMLElement] {\n const tr = TSU.DOM.createNode(\"tr\", {\n parent: this.tableElement, // parent,\n attrs: {\n class: prefix + \"Row\",\n id: prefix + \"Row\" + id,\n },\n });\n let td1: HTMLElement | null = null;\n if (withAnnotation) {\n td1 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"AnnotationCell\",\n id: prefix + \"Annotation\" + id,\n },\n }) as HTMLElement;\n }\n const td2 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"ContentCell\",\n id: prefix + \"Content\" + id,\n colspan: withAnnotation ? 1 : 2,\n },\n }) as HTMLElement;\n return [td1!, td2];\n }\n\n public newLineRoot(parent: Element, line: Line): SVGSVGElement {\n const [td1, td2] = this.addNewRow(line.uuid + \"\", \"line\");\n // Hacky solution to \"line headings\"\n if (line.marginText) {\n td1.innerHTML = line.marginText;\n }\n return TSU.DOM.createSVGNode(\"svg\", {\n parent: td2, // parent\n attrs: {\n style: \"margin-bottom: 10px\",\n class: \"lineRootSVG\",\n },\n }) as SVGSVGElement;\n }\n\n ensureLineView(line: Line): LineView {\n let lineView = this.getLineView(line);\n if (lineView == null) {\n const layoutParams = line.layoutParams || null;\n const svgElem = this.newLineRoot(this.tableElement, line);\n lineView = new LineView(svgElem, line, {\n layoutParams: layoutParams,\n } as any);\n if (!line.isEmpty) {\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(layoutParams != null, \"Layout params for a non empty line *should* exist\");\n lineView.gridModel = this.beatLayout!.getGridModelForLine(line.uuid);\n }\n this.lineViews.push(lineView);\n }\n return lineView;\n }\n\n getLineView(line: Line): TSU.Nullable<LineView> {\n return this.lineViews.find((l) => l.line == line) || null;\n }\n\n get currentLineView(): LineView {\n return this.lineViews[this.lineViews.length - 1];\n }\n\n clear(): void {\n this.lineViews = [];\n // Mapping from line id -> list of beats in each of its roles\n this.currentSVGElement = null;\n this.tableElement.innerHTML = \"\";\n this.beatViews = new Map<number, BeatView>();\n }\n\n /**\n * Layout all the blocks in the Notation along with their corresponding blocks.\n * Key thing is here is an opportunity to perform any batch rendering as needed.\n */\n refreshLayout(): void {\n const lines = [] as Line[];\n const lineViews = [] as LineView[];\n for (const block of this.notation.blocks) {\n if (block.type == \"RawBlock\") {\n // Add the markdown here\n this.renderBlock(block as RawBlock);\n } else {\n lines.push(block as Line);\n const lineView = this.ensureLineView(block as Line);\n lineViews.push(lineView);\n }\n }\n\n const now = performance.now();\n for (const lineView of lineViews) {\n lineView.gridModel.lastUpdatedAt = now;\n }\n\n this.beatLayout.gridLayoutGroup.refreshLayout();\n\n for (const lineView of lineViews) {\n lineView.wrapToSize();\n }\n\n // now that all spacing has been calculated\n // go through all\n // for (const beatView of this.beatViews.values()) { beatView.refreshLayout(); }\n }\n\n renderBlock(raw: RawBlock): void {\n const [, td2] = this.addNewRow(raw.uuid + \"\", \"rawBlock\", false);\n if (raw.contentType == \"metadata\") {\n // we have a metadata block\n const meta = this.notation.metadata.get(raw.content);\n if (meta) {\n // For now ignore metadata with \":\" in the key\n if (meta.key.toLowerCase().indexOf(\":\") < 0) {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n const html = `<span class = \"${meta.key.toLowerCase()}\"><strong>${meta.key}</strong>: ${meta.value}</span>`;\n div.innerHTML = html;\n }\n }\n } else {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n div.innerHTML = this.markdownParser(raw.content.trim());\n }\n this.currentSVGElement = null;\n }\n\n beatViews = new Map<number, BeatView>();\n markerViews = new Map<string, MarkerView>();\n viewForBeat(cell: GridCell): GridCellView {\n if (cell.colIndex % 3 == 1) {\n // beat view needed\n const beat = cell.value;\n let curr = this.beatViews.get(beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n // how to get the bar and beat index for a given beat in a given row?\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n curr = new BeatView(cell, beat, lineView.gElem, lp.cycle);\n this.beatViews.set(beat.uuid, curr);\n }\n return curr;\n } else {\n // markers view\n const marker = cell.value;\n const beat = marker.beat as Beat;\n let curr = this.markerViews.get(\"pre:\" + beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n const isPreMarker = cell.colIndex % 3 == 0;\n curr = new MarkerView(cell, beat, marker.markers, isPreMarker, lineView.gElem);\n this.markerViews.set(\"pre:\" + beat.uuid, curr);\n }\n return curr;\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { Embelishment } from "../shapes";
|
|
2
|
+
import { GridCell, GridCellView } from "../grids";
|
|
3
|
+
import { ElementShape } from "../shapes";
|
|
4
|
+
import { Marker } from "../core";
|
|
5
|
+
import { Beat } from "../beats";
|
|
2
6
|
import { BeatView as BeatViewBase } from "../beatview";
|
|
7
|
+
export declare class MarkerView extends ElementShape<SVGGElement> implements GridCellView {
|
|
8
|
+
readonly cell: GridCell;
|
|
9
|
+
readonly beat: Beat;
|
|
10
|
+
readonly markers: Marker[];
|
|
11
|
+
readonly isPreMarker: boolean;
|
|
12
|
+
readonly rootElement: SVGGraphicsElement;
|
|
13
|
+
needsLayout: boolean;
|
|
14
|
+
rootGroup: SVGGElement;
|
|
15
|
+
textElement: SVGTextElement;
|
|
16
|
+
constructor(cell: GridCell, beat: Beat, markers: Marker[], isPreMarker: boolean, rootElement: SVGGraphicsElement, config?: any);
|
|
17
|
+
refreshLayout(): void;
|
|
18
|
+
protected updateBounds(x: null | number, y: null | number, w: null | number, h: null | number): [number | null, number | null, number | null, number | null];
|
|
19
|
+
}
|
|
3
20
|
export declare class BeatView extends BeatViewBase {
|
|
4
21
|
createAtomView(): import("../shapes").AtomView;
|
|
5
22
|
refreshLayout(): void;
|
|
@@ -1,6 +1,45 @@
|
|
|
1
|
+
import * as TSU from "@panyam/tsutils";
|
|
2
|
+
import { ElementShape } from "../shapes";
|
|
1
3
|
import { createAtomView } from "./atomviews";
|
|
2
4
|
import { BeatView as BeatViewBase } from "../beatview";
|
|
3
5
|
import { BeatStartLines, BeatEndLines } from "./embelishments";
|
|
6
|
+
export class MarkerView extends ElementShape {
|
|
7
|
+
constructor(cell, beat, markers, isPreMarker, rootElement, config) {
|
|
8
|
+
const rootGroup = TSU.DOM.createSVGNode("g", {
|
|
9
|
+
parent: rootElement,
|
|
10
|
+
attrs: {
|
|
11
|
+
class: "markerView",
|
|
12
|
+
pre: isPreMarker,
|
|
13
|
+
roleName: beat.role.name,
|
|
14
|
+
beatIndex: "" + beat.index,
|
|
15
|
+
gridRow: cell.rowIndex,
|
|
16
|
+
gridCol: cell.colIndex,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
super(rootGroup);
|
|
20
|
+
this.cell = cell;
|
|
21
|
+
this.beat = beat;
|
|
22
|
+
this.markers = markers;
|
|
23
|
+
this.isPreMarker = isPreMarker;
|
|
24
|
+
this.rootElement = rootElement;
|
|
25
|
+
this.needsLayout = true;
|
|
26
|
+
this.rootGroup = rootGroup;
|
|
27
|
+
this.textElement = TSU.DOM.createSVGNode("text", {
|
|
28
|
+
parent: rootGroup,
|
|
29
|
+
attrs: {
|
|
30
|
+
class: "markerText",
|
|
31
|
+
pre: isPreMarker,
|
|
32
|
+
},
|
|
33
|
+
text: this.markers[0].text,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
refreshLayout() {
|
|
37
|
+
this.rootGroup.setAttribute("transform", "translate(" + this.x + "," + this.y + ")");
|
|
38
|
+
}
|
|
39
|
+
updateBounds(x, y, w, h) {
|
|
40
|
+
return [x, y, NaN, NaN];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
4
43
|
export class BeatView extends BeatViewBase {
|
|
5
44
|
createAtomView() {
|
|
6
45
|
return createAtomView(this.element, this.beat.atom, this.beat.role.defaultToNotes);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beatviews.js","sourceRoot":"","sources":["../../../src/carnatic/beatviews.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"beatviews.js","sourceRoot":"","sources":["../../../src/carnatic/beatviews.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAGvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/D,MAAM,OAAO,UAAW,SAAQ,YAAyB;IAIvD,YACkB,IAAc,EACd,IAAU,EACV,OAAiB,EACjB,WAAoB,EACpB,WAA+B,EAC/C,MAAY;QAEZ,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE;YAC3C,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE;gBACL,KAAK,EAAE,YAAY;gBACnB,GAAG,EAAE,WAAW;gBAChB,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;gBACxB,SAAS,EAAE,EAAE,GAAG,I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AAC,MAAM,GAAG,CAAC,EAAE;wBAE1C,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;wBACnD,aAAa,GAAG,CAAC,GAAG,CAAC,CAAC;qBACvB;yBAAM;wBAEL,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;wBAChD,aAAa,GAAG,CAAC,GAAG,CAAC,CAAC;qBACvB;iBACF;aACF;SACF;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Embelishment } from \"../shapes\";\nimport { GridCell, GridCellView } from \"../grids\";\nimport { ElementShape } from \"../shapes\";\nimport { createAtomView } from \"./atomviews\";\nimport { Marker } from \"../core\";\nimport { Beat } from \"../beats\";\nimport { BeatView as BeatViewBase } from \"../beatview\";\nimport { BeatStartLines, BeatEndLines } from \"./embelishments\";\n\nexport class MarkerView extends ElementShape<SVGGElement> implements GridCellView {\n needsLayout = true;\n rootGroup: SVGGElement;\n textElement: SVGTextElement;\n constructor(\n public readonly cell: GridCell,\n public readonly beat: Beat,\n public readonly markers: Marker[],\n public readonly isPreMarker: boolean,\n public readonly rootElement: SVGGraphicsElement,\n config?: any,\n ) {\n const rootGroup = TSU.DOM.createSVGNode(\"g\", {\n parent: rootElement,\n attrs: {\n class: \"markerView\",\n pre: isPreMarker,\n roleName: beat.role.name,\n beatIndex: \"\" + beat.index,\n gridRow: cell.rowIndex,\n gridCol: cell.colIndex,\n },\n });\n super(rootGroup);\n this.rootGroup = rootGroup as SVGGElement;\n this.textElement = TSU.DOM.createSVGNode(\"text\", {\n parent: rootGroup,\n attrs: {\n class: \"markerText\",\n pre: isPreMarker,\n },\n text: this.markers[0].text,\n });\n }\n\n refreshLayout(): void {\n // TODO - move this code out to refreshLayout?\n // set the glyphs Y first so we can layout others\n this.rootGroup.setAttribute(\"transform\", \"translate(\" + this.x + \",\" + this.y + \")\");\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, NaN, NaN];\n }\n}\n\nexport class BeatView extends BeatViewBase {\n createAtomView() {\n return createAtomView(this.element, this.beat.atom, this.beat.role.defaultToNotes);\n }\n\n refreshLayout(): void {\n const newX = this.hasX ? this._x : 0;\n const newY = this.hasY ? this._y : 0;\n this.element.setAttribute(\"transform\", \"translate(\" + newX + \",\" + newY + \")\");\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n protected createEmbelishments(): Embelishment[] {\n let embelishments: Embelishment[] = [];\n const beat = this.beat;\n // TODO - Should this be the group's parent element?\n const rootElement = this.rootElement;\n if (beat.beatIndex == 0 && beat.barIndex == 0 && beat.instance == 0) {\n // first beat in bar - Do a BarStart\n const emb = new BeatStartLines(this, rootElement);\n embelishments = [emb];\n } else {\n const cycle = this.cycle;\n const bar = cycle.bars[beat.barIndex];\n if (beat.beatIndex == bar.beatCount - 1) {\n // It is important that we are not just looking at the last beat of the bar\n // but also in the last \"instance\" of the beat in this bar to account for\n // kalais\n if (beat.instance == bar.instanceCount(beat.beatIndex) - 1) {\n if (beat.barIndex == cycle.bars.length - 1) {\n // last beat in last bar so - do a thalam end (2 lines)\n const emb = new BeatEndLines(this, rootElement, 2);\n embelishments = [emb];\n } else {\n // end of a bar so single line end\n const emb = new BeatEndLines(this, rootElement);\n embelishments = [emb];\n }\n }\n }\n }\n return embelishments;\n }\n}\n"]}
|
package/lib/esm/shapes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AASvC,MAAM,OAAgB,KAAK;IAA3B;QAEW,YAAO,GAAW,KAAK,CAAC,SAAS,EAAE,CAAC;QAQnC,OAAE,GAAkB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,WAAW,GAAG,GAAG,CAAC;SACjD;QACD,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAOvD,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,KAAK,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACnC,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAC7C,KAAK,IAAI,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,aAAa;YAAE,CAAC,CAAC,aAAa,EAAE,CAAC;QACtD,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;SAClD;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAES,mBAAmB;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,SAAS,CAAC,MAAW;QACnB,IAAI,aAAa,IAAI,MAAM;YAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACnE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Atom, LeafAtom, Group } from \"./core\";\n\n/**\n * Base class of all renderable objects for caching things like bounding boxes etc.\n * We do this since a lot of the property setters dont change bounding boxes but\n * bounding box reads are a bit slow in general. This also allows us to test\n * layouts, positioning etc without having to worry about implementation details.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n /**\n * Note that x and y coordinates are not always the x and y coordinates\n * of the bounding box.\n * Eg a circle's x and y coordinates are its center point and not the\n * top left corner.\n * These \"main\" coordinates are referred as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n children: Shape[] = [];\n\n get bbox(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox();\n }\n return this._bbox;\n }\n\n /**\n * Sizes can have a minimum size.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n }\n return this._minSize;\n }\n\n /**\n * refreshBBox is called by the Shape when it knows the bbox it is tracking\n * cannot be trusted and has to be refreshed by calling native methods.\n */\n protected abstract refreshBBox(): TSU.Geom.Rect;\n protected abstract refreshMinSize(): TSU.Geom.Size;\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n invalidateBounds(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n\n /**\n * Sets the x or y coordinate of this shape in coordinate system within its\n * parent.\n *\n * Note that null and NaN are valid values and mean the following:\n * null - Dont change the value. Passed to \"ignore\" effects.\n * NaN - Ensure the value is set to null so that the bounding box specific coord is used going forward.\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n get hasHeight(): boolean {\n return this._height != null && !isNaN(this._height);\n }\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n return this._x || 0;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * This is called when bounds or other properties of a shape have changed to\n * give the shape an opportunity to layout the children. For shapes\n * with no children this is a no-op. It is expected the Shape will keep track\n * of all changes so it can apply them all in in one go in this method - A\n * form of \"commit\"ing the layout transaction.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\nexport abstract class Embelishment extends Shape {}\n\nexport class ElementShape<T extends SVGGraphicsElement = SVGGraphicsElement> extends Shape {\n constructor(public readonly element: T) {\n super();\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n if (this.hasX) this.element.setAttribute(\"x\", \"\" + this._x);\n if (this.hasY) this.element.setAttribute(\"y\", \"\" + this._y);\n }\n}\n\nexport abstract class AtomView extends Shape {\n depth = 0;\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n baseline: number;\n ascent: number;\n descent: number;\n capHeight: number;\n leading: number;\n\n abstract isLeaf(): boolean;\n\n /**\n * Creates views needed for this AtomView.\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n}\n\nexport abstract class LeafAtomView extends AtomView {\n constructor(public leafAtom: LeafAtom) {\n super();\n }\n\n isLeaf(): boolean {\n return true;\n }\n\n get viewId(): number {\n return this.leafAtom.uuid;\n }\n\n /*\n embRoot(): SVGGraphicsElement {\n let rootElem = this.glyph.element.parentElement as any as SVGGraphicsElement;\n while (rootElem && (rootElem.tagName == \"tspan\" || rootElem.tagName == \"text\")) {\n rootElem = rootElem.parentElement as any as SVGGraphicsElement;\n }\n return rootElem;\n }\n */\n}\n\n/**\n * An GroupView that contains a collection of AtomViews.\n */\nexport abstract class GroupView extends AtomView {\n protected atomSpacing: number;\n protected groupElement: SVGGElement;\n protected atomViews: AtomView[] = [];\n private _embelishments: Embelishment[];\n defaultToNotes = true;\n needsLayout = true;\n scaleFactor = 1.0;\n constructor(public group: Group, config?: any) {\n super();\n this.atomSpacing = 5;\n this.setStyles(config || {});\n }\n\n /**\n * Creates views needed for this AtomView.\n */\n createElements(parent: SVGGraphicsElement): void {\n this.groupElement = TSU.DOM.createSVGNode(\"g\", {\n parent: parent,\n attrs: {\n class: \"groupViewRoot\",\n id: \"groupViewRoot\" + this.group.uuid,\n },\n });\n\n // now create child atom views for each atom in this Group\n for (const atom of this.group.atoms.values()) {\n const atomView = this.createAtomView(atom);\n this.atomViews.push(atomView);\n }\n this.invalidateBounds();\n }\n\n isLeaf(): boolean {\n return false;\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.groupElement);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n let totalWidth = 0;\n let maxHeight = 0;\n this.atomViews.forEach((av, index) => {\n const ms = av.minSize;\n totalWidth += ms.width + this.atomSpacing;\n maxHeight = Math.max(maxHeight, ms.height);\n });\n return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);\n }\n\n abstract createAtomView(atom: Atom): AtomView;\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n let transform = \"translate(\" + this.x + \",\" + this.y + \")\";\n if (this.scaleFactor < 1) {\n transform += \" scale(\" + this.scaleFactor + \")\";\n }\n this.groupElement.setAttribute(\"transform\", transform);\n // if (this.widthChanged) {\n // All our atoms have to be laid out between startX and endX\n // old way of doing where we just set dx between atom views\n // this worked when atomviews were single glyphs. But\n // as atomViews can be complex (eg with accents and pre/post\n // spaces etc) explicitly setting x/y may be important\n let currX = 0;\n const currY = 0; // null; // this.y; // + 10;\n this.atomViews.forEach((av, index) => {\n av.setBounds(currX, currY, null, null, true);\n currX += this.atomSpacing + av.minSize.width;\n });\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n protected createEmbelishments(): Embelishment[] {\n return [];\n }\n\n setStyles(config: any): void {\n if (\"atomSpacing\" in config) this.atomSpacing = config.atomSpacing;\n this.needsLayout = true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AASvC,MAAM,OAAgB,KAAK;IAA3B;QAEW,YAAO,GAAW,KAAK,CAAC,SAAS,EAAE,CAAC;QAQnC,OAAE,GAAkB,IAAI,CAAC;QACzB,OAAE,GAAkB,IAAI,CAAC;QACzB,WAAM,GAAkB,IAAI,CAAC;QAC7B,YAAO,GAAkB,IAAI,CAAC;QAG9B,gBAAW,GAAiB,IAAI,CAAC;QAC3C,aAAQ,GAAY,EAAE,CAAC;IA+LzB,CAAC;IA7LC,IAAI,IAAI;QACN,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;SACjC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAMD,IAAI,OAAO;QACT,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;SACvC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAeD,gBAAgB;QACd,IAAI,CAAC,QAAQ,GAAG,IAAgC,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,IAAgC,CAAC;IAChD,CAAC;IAUD,SAAS,CACP,CAAgB,EAChB,CAAgB,EAChB,CAAgB,EAChB,CAAgB,EAChB,WAAW,GAAG,KAAK;QAEn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AC;SAClD;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAES,mBAAmB;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,SAAS,CAAC,MAAW;QACnB,IAAI,aAAa,IAAI,MAAM;YAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACnE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Atom, LeafAtom, Group } from \"./core\";\n\n/**\n * Base class of all renderable objects for caching things like bounding boxes etc.\n * We do this since a lot of the property setters dont change bounding boxes but\n * bounding box reads are a bit slow in general. This also allows us to test\n * layouts, positioning etc without having to worry about implementation details.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n /**\n * Note that x and y coordinates are not always the x and y coordinates\n * of the bounding box.\n * Eg a circle's x and y coordinates are its center point and not the\n * top left corner.\n * These \"main\" coordinates are referred as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n children: Shape[] = [];\n\n get bbox(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox();\n }\n return this._bbox;\n }\n\n /**\n * Sizes can have a minimum size.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n }\n return this._minSize;\n }\n\n /**\n * refreshBBox is called by the Shape when it knows the bbox it is tracking\n * cannot be trusted and has to be refreshed by calling native methods.\n */\n protected abstract refreshBBox(): TSU.Geom.Rect;\n protected abstract refreshMinSize(): TSU.Geom.Size;\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n invalidateBounds(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n\n /**\n * Sets the x or y coordinate of this shape in coordinate system within its\n * parent.\n *\n * Note that null and NaN are valid values and mean the following:\n * null - Dont change the value. Passed to \"ignore\" effects.\n * NaN - Ensure the value is set to null so that the bounding box specific coord is used going forward.\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n get hasHeight(): boolean {\n return this._height != null && !isNaN(this._height);\n }\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n return this._x || 0;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * This is called when bounds or other properties of a shape have changed to\n * give the shape an opportunity to layout the children. For shapes\n * with no children this is a no-op. It is expected the Shape will keep track\n * of all changes so it can apply them all in in one go in this method - A\n * form of \"commit\"ing the layout transaction.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\nexport abstract class Embelishment extends Shape {}\n\nexport class ElementShape<T extends SVGGraphicsElement = SVGGraphicsElement> extends Shape {\n constructor(public readonly element: T) {\n super();\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n if (this.hasX) this.element.setAttribute(\"x\", \"\" + this._x);\n if (this.hasY) this.element.setAttribute(\"y\", \"\" + this._y);\n }\n}\n\nexport abstract class AtomView extends Shape {\n depth = 0;\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n baseline: number;\n ascent: number;\n descent: number;\n capHeight: number;\n leading: number;\n\n abstract isLeaf(): boolean;\n\n /**\n * Creates views needed for this AtomView.\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n}\n\nexport abstract class LeafAtomView extends AtomView {\n constructor(public leafAtom: LeafAtom) {\n super();\n }\n\n isLeaf(): boolean {\n return true;\n }\n\n get viewId(): number {\n return this.leafAtom.uuid;\n }\n}\n\n/**\n * An GroupView that contains a collection of AtomViews.\n */\nexport abstract class GroupView extends AtomView {\n protected atomSpacing: number;\n protected groupElement: SVGGElement;\n protected atomViews: AtomView[] = [];\n private _embelishments: Embelishment[];\n defaultToNotes = true;\n needsLayout = true;\n scaleFactor = 1.0;\n constructor(public group: Group, config?: any) {\n super();\n this.atomSpacing = 5;\n this.setStyles(config || {});\n }\n\n /**\n * Creates views needed for this AtomView.\n */\n createElements(parent: SVGGraphicsElement): void {\n this.groupElement = TSU.DOM.createSVGNode(\"g\", {\n parent: parent,\n attrs: {\n class: \"groupViewRoot\",\n id: \"groupViewRoot\" + this.group.uuid,\n },\n });\n\n // now create child atom views for each atom in this Group\n for (const atom of this.group.atoms.values()) {\n const atomView = this.createAtomView(atom);\n this.atomViews.push(atomView);\n }\n this.invalidateBounds();\n }\n\n isLeaf(): boolean {\n return false;\n }\n\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.groupElement);\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n let totalWidth = 0;\n let maxHeight = 0;\n this.atomViews.forEach((av, index) => {\n const ms = av.minSize;\n totalWidth += ms.width + this.atomSpacing;\n maxHeight = Math.max(maxHeight, ms.height);\n });\n return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);\n }\n\n abstract createAtomView(atom: Atom): AtomView;\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n let transform = \"translate(\" + this.x + \",\" + this.y + \")\";\n if (this.scaleFactor < 1) {\n transform += \" scale(\" + this.scaleFactor + \")\";\n }\n this.groupElement.setAttribute(\"transform\", transform);\n // if (this.widthChanged) {\n // All our atoms have to be laid out between startX and endX\n // old way of doing where we just set dx between atom views\n // this worked when atomviews were single glyphs. But\n // as atomViews can be complex (eg with accents and pre/post\n // spaces etc) explicitly setting x/y may be important\n let currX = 0;\n const currY = 0; // null; // this.y; // + 10;\n this.atomViews.forEach((av, index) => {\n av.setBounds(currX, currY, null, null, true);\n currX += this.atomSpacing + av.minSize.width;\n });\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n protected createEmbelishments(): Embelishment[] {\n return [];\n }\n\n setStyles(config: any): void {\n if (\"atomSpacing\" in config) this.atomSpacing = config.atomSpacing;\n this.needsLayout = true;\n }\n}\n"]}
|
package/package.json
CHANGED