notations 1.0.7 → 1.0.9
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/LICENSE +674 -0
- package/README.md +3 -2
- package/dist/notations.umd.js +127 -88
- package/dist/notations.umd.min.js +6 -13
- package/dist/notations.umd.min.js.map +1 -1
- package/lib/cjs/beats.d.ts +2 -0
- package/lib/cjs/beats.js +38 -20
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/beatview.d.ts +2 -2
- package/lib/cjs/beatview.js +3 -1
- package/lib/cjs/beatview.js.map +1 -1
- package/lib/cjs/carnatic/atomviews.js +18 -1
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/beatviews.d.ts +1 -1
- package/lib/cjs/carnatic/beatviews.js +4 -1
- package/lib/cjs/carnatic/beatviews.js.map +1 -1
- package/lib/cjs/core.d.ts +13 -7
- package/lib/cjs/core.js +28 -13
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/entity.d.ts +12 -0
- package/lib/cjs/entity.js +18 -0
- package/lib/cjs/entity.js.map +1 -1
- package/lib/cjs/iterators.js +7 -5
- package/lib/cjs/iterators.js.map +1 -1
- package/lib/cjs/notation.d.ts +8 -9
- package/lib/cjs/notation.js +2 -11
- package/lib/cjs/notation.js.map +1 -1
- package/lib/cjs/parser.d.ts +2 -3
- package/lib/cjs/parser.js +10 -37
- package/lib/cjs/parser.js.map +1 -1
- package/lib/cjs/shapes.js +2 -0
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/cjs/web/components/DockViewPlayground.js +8 -6
- package/lib/cjs/web/components/DockViewPlayground.js.map +1 -1
- package/lib/esm/beats.d.ts +2 -0
- package/lib/esm/beats.js +38 -20
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/beatview.d.ts +2 -2
- package/lib/esm/beatview.js +3 -1
- package/lib/esm/beatview.js.map +1 -1
- package/lib/esm/carnatic/atomviews.js +18 -1
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/beatviews.d.ts +1 -1
- package/lib/esm/carnatic/beatviews.js +4 -1
- package/lib/esm/carnatic/beatviews.js.map +1 -1
- package/lib/esm/core.d.ts +13 -7
- package/lib/esm/core.js +29 -14
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/entity.d.ts +12 -0
- package/lib/esm/entity.js +17 -0
- package/lib/esm/entity.js.map +1 -1
- package/lib/esm/iterators.js +7 -5
- package/lib/esm/iterators.js.map +1 -1
- package/lib/esm/notation.d.ts +8 -9
- package/lib/esm/notation.js +3 -12
- package/lib/esm/notation.js.map +1 -1
- package/lib/esm/parser.d.ts +2 -3
- package/lib/esm/parser.js +10 -37
- package/lib/esm/parser.js.map +1 -1
- package/lib/esm/shapes.js +3 -1
- package/lib/esm/shapes.js.map +1 -1
- package/lib/esm/web/components/DockViewPlayground.js +9 -7
- package/lib/esm/web/components/DockViewPlayground.js.map +1 -1
- package/package.json +1 -1
package/lib/esm/entity.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
export function ParamsMixin(Base) {
|
|
2
|
+
class Mixed extends Base {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.params = [];
|
|
6
|
+
}
|
|
7
|
+
getParam(key) {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
return (_b = (_a = this.params.find((p) => p.key === key)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
|
|
10
|
+
}
|
|
11
|
+
getParamAt(index) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
return (_b = (_a = this.params[index]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return Mixed;
|
|
17
|
+
}
|
|
1
18
|
export class Entity {
|
|
2
19
|
constructor(config = null) {
|
|
3
20
|
this.TYPE = "Entity";
|
package/lib/esm/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":"AAqBA,MAAM,UAAU,WAAW,CAAoD,IAAO;IACpF,MAAe,KAAM,SAAQ,IAAI;QAAjC;;YACE,WAAM,GAAe,EAAE,CAAC;QAmB1B,CAAC;QAZC,QAAQ,CAAC,GAAW;;YAClB,OAAO,MAAA,MAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,0CAAE,KAAK,mCAAI,IAAI,CAAC;QAC/D,CAAC;QAOD,UAAU,CAAC,KAAa;;YACtB,OAAO,MAAA,MAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0CAAE,KAAK,mCAAI,IAAI,CAAC;QAC3C,CAAC;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAgBD,MAAM,OAAO,MAAM;IAmBjB,YAAY,SAAc,IAAI;QAlBrB,SAAI,GAAW,QAAQ,CAAC;QAIxB,SAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAEvB,YAAO,GAAyB,IAAI,CAAC;QAMrC,mBAAc,GAAG,KAAK,CAAC;QAO/B,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QACtB,IAAI,MAAM,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC7E,CAAC;IAOD,YAAY;QACV,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAMD,aAAa;QACX,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAKD,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAKD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAMD,SAAS,CAAC,MAA4B;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAOD,UAAU;QACR,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAMD,QAAQ;QACN,OAAO,eAAe,IAAI,CAAC,IAAI,GAAG,CAAC;IACrC,CAAC;IAQD,MAAM,CAAC,OAAa,EAAE,MAAM,GAAG,KAAK;QAClC,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IAUD,KAAK;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjB,OAAO,GAAG,CAAC;IACb,CAAC;IAMD,MAAM,CAAC,OAAa;IAEpB,CAAC;IAMS,WAAW;QACnB,OAAO,IAAK,IAAI,CAAC,WAAmB,EAAE,CAAC;IACzC,CAAC;;AAtHc,cAAO,GAAG,CAAC,AAAJ,CAAK;AA6H7B,MAAM,OAAgB,WAAY,SAAQ,MAAM;IAAhD;;QACW,SAAI,GAAW,aAAa,CAAC;IAgBxC,CAAC;IAHC,MAAM,CAAC,OAAa;QAClB,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\n\n/**\n * Parameter type for commands and markers.\n * Used by both Command and Marker classes.\n */\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\n\n/**\n * Interface for entities that have parameters.\n */\nexport interface HasParams {\n params: CmdParam[];\n}\n\n/**\n * Mixin that adds parameter handling to a class.\n * Provides getParam and getParamAt methods.\n * Works with both concrete and abstract base classes.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function ParamsMixin<T extends abstract new (...args: any[]) => object>(Base: T) {\n abstract class Mixed extends Base implements HasParams {\n params: CmdParam[] = [];\n\n /**\n * Gets a parameter value by key.\n * @param key The parameter key to look for\n * @returns The parameter value, or null if not found\n */\n getParam(key: string): any {\n return this.params.find((p) => p.key === key)?.value ?? null;\n }\n\n /**\n * Gets a parameter value by index (for positional params).\n * @param index The parameter index\n * @returns The parameter value, or null if not found\n */\n getParamAt(index: number): any {\n return this.params[index]?.value ?? null;\n }\n }\n return Mixed;\n}\n\n/**\n * A common Entity base class with support for unique IDs, parent references,\n * copying, and debug info. This serves as the foundation for all entities\n * in the notation system.\n *\n * Note: Child management is intentionally NOT included here. Each container type\n * (BlockContainer, Line, Group, etc.) defines its own child management with\n * appropriate types.\n *\n * Observer Pattern:\n * Each observable entity subclass (Group, Role, Line, Block) manages its own\n * typed observer list. This provides type safety and clear contracts between\n * observables and observers.\n */\nexport class Entity {\n readonly TYPE: string = \"Entity\";\n\n private static counter = 0;\n /** Unique identifier for this entity */\n readonly uuid = Entity.counter++;\n /** Parent entity in the tree hierarchy */\n protected _parent: TSU.Nullable<Entity> = null;\n\n /**\n * Whether events/observer notifications are enabled for this entity.\n * Subclasses check this flag before notifying observers.\n */\n protected _eventsEnabled = false;\n\n /**\n * Creates a new Entity.\n * @param config Optional configuration object\n */\n constructor(config: any = null) {\n config = config || {};\n if (config.metadata) throw new Error(\"See where metadata is being passed\");\n }\n\n /**\n * Enables observer notifications for this entity.\n * Call this to activate change notifications on entities that support them.\n * @returns This entity for method chaining\n */\n enableEvents(): this {\n this._eventsEnabled = true;\n return this;\n }\n\n /**\n * Disables observer notifications for this entity.\n * @returns This entity for method chaining\n */\n disableEvents(): this {\n this._eventsEnabled = false;\n return this;\n }\n\n /**\n * Checks if events/observer notifications are enabled.\n */\n get eventsEnabled(): boolean {\n return this._eventsEnabled;\n }\n\n /**\n * Gets the parent entity.\n */\n get parent(): TSU.Nullable<Entity> {\n return this._parent;\n }\n\n /**\n * Sets the parent entity.\n * @param parent The parent entity to set\n */\n setParent(parent: TSU.Nullable<Entity>): void {\n this._parent = parent;\n }\n\n /**\n * Returns a debug-friendly representation of this entity.\n * Usually overridden by children to add more debug info.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { type: this.TYPE };\n }\n\n /**\n * Returns a simple string representation of this Entity.\n * @returns A string representation\n */\n toString(): string {\n return `Entity(id = ${this.uuid})`;\n }\n\n /**\n * Checks if this Entity is equal to another Entity.\n * @param another The Entity to compare with\n * @param expect Optional parameter\n * @returns True if the Entities are equal, false otherwise\n */\n equals(another: this, expect = false): boolean {\n if (this.TYPE != another.TYPE) return false;\n return true;\n }\n\n /**\n * Creates a clone of this entity.\n * Cloning is a two-part process:\n * 1. Creation of a new instance via this.newInstance()\n * 2. Copying of data into the new instance via this.copyTo()\n *\n * @returns A new instance of the same type with the same properties\n */\n clone(): this {\n const out = this.newInstance();\n this.copyTo(out);\n return out;\n }\n\n /**\n * Copies information about this instance into another instance of the same type.\n * @param another The target instance to copy properties to\n */\n copyTo(another: this): void {\n // Subclasses override to copy their specific properties\n }\n\n /**\n * First part of the cloning process where the instance is created.\n * @returns A new instance of the same type\n */\n protected newInstance(): this {\n return new (this.constructor as any)();\n }\n}\n\n/**\n * Music is all about timing! TimedEntities are base of all entities that\n * have a duration. This is an abstract class that all timed entities inherit from.\n */\nexport abstract class TimedEntity extends Entity {\n readonly TYPE: string = \"TimedEntity\";\n\n /**\n * Gets the duration of this entity in terms of beats.\n * By default, entity durations are readonly.\n */\n abstract get duration(): TSU.Num.Fraction;\n\n /**\n * Checks if this TimedEntity is equal to another TimedEntity.\n * @param another The TimedEntity to compare with\n * @returns True if the TimedEntities are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.duration.equals(another.duration);\n }\n}\n"]}
|
package/lib/esm/iterators.js
CHANGED
|
@@ -109,7 +109,7 @@ export class WindowIterator {
|
|
|
109
109
|
next() {
|
|
110
110
|
const out = this.peek();
|
|
111
111
|
this.peeked = null;
|
|
112
|
-
if (out != null) {
|
|
112
|
+
if (out != null && out.participatesInTiming) {
|
|
113
113
|
this.currOffset = this.currOffset.plus(out.duration, true);
|
|
114
114
|
}
|
|
115
115
|
return out;
|
|
@@ -130,10 +130,12 @@ export class WindowIterator {
|
|
|
130
130
|
const next = this.next();
|
|
131
131
|
TSU.assert(next != null, "Next cannot be null here");
|
|
132
132
|
out.push(next);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
if (next.participatesInTiming) {
|
|
134
|
+
const spillOver = next.splitAt(remaining);
|
|
135
|
+
remaining = remaining.minus(next.duration);
|
|
136
|
+
if (spillOver != null) {
|
|
137
|
+
this.atomQueue.pushFront(spillOver);
|
|
138
|
+
}
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
return [out, remaining.isZero];
|
package/lib/esm/iterators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/iterators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAkB,KAAK,EAAS,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAUhE,MAAM,OAAO,QAAS,SAAQ,WAAW;IAoBvC,YACS,IAAc,EACrB,SAAc,IAAI;QAElB,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QAHxB,SAAI,GAAJ,IAAI,CAAU;QApBd,SAAI,GAAG,UAAU,CAAC;QAwBzB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAA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,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;oBACtC,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC7C,CAAC;qBAAM,CAAC;oBAGN,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;oBACzE,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;oBAC1B,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { TimedEntity } from \"./entity\";\nimport { Atom, LeafAtom, Space, Group, AtomType } from \"./core\";\n\ntype Fraction = TSU.Num.Fraction;\n// type FlatAtom2 = [atom: Atom, duration: TSU.Num.Fraction, offset: TSU.Num.Fraction];\n\n/**\n * Represents a flattened atom with timing information.\n * FlatAtom is used to process nested atom structures in a flat, sequential manner\n * with proper timing information.\n */\nexport class FlatAtom extends TimedEntity {\n readonly TYPE = \"FlatAtom\";\n\n /** Nesting depth of this atom in the original structure */\n depth: number;\n\n /** Duration of this atom */\n duration: TSU.Num.Fraction;\n\n /** Time offset of this atom */\n offset: TSU.Num.Fraction;\n\n /** Whether this atom is a continuation of a previous atom */\n private isContinuation: boolean;\n\n /**\n * Creates a new FlatAtom.\n * @param atom The leaf atom this flat atom represents\n * @param config Optional configuration with depth, duration, offset, and continuation info\n */\n constructor(\n public atom: LeafAtom,\n config: any = null,\n ) {\n super((config = config || {}));\n this.depth = config.depth || 0;\n this.duration = config.duration || atom.duration;\n this.offset = config.offset || TSU.Num.Fraction.ZERO;\n this.isContinuation = \"isContinuation\" in config ? config.isContinuation : false;\n }\n\n /**\n * Gets the end offset of this atom (offset + duration).\n */\n get endOffset(): TSU.Num.Fraction {\n return this.offset.plus(this.duration);\n }\n\n /**\n * Returns a debug-friendly representation of this FlatAtom.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = {\n ...super.debugValue(),\n atom: this.atom.debugValue(),\n duration: this.duration.toString(),\n offset: this.offset.toString(),\n depth: this.depth,\n };\n if (this.isContinuation) out.isContinuation = true;\n return out;\n }\n}\n\n/**\n * A nested atom iterator that returns one atom at a time at the leaf-most level.\n * If we have a Group (or nested Groups) only the leaf atoms are returned as if\n * in an in-order traversal, thus ensuring time order of atoms.\n */\nexport class AtomIterator {\n private atomQueue = new TSU.Lists.List<[Atom, number, Fraction]>();\n private currOffset = TSU.Num.Fraction.ZERO;\n private peeked: TSU.Nullable<FlatAtom> = null;\n\n /**\n * Creates a new AtomIterator with optional initial atoms.\n * @param atoms Initial atoms to iterate through\n */\n constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\n * @param atoms The atoms to add to the queue\n * @returns This iterator instance for method chaining\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add([atom, 0, atom.duration]);\n }\n return this;\n }\n\n /**\n * Gets the next atom in the sequence and advances the iterator.\n * @returns The next FlatAtom, or null if no more atoms are available\n */\n next(): TSU.Nullable<FlatAtom> {\n const out = this.peek();\n this.peeked = null;\n if (out != null) {\n this.currOffset = this.currOffset.plus(out.duration).factorized;\n }\n return out;\n }\n\n /**\n * Peeks at the next atom without advancing the iterator.\n * @returns The next FlatAtom, or null if no more atoms are available\n */\n peek(): TSU.Nullable<FlatAtom> {\n if (this.peeked == null) {\n if (this.hasNext) {\n const [nextAtom, nextDepth, nextDuration] = this.atomQueue.popFront();\n this.peeked = new FlatAtom(nextAtom as LeafAtom, {\n depth: nextDepth,\n offset: this.currOffset,\n duration: nextDuration,\n });\n }\n }\n return this.peeked;\n }\n\n /**\n * Checks if more atoms are available in this iterator.\n * This may process group atoms to find the next leaf atom.\n */\n get hasNext(): boolean {\n while (this.atomQueue.first != null) {\n // Get from front of queue\n const [nextAtom, nextDepth, nextDuration] = this.atomQueue.first.value;\n if (nextAtom.TYPE != AtomType.GROUP) {\n return true;\n } else {\n this.atomQueue.popFront();\n const group = nextAtom as Group;\n for (const child of group.atoms.reversedValues()) {\n this.atomQueue.pushFront([\n child,\n nextDepth + 1,\n nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,\n ]);\n }\n }\n }\n return false;\n }\n\n /**\n * Gets the atom with the minimum offset from multiple iterators.\n * @param iterators An array of AtomIterators to compare\n * @returns A tuple containing the index of the selected iterator and its next atom\n */\n static getMin(iterators: AtomIterator[]): [number, FlatAtom] {\n let currRole = -1;\n let currAtom: TSU.Nullable<FlatAtom> = null;\n for (let ri = 0; ri < iterators.length; ri++) {\n const flatAtom = iterators[ri].peek();\n if (flatAtom != null) {\n if (currAtom == null || flatAtom.offset.cmp(currAtom.offset) < 0) {\n currRole = ri;\n currAtom = flatAtom;\n }\n }\n }\n if (currRole >= 0) {\n iterators[currRole].next();\n }\n return [currRole, currAtom!];\n }\n}\n\n/**\n * An iterator that provides atoms within specified time windows.\n * WindowIterator allows fetching atoms to cover a specific duration,\n * handling the splitting of atoms if necessary.\n */\nexport class WindowIterator {\n private atomQueue = new TSU.Lists.List<Atom>();\n private currOffset = TSU.Num.Fraction.ZERO;\n private peeked: TSU.Nullable<Atom> = null;\n\n /**\n * Creates a new WindowIterator with optional initial atoms.\n * @param atoms Initial atoms to iterate through\n */\n constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be served by this iterator.\n * @param atoms The atoms to add to the queue\n * @returns This iterator instance for method chaining\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add(atom);\n }\n return this;\n }\n\n /**\n * Gets the next atom in the sequence and advances the iterator.\n * @returns The next Atom, or null if no more atoms are available\n */\n next(): TSU.Nullable<Atom> {\n const out = this.peek();\n this.peeked = null;\n if (out != null) {\n this.currOffset = this.currOffset.plus(out.duration, true);\n }\n return out;\n }\n\n /**\n * Peeks at the next atom without advancing the iterator.\n * @returns The next Atom, or null if no more atoms are available\n */\n peek(): TSU.Nullable<Atom> {\n if (this.peeked == null && this.hasMore) {\n this.peeked = this.atomQueue.popFront();\n }\n return this.peeked;\n }\n\n /**\n * Checks if more atoms are available in this iterator.\n */\n get hasMore(): boolean {\n return !this.atomQueue.isEmpty;\n }\n\n /**\n * Gets atoms to cover the specified duration.\n *\n * If the number of atoms left in the iterator is 0, an empty list\n * is returned. Otherwise, the duration of atoms returned will cover\n * the given duration even if padding with Space atoms is necessary.\n *\n * @param duration The duration to cover\n * @returns A tuple containing the array of atoms and whether the full duration was filled\n */\n get(duration: TSU.Num.Fraction): [Atom[], boolean] {\n const out: Atom[] = [];\n let remaining = duration;\n while (remaining.isGTNum(0) && this.hasMore) {\n const next = this.next();\n TSU.assert(next != null, \"Next cannot be null here\");\n out.push(next);\n const spillOver = next.splitAt(remaining);\n remaining = remaining.minus(next.duration);\n if (spillOver != null) {\n // push the spill over to the front of the queue to be\n // picked up on the next \"get\" call\n this.atomQueue.pushFront(spillOver);\n }\n }\n return [out, remaining.isZero];\n }\n}\n\n/**\n * An iterator that provides atoms with specific durations.\n * DurationIterator ensures that atoms fit within specified duration windows,\n * splitting atoms if necessary to fit.\n */\nexport class DurationIterator {\n private atomIterator: AtomIterator;\n private spillOver: TSU.Nullable<FlatAtom> = null;\n\n /**\n * Creates a new DurationIterator.\n * @param atomIterator The AtomIterator to use as a source of atoms\n */\n constructor(atomIterator: AtomIterator) {\n this.atomIterator = atomIterator;\n }\n\n /**\n * Checks if more atoms are available in this iterator.\n */\n get hasMore(): boolean {\n if (this.spillOver != null) {\n return true;\n }\n return this.atomIterator.hasNext;\n }\n\n /**\n * Gets atoms to cover the specified duration.\n *\n * If the number of atoms left in the iterator is 0, an empty list\n * is returned. Otherwise, the duration of atoms returned will cover\n * the given duration even if padding with Space atoms is necessary.\n *\n * @param duration The duration to cover\n * @returns A tuple containing the array of FlatAtoms and whether the full duration was filled\n */\n get(duration: TSU.Num.Fraction): [FlatAtom[], boolean] {\n const iter = this.atomIterator;\n const out: FlatAtom[] = [];\n let remaining = duration;\n while (remaining.isGTNum(0)) {\n const next = this.spillOver == null ? iter.next() : this.spillOver;\n this.spillOver = null;\n if (next == null) {\n // stop here\n break;\n } else {\n out.push(next);\n if (next.duration.cmp(remaining) <= 0) {\n remaining = remaining.minus(next.duration);\n } else {\n // Next leaf atom is > duration\n // so split it into two\n this.spillOver = new FlatAtom(new Space(next.duration.minus(remaining)));\n next.duration = remaining;\n remaining = TSU.Num.Fraction.ZERO;\n }\n }\n }\n return [out, remaining.isZero];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/iterators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAkB,KAAK,EAAS,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAUhE,MAAM,OAAO,QAAS,SAAQ,WAAW;IAoBvC,YACS,IAAc,EACrB,SAAc,IAAI;QAElB,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QAHxB,SAAI,GAAJ,IAAI,CAAU;QApBd,SAAI,GAAG,UAAU,CAAC;QAwBzB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,gBAAg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AAS,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC7C,CAAC;qBAAM,CAAC;oBAGN,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;oBACzE,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;oBAC1B,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { TimedEntity } from \"./entity\";\nimport { Atom, LeafAtom, Space, Group, AtomType } from \"./core\";\n\ntype Fraction = TSU.Num.Fraction;\n// type FlatAtom2 = [atom: Atom, duration: TSU.Num.Fraction, offset: TSU.Num.Fraction];\n\n/**\n * Represents a flattened atom with timing information.\n * FlatAtom is used to process nested atom structures in a flat, sequential manner\n * with proper timing information.\n */\nexport class FlatAtom extends TimedEntity {\n readonly TYPE = \"FlatAtom\";\n\n /** Nesting depth of this atom in the original structure */\n depth: number;\n\n /** Duration of this atom */\n duration: TSU.Num.Fraction;\n\n /** Time offset of this atom */\n offset: TSU.Num.Fraction;\n\n /** Whether this atom is a continuation of a previous atom */\n private isContinuation: boolean;\n\n /**\n * Creates a new FlatAtom.\n * @param atom The leaf atom this flat atom represents\n * @param config Optional configuration with depth, duration, offset, and continuation info\n */\n constructor(\n public atom: LeafAtom,\n config: any = null,\n ) {\n super((config = config || {}));\n this.depth = config.depth || 0;\n this.duration = config.duration || atom.duration;\n this.offset = config.offset || TSU.Num.Fraction.ZERO;\n this.isContinuation = \"isContinuation\" in config ? config.isContinuation : false;\n }\n\n /**\n * Gets the end offset of this atom (offset + duration).\n */\n get endOffset(): TSU.Num.Fraction {\n return this.offset.plus(this.duration);\n }\n\n /**\n * Returns a debug-friendly representation of this FlatAtom.\n * @returns An object containing debug information\n */\n debugValue(): any {\n const out = {\n ...super.debugValue(),\n atom: this.atom.debugValue(),\n duration: this.duration.toString(),\n offset: this.offset.toString(),\n depth: this.depth,\n };\n if (this.isContinuation) out.isContinuation = true;\n return out;\n }\n}\n\n/**\n * A nested atom iterator that returns one atom at a time at the leaf-most level.\n * If we have a Group (or nested Groups) only the leaf atoms are returned as if\n * in an in-order traversal, thus ensuring time order of atoms.\n */\nexport class AtomIterator {\n private atomQueue = new TSU.Lists.List<[Atom, number, Fraction]>();\n private currOffset = TSU.Num.Fraction.ZERO;\n private peeked: TSU.Nullable<FlatAtom> = null;\n\n /**\n * Creates a new AtomIterator with optional initial atoms.\n * @param atoms Initial atoms to iterate through\n */\n constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\n * @param atoms The atoms to add to the queue\n * @returns This iterator instance for method chaining\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add([atom, 0, atom.duration]);\n }\n return this;\n }\n\n /**\n * Gets the next atom in the sequence and advances the iterator.\n * @returns The next FlatAtom, or null if no more atoms are available\n */\n next(): TSU.Nullable<FlatAtom> {\n const out = this.peek();\n this.peeked = null;\n if (out != null) {\n this.currOffset = this.currOffset.plus(out.duration).factorized;\n }\n return out;\n }\n\n /**\n * Peeks at the next atom without advancing the iterator.\n * @returns The next FlatAtom, or null if no more atoms are available\n */\n peek(): TSU.Nullable<FlatAtom> {\n if (this.peeked == null) {\n if (this.hasNext) {\n const [nextAtom, nextDepth, nextDuration] = this.atomQueue.popFront();\n this.peeked = new FlatAtom(nextAtom as LeafAtom, {\n depth: nextDepth,\n offset: this.currOffset,\n duration: nextDuration,\n });\n }\n }\n return this.peeked;\n }\n\n /**\n * Checks if more atoms are available in this iterator.\n * This may process group atoms to find the next leaf atom.\n */\n get hasNext(): boolean {\n while (this.atomQueue.first != null) {\n // Get from front of queue\n const [nextAtom, nextDepth, nextDuration] = this.atomQueue.first.value;\n if (nextAtom.TYPE != AtomType.GROUP) {\n return true;\n } else {\n this.atomQueue.popFront();\n const group = nextAtom as Group;\n for (const child of group.atoms.reversedValues()) {\n this.atomQueue.pushFront([\n child,\n nextDepth + 1,\n nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,\n ]);\n }\n }\n }\n return false;\n }\n\n /**\n * Gets the atom with the minimum offset from multiple iterators.\n * @param iterators An array of AtomIterators to compare\n * @returns A tuple containing the index of the selected iterator and its next atom\n */\n static getMin(iterators: AtomIterator[]): [number, FlatAtom] {\n let currRole = -1;\n let currAtom: TSU.Nullable<FlatAtom> = null;\n for (let ri = 0; ri < iterators.length; ri++) {\n const flatAtom = iterators[ri].peek();\n if (flatAtom != null) {\n if (currAtom == null || flatAtom.offset.cmp(currAtom.offset) < 0) {\n currRole = ri;\n currAtom = flatAtom;\n }\n }\n }\n if (currRole >= 0) {\n iterators[currRole].next();\n }\n return [currRole, currAtom!];\n }\n}\n\n/**\n * An iterator that provides atoms within specified time windows.\n * WindowIterator allows fetching atoms to cover a specific duration,\n * handling the splitting of atoms if necessary.\n */\nexport class WindowIterator {\n private atomQueue = new TSU.Lists.List<Atom>();\n private currOffset = TSU.Num.Fraction.ZERO;\n private peeked: TSU.Nullable<Atom> = null;\n\n /**\n * Creates a new WindowIterator with optional initial atoms.\n * @param atoms Initial atoms to iterate through\n */\n constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be served by this iterator.\n * @param atoms The atoms to add to the queue\n * @returns This iterator instance for method chaining\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add(atom);\n }\n return this;\n }\n\n /**\n * Gets the next atom in the sequence and advances the iterator.\n * For atoms with participatesInTiming=false, the offset is not advanced.\n * @returns The next Atom, or null if no more atoms are available\n */\n next(): TSU.Nullable<Atom> {\n const out = this.peek();\n this.peeked = null;\n if (out != null && out.participatesInTiming) {\n this.currOffset = this.currOffset.plus(out.duration, true);\n }\n return out;\n }\n\n /**\n * Peeks at the next atom without advancing the iterator.\n * @returns The next Atom, or null if no more atoms are available\n */\n peek(): TSU.Nullable<Atom> {\n if (this.peeked == null && this.hasMore) {\n this.peeked = this.atomQueue.popFront();\n }\n return this.peeked;\n }\n\n /**\n * Checks if more atoms are available in this iterator.\n */\n get hasMore(): boolean {\n return !this.atomQueue.isEmpty;\n }\n\n /**\n * Gets atoms to cover the specified duration.\n *\n * If the number of atoms left in the iterator is 0, an empty list\n * is returned. Otherwise, the duration of atoms returned will cover\n * the given duration even if padding with Space atoms is necessary.\n *\n * Atoms with participatesInTiming=false (like Markers) are returned\n * but don't consume any of the requested duration.\n *\n * @param duration The duration to cover\n * @returns A tuple containing the array of atoms and whether the full duration was filled\n */\n get(duration: TSU.Num.Fraction): [Atom[], boolean] {\n const out: Atom[] = [];\n let remaining = duration;\n while (remaining.isGTNum(0) && this.hasMore) {\n const next = this.next();\n TSU.assert(next != null, \"Next cannot be null here\");\n out.push(next);\n\n // Only process timing for atoms that participate in timing\n // Markers and other non-timing atoms are returned without consuming duration\n if (next.participatesInTiming) {\n const spillOver = next.splitAt(remaining);\n remaining = remaining.minus(next.duration);\n if (spillOver != null) {\n // push the spill over to the front of the queue to be\n // picked up on the next \"get\" call\n this.atomQueue.pushFront(spillOver);\n }\n }\n }\n return [out, remaining.isZero];\n }\n}\n\n/**\n * An iterator that provides atoms with specific durations.\n * DurationIterator ensures that atoms fit within specified duration windows,\n * splitting atoms if necessary to fit.\n */\nexport class DurationIterator {\n private atomIterator: AtomIterator;\n private spillOver: TSU.Nullable<FlatAtom> = null;\n\n /**\n * Creates a new DurationIterator.\n * @param atomIterator The AtomIterator to use as a source of atoms\n */\n constructor(atomIterator: AtomIterator) {\n this.atomIterator = atomIterator;\n }\n\n /**\n * Checks if more atoms are available in this iterator.\n */\n get hasMore(): boolean {\n if (this.spillOver != null) {\n return true;\n }\n return this.atomIterator.hasNext;\n }\n\n /**\n * Gets atoms to cover the specified duration.\n *\n * If the number of atoms left in the iterator is 0, an empty list\n * is returned. Otherwise, the duration of atoms returned will cover\n * the given duration even if padding with Space atoms is necessary.\n *\n * @param duration The duration to cover\n * @returns A tuple containing the array of FlatAtoms and whether the full duration was filled\n */\n get(duration: TSU.Num.Fraction): [FlatAtom[], boolean] {\n const iter = this.atomIterator;\n const out: FlatAtom[] = [];\n let remaining = duration;\n while (remaining.isGTNum(0)) {\n const next = this.spillOver == null ? iter.next() : this.spillOver;\n this.spillOver = null;\n if (next == null) {\n // stop here\n break;\n } else {\n out.push(next);\n if (next.duration.cmp(remaining) <= 0) {\n remaining = remaining.minus(next.duration);\n } else {\n // Next leaf atom is > duration\n // so split it into two\n this.spillOver = new FlatAtom(new Space(next.duration.minus(remaining)));\n next.duration = remaining;\n remaining = TSU.Num.Fraction.ZERO;\n }\n }\n }\n return [out, remaining.isZero];\n }\n}\n"]}
|
package/lib/esm/notation.d.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
|
-
import { Entity } from "./entity";
|
|
2
|
+
import { Entity, CmdParam } from "./entity";
|
|
3
3
|
import { Cycle } from "./cycle";
|
|
4
4
|
import { Line } from "./core";
|
|
5
5
|
import { RoleDef, RawBlock, BlockItem, Block, SectionBlock, RepeatBlock, CycleBlock, BeatDurationBlock, BreaksBlock, RoleBlock, GroupBlock, isBlock, isLine, isRawBlock, findContainingBlock } from "./block";
|
|
6
6
|
export { RoleDef, RawBlock, BlockItem, Block, SectionBlock, RepeatBlock, CycleBlock, BeatDurationBlock, BreaksBlock, RoleBlock, GroupBlock, isBlock, isLine, isRawBlock, findContainingBlock, };
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export { CmdParam } from "./entity";
|
|
8
|
+
declare const EntityWithParams: (abstract new (...args: any[]) => {
|
|
9
|
+
params: CmdParam[];
|
|
10
|
+
getParam(key: string): any;
|
|
11
|
+
getParamAt(index: number): any;
|
|
12
|
+
}) & typeof Entity;
|
|
13
|
+
export declare abstract class Command extends EntityWithParams {
|
|
12
14
|
autoGenerated: boolean;
|
|
13
15
|
prevSibling: null | Command;
|
|
14
16
|
nextSibling: null | Command;
|
|
15
|
-
params: CmdParam[];
|
|
16
17
|
index: number;
|
|
17
18
|
constructor(params?: CmdParam[]);
|
|
18
19
|
validateParams(): void;
|
|
19
20
|
get name(): string;
|
|
20
21
|
debugValue(): any;
|
|
21
|
-
getParam(name: string): any;
|
|
22
|
-
getParamAt(index: number): any;
|
|
23
22
|
abstract applyToBlock(container: Block): void;
|
|
24
23
|
applyToNotation(notation: Notation): void;
|
|
25
24
|
}
|
package/lib/esm/notation.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Entity } from "./entity";
|
|
1
|
+
import { Entity, ParamsMixin } from "./entity";
|
|
2
2
|
import { Cycle } from "./cycle";
|
|
3
3
|
import { Line } from "./core";
|
|
4
4
|
import { RoleDef, RawBlock, Block, SectionBlock, RepeatBlock, CycleBlock, BeatDurationBlock, BreaksBlock, RoleBlock, GroupBlock, isBlock, isLine, isRawBlock, findContainingBlock, } from "./block";
|
|
5
5
|
export { RoleDef, RawBlock, Block, SectionBlock, RepeatBlock, CycleBlock, BeatDurationBlock, BreaksBlock, RoleBlock, GroupBlock, isBlock, isLine, isRawBlock, findContainingBlock, };
|
|
6
|
-
|
|
6
|
+
const EntityWithParams = ParamsMixin(Entity);
|
|
7
|
+
export class Command extends EntityWithParams {
|
|
7
8
|
constructor(params = []) {
|
|
8
9
|
super();
|
|
9
10
|
this.autoGenerated = false;
|
|
@@ -21,16 +22,6 @@ export class Command extends Entity {
|
|
|
21
22
|
debugValue() {
|
|
22
23
|
return { name: this.name, index: this.index, params: this.params };
|
|
23
24
|
}
|
|
24
|
-
getParam(name) {
|
|
25
|
-
for (const param of this.params) {
|
|
26
|
-
if (param.key == name)
|
|
27
|
-
return param.value;
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
getParamAt(index) {
|
|
32
|
-
return index < this.params.length ? this.params[index].value : null;
|
|
33
|
-
}
|
|
34
25
|
applyToNotation(notation) {
|
|
35
26
|
this.applyToBlock(notation);
|
|
36
27
|
}
|
package/lib/esm/notation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EACL,OAAO,EACP,QAAQ,EAER,KAAK,EACL,YAAY,EACZ,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,OAAO,EACP,QAAQ,EAER,KAAK,EACL,YAAY,EACZ,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,mBAAmB,GACpB,CAAC;AAYF,MAAM,OAAgB,OAAQ,SAAQ,MAAM;IAoB1C,YAAY,SAAqB,EAAE;QACjC,KAAK,EAAE,CAAC;QAnBV,kBAAa,GAAG,KAAK,CAAC;QAGtB,gBAAW,GAAmB,IAAI,CAAC;QAGnC,gBAAW,GAAmB,IAAI,CAAC;QAcjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAMD,cAAc;IAEd,CAAC;IAKD,IAAI,I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QACb,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;YACnD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,OAAO,IAAI,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAQD,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACxB,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAMD,OAAO;QACL,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;YAGnD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport {\n RoleDef,\n RawBlock,\n BlockItem,\n Block,\n SectionBlock,\n RepeatBlock,\n CycleBlock,\n BeatDurationBlock,\n BreaksBlock,\n RoleBlock,\n GroupBlock,\n isBlock,\n isLine,\n isRawBlock,\n findContainingBlock,\n} from \"./block\";\n\n// Re-export for backward compatibility\nexport {\n RoleDef,\n RawBlock,\n BlockItem,\n Block,\n SectionBlock,\n RepeatBlock,\n CycleBlock,\n BeatDurationBlock,\n BreaksBlock,\n RoleBlock,\n GroupBlock,\n isBlock,\n isLine,\n isRawBlock,\n findContainingBlock,\n};\n\n/**\n * Type representing a command parameter with optional key and value.\n */\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\n\n/**\n * Base class for commands in the notation.\n * Commands modify the notation in various ways, such as adding content,\n * changing layout, setting roles, etc.\n */\nexport abstract class Command extends Entity {\n /** Whether this command was auto-generated */\n autoGenerated = false;\n\n /** Previous command in the sequence */\n prevSibling: null | Command = null;\n\n /** Next command in the sequence */\n nextSibling: null | Command = null;\n\n /** Parameters for this command */\n params: CmdParam[];\n\n /** Index of this command in the sequence */\n index: number;\n\n /**\n * Creates a new Command.\n * @param params Optional parameters for the command\n */\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n //\n }\n\n /**\n * Gets the name of this command.\n */\n get name(): string {\n return this.constructor.name;\n }\n\n /**\n * Returns a debug-friendly representation of this command.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { name: this.name, index: this.index, params: this.params };\n }\n\n /**\n * Gets a parameter value by name.\n * @param name The name of the parameter\n * @returns The parameter value, or null if not found\n */\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n /**\n * Gets a parameter value by index.\n * @param index The index of the parameter\n * @returns The parameter value, or null if not found\n */\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n\n /**\n * Applies this command to a block (the primary method).\n * Since Notation extends Block, this works for both.\n * @param container The block to apply this command to\n */\n abstract applyToBlock(container: Block): void;\n\n /**\n * @deprecated Use applyToBlock instead\n * Applies this command to a notation.\n * Default implementation delegates to applyToBlock.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n this.applyToBlock(notation);\n }\n}\n\n/**\n * Represents metadata for the notation.\n */\nexport class MetaData {\n /**\n * Creates a new MetaData.\n * @param key The key for this metadata\n * @param value The value of this metadata\n * @param params Optional additional parameters\n */\n constructor(\n public readonly key: string,\n public readonly value: string,\n public readonly params?: any,\n ) {\n params = params || {};\n }\n}\n\n/**\n * The main class representing a complete notation.\n * Notation is the root Block of the notation hierarchy.\n * It contains all the elements, settings, and layout information for a piece of music.\n */\nexport class Notation extends Block {\n readonly TYPE = \"Notation\";\n\n // ============================================\n // Notation-specific properties\n // ============================================\n\n /** Metadata associated with this notation */\n metadata = new Map<string, MetaData>();\n\n /** Handler for missing roles */\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n /**\n * Creates a new Notation.\n */\n constructor() {\n super(\"notation\", null);\n // Set default values for root notation\n this.localCycle = Cycle.DEFAULT;\n this.localAtomsPerBeat = 1;\n this.localBreaks = [];\n }\n\n // ============================================\n // Backward compatibility aliases\n // ============================================\n\n /**\n * @deprecated Use blockItems instead\n * Legacy accessor for blocks array.\n */\n get blocks(): BlockItem[] {\n return this.blockItems;\n }\n\n /**\n * @deprecated Use localAtomsPerBeat instead\n * Legacy accessor for current atoms per beat.\n */\n get currentAPB(): number {\n return this.localAtomsPerBeat ?? 1;\n }\n\n set currentAPB(value: number) {\n this.localAtomsPerBeat = value;\n }\n\n /**\n * @deprecated Use localCycle instead\n * Legacy accessor for current cycle.\n */\n get currentCycle(): Cycle {\n return this.localCycle ?? Cycle.DEFAULT;\n }\n\n set currentCycle(value: Cycle) {\n this.localCycle = value;\n }\n\n /**\n * @deprecated Use localBreaks instead\n * Legacy accessor for current breaks.\n */\n get currentBreaks(): number[] {\n return this.localBreaks ?? [];\n }\n\n set currentBreaks(value: number[]) {\n this.localBreaks = value;\n }\n\n /**\n * @deprecated Use localRoles instead\n * Legacy accessor for roles array.\n */\n get roles(): RoleDef[] {\n return Array.from(this.localRoles.values());\n }\n\n // ============================================\n // Overridden methods\n // ============================================\n\n /**\n * Sets the current role by name.\n * Uses onMissingRole callback for auto-creation of missing roles.\n * @param name The name of the role to set as current\n * @throws Error if the name is empty or the role is not found\n */\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRole(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n /**\n * Gets a role definition by name.\n * Handles empty name by returning the last added role.\n * @param name The name of the role\n * @returns The role definition, or null if not found\n */\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name === \"\") {\n // Return the last added role if name is empty\n const roles = Array.from(this.localRoles.values());\n return roles[roles.length - 1] || null;\n }\n return this.localRoles.get(name) ?? null;\n }\n\n /**\n * Creates a new role definition.\n * @param name The name of the role\n * @param notesOnly Whether the role contains only notes, defaults to false\n * @returns The created role definition\n * @throws Error if the name is empty or the role already exists\n */\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name === \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n if (this.localRoles.has(name)) {\n throw new Error(\"Role already exists: \" + name);\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.localRoles.size;\n this.localRoles.set(name, rd);\n\n return rd;\n }\n\n // ============================================\n // Additional methods\n // ============================================\n\n /**\n * Adds a line to this notation.\n * @param line The line to add\n */\n addLine(line: Line): void {\n this.addBlockItem(line);\n }\n\n /**\n * Removes a line from this notation.\n * @param line The line to remove\n * @returns The index of the removed line, or -1 if not found\n */\n removeLine(line: Line): number {\n return this.removeBlockItem(line);\n }\n\n /**\n * Adds a raw block to this notation.\n * @param raw The raw block to add\n */\n addRawBlock(raw: RawBlock): void {\n this.addBlockItem(raw);\n this.resetLine();\n }\n\n /**\n * Adds metadata to this notation.\n * @param meta The metadata to add\n * @param addBlock Whether to add a corresponding raw block, defaults to true\n */\n addMetaData(meta: MetaData, addBlock = true): void {\n if (addBlock && !this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n /**\n * Resets the current line pointer to null.\n */\n resetLine(): void {\n this._currentLine = null;\n }\n\n /**\n * Returns a debug-friendly representation of this notation.\n * Uses Notation-specific property names for backward compatibility.\n * @returns An object containing debug information\n */\n debugValue(): any {\n // Use Notation-specific names (blocks, currentCycle, etc.)\n // instead of Block names (blockItems, localCycle, etc.)\n // to maintain backward compatibility with existing tests\n return {\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentBreaks: this.currentBreaks,\n currentCycle: this.currentCycle?.uuid,\n roles: this.roles,\n };\n }\n\n // Need protected access to _currRoleDef for setCurrRole override\n protected _currRoleDef: TSU.Nullable<RoleDef> = null;\n\n /**\n * Gets the current role definition.\n */\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n const roles = Array.from(this.localRoles.values());\n if (roles.length === 0) {\n return null;\n } else {\n this._currRoleDef = roles[roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n // Need protected access to _currentLine for resetLine\n protected _currentLine: Line | null = null;\n\n /**\n * Gets the current line, creating it if needed.\n */\n get currentLine(): Line {\n if (this._currentLine == null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n /**\n * Creates a new line and makes it the current line.\n * @returns The newly created line\n */\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mapp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,CAAC;YAGnD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity, CmdParam, ParamsMixin } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport {\n RoleDef,\n RawBlock,\n BlockItem,\n Block,\n SectionBlock,\n RepeatBlock,\n CycleBlock,\n BeatDurationBlock,\n BreaksBlock,\n RoleBlock,\n GroupBlock,\n isBlock,\n isLine,\n isRawBlock,\n findContainingBlock,\n} from \"./block\";\n\n// Re-export for backward compatibility\nexport {\n RoleDef,\n RawBlock,\n BlockItem,\n Block,\n SectionBlock,\n RepeatBlock,\n CycleBlock,\n BeatDurationBlock,\n BreaksBlock,\n RoleBlock,\n GroupBlock,\n isBlock,\n isLine,\n isRawBlock,\n findContainingBlock,\n};\n\n// Re-export CmdParam for backwards compatibility\nexport { CmdParam } from \"./entity\";\n\n// Apply ParamsMixin to Entity for Command base class\nconst EntityWithParams = ParamsMixin(Entity);\n\n/**\n * Base class for commands in the notation.\n * Commands modify the notation in various ways, such as adding content,\n * changing layout, setting roles, etc.\n */\nexport abstract class Command extends EntityWithParams {\n /** Whether this command was auto-generated */\n autoGenerated = false;\n\n /** Previous command in the sequence */\n prevSibling: null | Command = null;\n\n /** Next command in the sequence */\n nextSibling: null | Command = null;\n\n /** Index of this command in the sequence */\n index: number;\n\n /**\n * Creates a new Command.\n * @param params Optional parameters for the command\n */\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n //\n }\n\n /**\n * Gets the name of this command.\n */\n get name(): string {\n return this.constructor.name;\n }\n\n /**\n * Returns a debug-friendly representation of this command.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { name: this.name, index: this.index, params: this.params };\n }\n\n /**\n * Applies this command to a block (the primary method).\n * Since Notation extends Block, this works for both.\n * @param container The block to apply this command to\n */\n abstract applyToBlock(container: Block): void;\n\n /**\n * @deprecated Use applyToBlock instead\n * Applies this command to a notation.\n * Default implementation delegates to applyToBlock.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n this.applyToBlock(notation);\n }\n}\n\n/**\n * Represents metadata for the notation.\n */\nexport class MetaData {\n /**\n * Creates a new MetaData.\n * @param key The key for this metadata\n * @param value The value of this metadata\n * @param params Optional additional parameters\n */\n constructor(\n public readonly key: string,\n public readonly value: string,\n public readonly params?: any,\n ) {\n params = params || {};\n }\n}\n\n/**\n * The main class representing a complete notation.\n * Notation is the root Block of the notation hierarchy.\n * It contains all the elements, settings, and layout information for a piece of music.\n */\nexport class Notation extends Block {\n readonly TYPE = \"Notation\";\n\n // ============================================\n // Notation-specific properties\n // ============================================\n\n /** Metadata associated with this notation */\n metadata = new Map<string, MetaData>();\n\n /** Handler for missing roles */\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n /**\n * Creates a new Notation.\n */\n constructor() {\n super(\"notation\", null);\n // Set default values for root notation\n this.localCycle = Cycle.DEFAULT;\n this.localAtomsPerBeat = 1;\n this.localBreaks = [];\n }\n\n // ============================================\n // Backward compatibility aliases\n // ============================================\n\n /**\n * @deprecated Use blockItems instead\n * Legacy accessor for blocks array.\n */\n get blocks(): BlockItem[] {\n return this.blockItems;\n }\n\n /**\n * @deprecated Use localAtomsPerBeat instead\n * Legacy accessor for current atoms per beat.\n */\n get currentAPB(): number {\n return this.localAtomsPerBeat ?? 1;\n }\n\n set currentAPB(value: number) {\n this.localAtomsPerBeat = value;\n }\n\n /**\n * @deprecated Use localCycle instead\n * Legacy accessor for current cycle.\n */\n get currentCycle(): Cycle {\n return this.localCycle ?? Cycle.DEFAULT;\n }\n\n set currentCycle(value: Cycle) {\n this.localCycle = value;\n }\n\n /**\n * @deprecated Use localBreaks instead\n * Legacy accessor for current breaks.\n */\n get currentBreaks(): number[] {\n return this.localBreaks ?? [];\n }\n\n set currentBreaks(value: number[]) {\n this.localBreaks = value;\n }\n\n /**\n * @deprecated Use localRoles instead\n * Legacy accessor for roles array.\n */\n get roles(): RoleDef[] {\n return Array.from(this.localRoles.values());\n }\n\n // ============================================\n // Overridden methods\n // ============================================\n\n /**\n * Sets the current role by name.\n * Uses onMissingRole callback for auto-creation of missing roles.\n * @param name The name of the role to set as current\n * @throws Error if the name is empty or the role is not found\n */\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRole(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n /**\n * Gets a role definition by name.\n * Handles empty name by returning the last added role.\n * @param name The name of the role\n * @returns The role definition, or null if not found\n */\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name === \"\") {\n // Return the last added role if name is empty\n const roles = Array.from(this.localRoles.values());\n return roles[roles.length - 1] || null;\n }\n return this.localRoles.get(name) ?? null;\n }\n\n /**\n * Creates a new role definition.\n * @param name The name of the role\n * @param notesOnly Whether the role contains only notes, defaults to false\n * @returns The created role definition\n * @throws Error if the name is empty or the role already exists\n */\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name === \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n if (this.localRoles.has(name)) {\n throw new Error(\"Role already exists: \" + name);\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.localRoles.size;\n this.localRoles.set(name, rd);\n\n return rd;\n }\n\n // ============================================\n // Additional methods\n // ============================================\n\n /**\n * Adds a line to this notation.\n * @param line The line to add\n */\n addLine(line: Line): void {\n this.addBlockItem(line);\n }\n\n /**\n * Removes a line from this notation.\n * @param line The line to remove\n * @returns The index of the removed line, or -1 if not found\n */\n removeLine(line: Line): number {\n return this.removeBlockItem(line);\n }\n\n /**\n * Adds a raw block to this notation.\n * @param raw The raw block to add\n */\n addRawBlock(raw: RawBlock): void {\n this.addBlockItem(raw);\n this.resetLine();\n }\n\n /**\n * Adds metadata to this notation.\n * @param meta The metadata to add\n * @param addBlock Whether to add a corresponding raw block, defaults to true\n */\n addMetaData(meta: MetaData, addBlock = true): void {\n if (addBlock && !this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n /**\n * Resets the current line pointer to null.\n */\n resetLine(): void {\n this._currentLine = null;\n }\n\n /**\n * Returns a debug-friendly representation of this notation.\n * Uses Notation-specific property names for backward compatibility.\n * @returns An object containing debug information\n */\n debugValue(): any {\n // Use Notation-specific names (blocks, currentCycle, etc.)\n // instead of Block names (blockItems, localCycle, etc.)\n // to maintain backward compatibility with existing tests\n return {\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentBreaks: this.currentBreaks,\n currentCycle: this.currentCycle?.uuid,\n roles: this.roles,\n };\n }\n\n // Need protected access to _currRoleDef for setCurrRole override\n protected _currRoleDef: TSU.Nullable<RoleDef> = null;\n\n /**\n * Gets the current role definition.\n */\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n const roles = Array.from(this.localRoles.values());\n if (roles.length === 0) {\n return null;\n } else {\n this._currRoleDef = roles[roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n // Need protected access to _currentLine for resetLine\n protected _currentLine: Line | null = null;\n\n /**\n * Gets the current line, creating it if needed.\n */\n get currentLine(): Line {\n if (this._currentLine == null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n /**\n * Creates a new line and makes it the current line.\n * @returns The newly created line\n */\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n}\n"]}
|
package/lib/esm/parser.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
2
|
import * as G from "galore";
|
|
3
3
|
import * as TLEX from "tlex";
|
|
4
|
-
import { Literal, Note, Atom, Rest, Space, Group } from "./core";
|
|
4
|
+
import { Literal, Note, Atom, Rest, Space, Group, Marker } from "./core";
|
|
5
5
|
import { Notation, Command, CmdParam } from "./notation";
|
|
6
6
|
import { Block } from "./block";
|
|
7
7
|
export declare class BlockCommand extends Command {
|
|
@@ -30,8 +30,7 @@ export declare class Parser {
|
|
|
30
30
|
newRest: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Rest;
|
|
31
31
|
newDoubleSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Space;
|
|
32
32
|
newSilentSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Space;
|
|
33
|
-
|
|
34
|
-
applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
|
|
33
|
+
newMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Marker;
|
|
35
34
|
applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
|
|
36
35
|
newArray: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any[];
|
|
37
36
|
concatAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
|
package/lib/esm/parser.js
CHANGED
|
@@ -34,12 +34,9 @@ const [parser] = G.newParser(String.raw `
|
|
|
34
34
|
%token EMBELISHMENT /~[^\s]*/ { toEmbelishment }
|
|
35
35
|
%token NUMBER /-?\d+/ { toNumber }
|
|
36
36
|
%token BOOLEAN /true|false/ { toBoolean }
|
|
37
|
-
%token POST_MARKER /<<"(([^"\\\n]|\\.|\\\n)*)"/ { toMarker }
|
|
38
|
-
%token POST_MARKER /<<'(([^'\\\n]|\\.|\\\n)*)'/ { toMarker }
|
|
39
|
-
%token PRE_MARKER /"(([^"\\\n]|\\.|\\\n)*)">>/ { toMarker }
|
|
40
|
-
%token PRE_MARKER /'(([^'\\\n]|\\.|\\\n)*)'>>/ { toMarker }
|
|
41
37
|
%token STRING /"([^"\\\n]|\\.|\\\n)*"/ { toString }
|
|
42
38
|
%token STRING /'([^'\\\n]|\\.|\\\n)*'/ { toString }
|
|
39
|
+
%token MARKER_NAME /\\@{IDENT}/ { toMarkerName }
|
|
43
40
|
%token DOTS_IDENT /(\.+)({IdentChar}+)/ { toOctavedNote }
|
|
44
41
|
%token IDENT_DOTS /({IdentChar}+)(\.+)/ { toOctavedNote }
|
|
45
42
|
%token IDENT_COLON /{IdentChar}+:/ { toRoleSelector }
|
|
@@ -83,14 +80,10 @@ const [parser] = G.newParser(String.raw `
|
|
|
83
80
|
Atoms -> Atoms Atom { concatAtoms } ;
|
|
84
81
|
Atoms -> { newArray } ;
|
|
85
82
|
|
|
86
|
-
Atom ->
|
|
87
|
-
| PreMarkedAtom
|
|
88
|
-
;
|
|
89
|
-
PreMarkedAtom -> Leaf
|
|
90
|
-
| PRE_MARKER PreMarkedAtom { applyPreMarker }
|
|
91
|
-
;
|
|
83
|
+
Atom -> Leaf ;
|
|
92
84
|
|
|
93
|
-
Leaf -> Space | Lit | Group | Rest
|
|
85
|
+
Leaf -> Space | Lit | Group | Rest | Marker ;
|
|
86
|
+
Marker -> MARKER_NAME CommandParams { newMarker } ;
|
|
94
87
|
Leaf -> Duration Leaf { applyDuration } ;
|
|
95
88
|
Rest -> HYPHEN { newRest };
|
|
96
89
|
Space -> COMMA { newSpace }
|
|
@@ -154,15 +147,8 @@ const [parser] = G.newParser(String.raw `
|
|
|
154
147
|
token.value = token.value.substring(1, token.value.length - 1);
|
|
155
148
|
return token;
|
|
156
149
|
},
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
throw new Error("Invalid token for converting to note: " + token.tag);
|
|
160
|
-
}
|
|
161
|
-
const isBefore = token.tag == "PRE_MARKER";
|
|
162
|
-
const markerText = isBefore
|
|
163
|
-
? token.value.substring(1, token.value.length - 3)
|
|
164
|
-
: token.value.substring(3, token.value.length - 1);
|
|
165
|
-
token.value = new Marker(markerText, isBefore);
|
|
150
|
+
toMarkerName: (token, _tape, _owner) => {
|
|
151
|
+
token.value = token.value.substring(2);
|
|
166
152
|
return token;
|
|
167
153
|
},
|
|
168
154
|
toOctavedNote: (token, _tape, _owner) => {
|
|
@@ -344,23 +330,10 @@ export class Parser {
|
|
|
344
330
|
newSilentSpace: (_rule, _parent, ..._children) => {
|
|
345
331
|
return new Space(ONE, true);
|
|
346
332
|
},
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
leaf.markersBefore = [];
|
|
352
|
-
}
|
|
353
|
-
leaf.markersBefore.splice(0, 0, marker);
|
|
354
|
-
return leaf;
|
|
355
|
-
},
|
|
356
|
-
applyPostMarker: (rule, parent, ...children) => {
|
|
357
|
-
const leaf = children[0].value;
|
|
358
|
-
const marker = children[1].value;
|
|
359
|
-
if (!leaf.markersAfter) {
|
|
360
|
-
leaf.markersAfter = [];
|
|
361
|
-
}
|
|
362
|
-
leaf.markersAfter.push(marker);
|
|
363
|
-
return leaf;
|
|
333
|
+
newMarker: (rule, parent, ...children) => {
|
|
334
|
+
const name = children[0].value;
|
|
335
|
+
const params = children[1].value || [];
|
|
336
|
+
return new Marker(name, params);
|
|
364
337
|
},
|
|
365
338
|
applyDuration: (rule, parent, ...children) => {
|
|
366
339
|
let dur = children[0].value;
|
package/lib/esm/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAQ,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,QAAQ,IAAI,IAAI,EAAE,OAAO,EAAY,MAAM,YAAY,CAAC;AAC3E,OAAO,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,SAAS,EACT,YAAY,EACZ,UAAU,EACV,UAAU,EACV,OAAO,EACP,WAAW,EACX,MAAM,GACP,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAEvC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AACjC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAW5B,MAAM,CAAC,MAAM,CAAe,GAAG,CAAC,CAAC,SAAS,CACxC,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkHP,EACH;IACE,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,MAAM;IACZ,aAAa,EAAE,IAAI;IACnB,aAAa,EAAE;QACb,cAA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AO,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport * as TLEX from \"tlex\";\nimport YAML from \"yaml\";\nimport { Literal, AtomType, Note, Atom, Rest, Space, Syllable, Group, Marker } from \"./core\";\nimport { Notation, MetaData as Meta, Command, CmdParam } from \"./notation\";\nimport {\n RawEmbedding,\n ApplyLayout,\n AddAtoms,\n SetCycle,\n SetBeatDuration,\n SetBreaks,\n ActivateRole,\n CreateRole,\n CreateLine,\n Section,\n ScopedGroup,\n Repeat,\n} from \"./commands\";\n\n// TODO - Make this plugable from the client instead of hard coded\nimport * as carnatic from \"./carnatic\";\n\nconst ONE = TSU.Num.Fraction.ONE;\nconst TWO = ONE.timesNum(2);\n\n/**\n * V4 of our parser builds on V3 and has the following improvements:\n *\n * 1. Embedding Headings to demarcate sections so users dont have to use\n * explicit MD for headings.\n * 2. Unlike V3 here users break out *of* song instead instead break out \"into\"\n * song. So users spend more time writing notation and less worrying about\n * other things like headings etc.\n */\nconst [parser /*itemGraph*/] = G.newParser(\n String.raw`\n %define IdentChar /[^%!@$#&\\^|\\[\\]={}()<>+\\-,;~: \\t\\f\\r\\n\\v\\\\\\.\\'\\\"]/\n\n %token BSLASH \"\\\\\"\n %token OPEN_SQ \"[\"\n %token CLOSE_SQ \"]\"\n %token EQUALS \"=\"\n %token OPEN_PAREN \"(\"\n %token CLOSE_PAREN \")\"\n %token OPEN_BRACE \"{\"\n %token CLOSE_BRACE \"}\"\n %token SLASH \"/\"\n %token STAR \"*\"\n %token CARET \"^\"\n // %skip \"-\"\n %token COMMA \",\"\n %token SEMI_COLON \";\"\n %token COLON \":\"\n\n %token FRONT_MATTER /^---$/m { toFrontMatter }\n %token SINGLE_LINE_RAW_STRING />(.*)$/m { toSingleLineRawString }\n %token MULTI_LINE_RAW_STRING /r(#{0,})\"/ { toMultiLineRawString }\n\n %token EMBELISHMENT /~[^\\s]*/ { toEmbelishment }\n %token NUMBER /-?\\d+/ { toNumber }\n %token BOOLEAN /true|false/ { toBoolean }\n %token POST_MARKER /<<\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\"/ { toMarker }\n %token POST_MARKER /<<'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'/ { toMarker }\n %token PRE_MARKER /\"(([^\"\\\\\\n]|\\\\.|\\\\\\n)*)\">>/ { toMarker }\n %token PRE_MARKER /'(([^'\\\\\\n]|\\\\.|\\\\\\n)*)'>>/ { toMarker }\n %token STRING /\"([^\"\\\\\\n]|\\\\.|\\\\\\n)*\"/ { toString }\n %token STRING /'([^'\\\\\\n]|\\\\.|\\\\\\n)*'/ { toString }\n %token DOTS_IDENT /(\\.+)({IdentChar}+)/ { toOctavedNote }\n %token IDENT_DOTS /({IdentChar}+)(\\.+)/ { toOctavedNote }\n %token IDENT_COLON /{IdentChar}+:/ { toRoleSelector }\n %token IDENT /{IdentChar}+/\n %token BSLASH_IDENT /\\\\{IDENT}/ { toCommandName }\n %token BSLASH_NUMBER /\\\\{NUMBER}/\n %token HYPHEN /-/\n %skip /[ \\t\\n\\f\\r]+/\n %skip_flex \"//.*$\"\n %skip /\\/\\*.*?\\*\\//\n\n Document -> Elements\n | FRONT_MATTER Elements { prependFrontMatter }\n ;\n\n Elements -> Elements Command Atoms { appendCommand } \n | Elements RoleSelector Atoms { appendRoleSelector } \n | Elements Embedding Atoms { insertEmbedding }\n | Atoms { appendAtoms }\n ;\n\n Embedding -> SINGLE_LINE_RAW_STRING | MULTI_LINE_RAW_STRING ;\n\n Command -> BSLASH_IDENT CommandParams ? OptBlock { newCommandWithBlock } ;\n CommandParams -> OPEN_PAREN ParamList ? CLOSE_PAREN { $2 } ;\n OptBlock -> Block\n | { nullBlock }\n ;\n Block -> BlockStart Elements CLOSE_BRACE { endBlock } ;\n BlockStart -> OPEN_BRACE { beginBlock } ;\n\n ParamList -> ParamList COMMA Param { concatParamList } ;\n ParamList -> Param { newParamList };\n Param -> ParamValue { newParam } ;\n Param -> ParamKey EQUALS ParamValue { newParam } ;\n ParamKey -> IDENT ;\n ParamValue -> ( STRING | Fraction | NUMBER | BOOLEAN ) ;\n\n RoleSelector -> IDENT_COLON ;\n\n Atoms -> Atoms Atom { concatAtoms } ;\n Atoms -> { newArray } ;\n\n Atom -> Atom POST_MARKER { applyPostMarker }\n | PreMarkedAtom\n ;\n PreMarkedAtom -> Leaf\n | PRE_MARKER PreMarkedAtom { applyPreMarker }\n ;\n\n Leaf -> Space | Lit | Group | Rest ;\n Leaf -> Duration Leaf { applyDuration } ;\n Rest -> HYPHEN { newRest };\n Space -> COMMA { newSpace } \n | SEMI_COLON { newDoubleSpace } \n | UNDER_SCORE { newSilentSpace } \n ;\n\n /* - An alternative representation to support both pre and\n * post embelishment operators. Here PRE_EMBs have a higher\n * associativity over POST_EMBs\n */\n Lit -> Lit POST_EMB { litWithPostEmb }\n | PreEmbLit\n ;\n\n PreEmbLit -> LitToken \n | LitToken CARET NUMBER { litWithCaret }\n | LitToken CARET STAR { litWithCaret }\n | PRE_EMB PreEmbLit { litWithPreEmb }\n ;\n \n LitToken -> DOTS_IDENT { litToAtom }\n | IDENT { litToAtom }\n | IDENT_DOTS { litToAtom }\n | STRING { litToAtom }\n ;\n\n Group -> OPEN_SQ Atoms CLOSE_SQ { newGroup };\n\n Duration -> Fraction | NUMBER;\n Fraction -> NUMBER SLASH NUMBER { newFraction } ;\n `,\n {\n debug: \"\",\n type: \"lalr\",\n leftRecursive: true,\n tokenHandlers: {\n toEmbelishment: (token: TLEX.Token, tape: TLEX.TapeInterface, owner: any) => {\n const [emb, pre] = owner.parseEmbelishment(token.value);\n if (emb == null) {\n console.log(\"Skipping Embelishment: \", token.value);\n owner.errors.push(\n new TLEX.TokenizerError(\n `Invalid embelishment: ${token.value}`,\n token.start,\n 1 + token.end - token.start,\n \"InvalidEmbelishment\",\n token.value,\n ),\n );\n return null;\n }\n token.value = emb;\n token.tag = pre ? \"PRE_EMB\" : \"POST_EMB\";\n return token;\n },\n toCommandName: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = token.value.substring(1);\n return token;\n },\n toBoolean: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = token.value == \"true\";\n return token;\n },\n toNumber: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = parseInt(token.value);\n return token;\n },\n toString: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = token.value.substring(1, token.value.length - 1);\n return token;\n },\n toMarker: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n if (token.tag != \"PRE_MARKER\" && token.tag != \"POST_MARKER\") {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n const isBefore = token.tag == \"PRE_MARKER\";\n const markerText = isBefore\n ? token.value.substring(1, token.value.length - 3)\n : token.value.substring(3, token.value.length - 1);\n // console.log(\"TokVal: \", token.value, token.positions);\n // console.log(\"Marker Text: \", markerText, isBefore);\n token.value = new Marker(markerText, isBefore);\n return token;\n },\n toOctavedNote: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n if (token.tag == \"DOTS_IDENT\") {\n const octave = token.positions[1][1] - token.positions[1][0];\n const note = token.value.substring(octave);\n token.value = new Note(note, ONE, -octave);\n } else if (token.tag == \"IDENT_DOTS\") {\n const octave = token.positions[2][1] - token.positions[2][0];\n const note = token.value.substring(0, token.value.length - octave);\n token.value = new Note(note, ONE, octave);\n } else {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n return token;\n },\n toRoleSelector: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = token.value.substring(0, token.value.length - 1);\n return token;\n },\n toLineAnnotation: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n // skip the initial \"!\"\n token.value = token.value.substring(1);\n return token;\n },\n toSingleLineRawString: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n // skip the initial \">\"\n token.value = token.value.substring(1);\n return token;\n },\n toMultiLineRawString: (token: TLEX.Token, tape: TLEX.TapeInterface, _owner: any) => {\n // consume everything until \"#<N times> as start\n const hashes = tape.substring(token.positions[1][0], token.positions[1][1]);\n const endPat = '\"' + hashes;\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of Raw String Literal: '\" + endPat + \"'\");\n }\n token.value = tape.substring(startPos, endPos);\n return token;\n },\n toFrontMatter: (token: TLEX.Token, tape: TLEX.TapeInterface, _owner: any) => {\n // skip the initial \">\"\n const endPat = \"\\n---\";\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of front matter\");\n }\n token.value = tape.substring(startPos, endPos);\n // console.log(\"Found FM: \", token.value);\n return token;\n },\n },\n },\n);\n\n/**\n * A notation doc is a list of lines that are found in a single document.\n *\n * Since our document (md or html etc) can contain multiple snippets\n * all these snippets are related\n */\nimport {\n Block,\n SectionBlock,\n RepeatBlock,\n CycleBlock,\n BeatDurationBlock,\n BreaksBlock,\n RoleBlock,\n GroupBlock,\n} from \"./block\";\nimport { parseCycle } from \"./utils\";\n\n/**\n * Wrapper for a command that has a block of child commands.\n * When applied, it creates the appropriate Block subclass and applies child commands to it.\n */\nexport class BlockCommand extends Command {\n readonly innerCommand: Command;\n readonly blockCommands: Command[];\n\n constructor(innerCommand: Command, blockCommands: Command[]) {\n super(innerCommand.params);\n this.innerCommand = innerCommand;\n this.blockCommands = blockCommands;\n }\n\n get name(): string {\n return `Block(${this.innerCommand.name})`;\n }\n\n /**\n * Creates the appropriate Block subclass based on the inner command type.\n */\n private createBlock(parent: Block): Block {\n const cmd = this.innerCommand;\n\n if (cmd instanceof Section) {\n return new SectionBlock(cmd.sectionName, parent);\n } else if (cmd instanceof Repeat) {\n return new RepeatBlock(cmd.count, parent);\n } else if (cmd instanceof SetCycle) {\n const cycle = parseCycle(cmd.getParamAt(0));\n return new CycleBlock(cycle, parent);\n } else if (cmd instanceof SetBeatDuration) {\n return new BeatDurationBlock(cmd.beatDuration, parent);\n } else if (cmd instanceof SetBreaks) {\n return new BreaksBlock(cmd.pattern, parent);\n } else if (cmd instanceof CreateRole) {\n const roleName = cmd.getParamAt(0);\n return new RoleBlock(roleName, cmd.notesOnly, parent);\n } else if (cmd instanceof ScopedGroup) {\n return new GroupBlock(cmd.groupName || null, parent);\n } else {\n // Generic block for other commands\n return new Block(cmd.name.toLowerCase(), parent);\n }\n }\n\n debugValue(): any {\n return {\n name: this.name,\n index: this.index,\n innerCommand: this.innerCommand.debugValue(),\n blockCommands: this.blockCommands.map((cmd) => cmd.debugValue()),\n };\n }\n\n applyToNotation(notation: Notation): void {\n // Create the appropriate Block subclass\n // Cast notation as Block since Notation will extend Block\n const block = this.createBlock(notation as unknown as Block);\n\n // Apply all child commands to the block\n for (const cmd of this.blockCommands) {\n cmd.applyToBlock(block);\n }\n\n // Add the block to the notation\n notation.addBlockItem(block);\n }\n\n applyToBlock(container: Block): void {\n // Create the appropriate Block subclass\n const block = this.createBlock(container);\n\n // Apply all child commands to the block\n for (const cmd of this.blockCommands) {\n cmd.applyToBlock(block);\n }\n\n // Add the block to the container\n container.addBlockItem(block);\n }\n}\n\nexport class Parser {\n errors: (TLEX.TokenizerError | G.ParseError)[] = [];\n metadata: any = {};\n readonly commands: Command[] = [];\n // Stack to track command indices when entering blocks\n private blockStartStack: number[] = [];\n\n protected ruleHandlers = {\n newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return new TSU.Num.Fraction(children[0].value);\n } else {\n return new TSU.Num.Fraction(children[0].value, children[2].value);\n }\n },\n newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const out = new Group(...children[1].value).setDuration(TWO, true);\n return out;\n },\n litWithCaret: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = Note.fromLit(children[0].value as Literal);\n const opnode = children[2];\n const shiftValue = opnode.sym.label == \"STAR\" ? true : opnode.value;\n lit.shift = shiftValue;\n return lit;\n },\n litWithPreEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const emb = children[0];\n const lit = children[1].value as Literal;\n lit.embelishments.splice(0, 0, emb.value);\n return lit;\n },\n litWithPostEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0].value as Literal;\n const emb = children[1];\n lit.embelishments.push(emb);\n return lit;\n },\n litToAtom: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0];\n if (lit.sym.label == \"DOTS_IDENT\" || lit.sym.label == \"IDENT_DOTS\") {\n return lit.value;\n } else if (lit.sym.label == \"IDENT\") {\n // Mark this as a Literal to be processed later\n return new Literal(lit.value);\n // return role.notesOnly ? new Note(lit.value) : new Syllable(lit.value);\n } else if (lit.sym.label == \"STRING\") {\n // const role = this.snippet.currRole;\n // if (role.notesOnly) throw new Error(\"Strings cannot appear in notes only mode\");\n return new Syllable(lit.value);\n } else {\n throw new Error(\"Invalid lit: \" + lit);\n }\n },\n newSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n return new Space();\n },\n newRest: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n return new Rest();\n },\n newDoubleSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n return new Space(ONE.timesNum(2));\n },\n newSilentSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n return new Space(ONE, true);\n },\n applyPreMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const marker = children[0].value as Marker;\n const leaf = children[1].value as Atom;\n // console.log(\"marker, leaf: \", marker, leaf);\n if (!leaf.markersBefore) {\n leaf.markersBefore = [];\n }\n leaf.markersBefore.splice(0, 0, marker);\n return leaf;\n },\n applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const leaf = children[0].value as Atom;\n const marker = children[1].value as Marker;\n if (!leaf.markersAfter) {\n leaf.markersAfter = [];\n }\n leaf.markersAfter.push(marker);\n return leaf;\n },\n applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n let dur = children[0].value as TSU.Num.Fraction | number;\n const leaf = children[1].value as Atom;\n if (typeof dur === \"number\") {\n dur = ONE.timesNum(dur);\n }\n if (leaf.TYPE == AtomType.GROUP) {\n (leaf as Group).setDuration(dur, true);\n } else {\n leaf.duration = dur;\n }\n return leaf;\n },\n newArray: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // create an array of values from all the values of child nodes\n return children.map((c) => c.value);\n },\n concatAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value;\n const atom = children[1].value;\n atoms.push(atom);\n return atoms;\n },\n newParam: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return { key: null, value: children[0].value };\n } else {\n return { key: children[0].value, value: children[2].value };\n }\n },\n newParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return [children[0].value];\n },\n concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const params = children[0].value;\n const newParam = children[2].value;\n params.push(newParam);\n return params;\n },\n // Block handling semantic actions\n beginBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n // Push current command count to track where this block's commands start\n this.blockStartStack.push(this.commands.length);\n return null;\n },\n endBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n // Pop the start index and extract commands added since then\n const startIndex = this.blockStartStack.pop()!;\n const blockCommands = this.commands.splice(startIndex);\n return blockCommands;\n },\n nullBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n // No block present\n return null;\n },\n newCommandWithBlock: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const name = children[0].value;\n const params = children[1].value;\n const blockCommands = children[2].value as Command[] | null;\n\n const innerCommand = this.createCommand(name, params);\n\n if (blockCommands !== null) {\n // Wrap in BlockCommand\n return new BlockCommand(innerCommand, blockCommands);\n } else {\n // No block, return regular command\n return innerCommand;\n }\n },\n appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n prependFrontMatter: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const fm = children[0].value;\n // console.log(\"Child 0: \", fm);\n // console.log(\"Child 1: \", children[1].value);\n const data = YAML.parse(fm);\n console.log(\"Parsed FM: \", data);\n this.metadata = data;\n return children[1].value;\n },\n appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const command = children[1].value as Command;\n this.addCommand(command);\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const roleName = children[1].value;\n const lName = roleName.toLowerCase().trim();\n this.addCommand(new ActivateRole([{ key: null, value: lName }]));\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // How to handle embeddings - these are just blocks\n // to escape out of song (most likely for some rendering of html/md etc)\n const rawVal = children[1].value;\n this.addCommand(new RawEmbedding([{ key: null, value: rawVal }]));\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n };\n\n constructor(_config?: any) {\n // config = config || {};\n }\n\n createCommand(name: string, params: CmdParam[]): Command {\n const lName = name.trim().toLowerCase();\n params = params || [];\n if (lName == \"line\") {\n return new CreateLine(params);\n // } else if (lName == \"meta\") { return new MetaData(params);\n } else if (lName == \"role\") {\n return new CreateRole(params);\n } else if (lName == \"layout\") {\n return new ApplyLayout(params);\n } else if (lName == \"beatduration\") {\n return new SetBeatDuration(params);\n } else if (lName == \"breaks\") {\n return new SetBreaks(params);\n } else if (lName == \"cycle\") {\n return new SetCycle(params);\n } else if (lName == \"section\") {\n return new Section(params);\n } else if (lName == \"group\") {\n return new ScopedGroup(params);\n } else if (lName == \"repeat\") {\n return new Repeat(params);\n } else {\n // Try to set this as the current role\n throw new Error(\"Invalid command: \" + lName);\n }\n }\n\n addCommand(cmd: Command): void {\n cmd.index = this.commands.length;\n this.commands.push(cmd);\n }\n\n parse(input: string): any {\n this.errors = [];\n try {\n const ptree = parser.parse(input, {\n tokenizerContext: this,\n ruleHandlers: this.ruleHandlers,\n onTokenError: (err: TLEX.TokenizerError) => {\n this.errors.push(err);\n return true;\n },\n });\n return ptree;\n } catch (err) {\n if (err instanceof G.ParseError) {\n this.errors.push(err);\n } else {\n throw err;\n }\n }\n return null;\n }\n\n parseAndBuild(input: string): [Notation, G.ParseError[]] {\n this.parse(input);\n const notation = new Notation();\n const errors: G.ParseError[] = [];\n errors.push(...this.errors);\n\n // First add the metadata then we can set it\n for (const key in this.metadata) notation.addMetaData(new Meta(key, this.metadata[key]));\n for (const cmd of this.commands) cmd.applyToNotation(notation);\n return [notation, errors];\n }\n\n parseEmbelishment(value: string): [any, boolean] {\n return carnatic.parseEmbelishment(value);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,IAAI,MA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"galore\";\nimport * as TLEX from \"tlex\";\nimport YAML from \"yaml\";\nimport { Literal, AtomType, Note, Atom, Rest, Space, Syllable, Group, Marker } from \"./core\";\nimport { Notation, MetaData as Meta, Command, CmdParam } from \"./notation\";\nimport {\n RawEmbedding,\n ApplyLayout,\n AddAtoms,\n SetCycle,\n SetBeatDuration,\n SetBreaks,\n ActivateRole,\n CreateRole,\n CreateLine,\n Section,\n ScopedGroup,\n Repeat,\n} from \"./commands\";\n\n// TODO - Make this plugable from the client instead of hard coded\nimport * as carnatic from \"./carnatic\";\n\nconst ONE = TSU.Num.Fraction.ONE;\nconst TWO = ONE.timesNum(2);\n\n/**\n * V4 of our parser builds on V3 and has the following improvements:\n *\n * 1. Embedding Headings to demarcate sections so users dont have to use\n * explicit MD for headings.\n * 2. Unlike V3 here users break out *of* song instead instead break out \"into\"\n * song. So users spend more time writing notation and less worrying about\n * other things like headings etc.\n */\nconst [parser /*itemGraph*/] = G.newParser(\n String.raw`\n %define IdentChar /[^%!@$#&\\^|\\[\\]={}()<>+\\-,;~: \\t\\f\\r\\n\\v\\\\\\.\\'\\\"]/\n\n %token BSLASH \"\\\\\"\n %token OPEN_SQ \"[\"\n %token CLOSE_SQ \"]\"\n %token EQUALS \"=\"\n %token OPEN_PAREN \"(\"\n %token CLOSE_PAREN \")\"\n %token OPEN_BRACE \"{\"\n %token CLOSE_BRACE \"}\"\n %token SLASH \"/\"\n %token STAR \"*\"\n %token CARET \"^\"\n // %skip \"-\"\n %token COMMA \",\"\n %token SEMI_COLON \";\"\n %token COLON \":\"\n\n %token FRONT_MATTER /^---$/m { toFrontMatter }\n %token SINGLE_LINE_RAW_STRING />(.*)$/m { toSingleLineRawString }\n %token MULTI_LINE_RAW_STRING /r(#{0,})\"/ { toMultiLineRawString }\n\n %token EMBELISHMENT /~[^\\s]*/ { toEmbelishment }\n %token NUMBER /-?\\d+/ { toNumber }\n %token BOOLEAN /true|false/ { toBoolean }\n %token STRING /\"([^\"\\\\\\n]|\\\\.|\\\\\\n)*\"/ { toString }\n %token STRING /'([^'\\\\\\n]|\\\\.|\\\\\\n)*'/ { toString }\n %token MARKER_NAME /\\\\@{IDENT}/ { toMarkerName }\n %token DOTS_IDENT /(\\.+)({IdentChar}+)/ { toOctavedNote }\n %token IDENT_DOTS /({IdentChar}+)(\\.+)/ { toOctavedNote }\n %token IDENT_COLON /{IdentChar}+:/ { toRoleSelector }\n %token IDENT /{IdentChar}+/\n %token BSLASH_IDENT /\\\\{IDENT}/ { toCommandName }\n %token BSLASH_NUMBER /\\\\{NUMBER}/\n %token HYPHEN /-/\n %skip /[ \\t\\n\\f\\r]+/\n %skip_flex \"//.*$\"\n %skip /\\/\\*.*?\\*\\//\n\n Document -> Elements\n | FRONT_MATTER Elements { prependFrontMatter }\n ;\n\n Elements -> Elements Command Atoms { appendCommand } \n | Elements RoleSelector Atoms { appendRoleSelector } \n | Elements Embedding Atoms { insertEmbedding }\n | Atoms { appendAtoms }\n ;\n\n Embedding -> SINGLE_LINE_RAW_STRING | MULTI_LINE_RAW_STRING ;\n\n Command -> BSLASH_IDENT CommandParams ? OptBlock { newCommandWithBlock } ;\n CommandParams -> OPEN_PAREN ParamList ? CLOSE_PAREN { $2 } ;\n OptBlock -> Block\n | { nullBlock }\n ;\n Block -> BlockStart Elements CLOSE_BRACE { endBlock } ;\n BlockStart -> OPEN_BRACE { beginBlock } ;\n\n ParamList -> ParamList COMMA Param { concatParamList } ;\n ParamList -> Param { newParamList };\n Param -> ParamValue { newParam } ;\n Param -> ParamKey EQUALS ParamValue { newParam } ;\n ParamKey -> IDENT ;\n ParamValue -> ( STRING | Fraction | NUMBER | BOOLEAN ) ;\n\n RoleSelector -> IDENT_COLON ;\n\n Atoms -> Atoms Atom { concatAtoms } ;\n Atoms -> { newArray } ;\n\n Atom -> Leaf ;\n\n Leaf -> Space | Lit | Group | Rest | Marker ;\n Marker -> MARKER_NAME CommandParams { newMarker } ;\n Leaf -> Duration Leaf { applyDuration } ;\n Rest -> HYPHEN { newRest };\n Space -> COMMA { newSpace } \n | SEMI_COLON { newDoubleSpace } \n | UNDER_SCORE { newSilentSpace } \n ;\n\n /* - An alternative representation to support both pre and\n * post embelishment operators. Here PRE_EMBs have a higher\n * associativity over POST_EMBs\n */\n Lit -> Lit POST_EMB { litWithPostEmb }\n | PreEmbLit\n ;\n\n PreEmbLit -> LitToken \n | LitToken CARET NUMBER { litWithCaret }\n | LitToken CARET STAR { litWithCaret }\n | PRE_EMB PreEmbLit { litWithPreEmb }\n ;\n \n LitToken -> DOTS_IDENT { litToAtom }\n | IDENT { litToAtom }\n | IDENT_DOTS { litToAtom }\n | STRING { litToAtom }\n ;\n\n Group -> OPEN_SQ Atoms CLOSE_SQ { newGroup };\n\n Duration -> Fraction | NUMBER;\n Fraction -> NUMBER SLASH NUMBER { newFraction } ;\n `,\n {\n debug: \"\",\n type: \"lalr\",\n leftRecursive: true,\n tokenHandlers: {\n toEmbelishment: (token: TLEX.Token, tape: TLEX.TapeInterface, owner: any) => {\n const [emb, pre] = owner.parseEmbelishment(token.value);\n if (emb == null) {\n console.log(\"Skipping Embelishment: \", token.value);\n owner.errors.push(\n new TLEX.TokenizerError(\n `Invalid embelishment: ${token.value}`,\n token.start,\n 1 + token.end - token.start,\n \"InvalidEmbelishment\",\n token.value,\n ),\n );\n return null;\n }\n token.value = emb;\n token.tag = pre ? \"PRE_EMB\" : \"POST_EMB\";\n return token;\n },\n toCommandName: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = token.value.substring(1);\n return token;\n },\n toBoolean: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = token.value == \"true\";\n return token;\n },\n toNumber: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = parseInt(token.value);\n return token;\n },\n toString: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = token.value.substring(1, token.value.length - 1);\n return token;\n },\n toMarkerName: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n // Extract marker name from \\@markerName - skip the \\@\n token.value = token.value.substring(2);\n return token;\n },\n toOctavedNote: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n if (token.tag == \"DOTS_IDENT\") {\n const octave = token.positions[1][1] - token.positions[1][0];\n const note = token.value.substring(octave);\n token.value = new Note(note, ONE, -octave);\n } else if (token.tag == \"IDENT_DOTS\") {\n const octave = token.positions[2][1] - token.positions[2][0];\n const note = token.value.substring(0, token.value.length - octave);\n token.value = new Note(note, ONE, octave);\n } else {\n throw new Error(\"Invalid token for converting to note: \" + token.tag);\n }\n return token;\n },\n toRoleSelector: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n token.value = token.value.substring(0, token.value.length - 1);\n return token;\n },\n toLineAnnotation: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n // skip the initial \"!\"\n token.value = token.value.substring(1);\n return token;\n },\n toSingleLineRawString: (token: TLEX.Token, _tape: TLEX.TapeInterface, _owner: any) => {\n // skip the initial \">\"\n token.value = token.value.substring(1);\n return token;\n },\n toMultiLineRawString: (token: TLEX.Token, tape: TLEX.TapeInterface, _owner: any) => {\n // consume everything until \"#<N times> as start\n const hashes = tape.substring(token.positions[1][0], token.positions[1][1]);\n const endPat = '\"' + hashes;\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of Raw String Literal: '\" + endPat + \"'\");\n }\n token.value = tape.substring(startPos, endPos);\n return token;\n },\n toFrontMatter: (token: TLEX.Token, tape: TLEX.TapeInterface, _owner: any) => {\n // skip the initial \">\"\n const endPat = \"\\n---\";\n const startPos = tape.index;\n const endPos = TLEX.TapeHelper.advanceAfter(tape, endPat) - endPat.length;\n if (endPos < 0) {\n throw new Error(\"EOF expected while finding end of front matter\");\n }\n token.value = tape.substring(startPos, endPos);\n // console.log(\"Found FM: \", token.value);\n return token;\n },\n },\n },\n);\n\n/**\n * A notation doc is a list of lines that are found in a single document.\n *\n * Since our document (md or html etc) can contain multiple snippets\n * all these snippets are related\n */\nimport {\n Block,\n SectionBlock,\n RepeatBlock,\n CycleBlock,\n BeatDurationBlock,\n BreaksBlock,\n RoleBlock,\n GroupBlock,\n} from \"./block\";\nimport { parseCycle } from \"./utils\";\n\n/**\n * Wrapper for a command that has a block of child commands.\n * When applied, it creates the appropriate Block subclass and applies child commands to it.\n */\nexport class BlockCommand extends Command {\n readonly innerCommand: Command;\n readonly blockCommands: Command[];\n\n constructor(innerCommand: Command, blockCommands: Command[]) {\n super(innerCommand.params);\n this.innerCommand = innerCommand;\n this.blockCommands = blockCommands;\n }\n\n get name(): string {\n return `Block(${this.innerCommand.name})`;\n }\n\n /**\n * Creates the appropriate Block subclass based on the inner command type.\n */\n private createBlock(parent: Block): Block {\n const cmd = this.innerCommand;\n\n if (cmd instanceof Section) {\n return new SectionBlock(cmd.sectionName, parent);\n } else if (cmd instanceof Repeat) {\n return new RepeatBlock(cmd.count, parent);\n } else if (cmd instanceof SetCycle) {\n const cycle = parseCycle(cmd.getParamAt(0));\n return new CycleBlock(cycle, parent);\n } else if (cmd instanceof SetBeatDuration) {\n return new BeatDurationBlock(cmd.beatDuration, parent);\n } else if (cmd instanceof SetBreaks) {\n return new BreaksBlock(cmd.pattern, parent);\n } else if (cmd instanceof CreateRole) {\n const roleName = cmd.getParamAt(0);\n return new RoleBlock(roleName, cmd.notesOnly, parent);\n } else if (cmd instanceof ScopedGroup) {\n return new GroupBlock(cmd.groupName || null, parent);\n } else {\n // Generic block for other commands\n return new Block(cmd.name.toLowerCase(), parent);\n }\n }\n\n debugValue(): any {\n return {\n name: this.name,\n index: this.index,\n innerCommand: this.innerCommand.debugValue(),\n blockCommands: this.blockCommands.map((cmd) => cmd.debugValue()),\n };\n }\n\n applyToNotation(notation: Notation): void {\n // Create the appropriate Block subclass\n // Cast notation as Block since Notation will extend Block\n const block = this.createBlock(notation as unknown as Block);\n\n // Apply all child commands to the block\n for (const cmd of this.blockCommands) {\n cmd.applyToBlock(block);\n }\n\n // Add the block to the notation\n notation.addBlockItem(block);\n }\n\n applyToBlock(container: Block): void {\n // Create the appropriate Block subclass\n const block = this.createBlock(container);\n\n // Apply all child commands to the block\n for (const cmd of this.blockCommands) {\n cmd.applyToBlock(block);\n }\n\n // Add the block to the container\n container.addBlockItem(block);\n }\n}\n\nexport class Parser {\n errors: (TLEX.TokenizerError | G.ParseError)[] = [];\n metadata: any = {};\n readonly commands: Command[] = [];\n // Stack to track command indices when entering blocks\n private blockStartStack: number[] = [];\n\n protected ruleHandlers = {\n newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return new TSU.Num.Fraction(children[0].value);\n } else {\n return new TSU.Num.Fraction(children[0].value, children[2].value);\n }\n },\n newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const out = new Group(...children[1].value).setDuration(TWO, true);\n return out;\n },\n litWithCaret: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = Note.fromLit(children[0].value as Literal);\n const opnode = children[2];\n const shiftValue = opnode.sym.label == \"STAR\" ? true : opnode.value;\n lit.shift = shiftValue;\n return lit;\n },\n litWithPreEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const emb = children[0];\n const lit = children[1].value as Literal;\n lit.embelishments.splice(0, 0, emb.value);\n return lit;\n },\n litWithPostEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0].value as Literal;\n const emb = children[1];\n lit.embelishments.push(emb);\n return lit;\n },\n litToAtom: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const lit = children[0];\n if (lit.sym.label == \"DOTS_IDENT\" || lit.sym.label == \"IDENT_DOTS\") {\n return lit.value;\n } else if (lit.sym.label == \"IDENT\") {\n // Mark this as a Literal to be processed later\n return new Literal(lit.value);\n // return role.notesOnly ? new Note(lit.value) : new Syllable(lit.value);\n } else if (lit.sym.label == \"STRING\") {\n // const role = this.snippet.currRole;\n // if (role.notesOnly) throw new Error(\"Strings cannot appear in notes only mode\");\n return new Syllable(lit.value);\n } else {\n throw new Error(\"Invalid lit: \" + lit);\n }\n },\n newSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n return new Space();\n },\n newRest: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n return new Rest();\n },\n newDoubleSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n return new Space(ONE.timesNum(2));\n },\n newSilentSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n return new Space(ONE, true);\n },\n newMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const name = children[0].value as string;\n const params = children[1].value || [];\n return new Marker(name, params);\n },\n applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n let dur = children[0].value as TSU.Num.Fraction | number;\n const leaf = children[1].value as Atom;\n if (typeof dur === \"number\") {\n dur = ONE.timesNum(dur);\n }\n if (leaf.TYPE == AtomType.GROUP) {\n (leaf as Group).setDuration(dur, true);\n } else {\n leaf.duration = dur;\n }\n return leaf;\n },\n newArray: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // create an array of values from all the values of child nodes\n return children.map((c) => c.value);\n },\n concatAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value;\n const atom = children[1].value;\n atoms.push(atom);\n return atoms;\n },\n newParam: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n if (children.length == 1) {\n return { key: null, value: children[0].value };\n } else {\n return { key: children[0].value, value: children[2].value };\n }\n },\n newParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n return [children[0].value];\n },\n concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const params = children[0].value;\n const newParam = children[2].value;\n params.push(newParam);\n return params;\n },\n // Block handling semantic actions\n beginBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n // Push current command count to track where this block's commands start\n this.blockStartStack.push(this.commands.length);\n return null;\n },\n endBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n // Pop the start index and extract commands added since then\n const startIndex = this.blockStartStack.pop()!;\n const blockCommands = this.commands.splice(startIndex);\n return blockCommands;\n },\n nullBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => {\n // No block present\n return null;\n },\n newCommandWithBlock: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const name = children[0].value;\n const params = children[1].value;\n const blockCommands = children[2].value as Command[] | null;\n\n const innerCommand = this.createCommand(name, params);\n\n if (blockCommands !== null) {\n // Wrap in BlockCommand\n return new BlockCommand(innerCommand, blockCommands);\n } else {\n // No block, return regular command\n return innerCommand;\n }\n },\n appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const atoms = children[0].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n prependFrontMatter: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const fm = children[0].value;\n // console.log(\"Child 0: \", fm);\n // console.log(\"Child 1: \", children[1].value);\n const data = YAML.parse(fm);\n console.log(\"Parsed FM: \", data);\n this.metadata = data;\n return children[1].value;\n },\n appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const command = children[1].value as Command;\n this.addCommand(command);\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n const roleName = children[1].value;\n const lName = roleName.toLowerCase().trim();\n this.addCommand(new ActivateRole([{ key: null, value: lName }]));\n\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => {\n // How to handle embeddings - these are just blocks\n // to escape out of song (most likely for some rendering of html/md etc)\n const rawVal = children[1].value;\n this.addCommand(new RawEmbedding([{ key: null, value: rawVal }]));\n const atoms = children[2].value as Atom[];\n if (atoms.length > 0) {\n this.addCommand(new AddAtoms(...atoms));\n }\n return null;\n },\n };\n\n constructor(_config?: any) {\n // config = config || {};\n }\n\n createCommand(name: string, params: CmdParam[]): Command {\n const lName = name.trim().toLowerCase();\n params = params || [];\n if (lName == \"line\") {\n return new CreateLine(params);\n // } else if (lName == \"meta\") { return new MetaData(params);\n } else if (lName == \"role\") {\n return new CreateRole(params);\n } else if (lName == \"layout\") {\n return new ApplyLayout(params);\n } else if (lName == \"beatduration\") {\n return new SetBeatDuration(params);\n } else if (lName == \"breaks\") {\n return new SetBreaks(params);\n } else if (lName == \"cycle\") {\n return new SetCycle(params);\n } else if (lName == \"section\") {\n return new Section(params);\n } else if (lName == \"group\") {\n return new ScopedGroup(params);\n } else if (lName == \"repeat\") {\n return new Repeat(params);\n } else {\n // Try to set this as the current role\n throw new Error(\"Invalid command: \" + lName);\n }\n }\n\n addCommand(cmd: Command): void {\n cmd.index = this.commands.length;\n this.commands.push(cmd);\n }\n\n parse(input: string): any {\n this.errors = [];\n try {\n const ptree = parser.parse(input, {\n tokenizerContext: this,\n ruleHandlers: this.ruleHandlers,\n onTokenError: (err: TLEX.TokenizerError) => {\n this.errors.push(err);\n return true;\n },\n });\n return ptree;\n } catch (err) {\n if (err instanceof G.ParseError) {\n this.errors.push(err);\n } else {\n throw err;\n }\n }\n return null;\n }\n\n parseAndBuild(input: string): [Notation, G.ParseError[]] {\n this.parse(input);\n const notation = new Notation();\n const errors: G.ParseError[] = [];\n errors.push(...this.errors);\n\n // First add the metadata then we can set it\n for (const key in this.metadata) notation.addMetaData(new Meta(key, this.metadata[key]));\n for (const cmd of this.commands) cmd.applyToNotation(notation);\n return [notation, errors];\n }\n\n parseEmbelishment(value: string): [any, boolean] {\n return carnatic.parseEmbelishment(value);\n }\n}\n"]}
|