notations 1.0.4 → 1.0.7
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/README.md +1 -0
- package/dist/NotationView.css +15 -0
- package/dist/NotationView.css.map +1 -1
- package/dist/NotationView.min.css +1 -1
- package/dist/NotationView.min.css.map +1 -1
- package/dist/notations.umd.js +469 -108
- package/dist/notations.umd.min.js +2 -2
- package/dist/notations.umd.min.js.map +1 -1
- package/lib/cjs/beats.js +1 -1
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/block.d.ts +4 -0
- package/lib/cjs/block.js +24 -0
- package/lib/cjs/block.js.map +1 -1
- package/lib/cjs/carnatic/NotationView.d.ts +1 -0
- package/lib/cjs/carnatic/NotationView.js +10 -0
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/carnatic/atomviews.d.ts +4 -1
- package/lib/cjs/carnatic/atomviews.js +18 -2
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/embelishments.d.ts +18 -1
- package/lib/cjs/carnatic/embelishments.js +87 -1
- package/lib/cjs/carnatic/embelishments.js.map +1 -1
- package/lib/cjs/core.d.ts +18 -3
- package/lib/cjs/core.js +161 -21
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/entity.d.ts +4 -0
- package/lib/cjs/entity.js +12 -0
- package/lib/cjs/entity.js.map +1 -1
- package/lib/cjs/events.d.ts +56 -0
- package/lib/cjs/events.js +27 -0
- package/lib/cjs/events.js.map +1 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/shapes.d.ts +13 -1
- package/lib/cjs/shapes.js +35 -7
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/esm/beats.js +1 -1
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/block.d.ts +4 -0
- package/lib/esm/block.js +24 -0
- package/lib/esm/block.js.map +1 -1
- package/lib/esm/carnatic/NotationView.d.ts +1 -0
- package/lib/esm/carnatic/NotationView.js +10 -0
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/carnatic/atomviews.d.ts +4 -1
- package/lib/esm/carnatic/atomviews.js +19 -3
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/embelishments.d.ts +18 -1
- package/lib/esm/carnatic/embelishments.js +85 -0
- package/lib/esm/carnatic/embelishments.js.map +1 -1
- package/lib/esm/core.d.ts +18 -3
- package/lib/esm/core.js +161 -21
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/entity.d.ts +4 -0
- package/lib/esm/entity.js +12 -0
- package/lib/esm/entity.js.map +1 -1
- package/lib/esm/events.d.ts +56 -0
- package/lib/esm/events.js +24 -0
- package/lib/esm/events.js.map +1 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/shapes.d.ts +13 -1
- package/lib/esm/shapes.js +34 -7
- package/lib/esm/shapes.js.map +1 -1
- package/package.json +3 -1
- package/styles/NotationView.scss +15 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare enum AtomChangeType {
|
|
2
|
+
ADD = "add",
|
|
3
|
+
INSERT = "insert",
|
|
4
|
+
REMOVE = "remove",
|
|
5
|
+
UPDATE = "update"
|
|
6
|
+
}
|
|
7
|
+
export interface AtomChangeEvent<T = any> {
|
|
8
|
+
type: AtomChangeType;
|
|
9
|
+
atoms: T[];
|
|
10
|
+
index?: number;
|
|
11
|
+
property?: string;
|
|
12
|
+
oldValue?: any;
|
|
13
|
+
newValue?: any;
|
|
14
|
+
}
|
|
15
|
+
export declare enum RoleChangeType {
|
|
16
|
+
ADD = "add",
|
|
17
|
+
REMOVE = "remove"
|
|
18
|
+
}
|
|
19
|
+
export interface RoleChangeEvent {
|
|
20
|
+
type: RoleChangeType;
|
|
21
|
+
roleName: string;
|
|
22
|
+
}
|
|
23
|
+
export declare enum BlockItemChangeType {
|
|
24
|
+
ADD = "add",
|
|
25
|
+
REMOVE = "remove"
|
|
26
|
+
}
|
|
27
|
+
export interface BlockItemChangeEvent<T = any> {
|
|
28
|
+
type: BlockItemChangeType;
|
|
29
|
+
item: T;
|
|
30
|
+
index?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface GroupObserver<TAtom = any, TGroup = any> {
|
|
33
|
+
onAtomsAdded?(group: TGroup, atoms: TAtom[], index: number): void;
|
|
34
|
+
onAtomsInserted?(group: TGroup, atoms: TAtom[], index: number): void;
|
|
35
|
+
onAtomsRemoved?(group: TGroup, atoms: TAtom[]): void;
|
|
36
|
+
}
|
|
37
|
+
export interface RoleObserver<TAtom = any, TRole = any> {
|
|
38
|
+
onAtomsAdded?(role: TRole, atoms: TAtom[], index: number): void;
|
|
39
|
+
onAtomsInserted?(role: TRole, atoms: TAtom[], index: number): void;
|
|
40
|
+
onAtomsRemoved?(role: TRole, atoms: TAtom[]): void;
|
|
41
|
+
}
|
|
42
|
+
export interface LineObserver<TRole = any, TLine = any> {
|
|
43
|
+
onRoleAdded?(line: TLine, roleName: string, role: TRole): void;
|
|
44
|
+
onRoleRemoved?(line: TLine, roleName: string): void;
|
|
45
|
+
}
|
|
46
|
+
export interface BlockObserver<TItem = any, TBlock = any> {
|
|
47
|
+
onItemAdded?(block: TBlock, item: TItem, index: number): void;
|
|
48
|
+
onItemRemoved?(block: TBlock, item: TItem, index: number): void;
|
|
49
|
+
}
|
|
50
|
+
export declare const ModelEvents: {
|
|
51
|
+
readonly ATOMS_CHANGED: "atomsChanged";
|
|
52
|
+
readonly ROLES_CHANGED: "rolesChanged";
|
|
53
|
+
readonly ITEMS_CHANGED: "itemsChanged";
|
|
54
|
+
readonly DURATION_CHANGED: "durationChanged";
|
|
55
|
+
};
|
|
56
|
+
export type ModelEventName = (typeof ModelEvents)[keyof typeof ModelEvents];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelEvents = exports.BlockItemChangeType = exports.RoleChangeType = exports.AtomChangeType = void 0;
|
|
4
|
+
var AtomChangeType;
|
|
5
|
+
(function (AtomChangeType) {
|
|
6
|
+
AtomChangeType["ADD"] = "add";
|
|
7
|
+
AtomChangeType["INSERT"] = "insert";
|
|
8
|
+
AtomChangeType["REMOVE"] = "remove";
|
|
9
|
+
AtomChangeType["UPDATE"] = "update";
|
|
10
|
+
})(AtomChangeType || (exports.AtomChangeType = AtomChangeType = {}));
|
|
11
|
+
var RoleChangeType;
|
|
12
|
+
(function (RoleChangeType) {
|
|
13
|
+
RoleChangeType["ADD"] = "add";
|
|
14
|
+
RoleChangeType["REMOVE"] = "remove";
|
|
15
|
+
})(RoleChangeType || (exports.RoleChangeType = RoleChangeType = {}));
|
|
16
|
+
var BlockItemChangeType;
|
|
17
|
+
(function (BlockItemChangeType) {
|
|
18
|
+
BlockItemChangeType["ADD"] = "add";
|
|
19
|
+
BlockItemChangeType["REMOVE"] = "remove";
|
|
20
|
+
})(BlockItemChangeType || (exports.BlockItemChangeType = BlockItemChangeType = {}));
|
|
21
|
+
exports.ModelEvents = {
|
|
22
|
+
ATOMS_CHANGED: "atomsChanged",
|
|
23
|
+
ROLES_CHANGED: "rolesChanged",
|
|
24
|
+
ITEMS_CHANGED: "itemsChanged",
|
|
25
|
+
DURATION_CHANGED: "durationChanged",
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":";;;AAwBA,IAAY,cASX;AATD,WAAY,cAAc;IAExB,6BAAW,CAAA;IAEX,mCAAiB,CAAA;IAEjB,mCAAiB,CAAA;IAEjB,mCAAiB,CAAA;AACnB,CAAC,EATW,cAAc,8BAAd,cAAc,QASzB;AAwBD,IAAY,cAKX;AALD,WAAY,cAAc;IAExB,6BAAW,CAAA;IAEX,mCAAiB,CAAA;AACnB,CAAC,EALW,cAAc,8BAAd,cAAc,QAKzB;AAeD,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAE7B,kCAAW,CAAA;IAEX,wCAAiB,CAAA;AACnB,CAAC,EALW,mBAAmB,mCAAnB,mBAAmB,QAK9B;AAgJY,QAAA,WAAW,GAAG;IAEzB,aAAa,EAAE,cAAc;IAE7B,aAAa,EAAE,cAAc;IAE7B,aAAa,EAAE,cAAc;IAE7B,gBAAgB,EAAE,iBAAiB;CAC3B,CAAC","sourcesContent":["/**\n * Model change events for incremental updates.\n *\n * This module defines the event types, interfaces, and observer patterns for\n * change notifications on model entities (Group, Role, Line, Block). These\n * events enable incremental updates to the rendering pipeline without full\n * re-renders.\n *\n * Uses the Observer pattern instead of pub/sub EventHub for:\n * - Type safety: Observers have strongly-typed method signatures\n * - Traceability: Easy to see who is observing what\n * - Explicit contracts: Clear interface between observable and observers\n *\n * Note: This module uses generic types to avoid circular dependencies with\n * core.ts and block.ts. The actual types are enforced at the call sites.\n */\n\n// ============================================\n// Event Types and Payloads\n// ============================================\n\n/**\n * Event types for Atom-related changes.\n */\nexport enum AtomChangeType {\n /** Atoms were added to the end */\n ADD = \"add\",\n /** Atoms were inserted at a specific position */\n INSERT = \"insert\",\n /** Atoms were removed */\n REMOVE = \"remove\",\n /** An atom's properties changed (duration, value, etc.) */\n UPDATE = \"update\",\n}\n\n/**\n * Event payload for atom changes in a Group or Role.\n * Generic T is typically Atom from core.ts.\n */\nexport interface AtomChangeEvent<T = any> {\n /** The type of change */\n type: AtomChangeType;\n /** The atoms that were added, inserted, or removed */\n atoms: T[];\n /** For INSERT: the index where atoms were inserted */\n index?: number;\n /** For UPDATE: the specific property that changed */\n property?: string;\n /** For UPDATE: the old value of the property */\n oldValue?: any;\n /** For UPDATE: the new value of the property */\n newValue?: any;\n}\n\n/**\n * Event types for Role-related changes on a Line.\n */\nexport enum RoleChangeType {\n /** A role was added to the line */\n ADD = \"add\",\n /** A role was removed from the line */\n REMOVE = \"remove\",\n}\n\n/**\n * Event payload for role changes on a Line.\n */\nexport interface RoleChangeEvent {\n /** The type of change */\n type: RoleChangeType;\n /** The role that was added or removed */\n roleName: string;\n}\n\n/**\n * Event types for BlockItem changes on a Block.\n */\nexport enum BlockItemChangeType {\n /** An item was added to the block */\n ADD = \"add\",\n /** An item was removed from the block */\n REMOVE = \"remove\",\n}\n\n/**\n * Event payload for block item changes.\n * Generic T is typically BlockItem (Block | Line | RawBlock) from block.ts.\n */\nexport interface BlockItemChangeEvent<T = any> {\n /** The type of change */\n type: BlockItemChangeType;\n /** The item that was added or removed */\n item: T;\n /** For ADD: the index where the item was added */\n index?: number;\n}\n\n// ============================================\n// Observer Interfaces\n// ============================================\n\n/**\n * Observer interface for Group atom changes.\n * Implement this interface to receive notifications when atoms are\n * added, inserted, or removed from a Group.\n *\n * @template TAtom The atom type (defaults to any to avoid circular deps)\n * @template TGroup The group type (defaults to any to avoid circular deps)\n */\nexport interface GroupObserver<TAtom = any, TGroup = any> {\n /**\n * Called when atoms are added to the end of the group.\n * @param group The group that changed\n * @param atoms The atoms that were added\n * @param index The index where atoms were added\n */\n onAtomsAdded?(group: TGroup, atoms: TAtom[], index: number): void;\n\n /**\n * Called when atoms are inserted at a specific position.\n * @param group The group that changed\n * @param atoms The atoms that were inserted\n * @param index The index where atoms were inserted\n */\n onAtomsInserted?(group: TGroup, atoms: TAtom[], index: number): void;\n\n /**\n * Called when atoms are removed from the group.\n * @param group The group that changed\n * @param atoms The atoms that were removed\n */\n onAtomsRemoved?(group: TGroup, atoms: TAtom[]): void;\n}\n\n/**\n * Observer interface for Role atom changes.\n * Implement this interface to receive notifications when atoms are\n * added, inserted, or removed from a Role.\n *\n * @template TAtom The atom type (defaults to any to avoid circular deps)\n * @template TRole The role type (defaults to any to avoid circular deps)\n */\nexport interface RoleObserver<TAtom = any, TRole = any> {\n /**\n * Called when atoms are added to the end of the role.\n * @param role The role that changed\n * @param atoms The atoms that were added\n * @param index The index where atoms were added\n */\n onAtomsAdded?(role: TRole, atoms: TAtom[], index: number): void;\n\n /**\n * Called when atoms are inserted at a specific position.\n * @param role The role that changed\n * @param atoms The atoms that were inserted\n * @param index The index where atoms were inserted\n */\n onAtomsInserted?(role: TRole, atoms: TAtom[], index: number): void;\n\n /**\n * Called when atoms are removed from the role.\n * @param role The role that changed\n * @param atoms The atoms that were removed\n */\n onAtomsRemoved?(role: TRole, atoms: TAtom[]): void;\n}\n\n/**\n * Observer interface for Line role changes.\n * Implement this interface to receive notifications when roles are\n * added or removed from a Line.\n *\n * @template TRole The role type (defaults to any to avoid circular deps)\n * @template TLine The line type (defaults to any to avoid circular deps)\n */\nexport interface LineObserver<TRole = any, TLine = any> {\n /**\n * Called when a role is added to the line.\n * @param line The line that changed\n * @param roleName The name of the added role\n * @param role The role that was added\n */\n onRoleAdded?(line: TLine, roleName: string, role: TRole): void;\n\n /**\n * Called when a role is removed from the line.\n * @param line The line that changed\n * @param roleName The name of the removed role\n */\n onRoleRemoved?(line: TLine, roleName: string): void;\n}\n\n/**\n * Observer interface for Block item changes.\n * Implement this interface to receive notifications when items are\n * added or removed from a Block.\n *\n * @template TItem The block item type (defaults to any to avoid circular deps)\n * @template TBlock The block type (defaults to any to avoid circular deps)\n */\nexport interface BlockObserver<TItem = any, TBlock = any> {\n /**\n * Called when an item is added to the block.\n * @param block The block that changed\n * @param item The item that was added\n * @param index The index where the item was added\n */\n onItemAdded?(block: TBlock, item: TItem, index: number): void;\n\n /**\n * Called when an item is removed from the block.\n * @param block The block that changed\n * @param item The item that was removed\n * @param index The index where the item was located\n */\n onItemRemoved?(block: TBlock, item: TItem, index: number): void;\n}\n\n// ============================================\n// Legacy Event Names (kept for compatibility)\n// ============================================\n\n/**\n * Model event names as constants.\n * @deprecated Use observer interfaces instead\n */\nexport const ModelEvents = {\n /** Emitted when atoms change in a Group or Role */\n ATOMS_CHANGED: \"atomsChanged\",\n /** Emitted when roles change on a Line */\n ROLES_CHANGED: \"rolesChanged\",\n /** Emitted when block items change on a Block */\n ITEMS_CHANGED: \"itemsChanged\",\n /** Emitted when an atom's duration changes */\n DURATION_CHANGED: \"durationChanged\",\n} as const;\n\n/**\n * Type for model event names.\n * @deprecated Use observer interfaces instead\n */\nexport type ModelEventName = (typeof ModelEvents)[keyof typeof ModelEvents];\n"]}
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -38,6 +38,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.Carnatic = exports.Utils = void 0;
|
|
40
40
|
__exportStar(require("./entity"), exports);
|
|
41
|
+
__exportStar(require("./events"), exports);
|
|
41
42
|
__exportStar(require("./cycle"), exports);
|
|
42
43
|
__exportStar(require("./core"), exports);
|
|
43
44
|
__exportStar(require("./iterators"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,iDAAiC;AACjC,uDAAuC","sourcesContent":["export * from \"./entity\";\nexport * from \"./cycle\";\nexport * from \"./core\";\nexport * from \"./iterators\";\nexport * from \"./layouts\";\nexport * from \"./grids\";\nexport * from \"./beats\";\nexport * from \"./notation\";\nexport * from \"./parser\";\nexport * from \"./shapes\";\nexport * from \"./loader\";\nexport * as Utils from \"./utils\";\nexport * as Carnatic from \"./carnatic\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,iDAAiC;AACjC,uDAAuC","sourcesContent":["export * from \"./entity\";\nexport * from \"./events\";\nexport * from \"./cycle\";\nexport * from \"./core\";\nexport * from \"./iterators\";\nexport * from \"./layouts\";\nexport * from \"./grids\";\nexport * from \"./beats\";\nexport * from \"./notation\";\nexport * from \"./parser\";\nexport * from \"./shapes\";\nexport * from \"./loader\";\nexport * as Utils from \"./utils\";\nexport * as Carnatic from \"./carnatic\";\n"]}
|
package/lib/cjs/shapes.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
2
|
import { Atom, LeafAtom, Group } from "./core";
|
|
3
|
+
export interface CollisionLayoutItem {
|
|
4
|
+
timeOffset: TSU.Num.Fraction;
|
|
5
|
+
duration: TSU.Num.Fraction;
|
|
6
|
+
glyphOffset: number;
|
|
7
|
+
minWidth: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CollisionLayoutResult {
|
|
10
|
+
x: number;
|
|
11
|
+
wasCollision: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function computeCollisionLayout(items: CollisionLayoutItem[], totalDuration: TSU.Num.Fraction, containerWidth: number): CollisionLayoutResult[];
|
|
3
14
|
export declare abstract class Shape {
|
|
4
15
|
private static idCounter;
|
|
5
16
|
readonly shapeId: number;
|
|
@@ -65,7 +76,7 @@ export declare abstract class LeafAtomView extends AtomView {
|
|
|
65
76
|
export declare abstract class GroupView extends AtomView {
|
|
66
77
|
group: Group;
|
|
67
78
|
protected atomSpacing: number;
|
|
68
|
-
|
|
79
|
+
groupElement: SVGGElement;
|
|
69
80
|
protected atomViews: AtomView[];
|
|
70
81
|
private _embelishments;
|
|
71
82
|
defaultToNotes: boolean;
|
|
@@ -73,6 +84,7 @@ export declare abstract class GroupView extends AtomView {
|
|
|
73
84
|
scaleFactor: number;
|
|
74
85
|
showContinuationMarkers: boolean;
|
|
75
86
|
protected continuationMarkerElements: SVGTextElement[];
|
|
87
|
+
contentWidth: number;
|
|
76
88
|
constructor(group: Group, config?: any);
|
|
77
89
|
get totalDuration(): TSU.Num.Fraction;
|
|
78
90
|
createElements(parent: SVGGraphicsElement): void;
|
package/lib/cjs/shapes.js
CHANGED
|
@@ -34,8 +34,26 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.GroupView = exports.LeafAtomView = exports.AtomView = exports.ElementShape = exports.Embelishment = exports.Shape = void 0;
|
|
37
|
+
exports.computeCollisionLayout = computeCollisionLayout;
|
|
37
38
|
const TSU = __importStar(require("@panyam/tsutils"));
|
|
38
39
|
const core_1 = require("./core");
|
|
40
|
+
function computeCollisionLayout(items, totalDuration, containerWidth) {
|
|
41
|
+
const results = [];
|
|
42
|
+
let prevItemEndX = 0;
|
|
43
|
+
let currTime = core_1.ZERO;
|
|
44
|
+
for (const item of items) {
|
|
45
|
+
const glyphX = totalDuration.isZero ? 0 : currTime.timesNum(containerWidth).divby(totalDuration).floor;
|
|
46
|
+
let realX = glyphX - item.glyphOffset;
|
|
47
|
+
const wasCollision = realX < prevItemEndX;
|
|
48
|
+
if (wasCollision) {
|
|
49
|
+
realX = prevItemEndX;
|
|
50
|
+
}
|
|
51
|
+
results.push({ x: realX, wasCollision });
|
|
52
|
+
prevItemEndX = realX + item.minWidth;
|
|
53
|
+
currTime = currTime.plus(item.duration);
|
|
54
|
+
}
|
|
55
|
+
return results;
|
|
56
|
+
}
|
|
39
57
|
class Shape {
|
|
40
58
|
constructor() {
|
|
41
59
|
this.shapeId = Shape.idCounter++;
|
|
@@ -239,13 +257,14 @@ class GroupView extends AtomView {
|
|
|
239
257
|
this.defaultToNotes = true;
|
|
240
258
|
this.needsLayout = true;
|
|
241
259
|
this.scaleFactor = 1.0;
|
|
242
|
-
this.showContinuationMarkers =
|
|
260
|
+
this.showContinuationMarkers = false;
|
|
243
261
|
this.continuationMarkerElements = [];
|
|
244
|
-
this.
|
|
262
|
+
this.contentWidth = 0;
|
|
263
|
+
this.atomSpacing = 2;
|
|
245
264
|
this.setStyles(config || {});
|
|
246
265
|
}
|
|
247
266
|
get totalDuration() {
|
|
248
|
-
return this.group.
|
|
267
|
+
return this.group.duration;
|
|
249
268
|
}
|
|
250
269
|
createElements(parent) {
|
|
251
270
|
this.groupElement = TSU.DOM.createSVGNode("g", {
|
|
@@ -282,7 +301,7 @@ class GroupView extends AtomView {
|
|
|
282
301
|
});
|
|
283
302
|
const totalDuration = this.group.totalChildDuration;
|
|
284
303
|
const totalDurValue = totalDuration.num / totalDuration.den;
|
|
285
|
-
const totalWidth = minWidthPerDuration * totalDurValue;
|
|
304
|
+
const totalWidth = Math.max(0, minWidthPerDuration * totalDurValue - this.atomSpacing);
|
|
286
305
|
return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);
|
|
287
306
|
}
|
|
288
307
|
updateBounds(x, y, w, h) {
|
|
@@ -294,16 +313,24 @@ class GroupView extends AtomView {
|
|
|
294
313
|
transform += " scale(" + this.scaleFactor + ")";
|
|
295
314
|
}
|
|
296
315
|
this.groupElement.setAttribute("transform", transform);
|
|
297
|
-
const
|
|
316
|
+
const unscaledContentHeight = this.minSize.height / this.scaleFactor;
|
|
317
|
+
const unscaledAllocatedHeight = this.hasHeight ? this.height / this.scaleFactor : unscaledContentHeight;
|
|
318
|
+
const currY = unscaledAllocatedHeight - unscaledContentHeight;
|
|
298
319
|
const totalDur = this.group.totalChildDuration;
|
|
299
320
|
const unscaledMinWidth = this.minSize.width / this.scaleFactor;
|
|
300
321
|
const groupWidth = this.hasWidth ? this.width / this.scaleFactor : unscaledMinWidth;
|
|
301
322
|
this.clearContinuationMarkers();
|
|
302
323
|
let currTime = core_1.ZERO;
|
|
324
|
+
let prevNoteEndX = 0;
|
|
303
325
|
this.atomViews.forEach((av, index) => {
|
|
304
326
|
const glyphX = totalDur.isZero ? 0 : currTime.timesNum(groupWidth).divby(totalDur).floor;
|
|
305
|
-
|
|
306
|
-
|
|
327
|
+
let realX = glyphX - av.glyphOffset;
|
|
328
|
+
if (realX < prevNoteEndX) {
|
|
329
|
+
realX = prevNoteEndX;
|
|
330
|
+
}
|
|
331
|
+
av.setBounds(realX, currY, null, null, true);
|
|
332
|
+
const avWidth = av.contentWidth || av.bbox.width;
|
|
333
|
+
prevNoteEndX = realX + avWidth;
|
|
307
334
|
if (this.showContinuationMarkers && !totalDur.isZero) {
|
|
308
335
|
const atomDur = av.totalDuration;
|
|
309
336
|
const durValue = atomDur.num / atomDur.den;
|
|
@@ -318,6 +345,7 @@ class GroupView extends AtomView {
|
|
|
318
345
|
}
|
|
319
346
|
currTime = currTime.plus(av.totalDuration);
|
|
320
347
|
});
|
|
348
|
+
this.contentWidth = prevNoteEndX;
|
|
321
349
|
this.invalidateBounds();
|
|
322
350
|
for (const e of this.embelishments)
|
|
323
351
|
e.refreshLayout();
|
package/lib/cjs/shapes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,iCAAqD;AASrD,MAAsB,KAAK;IAA3B;QAEW,YAAO,GAAW,KAAK,CAAC,SAAS,EAAE,CAAC;QASnC,OAAE,GAAkB,IAAI,CAAC;QACzB,OAAE,GAAkB,IAAI,CAAC;QACzB,WAAM,GAAkB,IAAI,CAAC;QAC7B,YAAO,GAAkB,IAAI,CAAC;QAG9B,gBAAW,GAAiB,IAAI,CAAC;QAE3C,aAAQ,GAAY,EAAE,CAAC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,cAAc,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAMS,mBAAmB;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAMD,SAAS,CAAC,MAAW;QACnB,IAAI,aAAa,IAAI,MAAM;YAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACnE,IAAI,yBAAyB,IAAI,MAAM;YAAE,IAAI,CAAC,uBAAuB,GAAG,MAAM,CAAC,uBAAuB,CAAC;QACvG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CACF;AAhUD,8BAgUC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { ZERO, Atom, LeafAtom, Group } from \"./core\";\n\n/**\n * Base class for all renderable objects.\n *\n * Shape caches properties like bounding boxes to improve performance,\n * since bounding box calculations can be expensive. This also allows\n * testing layouts and positioning without worrying about implementation details.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n\n /**\n * Note that x and y coordinates are not always the x and y coordinates\n * of the bounding box.\n * E.g., a circle's x and y coordinates are its center point and not the\n * top left corner.\n * These \"main\" coordinates are referred to 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 /** Child shapes contained within this shape */\n children: Shape[] = [];\n\n /**\n * Gets the bounding box of this shape.\n * Calculates it if it hasn't been calculated yet.\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 * Gets the minimum size of this shape.\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 * Refreshes the bounding box of this shape.\n * Called when the shape knows the bbox it is tracking cannot be trusted\n * and has to be refreshed by calling native methods.\n * @returns The refreshed bounding box\n */\n protected abstract refreshBBox(): TSU.Geom.Rect;\n\n /**\n * Refreshes the minimum size of this shape.\n * @returns The refreshed minimum size\n */\n protected abstract refreshMinSize(): TSU.Geom.Size;\n\n /**\n * Updates the bounds of this shape.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\n */\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 /**\n * Invalidates the cached bounds of this shape.\n * Forces recalculation of bounding box and minimum size.\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 bounds of this shape.\n *\n * Note that null and NaN are valid values and mean the following:\n * - null: Don't change the value\n * - NaN: Set the value to null (use the bounding box's value)\n *\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @param applyLayout Whether to apply layout immediately\n * @returns The updated bounds values\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 /**\n * Checks if this shape has an explicit x coordinate.\n */\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n /**\n * Checks if this shape has an explicit y coordinate.\n */\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n /**\n * Checks if this shape has an explicit width.\n */\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n /**\n * Checks if this shape has an explicit height.\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 /**\n * Gets the width of this shape.\n */\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n /**\n * Sets the width of this shape.\n */\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n /**\n * Gets the height of this shape.\n */\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n /**\n * Sets the height of this shape.\n */\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * Refreshes the layout of this shape.\n * Called when bounds or other properties have changed to give the shape an\n * opportunity to layout its children. For shapes with no children this is a no-op.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\n/**\n * Represents an embellishment applied to a musical element.\n */\nexport abstract class Embelishment extends Shape {}\n\n/**\n * A shape that wraps an SVG element.\n * ElementShape provides the base class for all shapes that are rendered as SVG elements.\n */\nexport class ElementShape<T extends SVGGraphicsElement = SVGGraphicsElement> extends Shape {\n /**\n * Creates a new ElementShape.\n * @param element The SVG element this shape wraps\n */\n constructor(public readonly element: T) {\n super();\n }\n\n /**\n * Refreshes the bounding box of this element.\n * @returns The refreshed bounding box\n */\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.element);\n }\n\n /**\n * Refreshes the minimum size of this element.\n * @returns The refreshed minimum size\n */\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n /**\n * Updates the bounds of this element.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\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 /**\n * Refreshes the layout of this element.\n * Updates the element's attributes based on the shape's properties.\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\n/**\n * Base class for views that represent atoms in the notation.\n * AtomView provides the visual representation of an atom.\n */\nexport abstract class AtomView extends Shape {\n /** Nesting depth of this atom in the structure */\n depth = 0;\n /** Index of the role containing this atom */\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 position for vertical alignment */\n baseline: number;\n /** Ascent (space above baseline) */\n ascent: number;\n /** Descent (space below baseline) */\n descent: number;\n /** Height of capital letters */\n capHeight: number;\n /** Space between lines */\n leading: number;\n\n /**\n * Checks if this atom view represents a leaf atom.\n */\n abstract isLeaf(): boolean;\n\n abstract get totalDuration(): TSU.Num.Fraction;\n\n /**\n * Returns the horizontal offset from the atom's origin to where the note glyph starts.\n * This accounts for left embellishments that appear before the note.\n * Used by GroupView to align note glyphs at their correct time positions.\n *\n * Default is 0 (glyph starts at origin). Subclasses with left embellishments\n * should override to return the width of left-side decorations.\n */\n get glyphOffset(): number {\n return 0;\n }\n\n /**\n * Creates the SVG elements needed for this atom view.\n * @param parent The parent SVG element to attach to\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n}\n\n/**\n * A view for leaf atoms (those that cannot contain other atoms).\n */\nexport abstract class LeafAtomView extends AtomView {\n /**\n * Creates a new LeafAtomView.\n * @param leafAtom The leaf atom this view represents\n */\n constructor(public leafAtom: LeafAtom) {\n super();\n }\n\n /**\n * Leaf atom views always return true for isLeaf().\n */\n isLeaf(): boolean {\n return true;\n }\n\n /**\n * Gets a unique identifier for this view based on the atom's UUID.\n */\n get viewId(): number {\n return this.leafAtom.uuid;\n }\n\n /**\n * Returns the total duration of the atom rendered by this view.\n */\n get totalDuration(): TSU.Num.Fraction {\n return this.leafAtom.duration;\n }\n}\n\n/**\n * A view for group atoms that contain multiple child atoms.\n */\nexport abstract class GroupView extends AtomView {\n /** Space between atoms in this group */\n protected atomSpacing: number;\n /** The SVG group element for this view */\n protected groupElement: SVGGElement;\n /** Views for the atoms in this group */\n protected atomViews: AtomView[] = [];\n private _embelishments: Embelishment[];\n /** Whether this group represents notes by default */\n defaultToNotes = true;\n /** Whether this view needs layout */\n needsLayout = true;\n /** Scale factor for this group */\n scaleFactor = 1.0;\n /**\n * When true, shows continuation markers (\",\") for atoms with duration > 1\n * instead of just leaving empty space.\n */\n showContinuationMarkers = true;\n /** SVG elements for continuation markers */\n protected continuationMarkerElements: SVGTextElement[] = [];\n\n /**\n * Creates a new GroupView.\n * @param group The group atom this view represents\n * @param config Optional configuration object\n */\n constructor(\n public group: Group,\n config?: any,\n ) {\n super();\n this.atomSpacing = 5;\n this.setStyles(config || {});\n }\n\n /**\n * Returns the total duration of the group rendered by this view.\n */\n get totalDuration(): TSU.Num.Fraction {\n return this.group.totalChildDuration;\n }\n\n /**\n * Creates the SVG elements needed for this group view.\n * @param parent The parent SVG element to attach to\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 /**\n * Group views always return false for isLeaf().\n */\n isLeaf(): boolean {\n return false;\n }\n\n /**\n * Refreshes the bounding box of this group.\n * @returns The refreshed bounding box\n */\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.groupElement);\n }\n\n /**\n * Refreshes the minimum size of this group using duration-based width calculation.\n *\n * ## Duration-Based Width Algorithm\n *\n * This algorithm ensures atoms with extended durations receive proportionally\n * more horizontal space. For example, with `\\beatDuration(4)` and input `S 2 R G M`:\n * - S has duration 1, R has duration 2, G has duration 1\n * - R should visually occupy twice the horizontal space of S or G\n *\n * ### Algorithm Steps:\n *\n * 1. **Calculate width per duration unit**: For each atom, compute the visual width\n * needed per unit of duration: `(visualWidth + spacing) / duration`\n *\n * 2. **Find maximum**: Take the maximum width-per-duration across all atoms.\n * This ensures every atom has enough space for its visual content.\n *\n * 3. **Scale by total duration**: Multiply the max width-per-duration by the\n * group's total duration to get the final group width.\n *\n * ### Example:\n * ```\n * Atoms: S(dur=1, width=10px), R(dur=2, width=10px), G(dur=1, width=10px)\n * Spacing: 5px\n *\n * Width per duration:\n * S: (10 + 5) / 1 = 15 px/unit\n * R: (10 + 5) / 2 = 7.5 px/unit\n * G: (10 + 5) / 1 = 15 px/unit\n *\n * Max width per duration: 15 px/unit\n * Total duration: 1 + 2 + 1 = 4 units\n * Group width: 15 * 4 = 60px\n *\n * Positioning:\n * S at x=0 (time 0/4 * 60 = 0)\n * R at x=15 (time 1/4 * 60 = 15)\n * G at x=45 (time 3/4 * 60 = 45)\n * ```\n *\n * @returns The refreshed minimum size\n */\n protected refreshMinSize(): TSU.Geom.Size {\n let maxHeight = 0;\n\n // Step 1: Calculate width per duration unit for each atom\n let minWidthPerDuration = 0;\n this.atomViews.forEach((av) => {\n const ms = av.minSize;\n const dur = av.totalDuration;\n if (!dur.isZero) {\n const durValue = dur.num / dur.den;\n const widthPerDur = (ms.width + this.atomSpacing) / durValue;\n // Step 2: Track maximum width per duration\n minWidthPerDuration = Math.max(minWidthPerDuration, widthPerDur);\n }\n maxHeight = Math.max(maxHeight, ms.height);\n });\n\n // Step 3: Scale by total duration\n const totalDuration = this.group.totalChildDuration;\n const totalDurValue = totalDuration.num / totalDuration.den;\n const totalWidth = minWidthPerDuration * totalDurValue;\n\n return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);\n }\n\n /**\n * Creates an atom view for a specific atom.\n * @param atom The atom to create a view for\n * @returns The created atom view\n */\n abstract createAtomView(atom: Atom): AtomView;\n\n /**\n * Updates the bounds of this group.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\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 /**\n * Refreshes the layout of this group using duration-based positioning.\n *\n * ## Duration-Based Positioning Algorithm\n *\n * Atoms are positioned at x-coordinates proportional to their time offset\n * within the group's total duration. This ensures that atoms with extended\n * durations visually occupy the correct amount of horizontal space.\n *\n * ### Width Source Priority:\n *\n * 1. **Column width** (preferred): If width was set via `setBounds()` from the\n * grid layout system (ColAlign), use that width. This enables global alignment\n * across all beats in the same column.\n *\n * 2. **Minimum size**: Fall back to `minSize.width` calculated by `refreshMinSize()`.\n *\n * ### Positioning Formula:\n * ```\n * xPosition = (timeOffset / totalDuration) * groupWidth\n * ```\n *\n * ### Continuation Markers:\n *\n * When `showContinuationMarkers` is true (default), atoms with duration > 1\n * will have \",\" markers rendered at each additional time slot. For example,\n * an atom with duration 2 will show \"R ,\" instead of \"R \".\n *\n * This helps users visually understand that the note continues through\n * multiple time slots without relying on empty space alone.\n *\n * ### Example:\n * ```\n * Input: S 2 R G (with beatDuration=4)\n * Group width: 60px, Total duration: 4 units\n *\n * Positioning:\n * S at x=0 (time 0, offset 0/4 * 60 = 0)\n * R at x=15 (time 1, offset 1/4 * 60 = 15)\n * \",\" at x=30 (continuation marker for R at time 2)\n * G at x=45 (time 3, offset 3/4 * 60 = 45)\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\n const currY = 0;\n const totalDur = this.group.totalChildDuration;\n\n // Width source priority: column width (for global alignment) > minSize\n const unscaledMinWidth = this.minSize.width / this.scaleFactor;\n const groupWidth = this.hasWidth ? this.width / this.scaleFactor : unscaledMinWidth;\n\n // Clear existing continuation markers before re-rendering\n this.clearContinuationMarkers();\n\n // Position each atom based on its time offset\n let currTime = ZERO;\n this.atomViews.forEach((av, index) => {\n // Calculate where the NOTE GLYPH should appear based on time offset\n const glyphX = totalDur.isZero ? 0 : currTime.timesNum(groupWidth).divby(totalDur).floor;\n // Subtract glyphOffset so left embellishments don't push the glyph past its time position\n // The atom origin is placed earlier, so the glyph ends up at the correct time position\n const xPos = Math.max(0, glyphX - av.glyphOffset);\n av.setBounds(xPos, currY, null, null, true);\n\n // Render continuation markers for atoms with duration > 1\n if (this.showContinuationMarkers && !totalDur.isZero) {\n const atomDur = av.totalDuration;\n const durValue = atomDur.num / atomDur.den;\n if (durValue > 1) {\n // Render one marker at each additional time slot within the atom's duration\n const numMarkers = Math.floor(durValue) - 1;\n for (let i = 1; i <= numMarkers; i++) {\n // Marker time = currTime + (atomDuration * i / floor(duration))\n const markerTime = currTime.plus(atomDur.timesNum(i).divbyNum(Math.floor(durValue)));\n const markerX = markerTime.timesNum(groupWidth).divby(totalDur).floor;\n this.renderContinuationMarker(markerX, currY);\n }\n }\n }\n\n currTime = currTime.plus(av.totalDuration);\n });\n\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n /**\n * Clears all continuation marker elements.\n */\n protected clearContinuationMarkers(): void {\n for (const el of this.continuationMarkerElements) {\n el.remove();\n }\n this.continuationMarkerElements = [];\n }\n\n /**\n * Renders a continuation marker (\",\") at the specified position.\n * @param x X position for the marker\n * @param y Y position for the marker\n */\n protected renderContinuationMarker(x: number, y: number): void {\n const marker = TSU.DOM.createSVGNode(\"text\", {\n parent: this.groupElement,\n attrs: {\n class: \"continuationMarker\",\n x: x.toString(),\n y: y.toString(),\n },\n text: \",\",\n }) as SVGTextElement;\n this.continuationMarkerElements.push(marker);\n }\n\n /**\n * Gets the embellishments for this group.\n */\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n /**\n * Creates the embellishments for this group.\n * @returns An array of embellishments\n */\n protected createEmbelishments(): Embelishment[] {\n return [];\n }\n\n /**\n * Sets the styles for this group.\n * @param config Style configuration object\n */\n setStyles(config: any): void {\n if (\"atomSpacing\" in config) this.atomSpacing = config.atomSpacing;\n if (\"showContinuationMarkers\" in config) this.showContinuationMarkers = config.showContinuationMarkers;\n this.needsLayout = true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":";;;;;;;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;QACd,CAAC;QACD,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;IACvC,CAAC;IAOS,wBAAwB,CAAC,CAAS,EAAE,CAAS;QACrD,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,EAAE;YAC3C,MAAM,EAAE,IAAI,CAAC,YAAY;YACzB,KAAK,EAAE;gBACL,KAAK,EAAE,oBAAoB;gBAC3B,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;gBACf,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;aAChB;YACD,IAAI,EAAE,GAAG;SACV,CAAmB,CAAC;QACrB,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAKD,IAAI,aAAa;QACf,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAMS,mBAAmB;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAMD,SAAS,CAAC,MAAW;QACnB,IAAI,aAAa,IAAI,MAAM;YAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACnE,IAAI,yBAAyB,IAAI,MAAM;YAAE,IAAI,CAAC,uBAAuB,GAAG,MAAM,CAAC,uBAAuB,CAAC;QACvG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;CACF;AAlXD,8BAkXC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { ZERO, Atom, LeafAtom, Group } from \"./core\";\n\n/**\n * Represents an item to be positioned in collision-based layout.\n */\nexport interface CollisionLayoutItem {\n /** Time offset as a fraction (numerator/denominator) */\n timeOffset: TSU.Num.Fraction;\n /** Duration of this item */\n duration: TSU.Num.Fraction;\n /** Width of pre-embellishments (extends left from glyph position) */\n glyphOffset: number;\n /** Minimum width of the item (includes all embellishments and glyph) */\n minWidth: number;\n}\n\n/**\n * Result of collision-based layout for a single item.\n */\nexport interface CollisionLayoutResult {\n /** The calculated x position for the item */\n x: number;\n /** Whether the item was pushed right due to collision */\n wasCollision: boolean;\n}\n\n/**\n * Computes collision-based positions for a sequence of items within a container.\n *\n * ## Algorithm\n *\n * 1. Calculate ideal glyph position: `glyphX = (timeOffset / totalDuration) * containerWidth`\n * 2. Pre-embellishments extend left: `realX = glyphX - glyphOffset`\n * 3. Collision check: if `realX < prevItemEndX`, then `realX = prevItemEndX`\n * 4. Track: `prevItemEndX = realX + minWidth`\n *\n * @param items Items to position (must be in time order)\n * @param totalDuration Total duration of all items\n * @param containerWidth Width of the container to position items within\n * @returns Array of positions for each item\n */\nexport function computeCollisionLayout(\n items: CollisionLayoutItem[],\n totalDuration: TSU.Num.Fraction,\n containerWidth: number,\n): CollisionLayoutResult[] {\n const results: CollisionLayoutResult[] = [];\n let prevItemEndX = 0;\n let currTime = ZERO;\n\n for (const item of items) {\n // 1. Calculate ideal glyph position based on time offset\n const glyphX = totalDuration.isZero ? 0 : currTime.timesNum(containerWidth).divby(totalDuration).floor;\n\n // 2. Pre-embellishments extend left from glyph position\n let realX = glyphX - item.glyphOffset;\n\n // 3. Collision check: push right if overlapping previous item\n const wasCollision = realX < prevItemEndX;\n if (wasCollision) {\n realX = prevItemEndX;\n }\n\n results.push({ x: realX, wasCollision });\n\n // 4. Track end position for next collision check\n prevItemEndX = realX + item.minWidth;\n\n currTime = currTime.plus(item.duration);\n }\n\n return results;\n}\n\n/**\n * Base class for all renderable objects.\n *\n * Shape caches properties like bounding boxes to improve performance,\n * since bounding box calculations can be expensive. This also allows\n * testing layouts and positioning without worrying about implementation details.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n\n /**\n * Note that x and y coordinates are not always the x and y coordinates\n * of the bounding box.\n * E.g., a circle's x and y coordinates are its center point and not the\n * top left corner.\n * These \"main\" coordinates are referred to 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 /** Child shapes contained within this shape */\n children: Shape[] = [];\n\n /**\n * Gets the bounding box of this shape.\n * Calculates it if it hasn't been calculated yet.\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 * Gets the minimum size of this shape.\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 * Refreshes the bounding box of this shape.\n * Called when the shape knows the bbox it is tracking cannot be trusted\n * and has to be refreshed by calling native methods.\n * @returns The refreshed bounding box\n */\n protected abstract refreshBBox(): TSU.Geom.Rect;\n\n /**\n * Refreshes the minimum size of this shape.\n * @returns The refreshed minimum size\n */\n protected abstract refreshMinSize(): TSU.Geom.Size;\n\n /**\n * Updates the bounds of this shape.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\n */\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 /**\n * Invalidates the cached bounds of this shape.\n * Forces recalculation of bounding box and minimum size.\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 bounds of this shape.\n *\n * Note that null and NaN are valid values and mean the following:\n * - null: Don't change the value\n * - NaN: Set the value to null (use the bounding box's value)\n *\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @param applyLayout Whether to apply layout immediately\n * @returns The updated bounds values\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 /**\n * Checks if this shape has an explicit x coordinate.\n */\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n /**\n * Checks if this shape has an explicit y coordinate.\n */\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n /**\n * Checks if this shape has an explicit width.\n */\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n /**\n * Checks if this shape has an explicit height.\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 /**\n * Gets the width of this shape.\n */\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n /**\n * Sets the width of this shape.\n */\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n /**\n * Gets the height of this shape.\n */\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n /**\n * Sets the height of this shape.\n */\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * Refreshes the layout of this shape.\n * Called when bounds or other properties have changed to give the shape an\n * opportunity to layout its children. For shapes with no children this is a no-op.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\n/**\n * Represents an embellishment applied to a musical element.\n */\nexport abstract class Embelishment extends Shape {}\n\n/**\n * A shape that wraps an SVG element.\n * ElementShape provides the base class for all shapes that are rendered as SVG elements.\n */\nexport class ElementShape<T extends SVGGraphicsElement = SVGGraphicsElement> extends Shape {\n /**\n * Creates a new ElementShape.\n * @param element The SVG element this shape wraps\n */\n constructor(public readonly element: T) {\n super();\n }\n\n /**\n * Refreshes the bounding box of this element.\n * @returns The refreshed bounding box\n */\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.element);\n }\n\n /**\n * Refreshes the minimum size of this element.\n * @returns The refreshed minimum size\n */\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n /**\n * Updates the bounds of this element.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\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 /**\n * Refreshes the layout of this element.\n * Updates the element's attributes based on the shape's properties.\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\n/**\n * Base class for views that represent atoms in the notation.\n * AtomView provides the visual representation of an atom.\n */\nexport abstract class AtomView extends Shape {\n /** Nesting depth of this atom in the structure */\n depth = 0;\n /** Index of the role containing this atom */\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 position for vertical alignment */\n baseline: number;\n /** Ascent (space above baseline) */\n ascent: number;\n /** Descent (space below baseline) */\n descent: number;\n /** Height of capital letters */\n capHeight: number;\n /** Space between lines */\n leading: number;\n\n /**\n * Checks if this atom view represents a leaf atom.\n */\n abstract isLeaf(): boolean;\n\n abstract get totalDuration(): TSU.Num.Fraction;\n\n /**\n * Returns the horizontal offset from the atom's origin to where the note glyph starts.\n * This accounts for left embellishments that appear before the note.\n * Used by GroupView to align note glyphs at their correct time positions.\n *\n * Default is 0 (glyph starts at origin). Subclasses with left embellishments\n * should override to return the width of left-side decorations.\n */\n get glyphOffset(): number {\n return 0;\n }\n\n /**\n * Creates the SVG elements needed for this atom view.\n * @param parent The parent SVG element to attach to\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n}\n\n/**\n * A view for leaf atoms (those that cannot contain other atoms).\n */\nexport abstract class LeafAtomView extends AtomView {\n /**\n * Creates a new LeafAtomView.\n * @param leafAtom The leaf atom this view represents\n */\n constructor(public leafAtom: LeafAtom) {\n super();\n }\n\n /**\n * Leaf atom views always return true for isLeaf().\n */\n isLeaf(): boolean {\n return true;\n }\n\n /**\n * Gets a unique identifier for this view based on the atom's UUID.\n */\n get viewId(): number {\n return this.leafAtom.uuid;\n }\n\n /**\n * Returns the total duration of the atom rendered by this view.\n */\n get totalDuration(): TSU.Num.Fraction {\n return this.leafAtom.duration;\n }\n}\n\n/**\n * A view for group atoms that contain multiple child atoms.\n */\nexport abstract class GroupView extends AtomView {\n /** Space between atoms in this group */\n protected atomSpacing: number;\n /** The SVG group element for this view */\n groupElement: SVGGElement;\n /** Views for the atoms in this group */\n protected atomViews: AtomView[] = [];\n private _embelishments: Embelishment[];\n /** Whether this group represents notes by default */\n defaultToNotes = true;\n /** Whether this view needs layout */\n needsLayout = true;\n /** Scale factor for this group */\n scaleFactor = 1.0;\n /**\n * When true, shows continuation markers (\",\") for atoms with duration > 1\n * instead of just leaving empty space.\n * Disabled by default as group bracket lines provide clearer visual boundaries.\n */\n showContinuationMarkers = false;\n /** SVG elements for continuation markers */\n protected continuationMarkerElements: SVGTextElement[] = [];\n /** Actual content width after layout (position of last atom + its width) */\n contentWidth = 0;\n\n /**\n * Creates a new GroupView.\n * @param group The group atom this view represents\n * @param config Optional configuration object\n */\n constructor(\n public group: Group,\n config?: any,\n ) {\n super();\n this.atomSpacing = 2;\n this.setStyles(config || {});\n }\n\n /**\n * Returns the total duration of the group rendered by this view.\n * This returns the group's actual duration (accounting for scaling),\n * not the raw sum of child durations.\n */\n get totalDuration(): TSU.Num.Fraction {\n return this.group.duration;\n }\n\n /**\n * Creates the SVG elements needed for this group view.\n * @param parent The parent SVG element to attach to\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 /**\n * Group views always return false for isLeaf().\n */\n isLeaf(): boolean {\n return false;\n }\n\n /**\n * Refreshes the bounding box of this group.\n * @returns The refreshed bounding box\n */\n protected refreshBBox(): TSU.Geom.Rect {\n return TSU.DOM.svgBBox(this.groupElement);\n }\n\n /**\n * Refreshes the minimum size of this group using duration-based width calculation.\n *\n * ## Duration-Based Width Algorithm\n *\n * This algorithm ensures atoms with extended durations receive proportionally\n * more horizontal space. For example, with `\\beatDuration(4)` and input `S 2 R G M`:\n * - S has duration 1, R has duration 2, G has duration 1\n * - R should visually occupy twice the horizontal space of S or G\n *\n * ### Algorithm Steps:\n *\n * 1. **Calculate width per duration unit**: For each atom, compute the visual width\n * needed per unit of duration: `(visualWidth + spacing) / duration`\n *\n * 2. **Find maximum**: Take the maximum width-per-duration across all atoms.\n * This ensures every atom has enough space for its visual content.\n *\n * 3. **Scale by total duration**: Multiply the max width-per-duration by the\n * group's total duration to get the final group width.\n *\n * ### Example:\n * ```\n * Atoms: S(dur=1, width=10px), R(dur=2, width=10px), G(dur=1, width=10px)\n * Spacing: 5px\n *\n * Width per duration:\n * S: (10 + 5) / 1 = 15 px/unit\n * R: (10 + 5) / 2 = 7.5 px/unit\n * G: (10 + 5) / 1 = 15 px/unit\n *\n * Max width per duration: 15 px/unit\n * Total duration: 1 + 2 + 1 = 4 units\n * Group width: 15 * 4 = 60px\n *\n * Positioning:\n * S at x=0 (time 0/4 * 60 = 0)\n * R at x=15 (time 1/4 * 60 = 15)\n * G at x=45 (time 3/4 * 60 = 45)\n * ```\n *\n * @returns The refreshed minimum size\n */\n protected refreshMinSize(): TSU.Geom.Size {\n let maxHeight = 0;\n\n // Step 1: Calculate width per duration unit for each atom\n let minWidthPerDuration = 0;\n this.atomViews.forEach((av) => {\n const ms = av.minSize;\n const dur = av.totalDuration;\n if (!dur.isZero) {\n const durValue = dur.num / dur.den;\n const widthPerDur = (ms.width + this.atomSpacing) / durValue;\n // Step 2: Track maximum width per duration\n minWidthPerDuration = Math.max(minWidthPerDuration, widthPerDur);\n }\n maxHeight = Math.max(maxHeight, ms.height);\n });\n\n // Step 3: Scale by total duration\n const totalDuration = this.group.totalChildDuration;\n const totalDurValue = totalDuration.num / totalDuration.den;\n // Subtract one atomSpacing since we don't need spacing after the last atom\n const totalWidth = Math.max(0, minWidthPerDuration * totalDurValue - this.atomSpacing);\n\n return new TSU.Geom.Size(totalWidth * this.scaleFactor, maxHeight * this.scaleFactor);\n }\n\n /**\n * Creates an atom view for a specific atom.\n * @param atom The atom to create a view for\n * @returns The created atom view\n */\n abstract createAtomView(atom: Atom): AtomView;\n\n /**\n * Updates the bounds of this group.\n * @param x New x coordinate, or null to keep current value\n * @param y New y coordinate, or null to keep current value\n * @param w New width, or null to keep current value\n * @param h New height, or null to keep current value\n * @returns The updated bounds values\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 /**\n * Refreshes the layout of this group using collision-based positioning.\n *\n * ## Collision-Based Layout Algorithm\n *\n * Atoms are positioned using time-based positioning with collision avoidance.\n * Each atom starts at its ideal time-based position, but is pushed right if\n * it would overlap with the previous atom (including embellishments).\n *\n * ### Algorithm:\n * ```\n * 1. Calculate ideal glyph position: glyphX = (time / totalDuration) * groupWidth\n * 2. Pre-embellishments extend left: realX = glyphX - preEmbellishmentWidth\n * 3. Collision check: if (realX < prevNoteEndX) realX = prevNoteEndX\n * 4. Position the atom at realX\n * 5. Track: prevNoteEndX = realX + atom.minSize.width\n * ```\n *\n * ### Width Source Priority:\n *\n * 1. **Column width** (preferred): If width was set via `setBounds()` from the\n * grid layout system (ColAlign), use that width. This enables global alignment\n * across all beats in the same column.\n *\n * 2. **Minimum size**: Fall back to `minSize.width` calculated by `refreshMinSize()`.\n *\n * ### Continuation Markers:\n *\n * When `showContinuationMarkers` is true (default), atoms with duration > 1\n * will have \",\" markers rendered at each additional time slot. For example,\n * an atom with duration 2 will show \"R ,\" instead of \"R \".\n *\n * ### Example (no collisions):\n * ```\n * Input: S R G M (equal duration, no embellishments)\n * Group width: 60px, Total duration: 4 units\n *\n * Positioning:\n * S at x=0 (time 0/4 * 60 = 0)\n * R at x=15 (time 1/4 * 60 = 15)\n * G at x=30 (time 2/4 * 60 = 30)\n * M at x=45 (time 3/4 * 60 = 45)\n * ```\n *\n * ### Example (with collision):\n * ```\n * Input: [Jaaru+S] R (S has 10px pre-embellishment, each atom 15px wide)\n * Group width: 60px, Total duration: 2 units\n *\n * Without collision avoidance:\n * S.glyphX = 0, S.realX = 0 - 10 = -10 (clamped to 0)\n * R.glyphX = 30, R overlaps with S\n *\n * With collision avoidance:\n * S at x=0 (prevNoteEndX becomes 15)\n * R.glyphX = 30, R.realX = 30 - 0 = 30\n * 30 >= 15, no collision, R at x=30\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\n // BASELINE ALIGNMENT: Position atoms at bottom of allocated height.\n // This ensures atoms align across beats with different bracket heights.\n // When beats in the same row have different content heights (e.g., due to\n // nested group brackets), all beats get the same allocated height from the\n // grid. By positioning content at the bottom, atom baselines align.\n const unscaledContentHeight = this.minSize.height / this.scaleFactor;\n const unscaledAllocatedHeight = this.hasHeight ? this.height / this.scaleFactor : unscaledContentHeight;\n const currY = unscaledAllocatedHeight - unscaledContentHeight;\n\n const totalDur = this.group.totalChildDuration;\n\n // Width source priority: column width (for global alignment) > minSize\n const unscaledMinWidth = this.minSize.width / this.scaleFactor;\n const groupWidth = this.hasWidth ? this.width / this.scaleFactor : unscaledMinWidth;\n\n // Clear existing continuation markers before re-rendering\n this.clearContinuationMarkers();\n\n // Position each atom using collision-based layout\n // Atoms start at their time-based position, but are pushed right if they would\n // overlap with the previous atom (including embellishments)\n let currTime = ZERO;\n let prevNoteEndX = 0;\n this.atomViews.forEach((av, index) => {\n // 1. Calculate ideal glyph position based on time offset\n const glyphX = totalDur.isZero ? 0 : currTime.timesNum(groupWidth).divby(totalDur).floor;\n\n // 2. Pre-embellishments extend left from glyph position\n // realX is where the atom origin should be placed\n let realX = glyphX - av.glyphOffset;\n\n // 3. Collision check: push right if overlapping previous atom\n if (realX < prevNoteEndX) {\n realX = prevNoteEndX;\n }\n\n // 4. Position the atom\n av.setBounds(realX, currY, null, null, true);\n\n // 5. Track end position for next collision check\n // For groups, use contentWidth (actual content) instead of bbox.width (which may include extra space).\n // For leaf atoms, use bbox.width.\n const avWidth = (av as any).contentWidth || av.bbox.width;\n prevNoteEndX = realX + avWidth;\n\n // Render continuation markers for atoms with duration > 1\n if (this.showContinuationMarkers && !totalDur.isZero) {\n const atomDur = av.totalDuration;\n const durValue = atomDur.num / atomDur.den;\n if (durValue > 1) {\n // Render one marker at each additional time slot within the atom's duration\n const numMarkers = Math.floor(durValue) - 1;\n for (let i = 1; i <= numMarkers; i++) {\n // Marker time = currTime + (atomDuration * i / floor(duration))\n const markerTime = currTime.plus(atomDur.timesNum(i).divbyNum(Math.floor(durValue)));\n const markerX = markerTime.timesNum(groupWidth).divby(totalDur).floor;\n this.renderContinuationMarker(markerX, currY);\n }\n }\n }\n\n currTime = currTime.plus(av.totalDuration);\n });\n\n // Track actual content width for bracket sizing\n this.contentWidth = prevNoteEndX;\n\n this.invalidateBounds();\n for (const e of this.embelishments) e.refreshLayout();\n this.invalidateBounds();\n }\n\n /**\n * Clears all continuation marker elements.\n */\n protected clearContinuationMarkers(): void {\n for (const el of this.continuationMarkerElements) {\n el.remove();\n }\n this.continuationMarkerElements = [];\n }\n\n /**\n * Renders a continuation marker (\",\") at the specified position.\n * @param x X position for the marker\n * @param y Y position for the marker\n */\n protected renderContinuationMarker(x: number, y: number): void {\n const marker = TSU.DOM.createSVGNode(\"text\", {\n parent: this.groupElement,\n attrs: {\n class: \"continuationMarker\",\n x: x.toString(),\n y: y.toString(),\n },\n text: \",\",\n }) as SVGTextElement;\n this.continuationMarkerElements.push(marker);\n }\n\n /**\n * Gets the embellishments for this group.\n */\n get embelishments(): Embelishment[] {\n if (!this._embelishments) {\n this._embelishments = this.createEmbelishments();\n }\n return this._embelishments;\n }\n\n /**\n * Creates the embellishments for this group.\n * @returns An array of embellishments\n */\n protected createEmbelishments(): Embelishment[] {\n return [];\n }\n\n /**\n * Sets the styles for this group.\n * @param config Style configuration object\n */\n setStyles(config: any): void {\n if (\"atomSpacing\" in config) this.atomSpacing = config.atomSpacing;\n if (\"showContinuationMarkers\" in config) this.showContinuationMarkers = config.showContinuationMarkers;\n this.needsLayout = true;\n }\n}\n"]}
|
package/lib/esm/beats.js
CHANGED
|
@@ -144,7 +144,7 @@ export class BeatColumn extends ColAlign {
|
|
|
144
144
|
this.offset = offset;
|
|
145
145
|
this.endOffset = endOffset;
|
|
146
146
|
this.markerType = markerType;
|
|
147
|
-
this.atomSpacing =
|
|
147
|
+
this.atomSpacing = 2;
|
|
148
148
|
offset = offset.factorized;
|
|
149
149
|
endOffset = endOffset.factorized;
|
|
150
150
|
this.key = BeatColumn.keyFor(offset, endOffset, markerType);
|
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,QAAQ,EAAU,KAAK,EAAc,KAAK,EAAQ,MAAM,IAAI,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAW,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAoB,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG/D,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAMjC,MAAM,OAAO,IAAI;IAqBf,YACkB,KAAa,EACb,IAAU,EACV,MAAgB,EAChB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,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\";\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"]}
|
|
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,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAW,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAoB,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG/D,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAMjC,MAAM,OAAO,IAAI;IAqBf,YACkB,KAAa,EACb,IAAU,EACV,MAAgB,EAChB,QAAkB,EAClB,QAAgB,EAChB,SAAiB,E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W,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\";\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 = 2;\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"]}
|
package/lib/esm/block.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Entity } from "./entity";
|
|
|
3
3
|
import { Cycle } from "./cycle";
|
|
4
4
|
import { Line } from "./core";
|
|
5
5
|
import { LayoutParams } from "./layouts";
|
|
6
|
+
import { BlockObserver } from "./events";
|
|
6
7
|
export declare class RoleDef {
|
|
7
8
|
name: string;
|
|
8
9
|
notesOnly: boolean;
|
|
@@ -31,7 +32,10 @@ export declare class Block extends Entity {
|
|
|
31
32
|
private _parentBlock;
|
|
32
33
|
protected _currRoleDef: TSU.Nullable<RoleDef>;
|
|
33
34
|
protected _currentLine: TSU.Nullable<Line>;
|
|
35
|
+
private _observers;
|
|
34
36
|
constructor(blockType: string, parent?: TSU.Nullable<Block>, name?: TSU.Nullable<string>);
|
|
37
|
+
addObserver(observer: BlockObserver<BlockItem, Block>): () => void;
|
|
38
|
+
removeObserver(observer: BlockObserver<BlockItem, Block>): void;
|
|
35
39
|
children(): BlockItem[];
|
|
36
40
|
get parentBlock(): TSU.Nullable<Block>;
|
|
37
41
|
get cycle(): TSU.Nullable<Cycle>;
|