notations 0.0.69 → 1.0.0

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.
Files changed (68) hide show
  1. package/dist/NotationView.css +20 -0
  2. package/dist/NotationView.css.map +1 -1
  3. package/dist/NotationView.min.css +1 -1
  4. package/dist/NotationView.min.css.map +1 -1
  5. package/dist/notations.umd.js +17425 -23624
  6. package/dist/notations.umd.min.js +8 -3
  7. package/dist/notations.umd.min.js.LICENSE.txt +0 -14
  8. package/dist/notations.umd.min.js.map +1 -1
  9. package/lib/cjs/beats.d.ts +4 -0
  10. package/lib/cjs/beats.js +19 -2
  11. package/lib/cjs/beats.js.map +1 -1
  12. package/lib/cjs/block.d.ts +85 -0
  13. package/lib/cjs/block.js +310 -0
  14. package/lib/cjs/block.js.map +1 -0
  15. package/lib/cjs/carnatic/NotationView.d.ts +11 -4
  16. package/lib/cjs/carnatic/NotationView.js +25 -11
  17. package/lib/cjs/carnatic/NotationView.js.map +1 -1
  18. package/lib/cjs/commands.d.ts +25 -11
  19. package/lib/cjs/commands.js +83 -31
  20. package/lib/cjs/commands.js.map +1 -1
  21. package/lib/cjs/entity.d.ts +3 -7
  22. package/lib/cjs/entity.js +7 -37
  23. package/lib/cjs/entity.js.map +1 -1
  24. package/lib/cjs/grids.d.ts +32 -3
  25. package/lib/cjs/grids.js +96 -9
  26. package/lib/cjs/grids.js.map +1 -1
  27. package/lib/cjs/index.d.ts +1 -0
  28. package/lib/cjs/index.js +1 -0
  29. package/lib/cjs/index.js.map +1 -1
  30. package/lib/cjs/loader.js +1 -41
  31. package/lib/cjs/loader.js.map +1 -1
  32. package/lib/cjs/notation.d.ts +20 -36
  33. package/lib/cjs/notation.js +100 -133
  34. package/lib/cjs/notation.js.map +1 -1
  35. package/lib/cjs/parser.d.ts +21 -6
  36. package/lib/cjs/parser.js +122 -23
  37. package/lib/cjs/parser.js.map +1 -1
  38. package/lib/esm/beats.d.ts +4 -0
  39. package/lib/esm/beats.js +19 -2
  40. package/lib/esm/beats.js.map +1 -1
  41. package/lib/esm/block.d.ts +85 -0
  42. package/lib/esm/block.js +293 -0
  43. package/lib/esm/block.js.map +1 -0
  44. package/lib/esm/carnatic/NotationView.d.ts +11 -4
  45. package/lib/esm/carnatic/NotationView.js +25 -11
  46. package/lib/esm/carnatic/NotationView.js.map +1 -1
  47. package/lib/esm/commands.d.ts +25 -11
  48. package/lib/esm/commands.js +80 -31
  49. package/lib/esm/commands.js.map +1 -1
  50. package/lib/esm/entity.d.ts +3 -7
  51. package/lib/esm/entity.js +7 -37
  52. package/lib/esm/entity.js.map +1 -1
  53. package/lib/esm/grids.d.ts +32 -3
  54. package/lib/esm/grids.js +96 -9
  55. package/lib/esm/grids.js.map +1 -1
  56. package/lib/esm/index.d.ts +1 -0
  57. package/lib/esm/index.js +1 -0
  58. package/lib/esm/index.js.map +1 -1
  59. package/lib/esm/loader.js +1 -8
  60. package/lib/esm/loader.js.map +1 -1
  61. package/lib/esm/notation.d.ts +20 -36
  62. package/lib/esm/notation.js +84 -128
  63. package/lib/esm/notation.js.map +1 -1
  64. package/lib/esm/parser.d.ts +21 -6
  65. package/lib/esm/parser.js +122 -24
  66. package/lib/esm/parser.js.map +1 -1
  67. package/package.json +3 -2
  68. package/styles/NotationView.scss +22 -0
@@ -4,6 +4,7 @@ import { CycleIterator } from "./cycle";
4
4
  import { WindowIterator } from "./iterators";
5
5
  import { LayoutParams } from "./layouts";
6
6
  import { GridModel, GridCell, ColAlign, GridLayoutGroup } from "./grids";
7
+ import { Block, BlockItem } from "./notation";
7
8
  type Fraction = TSU.Num.Fraction;
