notations 0.0.69 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/NotationView.css +20 -0
  2. package/dist/NotationView.css.map +1 -1
  3. package/dist/NotationView.min.css +1 -1
  4. package/dist/NotationView.min.css.map +1 -1
  5. package/dist/notations.umd.js +17425 -23624
  6. package/dist/notations.umd.min.js +8 -3
  7. package/dist/notations.umd.min.js.LICENSE.txt +0 -14
  8. package/dist/notations.umd.min.js.map +1 -1
  9. package/lib/cjs/beats.d.ts +4 -0
  10. package/lib/cjs/beats.js +19 -2
  11. package/lib/cjs/beats.js.map +1 -1
  12. package/lib/cjs/block.d.ts +85 -0
  13. package/lib/cjs/block.js +310 -0
  14. package/lib/cjs/block.js.map +1 -0
  15. package/lib/cjs/carnatic/NotationView.d.ts +11 -4
  16. package/lib/cjs/carnatic/NotationView.js +25 -11
  17. package/lib/cjs/carnatic/NotationView.js.map +1 -1
  18. package/lib/cjs/commands.d.ts +25 -11
  19. package/lib/cjs/commands.js +83 -31
  20. package/lib/cjs/commands.js.map +1 -1
  21. package/lib/cjs/entity.d.ts +3 -7
  22. package/lib/cjs/entity.js +7 -37
  23. package/lib/cjs/entity.js.map +1 -1
  24. package/lib/cjs/grids.d.ts +32 -3
  25. package/lib/cjs/grids.js +96 -9
  26. package/lib/cjs/grids.js.map +1 -1
  27. package/lib/cjs/index.d.ts +1 -0
  28. package/lib/cjs/index.js +1 -0
  29. package/lib/cjs/index.js.map +1 -1
  30. package/lib/cjs/loader.js +1 -41
  31. package/lib/cjs/loader.js.map +1 -1
  32. package/lib/cjs/notation.d.ts +20 -36
  33. package/lib/cjs/notation.js +100 -133
  34. package/lib/cjs/notation.js.map +1 -1
  35. package/lib/cjs/parser.d.ts +21 -6
  36. package/lib/cjs/parser.js +122 -23
  37. package/lib/cjs/parser.js.map +1 -1
  38. package/lib/esm/beats.d.ts +4 -0
  39. package/lib/esm/beats.js +19 -2
  40. package/lib/esm/beats.js.map +1 -1
  41. package/lib/esm/block.d.ts +85 -0
  42. package/lib/esm/block.js +293 -0
  43. package/lib/esm/block.js.map +1 -0
  44. package/lib/esm/carnatic/NotationView.d.ts +11 -4
  45. package/lib/esm/carnatic/NotationView.js +25 -11
  46. package/lib/esm/carnatic/NotationView.js.map +1 -1
  47. package/lib/esm/commands.d.ts +25 -11
  48. package/lib/esm/commands.js +80 -31
  49. package/lib/esm/commands.js.map +1 -1
  50. package/lib/esm/entity.d.ts +3 -7
  51. package/lib/esm/entity.js +7 -37
  52. package/lib/esm/entity.js.map +1 -1
  53. package/lib/esm/grids.d.ts +32 -3
  54. package/lib/esm/grids.js +96 -9
  55. package/lib/esm/grids.js.map +1 -1
  56. package/lib/esm/index.d.ts +1 -0
  57. package/lib/esm/index.js +1 -0
  58. package/lib/esm/index.js.map +1 -1
  59. package/lib/esm/loader.js +1 -8
  60. package/lib/esm/loader.js.map +1 -1
  61. package/lib/esm/notation.d.ts +20 -36
  62. package/lib/esm/notation.js +84 -128
  63. package/lib/esm/notation.js.map +1 -1
  64. package/lib/esm/parser.d.ts +21 -6
  65. package/lib/esm/parser.js +122 -24
  66. package/lib/esm/parser.js.map +1 -1
  67. package/package.json +3 -2
  68. package/styles/NotationView.scss +22 -0
package/lib/cjs/loader.js CHANGED
@@ -1,41 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.parse = parse;
37
4
  exports.load = load;
38
- const TSU = __importStar(require("@panyam/tsutils"));
39
5
  const beats_1 = require("./beats");
40
6
  const parser_1 = require("./parser");
