notations 0.0.40 → 0.0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/lib/cjs/beats.d.ts +111 -0
- package/lib/cjs/beats.js +523 -0
- package/lib/cjs/beats.js.map +1 -0
- package/lib/cjs/carnatic/LineView.d.ts +20 -0
- package/lib/cjs/carnatic/LineView.js +69 -0
- package/lib/cjs/carnatic/LineView.js.map +1 -0
- package/lib/cjs/carnatic/NotationView.d.ts +31 -0
- package/lib/cjs/carnatic/NotationView.js +250 -0
- package/lib/cjs/carnatic/NotationView.js.map +1 -0
- package/lib/cjs/carnatic/atomviews.d.ts +14 -7
- package/lib/cjs/carnatic/atomviews.js +170 -137
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/beatviews.d.ts +10 -14
- package/lib/cjs/carnatic/beatviews.js +53 -108
- package/lib/cjs/carnatic/beatviews.js.map +1 -1
- package/lib/cjs/carnatic/embelishments.d.ts +38 -32
- package/lib/cjs/carnatic/embelishments.js +35 -20
- package/lib/cjs/carnatic/embelishments.js.map +1 -1
- package/lib/cjs/carnatic/index.d.ts +2 -0
- package/lib/cjs/carnatic/index.js +2 -0
- package/lib/cjs/carnatic/index.js.map +1 -1
- package/lib/cjs/core.d.ts +15 -73
- package/lib/cjs/core.js +200 -568
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/cycle.d.ts +47 -0
- package/lib/cjs/cycle.js +492 -0
- package/lib/cjs/cycle.js.map +1 -0
- package/lib/cjs/entity.d.ts +24 -0
- package/lib/cjs/entity.js +135 -0
- package/lib/cjs/entity.js.map +1 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.js +3 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/iterators.d.ts +14 -2
- package/lib/cjs/iterators.js +79 -7
- package/lib/cjs/iterators.js.map +1 -1
- package/lib/cjs/layouts.d.ts +7 -106
- package/lib/cjs/layouts.js +4 -478
- package/lib/cjs/layouts.js.map +1 -1
- package/lib/cjs/loader.d.ts +2 -1
- package/lib/cjs/loader.js +32 -27
- package/lib/cjs/loader.js.map +1 -1
- package/lib/cjs/notation.d.ts +3 -1
- package/lib/cjs/notation.js +6 -4
- package/lib/cjs/notation.js.map +1 -1
- package/lib/cjs/parser.js +6 -5
- package/lib/cjs/parser.js.map +1 -1
- package/lib/cjs/shapes.d.ts +35 -14
- package/lib/cjs/shapes.js +153 -43
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/cjs/utils.d.ts +2 -1
- package/lib/cjs/utils.js +20 -8
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/beats.d.ts +111 -0
- package/lib/esm/beats.js +501 -0
- package/lib/esm/beats.js.map +1 -0
- package/lib/esm/carnatic/LineView.d.ts +20 -0
- package/lib/esm/carnatic/LineView.js +47 -0
- package/lib/esm/carnatic/LineView.js.map +1 -0
- package/lib/esm/carnatic/NotationView.d.ts +31 -0
- package/lib/esm/carnatic/NotationView.js +228 -0
- package/lib/esm/carnatic/NotationView.js.map +1 -0
- package/lib/esm/carnatic/atomviews.d.ts +14 -7
- package/lib/esm/carnatic/atomviews.js +170 -137
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/beatviews.d.ts +10 -14
- package/lib/esm/carnatic/beatviews.js +54 -109
- package/lib/esm/carnatic/beatviews.js.map +1 -1
- package/lib/esm/carnatic/embelishments.d.ts +38 -32
- package/lib/esm/carnatic/embelishments.js +34 -19
- package/lib/esm/carnatic/embelishments.js.map +1 -1
- package/lib/esm/carnatic/index.d.ts +2 -0
- package/lib/esm/carnatic/index.js +2 -0
- package/lib/esm/carnatic/index.js.map +1 -1
- package/lib/esm/core.d.ts +15 -73
- package/lib/esm/core.js +196 -564
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/cycle.d.ts +47 -0
- package/lib/esm/cycle.js +470 -0
- package/lib/esm/cycle.js.map +1 -0
- package/lib/esm/entity.d.ts +24 -0
- package/lib/esm/entity.js +132 -0
- package/lib/esm/entity.js.map +1 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/iterators.d.ts +14 -2
- package/lib/esm/iterators.js +75 -3
- package/lib/esm/iterators.js.map +1 -1
- package/lib/esm/layouts.d.ts +7 -106
- package/lib/esm/layouts.js +1 -475
- package/lib/esm/layouts.js.map +1 -1
- package/lib/esm/loader.d.ts +2 -1
- package/lib/esm/loader.js +28 -24
- package/lib/esm/loader.js.map +1 -1
- package/lib/esm/notation.d.ts +3 -1
- package/lib/esm/notation.js +3 -1
- package/lib/esm/notation.js.map +1 -1
- package/lib/esm/parser.js +6 -5
- package/lib/esm/parser.js.map +1 -1
- package/lib/esm/shapes.d.ts +35 -14
- package/lib/esm/shapes.js +152 -42
- package/lib/esm/shapes.js.map +1 -1
- package/lib/esm/utils.d.ts +2 -1
- package/lib/esm/utils.js +19 -7
- package/lib/esm/utils.js.map +1 -1
- package/package.json +33 -28
- package/styles/NotationView.scss +35 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __values = (this && this.__values) || function(o) {
|
|
18
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
+
if (m) return m.call(o);
|
|
20
|
+
if (o && typeof o.length === "number") return {
|
|
21
|
+
next: function () {
|
|
22
|
+
if (o && i >= o.length) o = void 0;
|
|
23
|
+
return { value: o && o[i++], done: !o };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.TimedEntity = exports.Entity = void 0;
|
|
30
|
+
var Entity = (function () {
|
|
31
|
+
function Entity(config) {
|
|
32
|
+
if (config === void 0) { config = null; }
|
|
33
|
+
this.uuid = Entity.counter++;
|
|
34
|
+
config = config || {};
|
|
35
|
+
if (config.metadata)
|
|
36
|
+
throw new Error("See where metadata is being passed");
|
|
37
|
+
}
|
|
38
|
+
Entity.prototype.debugValue = function () {
|
|
39
|
+
return { type: this.type };
|
|
40
|
+
};
|
|
41
|
+
Entity.prototype.children = function () {
|
|
42
|
+
return [];
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(Entity.prototype, "childCount", {
|
|
45
|
+
get: function () {
|
|
46
|
+
return this.children().length;
|
|
47
|
+
},
|
|
48
|
+
enumerable: false,
|
|
49
|
+
configurable: true
|
|
50
|
+
});
|
|
51
|
+
Entity.prototype.addChild = function (child, index) {
|
|
52
|
+
if (index === void 0) { index = -1; }
|
|
53
|
+
if (index < 0) {
|
|
54
|
+
this.children().push(child);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.children().splice(index, 0, child);
|
|
58
|
+
}
|
|
59
|
+
return this;
|
|
60
|
+
};
|
|
61
|
+
Entity.prototype.childAt = function (index) {
|
|
62
|
+
return this.children()[index];
|
|
63
|
+
};
|
|
64
|
+
Entity.prototype.indexOfChild = function (entity) {
|
|
65
|
+
var e_1, _a;
|
|
66
|
+
var i = 0;
|
|
67
|
+
try {
|
|
68
|
+
for (var _b = __values(this.children()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
69
|
+
var child = _c.value;
|
|
70
|
+
if (child == entity)
|
|
71
|
+
return i;
|
|
72
|
+
i++;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
76
|
+
finally {
|
|
77
|
+
try {
|
|
78
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
79
|
+
}
|
|
80
|
+
finally { if (e_1) throw e_1.error; }
|
|
81
|
+
}
|
|
82
|
+
return -1;
|
|
83
|
+
};
|
|
84
|
+
Entity.prototype.removeChildAt = function (index) {
|
|
85
|
+
var children = this.children();
|
|
86
|
+
var out = children[index];
|
|
87
|
+
children.splice(index, 1);
|
|
88
|
+
return out;
|
|
89
|
+
};
|
|
90
|
+
Entity.prototype.setChildAt = function (index, entity) {
|
|
91
|
+
this.children()[index] = entity;
|
|
92
|
+
return this;
|
|
93
|
+
};
|
|
94
|
+
Object.defineProperty(Entity.prototype, "type", {
|
|
95
|
+
get: function () {
|
|
96
|
+
return this.constructor.name;
|
|
97
|
+
},
|
|
98
|
+
enumerable: false,
|
|
99
|
+
configurable: true
|
|
100
|
+
});
|
|
101
|
+
Entity.prototype.toString = function () {
|
|
102
|
+
return "Entity(id = ".concat(this.uuid, ")");
|
|
103
|
+
};
|
|
104
|
+
Entity.prototype.equals = function (another, expect) {
|
|
105
|
+
if (expect === void 0) { expect = false; }
|
|
106
|
+
if (this.type != another.type)
|
|
107
|
+
return false;
|
|
108
|
+
return true;
|
|
109
|
+
};
|
|
110
|
+
Entity.prototype.clone = function () {
|
|
111
|
+
var out = this.newInstance();
|
|
112
|
+
this.copyTo(out);
|
|
113
|
+
return out;
|
|
114
|
+
};
|
|
115
|
+
Entity.prototype.copyTo = function (another) {
|
|
116
|
+
};
|
|
117
|
+
Entity.prototype.newInstance = function () {
|
|
118
|
+
return new this.constructor();
|
|
119
|
+
};
|
|
120
|
+
Entity.counter = 0;
|
|
121
|
+
return Entity;
|
|
122
|
+
}());
|
|
123
|
+
exports.Entity = Entity;
|
|
124
|
+
var TimedEntity = (function (_super) {
|
|
125
|
+
__extends(TimedEntity, _super);
|
|
126
|
+
function TimedEntity() {
|
|
127
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
128
|
+
}
|
|
129
|
+
TimedEntity.prototype.equals = function (another) {
|
|
130
|
+
return _super.prototype.equals.call(this, another) && this.duration.equals(another.duration);
|
|
131
|
+
};
|
|
132
|
+
return TimedEntity;
|
|
133
|
+
}(Entity));
|
|
134
|
+
exports.TimedEntity = TimedEntity;
|
|
135
|
+
//# sourceMappingURL=entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA;IAME,gBAAY,MAAkB;QAAlB,uBAAA,EAAA,aAAkB;QAJrB,SAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAK/B,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QACtB,IAAI,MAAM,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAE7E,CAAC;IAMD,2BAAU,GAAV;QAEE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAKD,yBAAQ,GAAR;QACE,OAAO,EAAE,CAAC;IACZ,CAAC;IAKD,sBAAI,8BAAU;aAAd;YACE,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC;QAChC,CAAC;;;OAAA;IAOD,yBAAQ,GAAR,UAAS,KAAa,EAAE,KAAU;QAAV,sBAAA,EAAA,SAAS,CAAC;QAChC,IAAI,KAAK,GAAG,CAAC,EAAE;YACb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uBAAA,EAAA,cAAc;QAClC,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAE5C,OAAO,IAAI,CAAC;IACd,CAAC;IAYD,sBAAK,GAAL;QACE,IAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjB,OAAO,GAAG,CAAC;IACb,CAAC;IAKD,uBAAM,GAAN,UAAO,OAAa;IAEpB,CAAC;IAKS,4BAAW,GAArB;QACE,OAAO,IAAK,IAAI,CAAC,WAAmB,EAAE,CAAC;IACzC,CAAC;IApJc,cAAO,GAAG,CAAC,CAAC;IAqJ7B,aAAC;CAAA,AAtJD,IAsJC;AAtJY,wBAAM;AA4JnB;IAA0C,+BAAM;IAAhD;;IAUA,CAAC;IAHC,4BAAM,GAAN,UAAO,OAAa;QAClB,OAAO,iBAAM,MAAM,YAAC,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzE,CAAC;IACH,kBAAC;AAAD,CAAC,AAVD,CAA0C,MAAM,GAU/C;AAVqB,kCAAW","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\n\n/**\n * A common Entity base class with support for unique IDs, copying, children and\n * debug info.\n */\nexport class Entity {\n private static counter = 0;\n readonly uuid = Entity.counter++;\n // private metadata: TSU.StringMap<any>;\n // parent: TSU.Nullable<Entity> = null;\n\n constructor(config: any = null) {\n config = config || {};\n if (config.metadata) throw new Error(\"See where metadata is being passed\");\n // this.metadata = config.metadata || {};\n }\n\n /**\n * debugValue returns information about this entity to be printed during a debug.\n * Usually overridden by children to add more debug info.\n */\n debugValue(): any {\n // if (Object.keys(this.metadata).length > 0) return { metadata: this.metadata, type: this.type };\n return { type: this.type };\n }\n\n /**\n * Children of this entity.\n */\n children(): Entity[] {\n return [];\n }\n\n /**\n * Property returning the count of child entities.\n */\n get childCount(): number {\n return this.children().length;\n }\n\n /**\n * Adds a child entity at a given index.\n * @param child Child entity to be aded.\n * @param index Index where the child is to be inserted. -1 to append at the end.\n */\n addChild(child: Entity, index = -1): this {\n if (index < 0) {\n this.children().push(child);\n } else {\n this.children().splice(index, 0, child);\n }\n return this;\n }\n\n /**\n * Returns the child at a given index.\n */\n childAt(index: number): Entity {\n return this.children()[index];\n }\n\n /**\n * Returns the index of a given child entity.\n *\n * @return the index where child exists otherwise -1.\n */\n indexOfChild(entity: Entity): number {\n let i = 0;\n for (const child of this.children()) {\n if (child == entity) return i;\n i++;\n }\n return -1;\n }\n\n removeChildAt(index: number): Entity {\n const children = this.children();\n const out = children[index];\n children.splice(index, 1);\n return out;\n }\n\n setChildAt(index: number, entity: Entity): this {\n this.children()[index] = entity;\n return this;\n }\n\n /*\n setMetadata(key: string, value: any): this {\n this.metadata[key] = value;\n return this;\n }\n\n getMetadata(key: string, recurse = true): any {\n if (key in this.metadata) {\n return this.metadata[key];\n }\n if (recurse && this.parent) {\n return this.parent.getMetadata(key);\n }\n return null;\n }\n */\n\n /**\n * Returns the type of this Entity.\n *\n * Type properties are used to identify the class type of Entities.\n */\n get type(): unknown {\n return this.constructor.name;\n }\n\n /**\n * Simple string representation of this Entity.\n */\n toString(): string {\n return `Entity(id = ${this.uuid})`;\n }\n\n equals(another: this, expect = false): boolean {\n if (this.type != another.type) return false;\n // check metadata too\n return true;\n }\n\n /**\n * All entities allow cloning in a way that is specific to the entity.\n * This allows application level \"copy/pasting\" of entities. Cloning\n * is a two part process:\n *\n * * Creation of a new instance of the same type via this.newInstance()\n * * Copying of data into the new instance.\n *\n * Both of these can be overridden.\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 */\n copyTo(another: this): void {\n // another.metadata = { ...this.metadata };\n }\n\n /**\n * First part of the cloning process where the instance is created.\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.\n */\nexport abstract class TimedEntity extends Entity {\n /**\n * Duration of this entity in beats.\n * By default entities durations are readonly\n */\n abstract get duration(): TSU.Num.Fraction;\n\n equals(another: this): boolean {\n return super.equals(another) && this.duration.equals(another.duration);\n }\n}\n"]}
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -23,9 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.Carnatic = exports.Utils = void 0;
|
|
26
|
+
__exportStar(require("./entity"), exports);
|
|
27
|
+
__exportStar(require("./cycle"), exports);
|
|
26
28
|
__exportStar(require("./core"), exports);
|
|
27
29
|
__exportStar(require("./iterators"), exports);
|
|
28
30
|
__exportStar(require("./layouts"), exports);
|
|
31
|
+
__exportStar(require("./beats"), exports);
|
|
29
32
|
__exportStar(require("./notation"), exports);
|
|
30
33
|
__exportStar(require("./parser"), exports);
|
|
31
34
|
__exportStar(require("./shapes"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,iDAAiC;AACjC,uDAAuC","sourcesContent":["export * from \"./core\";\nexport * from \"./iterators\";\nexport * from \"./layouts\";\nexport * from \"./notation\";\nexport * from \"./parser\";\nexport * from \"./shapes\";\nexport * from \"./loader\";\nexport * as Utils from \"./utils\";\nexport * as Carnatic from \"./carnatic\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,0CAAwB;AACxB,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,iDAAiC;AACjC,uDAAuC","sourcesContent":["export * from \"./entity\";\nexport * from \"./cycle\";\nexport * from \"./core\";\nexport * from \"./iterators\";\nexport * from \"./layouts\";\nexport * from \"./beats\";\nexport * from \"./notation\";\nexport * from \"./parser\";\nexport * from \"./shapes\";\nexport * from \"./loader\";\nexport * as Utils from \"./utils\";\nexport * as Carnatic from \"./carnatic\";\n"]}
|
package/lib/cjs/iterators.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
|
-
import { TimedEntity
|
|
2
|
+
import { TimedEntity } from "./entity";
|
|
3
|
+
import { Atom, LeafAtom } from "./core";
|
|
3
4
|
export declare class FlatAtom extends TimedEntity {
|
|
4
5
|
atom: LeafAtom;
|
|
5
6
|
depth: number;
|
|
6
7
|
duration: TSU.Num.Fraction;
|
|
7
8
|
offset: TSU.Num.Fraction;
|
|
8
|
-
isContinuation
|
|
9
|
+
private isContinuation;
|
|
9
10
|
constructor(atom: LeafAtom, config?: any);
|
|
10
11
|
get type(): unknown;
|
|
11
12
|
get endOffset(): TSU.Num.Fraction;
|
|
@@ -22,6 +23,17 @@ export declare class AtomIterator {
|
|
|
22
23
|
get hasNext(): boolean;
|
|
23
24
|
static getMin(iterators: AtomIterator[]): [number, FlatAtom];
|
|
24
25
|
}
|
|
26
|
+
export declare class WindowIterator {
|
|
27
|
+
private atomQueue;
|
|
28
|
+
private currOffset;
|
|
29
|
+
private peeked;
|
|
30
|
+
constructor(...atoms: Atom[]);
|
|
31
|
+
push(...atoms: Atom[]): this;
|
|
32
|
+
next(): TSU.Nullable<Atom>;
|
|
33
|
+
peek(): TSU.Nullable<Atom>;
|
|
34
|
+
get hasMore(): boolean;
|
|
35
|
+
get(duration: TSU.Num.Fraction): [Atom[], boolean];
|
|
36
|
+
}
|
|
25
37
|
export declare class DurationIterator {
|
|
26
38
|
private atomIterator;
|
|
27
39
|
private spillOver;
|
package/lib/cjs/iterators.js
CHANGED
|
@@ -81,9 +81,10 @@ var __values = (this && this.__values) || function(o) {
|
|
|
81
81
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
82
82
|
};
|
|
83
83
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
84
|
-
exports.DurationIterator = exports.AtomIterator = exports.FlatAtom = void 0;
|
|
84
|
+
exports.DurationIterator = exports.WindowIterator = exports.AtomIterator = exports.FlatAtom = void 0;
|
|
85
85
|
var TSU = __importStar(require("@panyam/tsutils"));
|
|
86
|
-
var
|
|
86
|
+
var entity_1 = require("./entity");
|
|
87
|
+
var core_1 = require("./core");
|
|
87
88
|
var FlatAtom = (function (_super) {
|
|
88
89
|
__extends(FlatAtom, _super);
|
|
89
90
|
function FlatAtom(atom, config) {
|
|
@@ -117,7 +118,7 @@ var FlatAtom = (function (_super) {
|
|
|
117
118
|
return out;
|
|
118
119
|
};
|
|
119
120
|
return FlatAtom;
|
|
120
|
-
}(
|
|
121
|
+
}(entity_1.TimedEntity));
|
|
121
122
|
exports.FlatAtom = FlatAtom;
|
|
122
123
|
var AtomIterator = (function () {
|
|
123
124
|
function AtomIterator() {
|
|
@@ -155,7 +156,7 @@ var AtomIterator = (function () {
|
|
|
155
156
|
var out = this.peek();
|
|
156
157
|
this.peeked = null;
|
|
157
158
|
if (out != null) {
|
|
158
|
-
this.currOffset = this.currOffset.plus(out.duration);
|
|
159
|
+
this.currOffset = this.currOffset.plus(out.duration).factorized;
|
|
159
160
|
}
|
|
160
161
|
return out;
|
|
161
162
|
};
|
|
@@ -177,7 +178,7 @@ var AtomIterator = (function () {
|
|
|
177
178
|
var e_2, _a;
|
|
178
179
|
while (this.atomQueue.first != null) {
|
|
179
180
|
var _b = __read(this.atomQueue.first.value, 3), nextAtom = _b[0], nextDepth = _b[1], nextDuration = _b[2];
|
|
180
|
-
if (nextAtom.type !=
|
|
181
|
+
if (nextAtom.type != core_1.AtomType.GROUP) {
|
|
181
182
|
return true;
|
|
182
183
|
}
|
|
183
184
|
else {
|
|
@@ -189,7 +190,7 @@ var AtomIterator = (function () {
|
|
|
189
190
|
this.atomQueue.pushFront([
|
|
190
191
|
child,
|
|
191
192
|
nextDepth + 1,
|
|
192
|
-
nextDuration.times(child.duration).divby(group.totalChildDuration),
|
|
193
|
+
nextDuration.times(child.duration).divby(group.totalChildDuration).factorized,
|
|
193
194
|
]);
|
|
194
195
|
}
|
|
195
196
|
}
|
|
@@ -227,6 +228,77 @@ var AtomIterator = (function () {
|
|
|
227
228
|
return AtomIterator;
|
|
228
229
|
}());
|
|
229
230
|
exports.AtomIterator = AtomIterator;
|
|
231
|
+
var WindowIterator = (function () {
|
|
232
|
+
function WindowIterator() {
|
|
233
|
+
var atoms = [];
|
|
234
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
235
|
+
atoms[_i] = arguments[_i];
|
|
236
|
+
}
|
|
237
|
+
this.atomQueue = new TSU.Lists.List();
|
|
238
|
+
this.currOffset = TSU.Num.Fraction.ZERO;
|
|
239
|
+
this.peeked = null;
|
|
240
|
+
this.push.apply(this, __spreadArray([], __read(atoms), false));
|
|
241
|
+
}
|
|
242
|
+
WindowIterator.prototype.push = function () {
|
|
243
|
+
var e_3, _a;
|
|
244
|
+
var atoms = [];
|
|
245
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
246
|
+
atoms[_i] = arguments[_i];
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
for (var atoms_2 = __values(atoms), atoms_2_1 = atoms_2.next(); !atoms_2_1.done; atoms_2_1 = atoms_2.next()) {
|
|
250
|
+
var atom = atoms_2_1.value;
|
|
251
|
+
this.atomQueue.add(atom);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
255
|
+
finally {
|
|
256
|
+
try {
|
|
257
|
+
if (atoms_2_1 && !atoms_2_1.done && (_a = atoms_2.return)) _a.call(atoms_2);
|
|
258
|
+
}
|
|
259
|
+
finally { if (e_3) throw e_3.error; }
|
|
260
|
+
}
|
|
261
|
+
return this;
|
|
262
|
+
};
|
|
263
|
+
WindowIterator.prototype.next = function () {
|
|
264
|
+
var out = this.peek();
|
|
265
|
+
this.peeked = null;
|
|
266
|
+
if (out != null) {
|
|
267
|
+
this.currOffset = this.currOffset.plus(out.duration, true);
|
|
268
|
+
}
|
|
269
|
+
return out;
|
|
270
|
+
};
|
|
271
|
+
WindowIterator.prototype.peek = function () {
|
|
272
|
+
if (this.peeked == null && this.hasMore) {
|
|
273
|
+
this.peeked = this.atomQueue.popFront();
|
|
274
|
+
}
|
|
275
|
+
return this.peeked;
|
|
276
|
+
};
|
|
277
|
+
Object.defineProperty(WindowIterator.prototype, "hasMore", {
|
|
278
|
+
get: function () {
|
|
279
|
+
return !this.atomQueue.isEmpty;
|
|
280
|
+
},
|
|
281
|
+
enumerable: false,
|
|
282
|
+
configurable: true
|
|
283
|
+
});
|
|
284
|
+
WindowIterator.prototype.get = function (duration) {
|
|
285
|
+
var out = [];
|
|
286
|
+
var remaining = duration;
|
|
287
|
+
while (remaining.isGTNum(0) && this.hasMore) {
|
|
288
|
+
var next = this.next();
|
|
289
|
+
TSU.assert(next != null, "Next cannot be null here");
|
|
290
|
+
out.push(next);
|
|
291
|
+
var spillOver = next.splitAt(remaining);
|
|
292
|
+
remaining = remaining.minus(next.duration);
|
|
293
|
+
if (spillOver != null) {
|
|
294
|
+
this.atomQueue.pushFront(spillOver);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return [out, remaining.isZero];
|
|
298
|
+
};
|
|
299
|
+
return WindowIterator;
|
|
300
|
+
}());
|
|
301
|
+
exports.WindowIterator = WindowIterator;
|
|
230
302
|
var DurationIterator = (function () {
|
|
231
303
|
function DurationIterator(atomIterator) {
|
|
232
304
|
this.spillOver = null;
|
|
@@ -258,7 +330,7 @@ var DurationIterator = (function () {
|
|
|
258
330
|
remaining = remaining.minus(next.duration);
|
|
259
331
|
}
|
|
260
332
|
else {
|
|
261
|
-
this.spillOver = new FlatAtom(new
|
|
333
|
+
this.spillOver = new FlatAtom(new core_1.Space(next.duration.minus(remaining)));
|
|
262
334
|
next.duration = remaining;
|
|
263
335
|
remaining = TSU.Num.Fraction.ZERO;
|
|
264
336
|
}
|
package/lib/cjs/iterators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/iterators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,uBAAyE;AAIzE;IAA8B,4BAAW;IAMvC,kBAAmB,IAAc,EAAE,MAAkB;QAAlB,uBAAA,EAAA,aAAkB;QAArD,YACE,kBAAM,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,SAK/B;QANkB,UAAI,GAAJ,IAAI,CAAU;QAE/B,KAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;QAC/B,KAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;QACjD,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrD,KAAI,CAAC,cAAc,GAAG,gBAAgB,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC;;IACnF,CAAC;IAKD,sBAAI,0BAAI;aAAR;YACE,OAAO,UAAU,CAAC;QACpB,CAAC;;;OAAA;IAED,sB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Entity, Atom, LeafAtom, Space, Group, AtomType } from \"./\";\n\ntype Fraction = TSU.Num.Fraction;\n\nexport class FlatAtom extends TimedEntity {\n depth: number;\n duration: TSU.Num.Fraction;\n offset: TSU.Num.Fraction;\n isContinuation: boolean;\n\n constructor(public atom: LeafAtom, config: any = null) {\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 * Returns the type of this Entity.\n */\n get type(): unknown {\n return \"FlatAtom\";\n }\n\n get endOffset(): TSU.Num.Fraction {\n return this.offset.plus(this.duration);\n }\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\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 constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\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 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);\n }\n return out;\n }\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 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),\n ]);\n }\n }\n }\n return false;\n }\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\nexport class DurationIterator {\n private atomIterator: AtomIterator;\n private spillOver: TSU.Nullable<FlatAtom> = null;\n\n constructor(atomIterator: AtomIterator) {\n this.atomIterator = atomIterator;\n }\n\n get hasMore(): boolean {\n if (this.spillOver != null) {\n return true;\n }\n return this.atomIterator.hasNext;\n }\n\n /**\n * Gets the atoms to cover the given duration.\n *\n * If the number of atoms left in the iterator is 0 then 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 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 atm 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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,YAAK,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;iBACnC;aACF;SACF;QACD,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IACH,uBAAC;AAAD,CAAC,AA/CD,IA+CC;AA/CY,4CAAgB","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\ntype FlatAtom2 = [atom: Atom, duration: TSU.Num.Fraction, offset: TSU.Num.Fraction];\n\nexport class FlatAtom extends TimedEntity {\n depth: number;\n duration: TSU.Num.Fraction;\n offset: TSU.Num.Fraction;\n private isContinuation: boolean;\n\n constructor(public atom: LeafAtom, config: any = null) {\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 * Returns the type of this Entity.\n */\n get type(): unknown {\n return \"FlatAtom\";\n }\n\n get endOffset(): TSU.Num.Fraction {\n return this.offset.plus(this.duration);\n }\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 constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\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 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 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 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 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\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 constructor(...atoms: Atom[]) {\n this.push(...atoms);\n }\n\n /**\n * Push atoms to be flattened and served by this iterator.\n */\n push(...atoms: Atom[]): this {\n for (const atom of atoms) {\n this.atomQueue.add(atom);\n }\n return this;\n }\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 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 get hasMore(): boolean {\n return !this.atomQueue.isEmpty;\n }\n\n /**\n * Gets the atoms to cover the given duration.\n *\n * If the number of atoms left in the iterator is 0 then 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 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 * Duration Iterators take a tree of Atoms and return atoms in given windowed\n * durations. This also ensures that a leaf atom can be further split if it is\n * larger than the required duration.\n */\nexport class DurationIterator {\n private atomIterator: AtomIterator;\n private spillOver: TSU.Nullable<FlatAtom> = null;\n\n constructor(atomIterator: AtomIterator) {\n this.atomIterator = atomIterator;\n }\n\n get hasMore(): boolean {\n if (this.spillOver != null) {\n return true;\n }\n return this.atomIterator.hasNext;\n }\n\n /**\n * Gets the atoms to cover the given duration.\n *\n * If the number of atoms left in the iterator is 0 then 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 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 atm 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/cjs/layouts.d.ts
CHANGED
|
@@ -1,110 +1,6 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
|
-
import {
|
|
3
|
-
import { AtomIterator, DurationIterator, FlatAtom } from "./iterators";
|
|
2
|
+
import { Cycle, CyclePosition } from "./cycle";
|
|
4
3
|
declare type Fraction = TSU.Num.Fraction;
|
|
5
|
-
interface BeatViewDelegate {
|
|
6
|
-
viewForBeat(beat: Beat): BeatView;
|
|
7
|
-
}
|
|
8
|
-
export interface BeatView {
|
|
9
|
-
readonly beat: Beat;
|
|
10
|
-
readonly needsLayout: boolean;
|
|
11
|
-
readonly minSize: TSU.Geom.Size;
|
|
12
|
-
x: number;
|
|
13
|
-
y: number;
|
|
14
|
-
width: number;
|
|
15
|
-
height: number;
|
|
16
|
-
refreshLayout(): void;
|
|
17
|
-
setStyles(config: any): void;
|
|
18
|
-
}
|
|
19
|
-
export declare class Beat {
|
|
20
|
-
readonly index: number;
|
|
21
|
-
readonly role: Role;
|
|
22
|
-
readonly offset: Fraction;
|
|
23
|
-
readonly duration: Fraction;
|
|
24
|
-
readonly barIndex: number;
|
|
25
|
-
readonly beatIndex: number;
|
|
26
|
-
readonly instance: number;
|
|
27
|
-
readonly prevBeat: null | Beat;
|
|
28
|
-
nextBeat: null | Beat;
|
|
29
|
-
private static idCounter;
|
|
30
|
-
layoutLine: number;
|
|
31
|
-
layoutColumn: number;
|
|
32
|
-
readonly uuid: number;
|
|
33
|
-
readonly atoms: FlatAtom[];
|
|
34
|
-
constructor(index: number, role: Role, offset: Fraction, duration: Fraction, barIndex: number, beatIndex: number, instance: number, prevBeat: null | Beat, nextBeat: null | Beat);
|
|
35
|
-
debugValue(): any;
|
|
36
|
-
get endOffset(): Fraction;
|
|
37
|
-
get filled(): boolean;
|
|
38
|
-
get remaining(): Fraction;
|
|
39
|
-
add(atom: FlatAtom): boolean;
|
|
40
|
-
ensureUniformSpaces(slotsPerBeat?: number): void;
|
|
41
|
-
}
|
|
42
|
-
export declare class BeatLayout {
|
|
43
|
-
readonly layoutParams: LayoutParams;
|
|
44
|
-
bcolNextList: Map<string, Set<string>>;
|
|
45
|
-
beatColumns: Map<string, BeatColumn>;
|
|
46
|
-
startingColumns: BeatColumn[];
|
|
47
|
-
columnForBeat: Map<number, BeatColumn>;
|
|
48
|
-
constructor(layoutParams: LayoutParams);
|
|
49
|
-
getBeatColumn(offset: Fraction, duration: Fraction): BeatColumn;
|
|
50
|
-
protected static keyFor(offset: Fraction, duration: Fraction): string;
|
|
51
|
-
protected addSuccessor(prev: BeatColumn, next: BeatColumn): void;
|
|
52
|
-
addBeat(beat: Beat): BeatColumn;
|
|
53
|
-
neighborsOf(beatColumn: BeatColumn): BeatColumn[];
|
|
54
|
-
readonly DEBUG = false;
|
|
55
|
-
evalColumnSizes(beatViewDelegate: BeatViewDelegate): void;
|
|
56
|
-
roleSpacing: number;
|
|
57
|
-
rowSpacing: number;
|
|
58
|
-
layoutBeatsForLine(line: Line, allRoleBeats: Beat[][], beatViewDelegate: BeatViewDelegate): void;
|
|
59
|
-
}
|
|
60
|
-
export declare class BeatRow {
|
|
61
|
-
readonly layoutLine: number;
|
|
62
|
-
rowIndex: number;
|
|
63
|
-
protected _y: number;
|
|
64
|
-
protected _maxHeight: number;
|
|
65
|
-
needsLayout: boolean;
|
|
66
|
-
rowSpacing: number;
|
|
67
|
-
beats: Beat[];
|
|
68
|
-
constructor(layoutLine: number, rowIndex: number);
|
|
69
|
-
get y(): number;
|
|
70
|
-
set y(val: number);
|
|
71
|
-
add(beat: Beat): void;
|
|
72
|
-
}
|
|
73
|
-
export declare class BeatColumn {
|
|
74
|
-
readonly offset: Fraction;
|
|
75
|
-
readonly duration: Fraction;
|
|
76
|
-
protected _x: number;
|
|
77
|
-
protected _maxWidth: number;
|
|
78
|
-
needsLayout: boolean;
|
|
79
|
-
atomSpacing: number;
|
|
80
|
-
paddingLeft: number;
|
|
81
|
-
paddingRight: number;
|
|
82
|
-
beats: Beat[];
|
|
83
|
-
constructor(offset: Fraction, duration: Fraction);
|
|
84
|
-
get x(): number;
|
|
85
|
-
setX(val: number, beatViewDelegate: BeatViewDelegate): void;
|
|
86
|
-
get maxWidth(): number;
|
|
87
|
-
setPadding(left: number, right: number): void;
|
|
88
|
-
evalMaxWidth(beatViewDelegate: BeatViewDelegate): number;
|
|
89
|
-
add(beat: Beat): void;
|
|
90
|
-
}
|
|
91
|
-
export declare class BeatsBuilder {
|
|
92
|
-
readonly role: Role;
|
|
93
|
-
readonly layoutParams: LayoutParams;
|
|
94
|
-
readonly startOffset: Fraction;
|
|
95
|
-
readonly beats: Beat[];
|
|
96
|
-
readonly startIndex: number;
|
|
97
|
-
readonly beatOffset: Fraction;
|
|
98
|
-
cycleIter: CycleIterator;
|
|
99
|
-
atomIter: AtomIterator;
|
|
100
|
-
durIter: DurationIterator;
|
|
101
|
-
onAtomAdded: (flatAtom: FlatAtom, beat: Beat) => void;
|
|
102
|
-
onBeatAdded: (beat: Beat) => void;
|
|
103
|
-
onBeatFilled: (beat: Beat) => void;
|
|
104
|
-
constructor(role: Role, layoutParams: LayoutParams, startOffset?: Fraction);
|
|
105
|
-
protected addBeat(): Beat;
|
|
106
|
-
addAtoms(...atoms: Atom[]): void;
|
|
107
|
-
}
|
|
108
4
|
export declare class LayoutParams {
|
|
109
5
|
private static counter;
|
|
110
6
|
readonly uuid: number;
|
|
@@ -121,7 +17,12 @@ export declare class LayoutParams {
|
|
|
121
17
|
equals(another: this): boolean;
|
|
122
18
|
lineBreaksEqual(another: number[]): boolean;
|
|
123
19
|
debugValue(): any;
|
|
124
|
-
getBeatLocation(beat:
|
|
20
|
+
getBeatLocation(beat: {
|
|
21
|
+
index: number;
|
|
22
|
+
barIndex: number;
|
|
23
|
+
beatIndex: number;
|
|
24
|
+
instance: number;
|
|
25
|
+
}): [number, number, Fraction];
|
|
125
26
|
get lineBreaks(): number[];
|
|
126
27
|
set lineBreaks(val: number[]);
|
|
127
28
|
refreshLayout(): void;
|