8
9
  export declare class Beat {
9
10
  readonly index: number;
@@ -67,9 +68,12 @@ export declare class GlobalBeatLayout {
67
68
  roleBeatsForLine: Map<number, Beat[][]>;
68
69
  beatColDAGsByLP: Map<number, BeatColDAG>;
69
70
  readonly gridLayoutGroup: GridLayoutGroup;
71
+ constructor(sharedGridLayoutGroup?: GridLayoutGroup);
70
72
  getGridModelForLine(lineid: LineId): GridModel;
71
73
  protected beatColDAGForLP(lpid: LPID): BeatColDAG;
72
74
  addLine(line: Line): void;
75
+ processBlock(block: Block): void;
76
+ protected processBlockItem(item: BlockItem): void;
73
77
  protected lineToRoleBeats(line: Line, gridModel: GridModel): Beat[][];
74
78
  protected addBeat(beat: Beat, gridModel: GridModel): GridCell;
75
79
  }
package/lib/cjs/beats.js CHANGED
@@ -38,6 +38,7 @@ const TSU = __importStar(require("@panyam/tsutils"));
38
38
  const _1 = require("./");
39
39
  const iterators_1 = require("./iterators");
40
40
  const grids_1 = require("./grids");
41
+ const notation_1 = require("./notation");
41
42
  const ZERO = TSU.Num.Fraction.ZERO;
42
43
  const ONE = TSU.Num.Fraction.ONE;
43
44
  class Beat {
@@ -239,11 +240,11 @@ class BeatColDAG {
239
240
  }
240
241
  exports.BeatColDAG = BeatColDAG;
241
242
  class GlobalBeatLayout {
242
- constructor() {
243
+ constructor(sharedGridLayoutGroup) {
243
244
  this.gridModelsForLine = new Map();
244
245
  this.roleBeatsForLine = new Map();
245
246
  this.beatColDAGsByLP = new Map();
246
- this.gridLayoutGroup = new grids_1.GridLayoutGroup();
247
+ this.gridLayoutGroup = sharedGridLayoutGroup !== null && sharedGridLayoutGroup !== void 0 ? sharedGridLayoutGroup : new grids_1.GridLayoutGroup();
247
248
  }
248
249
  getGridModelForLine(lineid) {
249
250
  let out = this.gridModelsForLine.get(lineid) || null;
@@ -269,6 +270,22 @@ class GlobalBeatLayout {
269
270
  this.lineToRoleBeats(line, gridModel);
270
271
  (_b = gridModel.eventHub) === null || _b === void 0 ? void 0 : _b.commitBatch();
271
272
  }
273
+ processBlock(block) {
274
+ for (const child of block.children()) {
275
+ this.processBlockItem(child);
276
+ }
277
+ }
278
+ processBlockItem(item) {
279
+ if ((0, notation_1.isLine)(item)) {
280
+ const line = item;
281
+ if (!line.isEmpty && line.layoutParams != null) {
282
+ this.addLine(line);
283
+ }
284
+ }
285
+ else if ((0, notation_1.isBlock)(item)) {
286
+ this.processBlock(item);
287
+ }
288
+ }
272
289
  lineToRoleBeats(line, gridModel) {
273
290
  const lp = line.layoutParams;
274
291
  const roleBeats = [];
@@ -1 +1 @@
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;AAMjC,MAAa,IAAI;IAqBf,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;QA5BrB,SAAI,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAKvB,sBAAiB,GAAG,KAAK,CAAC;IAwBjC,CAAC;IAMJ,UAAU;QACR,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;YACpB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YAC9B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;YAClC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS,EA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BAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvID,4CAuIC","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\n/**\n * Represents a single beat in the notation.\n * A beat contains one or more atoms and has a specific position in a bar.\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 later?\n\n /** The atom contained in this beat */\n atom: Atom;\n protected atomIsPlaceholder = false;\n\n /**\n * Creates a new Beat.\n * @param index The index of this beat in the sequence\n * @param role The role this beat belongs to\n * @param offset The time offset of this beat from the start\n * @param duration The duration of this beat\n * @param barIndex The index of the bar containing this beat\n * @param beatIndex The index of this beat within its bar\n * @param instance The instance number of this beat\n * @param prevBeat The previous beat in the sequence, if any\n * @param nextBeat The next beat in the sequence, if any\n */\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 /**\n * Returns a debug-friendly representation of this Beat.\n * @returns An object containing debug information\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 /**\n * Gets the end offset of this beat (offset + duration).\n */\n get endOffset(): Fraction {\n return this.offset.plus(this.duration);\n }\n\n /**\n * Checks if this beat is filled completely (no remaining space).\n */\n get filled(): boolean {\n return this.remaining.isZero;\n }\n\n /**\n * Gets the remaining duration available in this beat.\n */\n get remaining(): Fraction {\n return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;\n }\n\n /**\n * Adds an atom to this beat.\n * @param atom The atom to add\n * @returns True if the atom was added successfully, false if there's not enough space\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 /**\n * Gets all markers that should be displayed before this beat.\n * @returns An array of Marker objects\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 /**\n * Gets all markers that should be displayed after this beat.\n * @returns An array of Marker objects\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\n/**\n * Builds a sequence of beats from atoms according to layout parameters.\n * Used to convert a flat sequence of atoms into structured beats for display.\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\n /** Callback for when a beat has been filled */\n onBeatFilled: (beat: Beat) => void;\n\n /**\n * Creates a new BeatsBuilder.\n * @param role The role containing the atoms\n * @param layoutParams Layout parameters for structuring beats\n * @param startOffset The starting offset for the first beat, defaults to ZERO\n * @param atoms Initial atoms to add to the beats\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 /**\n * Adds atoms to be processed into beats.\n * @param atoms The atoms to add\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 /**\n * Adds a new beat to the sequence.\n * @returns The newly created beat\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\n/**\n * Represents a column of beats in a layout grid.\n * Used for aligning beats vertically in the notation.\n */\nexport class BeatColumn extends ColAlign {\n /** Spacing between atoms in this column */\n atomSpacing = 5;\n /** Unique key for this column */\n readonly key: string;\n\n /**\n * Creates a new BeatColumn.\n * @param offset The starting offset of this column\n * @param endOffset The ending offset of this column\n * @param markerType The type of marker for this column (negative: before, positive: after, zero: normal)\n */\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 /**\n * Generates a key for identifying columns with the same offsets and marker type.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker (negative: before, positive: after, zero: normal)\n * @returns A string key\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 * Manages the organization of beats into columns based on their offsets.\n * Used to create a directed acyclic graph (DAG) of beat columns for layout purposes.\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 /** Map of column keys to BeatColumn objects */\n beatColumns = new Map<string, BeatColumn>();\n\n /**\n * Creates a new BeatColDAG.\n * @param layoutGroup The layout group to associate with this DAG\n */\n constructor(public readonly layoutGroup: GridLayoutGroup) {\n //\n }\n\n /**\n * Gets the beat column for a given duration at the specified offset.\n * Creates a new column if none exists.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker\n * @returns The BeatColumn for the specified parameters\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 /**\n * Ensures a beat column exists for the given parameters.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker\n * @returns A tuple containing the column and whether it was newly created\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/** Type alias for line IDs */\ntype LineId = number;\n/** Type alias for layout parameter IDs */\ntype LPID = number;\n\n/**\n * Manages the beat layouts for all lines in a notation.\n * Handles the creation of grid models, positioning of beats, and alignment of beats across lines.\n */\nexport class GlobalBeatLayout {\n /** Map of line IDs to grid models */\n gridModelsForLine = new Map<LineId, GridModel>();\n /** Map of line IDs to arrays of beats for each role */\n roleBeatsForLine = new Map<LineId, Beat[][]>();\n /** Map of layout parameter IDs to beat column DAGs */\n beatColDAGsByLP = new Map<LPID, BeatColDAG>();\n /** The global layout group for all grid models */\n readonly gridLayoutGroup = new GridLayoutGroup();\n\n /**\n * Gets the GridModel associated with a particular line, creating one if it doesn't exist.\n * @param lineid The ID of the line\n * @returns The GridModel for the 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 /**\n * Gets the BeatColDAG for a specific layout parameter ID, creating one if it doesn't exist.\n * @param lpid The layout parameter ID\n * @returns The BeatColDAG for the layout parameters\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 * Adds a line to the beat layout.\n * This ensures that a line is broken down into beats and added into a dedicated GridModel.\n *\n * A line must also be given the layout params by which the beat breakdown will happen.\n * This LayoutParams object does not have to be unique per line (this non-constraint allows\n * beats to be aligned across lines).\n *\n * @param line The line to add\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 /**\n * Converts a line into a series of beats for each role.\n * @param line The line to convert\n * @param gridModel The grid model to use\n * @returns Arrays of beats for each role\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 a beat to the layout.\n * @param beat The beat to add\n * @param gridModel The grid model to add the beat to\n * @returns The grid cell containing the beat\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 nthLine = Math.floor(beat.index / lp.totalBeats);\n const realLine = lp.lineBreaks.length * nthLine + layoutLine;\n const realRow = line.roles.length * realLine + 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"]}
1
+ {"version":3,"file":"beats.js","sourceRoot":"","sources":["../../src/beats.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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,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,gBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;gBACxC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;gBACxB,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC,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;AA7KD,4CA6KC","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\";\nimport { Block, BlockItem, isLine, isBlock } from \"./notation\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\n/**\n * Represents a single beat in the notation.\n * A beat contains one or more atoms and has a specific position in a bar.\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 later?\n\n /** The atom contained in this beat */\n atom: Atom;\n protected atomIsPlaceholder = false;\n\n /**\n * Creates a new Beat.\n * @param index The index of this beat in the sequence\n * @param role The role this beat belongs to\n * @param offset The time offset of this beat from the start\n * @param duration The duration of this beat\n * @param barIndex The index of the bar containing this beat\n * @param beatIndex The index of this beat within its bar\n * @param instance The instance number of this beat\n * @param prevBeat The previous beat in the sequence, if any\n * @param nextBeat The next beat in the sequence, if any\n */\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 /**\n * Returns a debug-friendly representation of this Beat.\n * @returns An object containing debug information\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 /**\n * Gets the end offset of this beat (offset + duration).\n */\n get endOffset(): Fraction {\n return this.offset.plus(this.duration);\n }\n\n /**\n * Checks if this beat is filled completely (no remaining space).\n */\n get filled(): boolean {\n return this.remaining.isZero;\n }\n\n /**\n * Gets the remaining duration available in this beat.\n */\n get remaining(): Fraction {\n return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;\n }\n\n /**\n * Adds an atom to this beat.\n * @param atom The atom to add\n * @returns True if the atom was added successfully, false if there's not enough space\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 /**\n * Gets all markers that should be displayed before this beat.\n * @returns An array of Marker objects\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 /**\n * Gets all markers that should be displayed after this beat.\n * @returns An array of Marker objects\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\n/**\n * Builds a sequence of beats from atoms according to layout parameters.\n * Used to convert a flat sequence of atoms into structured beats for display.\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\n /** Callback for when a beat has been filled */\n onBeatFilled: (beat: Beat) => void;\n\n /**\n * Creates a new BeatsBuilder.\n * @param role The role containing the atoms\n * @param layoutParams Layout parameters for structuring beats\n * @param startOffset The starting offset for the first beat, defaults to ZERO\n * @param atoms Initial atoms to add to the beats\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 /**\n * Adds atoms to be processed into beats.\n * @param atoms The atoms to add\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 /**\n * Adds a new beat to the sequence.\n * @returns The newly created beat\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\n/**\n * Represents a column of beats in a layout grid.\n * Used for aligning beats vertically in the notation.\n */\nexport class BeatColumn extends ColAlign {\n /** Spacing between atoms in this column */\n atomSpacing = 5;\n /** Unique key for this column */\n readonly key: string;\n\n /**\n * Creates a new BeatColumn.\n * @param offset The starting offset of this column\n * @param endOffset The ending offset of this column\n * @param markerType The type of marker for this column (negative: before, positive: after, zero: normal)\n */\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 /**\n * Generates a key for identifying columns with the same offsets and marker type.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker (negative: before, positive: after, zero: normal)\n * @returns A string key\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 * Manages the organization of beats into columns based on their offsets.\n * Used to create a directed acyclic graph (DAG) of beat columns for layout purposes.\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 /** Map of column keys to BeatColumn objects */\n beatColumns = new Map<string, BeatColumn>();\n\n /**\n * Creates a new BeatColDAG.\n * @param layoutGroup The layout group to associate with this DAG\n */\n constructor(public readonly layoutGroup: GridLayoutGroup) {\n //\n }\n\n /**\n * Gets the beat column for a given duration at the specified offset.\n * Creates a new column if none exists.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker\n * @returns The BeatColumn for the specified parameters\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 /**\n * Ensures a beat column exists for the given parameters.\n * @param offset The starting offset\n * @param endOffset The ending offset\n * @param markerType The type of marker\n * @returns A tuple containing the column and whether it was newly created\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/** Type alias for line IDs */\ntype LineId = number;\n/** Type alias for layout parameter IDs */\ntype LPID = number;\n\n/**\n * Manages the beat layouts for all lines in a notation.\n * Handles the creation of grid models, positioning of beats, and alignment of beats across lines.\n */\nexport class GlobalBeatLayout {\n /** Map of line IDs to grid models */\n gridModelsForLine = new Map<LineId, GridModel>();\n /** Map of line IDs to arrays of beats for each role */\n roleBeatsForLine = new Map<LineId, Beat[][]>();\n /** Map of layout parameter IDs to beat column DAGs */\n beatColDAGsByLP = new Map<LPID, BeatColDAG>();\n /** The global layout group for all grid models */\n readonly gridLayoutGroup: GridLayoutGroup;\n\n /**\n * Creates a new GlobalBeatLayout.\n * @param sharedGridLayoutGroup Optional shared GridLayoutGroup for column alignment across multiple views.\n * If not provided, a new GridLayoutGroup is created internally.\n */\n constructor(sharedGridLayoutGroup?: GridLayoutGroup) {\n this.gridLayoutGroup = sharedGridLayoutGroup ?? new GridLayoutGroup();\n }\n\n /**\n * Gets the GridModel associated with a particular line, creating one if it doesn't exist.\n * @param lineid The ID of the line\n * @returns The GridModel for the 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 /**\n * Gets the BeatColDAG for a specific layout parameter ID, creating one if it doesn't exist.\n * @param lpid The layout parameter ID\n * @returns The BeatColDAG for the layout parameters\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 * Adds a line to the beat layout.\n * This ensures that a line is broken down into beats and added into a dedicated GridModel.\n *\n * A line must also be given the layout params by which the beat breakdown will happen.\n * This LayoutParams object does not have to be unique per line (this non-constraint allows\n * beats to be aligned across lines).\n *\n * @param line The line to add\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 /**\n * Recursively processes a block and its children to build beat layouts.\n * Uses block.children() to get expanded children (e.g., RepeatBlock expands to N copies).\n *\n * @param block The block to process\n */\n processBlock(block: Block): void {\n for (const child of block.children()) {\n this.processBlockItem(child);\n }\n }\n\n /**\n * Processes a single block item (Block, Line, or RawBlock).\n *\n * @param item The item to process\n */\n protected processBlockItem(item: BlockItem): void {\n if (isLine(item)) {\n const line = item as Line;\n if (!line.isEmpty && line.layoutParams != null) {\n this.addLine(line);\n }\n } else if (isBlock(item)) {\n this.processBlock(item as Block);\n }\n // RawBlocks are ignored (no beat layout for raw content)\n }\n\n /**\n * Converts a line into a series of beats for each role.\n * @param line The line to convert\n * @param gridModel The grid model to use\n * @returns Arrays of beats for each role\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 a beat to the layout.\n * @param beat The beat to add\n * @param gridModel The grid model to add the beat to\n * @returns The grid cell containing the beat\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 nthLine = Math.floor(beat.index / lp.totalBeats);\n const realLine = lp.lineBreaks.length * nthLine + layoutLine;\n const realRow = line.roles.length * realLine + 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"]}
@@ -0,0 +1,85 @@
1
+ import * as TSU from "@panyam/tsutils";
2
+ import { Entity } from "./entity";
3
+ import { Cycle } from "./cycle";
4
+ import { Line } from "./core";
5
+ import { LayoutParams } from "./layouts";
6
+ export declare class RoleDef {
7
+ name: string;
8
+ notesOnly: boolean;
9
+ index: number;
10
+ }
11
+ export declare class RawBlock extends Entity {
12
+ content: string;
13
+ contentType: string;
14
+ readonly TYPE: string;
15
+ constructor(content: string, contentType?: string);
16
+ debugValue(): any;
17
+ }
18
+ export type BlockItem = Block | Line | RawBlock;
19
+ export declare function isBlock(item: BlockItem): item is Block;
20
+ export declare function isLine(item: BlockItem): item is Line;
21
+ export declare function isRawBlock(item: BlockItem): item is RawBlock;
22
+ export declare class Block extends Entity {
23
+ readonly TYPE: string;
24
+ readonly blockType: string;
25
+ readonly name: TSU.Nullable<string>;
26
+ readonly blockItems: BlockItem[];
27
+ localCycle: TSU.Nullable<Cycle>;
28
+ localAtomsPerBeat: TSU.Nullable<number>;
29
+ localBreaks: TSU.Nullable<number[]>;
30
+ readonly localRoles: Map<string, RoleDef>;
31
+ private _parentBlock;
32
+ protected _currRoleDef: TSU.Nullable<RoleDef>;
33
+ protected _currentLine: TSU.Nullable<Line>;
34
+ constructor(blockType: string, parent?: TSU.Nullable<Block>, name?: TSU.Nullable<string>);
35
+ children(): BlockItem[];
36
+ get parentBlock(): TSU.Nullable<Block>;
37
+ get cycle(): TSU.Nullable<Cycle>;
38
+ get atomsPerBeat(): number;
39
+ get breaks(): number[];
40
+ private _unnamedLayoutParams;
41
+ private _namedLayoutParams;
42
+ private _layoutParams;
43
+ get unnamedLayoutParams(): ReadonlyArray<LayoutParams>;
44
+ get namedLayoutParams(): ReadonlyMap<string, LayoutParams>;
45
+ get layoutParams(): LayoutParams;
46
+ resetLayoutParams(): void;
47
+ protected snapshotLayoutParams(): LayoutParams;
48
+ protected findUnnamedLayoutParams(): LayoutParams | null;
49
+ ensureNamedLayoutParams(name: string): LayoutParams;
50
+ getRole(name: string): TSU.Nullable<RoleDef>;
51
+ get currRoleDef(): TSU.Nullable<RoleDef>;
52
+ setCurrRole(name: string): void;
53
+ get currentLine(): Line;
54
+ newLine(): Line;
55
+ resetLine(): void;
56
+ newRoleDef(name: string, notesOnly?: boolean): RoleDef;
57
+ addBlockItem(item: BlockItem): void;
58
+ removeBlockItem(item: BlockItem): number;
59
+ debugValue(): any;
60
+ }
61
+ export declare function findContainingBlock(entity: Entity): TSU.Nullable<Block>;
62
+ export declare class SectionBlock extends Block {
63
+ constructor(sectionName: string, parent?: TSU.Nullable<Block>);
64
+ children(): BlockItem[];
65
+ }
66
+ export declare class RepeatBlock extends Block {
67
+ readonly repeatCount: number;
68
+ constructor(repeatCount: number, parent?: TSU.Nullable<Block>);
69
+ children(): BlockItem[];
70
+ }
71
+ export declare class CycleBlock extends Block {
72
+ constructor(cycle: Cycle, parent?: TSU.Nullable<Block>);
73
+ }
74
+ export declare class BeatDurationBlock extends Block {
75
+ constructor(atomsPerBeat: number, parent?: TSU.Nullable<Block>);
76
+ }
77
+ export declare class BreaksBlock extends Block {
78
+ constructor(breaks: number[], parent?: TSU.Nullable<Block>);
79
+ }
80
+ export declare class RoleBlock extends Block {
81
+ constructor(roleName: string, notesOnly: boolean, parent?: TSU.Nullable<Block>);
82
+ }
83
+ export declare class GroupBlock extends Block {
84
+ constructor(groupName: string | null, parent?: TSU.Nullable<Block>);
85
+ }
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GroupBlock = exports.RoleBlock = exports.BreaksBlock = exports.BeatDurationBlock = exports.CycleBlock = exports.RepeatBlock = exports.SectionBlock = exports.Block = exports.RawBlock = exports.RoleDef = void 0;
4
+ exports.isBlock = isBlock;
5
+ exports.isLine = isLine;
6
+ exports.isRawBlock = isRawBlock;
7
+ exports.findContainingBlock = findContainingBlock;
8
+ const entity_1 = require("./entity");
9
+ const core_1 = require("./core");
10
+ const layouts_1 = require("./layouts");
11
+ class RoleDef {
12
+ constructor() {
13
+ this.name = "";
14
+ this.notesOnly = false;
15
+ this.index = 0;
16
+ }
17
+ }
18
+ exports.RoleDef = RoleDef;
19
+ class RawBlock extends entity_1.Entity {
20
+ constructor(content, contentType = "md") {
21
+ super();
22
+ this.content = content;
23
+ this.contentType = contentType;
24
+ this.TYPE = "RawBlock";
25
+ }
26
+ debugValue() {
27
+ return Object.assign(Object.assign({}, super.debugValue()), { content: this.content, contentType: this.contentType });
28
+ }
29
+ }
30
+ exports.RawBlock = RawBlock;
31
+ function isBlock(item) {
32
+ return item.TYPE === "Block";
33
+ }
34
+ function isLine(item) {
35
+ return item.TYPE === "Line";
36
+ }
37
+ function isRawBlock(item) {
38
+ return item.TYPE === "RawBlock";
39
+ }
40
+ class Block extends entity_1.Entity {
41
+ constructor(blockType, parent = null, name = null) {
42
+ super();
43
+ this.TYPE = "Block";
44
+ this.blockItems = [];
45
+ this.localCycle = null;
46
+ this.localAtomsPerBeat = null;
47
+ this.localBreaks = null;
48
+ this.localRoles = new Map();
49
+ this._parentBlock = null;
50
+ this._currRoleDef = null;
51
+ this._currentLine = null;
52
+ this._unnamedLayoutParams = [];
53
+ this._namedLayoutParams = new Map();
54
+ this._layoutParams = null;
55
+ this.blockType = blockType;
56
+ this.name = name;
57
+ this._parentBlock = parent;
58
+ if (parent) {
59
+ this.setParent(parent);
60
+ }
61
+ }
62
+ children() {
63
+ return this.blockItems;
64
+ }
65
+ get parentBlock() {
66
+ return this._parentBlock;
67
+ }
68
+ get cycle() {
69
+ var _a, _b;
70
+ if (this.localCycle !== null) {
71
+ return this.localCycle;
72
+ }
73
+ return (_b = (_a = this.parentBlock) === null || _a === void 0 ? void 0 : _a.cycle) !== null && _b !== void 0 ? _b : null;
74
+ }
75
+ get atomsPerBeat() {
76
+ var _a, _b;
77
+ if (this.localAtomsPerBeat !== null) {
78
+ return this.localAtomsPerBeat;
79
+ }
80
+ return (_b = (_a = this.parentBlock) === null || _a === void 0 ? void 0 : _a.atomsPerBeat) !== null && _b !== void 0 ? _b : 1;
81
+ }
82
+ get breaks() {
83
+ var _a, _b;
84
+ if (this.localBreaks !== null) {
85
+ return this.localBreaks;
86
+ }
87
+ return (_b = (_a = this.parentBlock) === null || _a === void 0 ? void 0 : _a.breaks) !== null && _b !== void 0 ? _b : [];
88
+ }
89
+ get unnamedLayoutParams() {
90
+ return this._unnamedLayoutParams;
91
+ }
92
+ get namedLayoutParams() {
93
+ return this._namedLayoutParams;
94
+ }
95
+ get layoutParams() {
96
+ if (this._layoutParams == null) {
97
+ this._layoutParams = this.findUnnamedLayoutParams();
98
+ if (this._layoutParams == null) {
99
+ this._layoutParams = this.snapshotLayoutParams();
100
+ this._unnamedLayoutParams.push(this._layoutParams);
101
+ }
102
+ }
103
+ return this._layoutParams;
104
+ }
105
+ resetLayoutParams() {
106
+ this._layoutParams = null;
107
+ this.resetLine();
108
+ }
109
+ snapshotLayoutParams() {
110
+ const effectiveCycle = this.cycle;
111
+ if (effectiveCycle == null) {
112
+ throw new Error("Cannot create layout params: no cycle defined");
113
+ }
114
+ return new layouts_1.LayoutParams({
115
+ cycle: effectiveCycle,
116
+ beatDuration: this.atomsPerBeat,
117
+ layout: this.breaks,
118
+ });
119
+ }
120
+ findUnnamedLayoutParams() {
121
+ const effectiveCycle = this.cycle;
122
+ if (effectiveCycle == null)
123
+ return null;
124
+ return (this._unnamedLayoutParams.find((lp) => {
125
+ return (lp.beatDuration == this.atomsPerBeat && effectiveCycle.equals(lp.cycle) && lp.lineBreaksEqual(this.breaks));
126
+ }) || null);
127
+ }
128
+ ensureNamedLayoutParams(name) {
129
+ let lp = this._namedLayoutParams.get(name) || null;
130
+ if (lp == null || this._layoutParams != lp) {
131
+ if (lp == null) {
132
+ lp = this.snapshotLayoutParams();
133
+ this._namedLayoutParams.set(name, lp);
134
+ }
135
+ else {
136
+ this.localCycle = lp.cycle;
137
+ this.localAtomsPerBeat = lp.beatDuration;
138
+ this.localBreaks = lp.lineBreaks;
139
+ }
140
+ this._layoutParams = lp;
141
+ this.resetLine();
142
+ }
143
+ return this._layoutParams;
144
+ }
145
+ getRole(name) {
146
+ var _a, _b;
147
+ const local = this.localRoles.get(name.toLowerCase());
148
+ if (local) {
149
+ return local;
150
+ }
151
+ return (_b = (_a = this.parentBlock) === null || _a === void 0 ? void 0 : _a.getRole(name)) !== null && _b !== void 0 ? _b : null;
152
+ }
153
+ get currRoleDef() {
154
+ if (this._currRoleDef !== null) {
155
+ return this._currRoleDef;
156
+ }
157
+ if (this.parentBlock) {
158
+ return this.parentBlock.currRoleDef;
159
+ }
160
+ const roles = Array.from(this.localRoles.values());
161
+ return roles.length > 0 ? roles[roles.length - 1] : null;
162
+ }
163
+ setCurrRole(name) {
164
+ name = name.trim().toLowerCase();
165
+ if (name === "") {
166
+ throw new Error("Role name cannot be empty");
167
+ }
168
+ let roleDef = this.getRole(name);
169
+ if (roleDef == null) {
170
+ roleDef = this.newRoleDef(name, name === "sw");
171
+ }
172
+ this._currRoleDef = roleDef;
173
+ }
174
+ get currentLine() {
175
+ if (this._currentLine === null) {
176
+ return this.newLine();
177
+ }
178
+ return this._currentLine;
179
+ }
180
+ newLine() {
181
+ if (this._currentLine !== null && this._currentLine.isEmpty) {
182
+ this.removeBlockItem(this._currentLine);
183
+ }
184
+ this._currentLine = new core_1.Line();
185
+ this.addBlockItem(this._currentLine);
186
+ return this._currentLine;
187
+ }
188
+ resetLine() {
189
+ this._currentLine = null;
190
+ }
191
+ newRoleDef(name, notesOnly = false) {
192
+ name = name.trim().toLowerCase();
193
+ if (name === "") {
194
+ throw new Error("Role name cannot be empty");
195
+ }
196
+ if (this.localRoles.has(name)) {
197
+ throw new Error(`Role '${name}' already exists in this block`);
198
+ }
199
+ const rd = new RoleDef();
200
+ rd.name = name;
201
+ rd.notesOnly = notesOnly;
202
+ rd.index = this.localRoles.size;
203
+ this.localRoles.set(name, rd);
204
+ return rd;
205
+ }
206
+ addBlockItem(item) {
207
+ item.setParent(this);
208
+ this.blockItems.push(item);
209
+ }
210
+ removeBlockItem(item) {
211
+ const index = this.blockItems.indexOf(item);
212
+ if (index >= 0) {
213
+ this.blockItems.splice(index, 1);
214
+ item.setParent(null);
215
+ }
216
+ return index;
217
+ }
218
+ debugValue() {
219
+ const out = Object.assign(Object.assign({}, super.debugValue()), { blockType: this.blockType, blockItems: this.blockItems.map((c) => c.debugValue()) });
220
+ if (this.name) {
221
+ out.name = this.name;
222
+ }
223
+ if (this.localCycle) {
224
+ out.localCycle = this.localCycle.uuid;
225
+ }
226
+ if (this.localAtomsPerBeat !== null) {
227
+ out.localAtomsPerBeat = this.localAtomsPerBeat;
228
+ }
229
+ if (this.localBreaks !== null) {
230
+ out.localBreaks = this.localBreaks;
231
+ }
232
+ if (this.localRoles.size > 0) {
233
+ out.localRoles = Array.from(this.localRoles.keys());
234
+ }
235
+ return out;
236
+ }
237
+ }
238
+ exports.Block = Block;
239
+ function findContainingBlock(entity) {
240
+ let current = entity.parent;
241
+ while (current !== null) {
242
+ if (current instanceof Block) {
243
+ return current;
244
+ }
245
+ current = current.parent;
246
+ }
247
+ return null;
248
+ }
249
+ class SectionBlock extends Block {
250
+ constructor(sectionName, parent = null) {
251
+ super("section", parent, sectionName);
252
+ }
253
+ children() {
254
+ const heading = new RawBlock(`# ${this.name}`, "md");
255
+ return [heading, ...this.blockItems];
256
+ }
257
+ }
258
+ exports.SectionBlock = SectionBlock;
259
+ class RepeatBlock extends Block {
260
+ constructor(repeatCount, parent = null) {
261
+ super("repeat", parent);
262
+ this.repeatCount = repeatCount;
263
+ }
264
+ children() {
265
+ if (this.repeatCount <= 0) {
266
+ return this.blockItems;
267
+ }
268
+ const expanded = [];
269
+ for (let i = 0; i < this.repeatCount; i++) {
270
+ expanded.push(...this.blockItems);
271
+ }
272
+ return expanded;
273
+ }
274
+ }
275
+ exports.RepeatBlock = RepeatBlock;
276
+ class CycleBlock extends Block {
277
+ constructor(cycle, parent = null) {
278
+ super("cycle", parent);
279
+ this.localCycle = cycle;
280
+ }
281
+ }
282
+ exports.CycleBlock = CycleBlock;
283
+ class BeatDurationBlock extends Block {
284
+ constructor(atomsPerBeat, parent = null) {
285
+ super("beatduration", parent);
286
+ this.localAtomsPerBeat = atomsPerBeat;
287
+ }
288
+ }
289
+ exports.BeatDurationBlock = BeatDurationBlock;
290
+ class BreaksBlock extends Block {
291
+ constructor(breaks, parent = null) {
292
+ super("breaks", parent);
293
+ this.localBreaks = breaks;
294
+ }
295
+ }
296
+ exports.BreaksBlock = BreaksBlock;
297
+ class RoleBlock extends Block {
298
+ constructor(roleName, notesOnly, parent = null) {
299
+ super("role", parent);
300
+ this.newRoleDef(roleName, notesOnly);
301
+ }
302
+ }
303
+ exports.RoleBlock = RoleBlock;
304
+ class GroupBlock extends Block {
305
+ constructor(groupName, parent = null) {
306
+ super("group", parent, groupName);
307
+ }
308
+ }
309
+ exports.GroupBlock = GroupBlock;
310
+ //# sourceMappingURL=block.js.map