41
7
  function parse(input) {
@@ -47,13 +13,7 @@ function load(codeText, config = {}) {
47
13
  const startTime = performance.now();
48
14
  const [notation, errors] = parse(codeText);
49
15
  const parseTime = performance.now();
50
- for (const block of notation.blocks) {
51
- if (block.TYPE == "Line" && !block.isEmpty) {
52
- const line = block;
53
- TSU.assert(line.layoutParams != null, "Layout params for a non empty line *SHOULD* exist");
54
- beatLayout.addLine(line);
55
- }
56
- }
16
+ beatLayout.processBlock(notation);
57
17
  const buildTime = performance.now();
58
18
  if (config.log) {
59
19
  console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,sBAEC;AASD,oBAkCC;AA1DD,qDAAuC;AAGvC,mCAA2C;AAC3C,qCAAkC;AASlC,SAAgB,KAAK,CAAC,KAAa;IACjC,OAAO,IAAI,eAAM,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC;AASD,SAAgB,IAAI,CAClB,QAAgB,EAChB,SAAc,EAAE;IAEhB,QAAQ,GAAG,QAAQ,IAAI,EAAE,CAAC;IAC1B,MAAM,UAAU,GAAG,IAAI,wBAAgB,EAAE,CAAC;IAC1C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAGpC,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpC,IAAI,KAAK,CAAC,IAAI,IAAI,MAAM,IAAI,CAAE,KAAc,CAAC,OAAO,EAAE,CAAC;YACrD,MAAM,IAAI,GAAG,KAAa,CAAC;YAG3B,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE,mDAAmD,CAAC,CAAC;YAC3F,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,GAAG,SAAS,mBAAmB,SAAS,GAAG,SAAS,IAAI,CAAC,CAAC;IAC7G,CAAC;IACD,OAAO;QACL,QAAQ;QACR,UAAU;QACV,MAAM;QACN;YACE,SAAS,EAAE,SAAS,GAAG,SAAS;YAChC,SAAS,EAAE,SAAS,GAAG,SAAS;SACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport { Line } from \"./core\";\nimport { GlobalBeatLayout } from \"./beats\";\nimport { Parser } from \"./parser\";\nimport { Notation } from \"./notation\";\n\n/**\n * Parses a notation string into a Notation object.\n *\n * @param input The notation string to parse\n * @returns A tuple containing the parsed Notation and any parsing errors\n */\nexport function parse(input: string): [Notation, G.ParseError[]] {\n return new Parser().parseAndBuild(input);\n}\n\n/**\n * Loads a notation from a string and builds the beat layout.\n *\n * @param codeText The notation string to load\n * @param config Optional configuration object\n * @returns A tuple containing the Notation, GlobalBeatLayout, parsing errors, and timing information\n */\nexport function load(\n codeText: string,\n config: any = {},\n): [Notation, GlobalBeatLayout, G.ParseError[], TSU.StringMap<number>] {\n codeText = codeText || \"\";\n const beatLayout = new GlobalBeatLayout();\n const startTime = performance.now();\n const [notation, errors] = parse(codeText);\n const parseTime = performance.now();\n\n // Create Line Beats\n for (const block of notation.blocks) {\n if (block.TYPE == \"Line\" && !(block as Line).isEmpty) {\n const line = block as Line;\n // LP should exist by now\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(line.layoutParams != null, \"Layout params for a non empty line *SHOULD* exist\");\n beatLayout.addLine(line);\n }\n }\n\n const buildTime = performance.now();\n if (config.log) {\n console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);\n }\n return [\n notation,\n beatLayout,\n errors,\n {\n parseTime: parseTime - startTime,\n buildTime: buildTime - parseTime,\n },\n ];\n}\n"]}
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/loader.ts"],"names":[],"mappings":";;AAYA,sBAEC;AASD,oBA2BC;AAhDD,mCAA2C;AAC3C,qCAAkC;AASlC,SAAgB,KAAK,CAAC,KAAa;IACjC,OAAO,IAAI,eAAM,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC;AASD,SAAgB,IAAI,CAClB,QAAgB,EAChB,SAAc,EAAE;IAEhB,QAAQ,GAAG,QAAQ,IAAI,EAAE,CAAC;IAC1B,MAAM,UAAU,GAAG,IAAI,wBAAgB,EAAE,CAAC;IAC1C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAIpC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAElC,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,4BAA4B,SAAS,GAAG,SAAS,mBAAmB,SAAS,GAAG,SAAS,IAAI,CAAC,CAAC;IAC7G,CAAC;IACD,OAAO;QACL,QAAQ;QACR,UAAU;QACV,MAAM;QACN;YACE,SAAS,EAAE,SAAS,GAAG,SAAS;YAChC,SAAS,EAAE,SAAS,GAAG,SAAS;SACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport * as G from \"galore\";\nimport { GlobalBeatLayout } from \"./beats\";\nimport { Parser } from \"./parser\";\nimport { Notation } from \"./notation\";\n\n/**\n * Parses a notation string into a Notation object.\n *\n * @param input The notation string to parse\n * @returns A tuple containing the parsed Notation and any parsing errors\n */\nexport function parse(input: string): [Notation, G.ParseError[]] {\n return new Parser().parseAndBuild(input);\n}\n\n/**\n * Loads a notation from a string and builds the beat layout.\n *\n * @param codeText The notation string to load\n * @param config Optional configuration object\n * @returns A tuple containing the Notation, GlobalBeatLayout, parsing errors, and timing information\n */\nexport function load(\n codeText: string,\n config: any = {},\n): [Notation, GlobalBeatLayout, G.ParseError[], TSU.StringMap<number>] {\n codeText = codeText || \"\";\n const beatLayout = new GlobalBeatLayout();\n const startTime = performance.now();\n const [notation, errors] = parse(codeText);\n const parseTime = performance.now();\n\n // Process all blocks recursively using block.children()\n // This handles nested blocks like \\repeat { }, \\section { }, etc.\n beatLayout.processBlock(notation);\n\n const buildTime = performance.now();\n if (config.log) {\n console.log(`V4 Document, Parse Time: ${parseTime - startTime}ms, Build Time: ${buildTime - parseTime}ms`);\n }\n return [\n notation,\n beatLayout,\n errors,\n {\n parseTime: parseTime - startTime,\n buildTime: buildTime - parseTime,\n },\n ];\n}\n"]}
@@ -2,12 +2,8 @@ import * as TSU from "@panyam/tsutils";
2
2
  import { Entity } from "./entity";
3
3
  import { Cycle } from "./cycle";
4
4
  import { Line } from "./core";
5
- import { LayoutParams } from "./layouts";
6
- export declare class RoleDef {
7
- name: string;
8
- notesOnly: boolean;
9
- index: number;
10
- }
5
+ import { RoleDef, RawBlock, BlockItem, Block, SectionBlock, RepeatBlock, CycleBlock, BeatDurationBlock, BreaksBlock, RoleBlock, GroupBlock, isBlock, isLine, isRawBlock, findContainingBlock } from "./block";
6
+ export { RoleDef, RawBlock, BlockItem, Block, SectionBlock, RepeatBlock, CycleBlock, BeatDurationBlock, BreaksBlock, RoleBlock, GroupBlock, isBlock, isLine, isRawBlock, findContainingBlock, };
11
7
  export type CmdParam = {
12
8
  key: TSU.Nullable<string>;
13
9
  value: any;
@@ -24,14 +20,8 @@ export declare abstract class Command extends Entity {
24
20
  debugValue(): any;
25
21
  getParam(name: string): any;
26
22
  getParamAt(index: number): any;
27
- abstract applyToNotation(notebook: Notation): void;
28
- }
29
- export declare class RawBlock extends Entity {
30
- content: string;
31
- contentType: string;
32
- readonly TYPE: string;
33
- constructor(content: string, contentType?: string);
34
- debugValue(): any;
23
+ abstract applyToBlock(container: Block): void;
24
+ applyToNotation(notation: Notation): void;
35
25
  }
36
26
  export declare class MetaData {
37
27
  readonly key: string;
@@ -39,37 +29,31 @@ export declare class MetaData {
39
29
  readonly params?: any | undefined;
40
30
  constructor(key: string, value: string, params?: any | undefined);
41
31
  }
42
- export declare class Notation extends Entity {
32
+ export declare class Notation extends Block {
43
33
  readonly TYPE = "Notation";
44
- private _unnamedLayoutParams;
45
- private _namedLayoutParams;
46
- private _currRoleDef;
47
- roles: RoleDef[];
48
- blocks: (Line | RawBlock)[];
49
- currentAPB: number;
50
- currentCycle: Cycle;
51
- currentBreaks: number[];
52
34
  metadata: Map<string, MetaData>;
53
35
  onMissingRole: (name: string) => RoleDef | null;
54
- get unnamedLayoutParams(): ReadonlyArray<LayoutParams>;
55
- get namedLayoutParams(): ReadonlyMap<string, LayoutParams>;
36
+ constructor();
37
+ get blocks(): BlockItem[];
38
+ get currentAPB(): number;
39
+ set currentAPB(value: number);
40
+ get currentCycle(): Cycle;
41
+ set currentCycle(value: Cycle);
42
+ get currentBreaks(): number[];
43
+ set currentBreaks(value: number[]);
44
+ get roles(): RoleDef[];
45
+ setCurrRole(name: string): void;
46
+ getRoleDef(name: string): TSU.Nullable<RoleDef>;
47
+ newRoleDef(name: string, notesOnly?: boolean): RoleDef;
56
48
  addLine(line: Line): void;
57
49
  removeLine(line: Line): number;
58
50
  addRawBlock(raw: RawBlock): void;
59
51
  addMetaData(meta: MetaData, addBlock?: boolean): void;
52
+ resetLine(): void;
60
53
  debugValue(): any;
61
- getRoleDef(name: string): TSU.Nullable<RoleDef>;
62
- newRoleDef(name: string, notesOnly?: boolean): RoleDef;
54
+ protected _currRoleDef: TSU.Nullable<RoleDef>;
63
55
  get currRoleDef(): RoleDef | null;
64
- setCurrRole(name: string): void;
65
- private _currentLine;
56
+ protected _currentLine: Line | null;
66
57
  get currentLine(): Line;
67
- resetLine(): void;
68
58
  newLine(): Line;
69
- private _layoutParams;
70
- resetLayoutParams(): void;
71
- get layoutParams(): LayoutParams;
72
- ensureNamedLayoutParams(name: string): LayoutParams;
73
- protected snapshotLayoutParams(): LayoutParams;
74
- protected findUnnamedLayoutParams(): LayoutParams | null;
75
59
  }
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Notation = exports.MetaData = exports.RawBlock = exports.Command = exports.RoleDef = void 0;
3
+ exports.Notation = exports.MetaData = exports.Command = exports.findContainingBlock = exports.isRawBlock = exports.isLine = exports.isBlock = exports.GroupBlock = exports.RoleBlock = exports.BreaksBlock = exports.BeatDurationBlock = exports.CycleBlock = exports.RepeatBlock = exports.SectionBlock = exports.Block = exports.RawBlock = exports.RoleDef = void 0;
4
4
  const entity_1 = require("./entity");
5
5
  const cycle_1 = require("./cycle");
6
6
  const core_1 = require("./core");
7
- const layouts_1 = require("./layouts");
8
- class RoleDef {
9
- constructor() {
10
- this.name = "";
11
- this.notesOnly = false;
12
- this.index = 0;
13
- }
14
- }
15
- exports.RoleDef = RoleDef;
7
+ const block_1 = require("./block");
8
+ Object.defineProperty(exports, "RoleDef", { enumerable: true, get: function () { return block_1.RoleDef; } });
9
+ Object.defineProperty(exports, "RawBlock", { enumerable: true, get: function () { return block_1.RawBlock; } });
10
+ Object.defineProperty(exports, "Block", { enumerable: true, get: function () { return block_1.Block; } });
11
+ Object.defineProperty(exports, "SectionBlock", { enumerable: true, get: function () { return block_1.SectionBlock; } });
12
+ Object.defineProperty(exports, "RepeatBlock", { enumerable: true, get: function () { return block_1.RepeatBlock; } });
13
+ Object.defineProperty(exports, "CycleBlock", { enumerable: true, get: function () { return block_1.CycleBlock; } });
14
+ Object.defineProperty(exports, "BeatDurationBlock", { enumerable: true, get: function () { return block_1.BeatDurationBlock; } });
15
+ Object.defineProperty(exports, "BreaksBlock", { enumerable: true, get: function () { return block_1.BreaksBlock; } });
16
+ Object.defineProperty(exports, "RoleBlock", { enumerable: true, get: function () { return block_1.RoleBlock; } });
17
+ Object.defineProperty(exports, "GroupBlock", { enumerable: true, get: function () { return block_1.GroupBlock; } });
18
+ Object.defineProperty(exports, "isBlock", { enumerable: true, get: function () { return block_1.isBlock; } });
19
+ Object.defineProperty(exports, "isLine", { enumerable: true, get: function () { return block_1.isLine; } });
20
+ Object.defineProperty(exports, "isRawBlock", { enumerable: true, get: function () { return block_1.isRawBlock; } });
21
+ Object.defineProperty(exports, "findContainingBlock", { enumerable: true, get: function () { return block_1.findContainingBlock; } });
16
22
  class Command extends entity_1.Entity {
17
23
  constructor(params = []) {
18
24
  super();
@@ -41,20 +47,11 @@ class Command extends entity_1.Entity {
41
47
  getParamAt(index) {
42
48
  return index < this.params.length ? this.params[index].value : null;
43
49
  }
44
- }
45
- exports.Command = Command;
46
- class RawBlock extends entity_1.Entity {
47
- constructor(content, contentType = "md") {
48
- super();
49
- this.content = content;
50
- this.contentType = contentType;
51
- this.TYPE = "RawBlock";
52
- }
53
- debugValue() {
54
- return Object.assign(Object.assign({}, super.debugValue()), { content: this.content, contentType: this.contentType });
50
+ applyToNotation(notation) {
51
+ this.applyToBlock(notation);
55
52
  }
56
53
  }
57
- exports.RawBlock = RawBlock;
54
+ exports.Command = Command;
58
55
  class MetaData {
59
56
  constructor(key, value, params) {
60
57
  this.key = key;
@@ -64,113 +61,128 @@ class MetaData {
64
61
  }
65
62
  }
66
63
  exports.MetaData = MetaData;
67
- class Notation extends entity_1.Entity {
64
+ class Notation extends block_1.Block {
68
65
  constructor() {
69
- super(...arguments);
66
+ super("notation", null);
70
67
  this.TYPE = "Notation";
71
- this._unnamedLayoutParams = [];
72
- this._namedLayoutParams = new Map();
73
- this._currRoleDef = null;
74
- this.roles = [];
75
- this.blocks = [];
76
- this.currentAPB = 1;
77
- this.currentCycle = cycle_1.Cycle.DEFAULT;
78
- this.currentBreaks = [];
79
68
  this.metadata = new Map();
80
69
  this.onMissingRole = (name) => this.newRoleDef(name, name == "sw");
70
+ this._currRoleDef = null;
81
71
  this._currentLine = null;
82
- this._layoutParams = null;
83
- }
84
- get unnamedLayoutParams() {
85
- return this._unnamedLayoutParams;
72
+ this.localCycle = cycle_1.Cycle.DEFAULT;
73
+ this.localAtomsPerBeat = 1;
74
+ this.localBreaks = [];
86
75
  }
87
- get namedLayoutParams() {
88
- return this._namedLayoutParams;
76
+ get blocks() {
77
+ return this.blockItems;
89
78
  }
90
- addLine(line) {
91
- this.blocks.push(line);
79
+ get currentAPB() {
80
+ var _a;
81
+ return (_a = this.localAtomsPerBeat) !== null && _a !== void 0 ? _a : 1;
92
82
  }
93
- removeLine(line) {
94
- const index = this.blocks.findIndex((l) => l == line);
95
- if (index >= 0) {
96
- this.blocks.splice(index, 1);
97
- }
98
- return index;
83
+ set currentAPB(value) {
84
+ this.localAtomsPerBeat = value;
99
85
  }
100
- addRawBlock(raw) {
101
- this.blocks.push(raw);
102
- this.resetLine();
86
+ get currentCycle() {
87
+ var _a;
88
+ return (_a = this.localCycle) !== null && _a !== void 0 ? _a : cycle_1.Cycle.DEFAULT;
103
89
  }
104
- addMetaData(meta, addBlock = true) {
105
- if (addBlock && !this.metadata.has(meta.key)) {
106
- const raw = new RawBlock(meta.key, "metadata");
107
- this.addRawBlock(raw);
108
- }
109
- this.metadata.set(meta.key, meta);
90
+ set currentCycle(value) {
91
+ this.localCycle = value;
110
92
  }
111
- debugValue() {
93
+ get currentBreaks() {
112
94
  var _a;
113
- return Object.assign(Object.assign({}, super.debugValue), { roles: this.roles, blocks: this.blocks.map((b) => b.debugValue()), currentAPB: this.currentAPB, currentCycle: (_a = this.currentCycle) === null || _a === void 0 ? void 0 : _a.uuid, currentBreaks: this.currentBreaks });
95
+ return (_a = this.localBreaks) !== null && _a !== void 0 ? _a : [];
114
96
  }
115
- getRoleDef(name) {
97
+ set currentBreaks(value) {
98
+ this.localBreaks = value;
99
+ }
100
+ get roles() {
101
+ return Array.from(this.localRoles.values());
102
+ }
103
+ setCurrRole(name) {
116
104
  name = name.trim().toLowerCase();
117
- if (name == "") {
118
- return this.roles[this.roles.length - 1] || null;
105
+ if (name.trim() == "") {
106
+ throw new Error("Role name cannot be empty");
119
107
  }
120
- for (let i = 0; i < this.roles.length; i++) {
121
- const rd = this.roles[i];
122
- if (name == rd.name)
123
- return rd;
108
+ const roleDef = this.getRole(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);
109
+ if (roleDef == null) {
110
+ throw new Error("Role not found: " + name);
124
111
  }
125
- return null;
112
+ this._currRoleDef = roleDef;
113
+ }
114
+ getRoleDef(name) {
115
+ var _a;
116
+ name = name.trim().toLowerCase();
117
+ if (name === "") {
118
+ const roles = Array.from(this.localRoles.values());
119
+ return roles[roles.length - 1] || null;
120
+ }
121
+ return (_a = this.localRoles.get(name)) !== null && _a !== void 0 ? _a : null;
126
122
  }
127
123
  newRoleDef(name, notesOnly = false) {
128
124
  name = name.trim().toLowerCase();
129
- if (name.trim() == "") {
125
+ if (name === "") {
130
126
  throw new Error("Role name cannot be empty");
131
127
  }
132
- const roleDef = this.getRoleDef(name);
133
- if (roleDef != null) {
134
- throw new Error("Role already exists");
128
+ if (this.localRoles.has(name)) {
129
+ throw new Error("Role already exists: " + name);
135
130
  }
136
- const rd = new RoleDef();
131
+ const rd = new block_1.RoleDef();
137
132
  rd.name = name;
138
133
  rd.notesOnly = notesOnly;
139
- rd.index = this.roles.length;
140
- this.roles.push(rd);
134
+ rd.index = this.localRoles.size;
135
+ this.localRoles.set(name, rd);
141
136
  return rd;
142
137
  }
138
+ addLine(line) {
139
+ this.addBlockItem(line);
140
+ }
141
+ removeLine(line) {
142
+ return this.removeBlockItem(line);
143
+ }
144
+ addRawBlock(raw) {
145
+ this.addBlockItem(raw);
146
+ this.resetLine();
147
+ }
148
+ addMetaData(meta, addBlock = true) {
149
+ if (addBlock && !this.metadata.has(meta.key)) {
150
+ const raw = new block_1.RawBlock(meta.key, "metadata");
151
+ this.addRawBlock(raw);
152
+ }
153
+ this.metadata.set(meta.key, meta);
154
+ }
155
+ resetLine() {
156
+ this._currentLine = null;
157
+ }
158
+ debugValue() {
159
+ var _a;
160
+ return {
161
+ blocks: this.blocks.map((b) => b.debugValue()),
162
+ currentAPB: this.currentAPB,
163
+ currentBreaks: this.currentBreaks,
164
+ currentCycle: (_a = this.currentCycle) === null || _a === void 0 ? void 0 : _a.uuid,
165
+ roles: this.roles,
166
+ };
167
+ }
143
168
  get currRoleDef() {
144
169
  if (this._currRoleDef == null) {
145
- if (this.roles.length == 0) {
170
+ const roles = Array.from(this.localRoles.values());
171
+ if (roles.length === 0) {
146
172
  return null;
147
173
  }
148
174
  else {
149
- this._currRoleDef = this.roles[this.roles.length - 1];
175
+ this._currRoleDef = roles[roles.length - 1];
150
176
  }
151
177
  }
152
178
  return this._currRoleDef;
153
179
  }
154
- setCurrRole(name) {
155
- name = name.trim().toLowerCase();
156
- if (name.trim() == "") {
157
- throw new Error("Role name cannot be empty");
158
- }
159
- const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);
160
- if (roleDef == null) {
161
- throw new Error("Role not found: " + name);
162
- }
163
- this._currRoleDef = roleDef;
164
- }
165
180
  get currentLine() {
166
181
  if (this._currentLine == null) {
167
182
  return this.newLine();
168
183
  }
169
184
  return this._currentLine;
170
185
  }
171
- resetLine() {
172
- this._currentLine = null;
173
- }
174
186
  newLine() {
175
187
  if (this._currentLine && this._currentLine.isEmpty) {
176
188
  this.removeLine(this._currentLine);
@@ -179,51 +191,6 @@ class Notation extends entity_1.Entity {
179
191
  this.addLine(this._currentLine);
180
192
  return this._currentLine;
181
193
  }
182
- resetLayoutParams() {
183
- this._layoutParams = null;
184
- this.resetLine();
185
- }
186
- get layoutParams() {
187
- if (this._layoutParams == null) {
188
- this._layoutParams = this.findUnnamedLayoutParams();
189
- if (this._layoutParams == null) {
190
- this._layoutParams = this.snapshotLayoutParams();
191
- this._unnamedLayoutParams.push(this._layoutParams);
192
- }
193
- }
194
- return this._layoutParams;
195
- }
196
- ensureNamedLayoutParams(name) {
197
- let lp = this._namedLayoutParams.get(name) || null;
198
- if (lp == null || this._layoutParams != lp) {
199
- if (lp == null) {
200
- lp = this.snapshotLayoutParams();
201
- this._namedLayoutParams.set(name, lp);
202
- }
203
- else {
204
- this.currentCycle = lp.cycle;
205
- this.currentAPB = lp.beatDuration;
206
- this.currentBreaks = lp.lineBreaks;
207
- }
208
- this._layoutParams = lp;
209
- this.resetLine();
210
- }
211
- return this._layoutParams;
212
- }
213
- snapshotLayoutParams() {
214
- return new layouts_1.LayoutParams({
215
- cycle: this.currentCycle,
216
- beatDuration: this.currentAPB,
217
- layout: this.currentBreaks,
218
- });
219
- }
220
- findUnnamedLayoutParams() {
221
- return (this._unnamedLayoutParams.find((lp) => {
222
- return (lp.beatDuration == this.currentAPB &&
223
- this.currentCycle.equals(lp.cycle) &&
224
- lp.lineBreaksEqual(this.currentBreaks));
225
- }) || null);
226
- }
227
194
  }
228
195
  exports.Notation = Notation;
229
196
  //# sourceMappingURL=notation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAClC,mCAAgC;AAChC,iCAA8B;AAC9B,uCAAyC;AAMzC,MAAa,OAAO;IAApB;QAEE,SAAI,GAAG,EAAE,CAAC;QAGV,cAAS,GAAG,KAAK,CAAC;QAGlB,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA;AATD,0BASC;AAYD,MAAsB,OAAQ,SAAQ,eAAM;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,IAAI;QACN,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;IAMD,UAAU;QACR,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IACrE,CAAC;IAOD,QAAQ,CAAC,IAAY;QACnB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,IAAI,KAAK,CAAC,GAAG,IAAI,IAAI;gBAAE,OAAO,KAAK,CAAC,KAAK,CAAC;Q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tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\n\n/**\n * Definition of a role in the notation.\n * A role represents a specific voice or part in the music notation.\n */\nexport class RoleDef {\n /** Name of the role */\n name = \"\";\n\n /** Whether this role contains only notes (true) or can also contain syllables/text (false) */\n notesOnly = false;\n\n /** Index of this role in the notation */\n index = 0;\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 notation.\n * @param notation The notation to apply this command to\n */\n abstract applyToNotation(notebook: Notation): void;\n}\n\n/**\n * Represents a raw block of content in the notation.\n * Raw blocks can contain arbitrary content like markdown, HTML, etc.\n */\nexport class RawBlock extends Entity {\n readonly TYPE: string = \"RawBlock\";\n\n /**\n * Creates a new RawBlock.\n * @param content The content of the block\n * @param contentType The type of content (e.g., \"md\" for markdown)\n */\n constructor(\n public content: string,\n public contentType: string = \"md\",\n ) {\n super();\n }\n\n /**\n * Returns a debug-friendly representation of this raw block.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), content: this.content, contentType: this.contentType };\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 contains all the elements, settings, and layout information for a piece of music.\n */\nexport class Notation extends Entity {\n readonly TYPE = \"Notation\";\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _currRoleDef: TSU.Nullable<RoleDef> = null;\n\n /** Roles defined in this notation */\n roles: RoleDef[] = [];\n\n /** Blocks (lines or raw blocks) in this notation */\n blocks: (Line | RawBlock)[] = [];\n\n /** Current beat duration multiplier */\n currentAPB = 1;\n\n /** Current cycle pattern */\n currentCycle: Cycle = Cycle.DEFAULT;\n\n /** Current line breaks pattern */\n currentBreaks: number[] = [];\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 * Gets the unnamed layout parameters.\n */\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n /**\n * Gets the named layout parameters.\n */\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\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.blocks.push(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 const index = this.blocks.findIndex((l) => l == line);\n if (index >= 0) {\n this.blocks.splice(index, 1);\n }\n return index;\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.blocks.push(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 * Returns a debug-friendly representation of this notation.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return {\n ...super.debugValue,\n roles: this.roles,\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentCycle: this.currentCycle?.uuid,\n currentBreaks: this.currentBreaks,\n };\n }\n\n /**\n * Gets a role definition by name.\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 this.roles[this.roles.length - 1] || null;\n }\n for (let i = 0; i < this.roles.length; i++) {\n const rd = this.roles[i];\n if (name == rd.name) return rd;\n }\n return 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.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name);\n if (roleDef != null) {\n throw new Error(\"Role already exists\");\n // roleDef.notesOnly = notesOnly;\n // return roleDef;\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.roles.length;\n this.roles.push(rd);\n\n return rd;\n }\n\n /**\n * Gets the current role definition.\n */\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n if (this.roles.length == 0) {\n return null;\n } else {\n this._currRoleDef = this.roles[this.roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n /**\n * Sets the current role by name.\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.getRoleDef(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 // Gets the current line, creating it if needed\n private _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 * Resets the current line pointer to null.\n */\n resetLine(): void {\n this._currentLine = null;\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 private _layoutParams: LayoutParams | null = null;\n\n /**\n * Resets the current layout parameters to null.\n */\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n /**\n * Gets the current layout parameters, creating or finding an appropriate one if needed.\n */\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\n this._layoutParams = this.findUnnamedLayoutParams();\n if (this._layoutParams == null) {\n this._layoutParams = this.snapshotLayoutParams();\n this._unnamedLayoutParams.push(this._layoutParams);\n }\n }\n return this._layoutParams;\n }\n\n /**\n * Ensures that named layout parameters with the given name exist.\n * Creates them if they don't exist, or updates current layout parameters to match.\n *\n * @param name The name of the layout parameters\n * @returns The layout parameters\n */\n ensureNamedLayoutParams(name: string): LayoutParams {\n let lp = this._namedLayoutParams.get(name) || null;\n if (lp == null || this._layoutParams != lp) {\n // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n /**\n * Creates a snapshot of the current layout parameters.\n * @returns A new LayoutParams object with the current settings\n */\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Finds an unnamed layout parameters object that matches the current settings.\n * @returns Matching layout parameters, or null if none found\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n}\n"]}
1
+ {"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAClC,mCAAgC;AAChC,iCAA8B;AAC9B,mCAgBiB;AAIf,wFAnBA,eAAO,OAmBA;AACP,yFAnBA,gBAAQ,OAmBA;AAER,sFAnBA,aAAK,OAmBA;AACL,6FAnBA,oBAAY,OAmBA;AACZ,4FAnBA,mBAAW,OAmBA;AACX,2FAnBA,kBAAU,OAmBA;AACV,kGAnBA,yBAAiB,OAmBA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AE,CAAC;YAGnD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,IAAI,WAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF;AAnQD,4BAmQC","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"]}
@@ -3,10 +3,22 @@ import * as G from "galore";
3
3
  import * as TLEX from "tlex";
4
4
  import { Literal, Note, Atom, Rest, Space, Group } from "./core";
5
5
  import { Notation, Command, CmdParam } from "./notation";
6
+ import { Block } from "./block";
7
+ export declare class BlockCommand extends Command {
8
+ readonly innerCommand: Command;
9
+ readonly blockCommands: Command[];
10
+ constructor(innerCommand: Command, blockCommands: Command[]);
11
+ get name(): string;
12
+ private createBlock;
13
+ debugValue(): any;
14
+ applyToNotation(notation: Notation): void;
15
+ applyToBlock(container: Block): void;
16
+ }
6
17
  export declare class Parser {
7
18
  errors: (TLEX.TokenizerError | G.ParseError)[];
8
19
  metadata: any;
9
20
  readonly commands: Command[];
21
+ private blockStartStack;
10
22
  protected ruleHandlers: {
11
23
  newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => TSU.Num.Fraction;
12
24
  newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Group;
@@ -14,10 +26,10 @@ export declare class Parser {
14
26
  litWithPreEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Literal;
15
27
  litWithPostEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Literal;
16
28
  litToAtom: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
17
- newSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Space;
18
- newRest: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Rest;
19
- newDoubleSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Space;
20
- newSilentSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Space;
29
+ newSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Space;
30
+ newRest: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Rest;
31
+ newDoubleSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Space;
32
+ newSilentSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Space;
21
33
  applyPreMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
22
34
  applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
23
35
  applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
@@ -29,14 +41,17 @@ export declare class Parser {
29
41
  };
30
42
  newParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any[];
31
43
  concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
32
- newCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Command;
44
+ beginBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => null;
45
+ endBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Command[];
46
+ nullBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => null;
47
+ newCommandWithBlock: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Command;
33
48
  appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
34
49
  prependFrontMatter: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
35
50
  appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
36
51
  appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
37
52
  insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
38
53
  };
39
- constructor(config?: any);
54
+ constructor(_config?: any);
40
55
  createCommand(name: string, params: CmdParam[]): Command;
41
56
  addCommand(cmd: Command): void;
42
57
  parse(input: string): any;