notations 0.0.60 → 0.0.63
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/lib/cjs/beats.js +17 -7
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/beatutils.js +18 -9
- package/lib/cjs/beatutils.js.map +1 -1
- package/lib/cjs/beatview.js +17 -7
- package/lib/cjs/beatview.js.map +1 -1
- package/lib/cjs/carnatic/LineView.d.ts +2 -2
- package/lib/cjs/carnatic/LineView.js +17 -7
- package/lib/cjs/carnatic/LineView.js.map +1 -1
- package/lib/cjs/carnatic/NotationView.d.ts +2 -2
- package/lib/cjs/carnatic/NotationView.js +17 -7
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/carnatic/atomviews.js +19 -9
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/beatviews.js +17 -7
- package/lib/cjs/carnatic/beatviews.js.map +1 -1
- package/lib/cjs/carnatic/embelishments.js +17 -7
- package/lib/cjs/carnatic/embelishments.js.map +1 -1
- package/lib/cjs/carnatic/gamakas.js +3 -3
- package/lib/cjs/carnatic/gamakas.js.map +1 -1
- package/lib/cjs/commands.js +17 -7
- package/lib/cjs/commands.js.map +1 -1
- package/lib/cjs/core.js +18 -8
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/cycle.js +17 -7
- package/lib/cjs/cycle.js.map +1 -1
- package/lib/cjs/entity.js.map +1 -1
- package/lib/cjs/grids.js +18 -8
- package/lib/cjs/grids.js.map +1 -1
- package/lib/cjs/index.js +17 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/iterators.js +17 -7
- package/lib/cjs/iterators.js.map +1 -1
- package/lib/cjs/layouts.js +17 -7
- package/lib/cjs/layouts.js.map +1 -1
- package/lib/cjs/loader.js +20 -19
- package/lib/cjs/loader.js.map +1 -1
- package/lib/cjs/notation.d.ts +3 -3
- package/lib/cjs/notation.js +2 -2
- package/lib/cjs/notation.js.map +1 -1
- package/lib/cjs/parser.d.ts +4 -2
- package/lib/cjs/parser.js +56 -11
- package/lib/cjs/parser.js.map +1 -1
- package/lib/cjs/shapes.js +17 -7
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/cjs/utils.js +23 -13
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/beatutils.js.map +1 -1
- package/lib/esm/beatview.js.map +1 -1
- package/lib/esm/carnatic/LineView.d.ts +2 -2
- package/lib/esm/carnatic/NotationView.d.ts +2 -2
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/beatviews.js.map +1 -1
- package/lib/esm/carnatic/embelishments.js.map +1 -1
- package/lib/esm/carnatic/gamakas.js.map +1 -1
- package/lib/esm/commands.js.map +1 -1
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/cycle.js.map +1 -1
- package/lib/esm/entity.js.map +1 -1
- package/lib/esm/grids.js.map +1 -1
- package/lib/esm/iterators.js.map +1 -1
- package/lib/esm/layouts.js.map +1 -1
- package/lib/esm/loader.js +1 -9
- package/lib/esm/loader.js.map +1 -1
- package/lib/esm/notation.d.ts +3 -3
- package/lib/esm/notation.js +2 -2
- package/lib/esm/notation.js.map +1 -1
- package/lib/esm/parser.d.ts +4 -2
- package/lib/esm/parser.js +38 -6
- package/lib/esm/parser.js.map +1 -1
- package/lib/esm/shapes.js.map +1 -1
- package/lib/esm/utils.js.map +1 -1
- package/package.json +34 -33
package/lib/cjs/cycle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cycle.js","sourceRoot":"","sources":["../../src/cycle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,qCAA+C;AAS/C,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnC,MAAM,GAAG,GAA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QACV,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;;AA7LH,sBA8LC;AAxLiB,aAAO,GAAG,IAAI,KAAK,CAAC;IAClC,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE;QACJ,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACrD,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACjD,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;KAClD;CACF,CAAC,CAAC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity, TimedEntity } from \"./entity\";\n\n/**\n * Alias to TSU.Num.Fraction in tsutils.\n */\ntype Fraction = TSU.Num.Fraction;\nexport type CyclePosition = [number, number, number];\nexport type CycleIterator = Generator<[CyclePosition, Fraction]>;\n\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\nexport class CycleCursor {\n constructor(public readonly cycle: Cycle, public barIndex = 0, public beatIndex = 0, public instance = 0) {}\n\n get next(): [CyclePosition, Fraction] {\n const currBar = this.cycle.bars[this.barIndex];\n const result: [CyclePosition, Fraction] = [\n [this.barIndex, this.beatIndex, this.instance],\n currBar.beatLengths[this.beatIndex],\n ];\n this.instance++;\n if (!currBar.beatCounts[this.beatIndex] || this.instance >= currBar.beatCounts[this.beatIndex]) {\n this.instance = 0;\n this.beatIndex++;\n if (this.beatIndex >= currBar.beatLengths.length) {\n this.beatIndex = 0;\n this.barIndex++;\n if (this.barIndex >= this.cycle.bars.length) {\n this.barIndex = 0;\n }\n }\n }\n return result;\n }\n\n get prev(): [CyclePosition, Fraction] {\n const currBar = this.cycle.bars[this.barIndex];\n const result: [CyclePosition, Fraction] = [\n [this.barIndex, this.beatIndex, this.instance],\n currBar.beatLengths[this.beatIndex],\n ];\n // TODO - result should be set *after* decrementing if we had already\n // done a \"next\" before this otherwise user may have to do a prev twice\n this.instance--;\n if (this.instance < 0) {\n this.beatIndex--;\n if (this.beatIndex < 0) {\n this.barIndex--;\n if (this.barIndex < 0) {\n this.barIndex = this.cycle.bars.length - 1;\n }\n this.beatIndex = this.cycle.bars[this.barIndex].beatCount - 1;\n }\n this.instance = (this.cycle.bars[this.barIndex].beatCounts[this.beatIndex] || 1) - 1;\n }\n return result;\n }\n}\n\nexport class Bar extends TimedEntity {\n readonly TYPE: string = \"Bar\";\n\n name: string;\n // Length/Duration of each beat.\n beatLengths: Fraction[] = [];\n\n // How many times should a beat be repeated - the Kalai!\n beatCounts: number[] = [];\n\n constructor(config: any = null) {\n super((config = config || {}));\n this.name = config.name || \"\";\n for (const bl of config.beatLengths || []) {\n if (typeof bl === \"number\") {\n this.beatLengths.push(TSU.Num.Frac(bl));\n } else {\n this.beatLengths.push(bl);\n }\n }\n for (const bc of config.beatCounts || []) {\n this.beatCounts.push(bc);\n }\n while (this.beatCounts.length < this.beatLengths.length) {\n this.beatCounts.push(1);\n }\n }\n\n debugValue(): any {\n return { ...super.debugValue(), name: name, beatLengths: this.beatLengths };\n }\n\n equals(another: this): boolean {\n if (!super.equals(another)) return false;\n if (this.beatLengths.length != another.beatLengths.length) return false;\n if (this.beatCounts.length != another.beatCounts.length) return false;\n for (let i = 0; i < this.beatLengths.length; i++) {\n if (!this.beatLengths[i].equals(another.beatLengths[i])) return false;\n }\n for (let i = 0; i < this.beatCounts.length; i++) {\n if (this.beatCounts[i] != another.beatCounts[i]) return false;\n }\n return true;\n }\n\n copyTo(another: this): void {\n super.copyTo(another);\n another.name = this.name;\n another.beatLengths = [...this.beatLengths];\n another.beatCounts = [...this.beatCounts];\n }\n\n instanceCount(beatIndex: number): number {\n if (beatIndex > this.beatCounts.length) {\n // by default each beat has 1 instance?\n return 1;\n } else {\n return this.beatCounts[beatIndex];\n }\n }\n\n get beatCount(): number {\n return this.beatLengths.length;\n }\n\n get totalBeatCount(): number {\n let out = 0;\n for (let i = 0; i < this.beatLengths.length; i++) {\n out += this.beatCounts[i] || 1;\n }\n return out;\n }\n\n /**\n * Total duration (of time) across all beats in this bar.\n */\n get duration(): Fraction {\n let total = ZERO;\n for (let i = 0; i < this.beatLengths.length; i++) {\n total = total.plus(this.beatLengths[i].timesNum(this.beatCounts[i] || 1));\n }\n return total;\n }\n}\n\n// Describes the cycle pattern\nexport class Cycle extends TimedEntity {\n readonly TYPE: string = \"Cycle\";\n\n name: string;\n bars: Bar[];\n\n static readonly DEFAULT = new Cycle({\n name: \"Adi Thalam\",\n bars: [\n new Bar({ name: \"Laghu\", beatLengths: [1, 1, 1, 1] }),\n new Bar({ name: \"Dhrutam\", beatLengths: [1, 1] }),\n new Bar({ name: \"Dhrutam\", beatLengths: [1, 1] }),\n ],\n });\n\n constructor(config: null | { name?: string; bars?: Bar[] } = null) {\n super((config = config || {}));\n this.name = config.name || \"\";\n this.bars = config.bars || [];\n }\n\n debugValue(): any {\n return { ...super.debugValue(), name: name, bars: this.bars.map((p) => p.debugValue()) };\n }\n\n children(): Entity[] {\n return this.bars;\n }\n\n equals(another: this): boolean {\n if (!super.equals(another)) {\n return false;\n }\n if (this.bars.length != another.bars.length) return false;\n for (let i = 0; i < this.bars.length; i++) {\n if (!this.bars[i].equals(another.bars[i])) return false;\n }\n return true;\n }\n\n /**\n * Given a global beat index returns four values [cycle,bar,beat,instance] where:\n *\n * cycle - The nth cycle in which the beat lies. Since the global beat\n * index can be greater the number of beats in this cycle this\n * allows us to wrap around. Similarly if beatindex is less than\n * 0 then we can also go behind a cycle.\n * bar - The mth bar in the nth cycle which the offset exists\n * beat - The beat within the mth bar in the nth cycle where the\n * offset lies\n * instance - The beat instance where the offset lies.\n * startOffset - Offset of the beat at this global index.\n */\n getAtIndex(globalIndex: number): [number, CyclePosition, Fraction] {\n let cycle = 0;\n while (globalIndex < 0) {\n globalIndex += this.totalBeatCount;\n cycle--;\n }\n if (globalIndex >= this.totalBeatCount) {\n cycle = Math.floor(globalIndex / this.totalBeatCount);\n }\n globalIndex = globalIndex % this.totalBeatCount;\n let offset = ZERO;\n for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {\n const bar = this.bars[barIndex];\n if (globalIndex >= bar.totalBeatCount) {\n globalIndex -= bar.totalBeatCount;\n offset = offset.plus(bar.duration);\n } else {\n // this is the bar!\n for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {\n const beatLength = bar.beatLengths[beatIndex];\n const beatCount = bar.beatCounts[beatIndex] || 1;\n if (globalIndex >= beatCount) {\n globalIndex -= beatCount;\n offset = offset.plus(beatLength.timesNum(beatCount));\n } else {\n // this is it\n const instance = globalIndex;\n return [cycle, [barIndex, beatIndex, instance], offset.plus(beatLength.timesNum(instance))];\n }\n }\n }\n }\n throw new Error(\"Should not be here!\");\n }\n\n /**\n * Given a global offset returns five values [cycle, bar,beat,instance,offset] where:\n *\n * cycle - The nth cycle in which the beat lies. Since the global offset can be\n * greater the duration of the cycle this allows us to wrap around.\n * Similarly if globalOffset is less than 0 then we can also go behind a cycle.\n * bar - The mth bar in the nth cycle which the offset exists\n * beat - The beat within the mth bar in the nth cycle where the offset lies\n * instance - The beat instance where the offset lies.\n * startOffset - The note offset within the beat where the global offset lies.\n * globalIndex - The beat index within the entire cycle and not just within the bar.\n */\n getPosition(globalOffset: Fraction): [number, CyclePosition, Fraction, number] {\n const duration = this.duration;\n let cycleNum = 0;\n if (globalOffset.isLT(ZERO)) {\n while (globalOffset.isLT(ZERO)) {\n cycleNum--;\n globalOffset = globalOffset.plus(duration);\n }\n } else if (globalOffset.isGTE(duration)) {\n const realOffset = globalOffset.mod(duration);\n globalOffset = globalOffset.minus(realOffset).divby(duration);\n TSU.assert(globalOffset.isWhole);\n cycleNum = globalOffset.floor;\n globalOffset = realOffset;\n }\n\n // here globalOffset is positive and >= 0 and < this.duration\n let globalIndex = 0;\n for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {\n const bar = this.bars[barIndex];\n const barDuration = bar.duration;\n if (globalOffset.isGTE(barDuration)) {\n globalOffset = globalOffset.minus(barDuration);\n } else {\n // this is the bar!\n for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {\n const beatLength = bar.beatLengths[beatIndex];\n const beatCount = bar.beatCounts[beatIndex] || 1;\n for (let instance = 0; instance < beatCount; instance++, globalIndex++) {\n if (globalOffset.isGTE(beatLength)) {\n globalOffset = globalOffset.minus(beatLength);\n } else {\n // this is it\n return [cycleNum, [barIndex, beatIndex, instance], globalOffset, globalIndex];\n }\n }\n }\n }\n globalIndex += bar.totalBeatCount;\n }\n\n throw new Error(\"Should not be here!\");\n }\n\n *iterateBeats(startBar = 0, startBeat = 0, startInstance = 0): CycleIterator {\n let barIndex = startBar;\n let beatIndex = startBeat;\n let instanceIndex = startInstance;\n while (true) {\n const currBar = this.bars[barIndex];\n yield [[barIndex, beatIndex, instanceIndex], currBar.beatLengths[beatIndex]];\n instanceIndex++;\n if (!currBar.beatCounts[beatIndex] || instanceIndex >= currBar.beatCounts[beatIndex]) {\n instanceIndex = 0;\n beatIndex++;\n if (beatIndex >= currBar.beatLengths.length) {\n beatIndex = 0;\n barIndex++;\n if (barIndex >= this.bars.length) {\n barIndex = 0;\n }\n }\n }\n }\n }\n\n copyTo(another: this): void {\n super.copyTo(another);\n another.name = this.name;\n another.bars = this.bars.map((x) => x.clone());\n }\n\n get beatCount(): number {\n let out = 0;\n for (const bar of this.bars) out += bar.beatCount;\n return out;\n }\n\n get totalBeatCount(): number {\n let out = 0;\n for (const bar of this.bars) out += bar.totalBeatCount;\n return out;\n }\n\n /**\n * Total duration (of time) across all bars in this cycle.\n */\n get duration(): Fraction {\n return this.bars.reduce((x, y) => x.plus(y.duration), ZERO);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cycle.js","sourceRoot":"","sources":["../../src/cycle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,qCAA+C;AAS/C,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAEjC,MAAa,WAAW;IACtB,YAA4B,KAAY,EAAS,WAAW,CAAC,EAAS,YAAY,CAAC,EAAS,WAAW,CAAC;QAA5E,UAAK,GAAL,KAAK,CAAO;QAAS,aAAQ,GAAR,QAAQ,CAAI;QAAS,cAAS,GAAT,SAAS,CAAI;QAAS,aAAQ,GAAR,QAAQ,CAAI;IAAG,CAAC;IAE5G,IAAI,IAAI;QACN,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,MAAM,GAA8B;YACxC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC;YAC9C,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;SACpC,CAAC;QACF,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/F,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;YAClB,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,IAAI,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,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AAC;QACrD,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACjD,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;KAClD;CACF,CAAC,AAPqB,CAOpB","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity, TimedEntity } from \"./entity\";\n\n/**\n * Alias to TSU.Num.Fraction in tsutils.\n */\ntype Fraction = TSU.Num.Fraction;\nexport type CyclePosition = [number, number, number];\nexport type CycleIterator = Generator<[CyclePosition, Fraction]>;\n\nconst ZERO = TSU.Num.Fraction.ZERO;\nconst ONE = TSU.Num.Fraction.ONE;\n\nexport class CycleCursor {\n constructor(public readonly cycle: Cycle, public barIndex = 0, public beatIndex = 0, public instance = 0) {}\n\n get next(): [CyclePosition, Fraction] {\n const currBar = this.cycle.bars[this.barIndex];\n const result: [CyclePosition, Fraction] = [\n [this.barIndex, this.beatIndex, this.instance],\n currBar.beatLengths[this.beatIndex],\n ];\n this.instance++;\n if (!currBar.beatCounts[this.beatIndex] || this.instance >= currBar.beatCounts[this.beatIndex]) {\n this.instance = 0;\n this.beatIndex++;\n if (this.beatIndex >= currBar.beatLengths.length) {\n this.beatIndex = 0;\n this.barIndex++;\n if (this.barIndex >= this.cycle.bars.length) {\n this.barIndex = 0;\n }\n }\n }\n return result;\n }\n\n get prev(): [CyclePosition, Fraction] {\n const currBar = this.cycle.bars[this.barIndex];\n const result: [CyclePosition, Fraction] = [\n [this.barIndex, this.beatIndex, this.instance],\n currBar.beatLengths[this.beatIndex],\n ];\n // TODO - result should be set *after* decrementing if we had already\n // done a \"next\" before this otherwise user may have to do a prev twice\n this.instance--;\n if (this.instance < 0) {\n this.beatIndex--;\n if (this.beatIndex < 0) {\n this.barIndex--;\n if (this.barIndex < 0) {\n this.barIndex = this.cycle.bars.length - 1;\n }\n this.beatIndex = this.cycle.bars[this.barIndex].beatCount - 1;\n }\n this.instance = (this.cycle.bars[this.barIndex].beatCounts[this.beatIndex] || 1) - 1;\n }\n return result;\n }\n}\n\nexport class Bar extends TimedEntity {\n readonly TYPE: string = \"Bar\";\n\n name: string;\n // Length/Duration of each beat.\n beatLengths: Fraction[] = [];\n\n // How many times should a beat be repeated - the Kalai!\n beatCounts: number[] = [];\n\n constructor(config: any = null) {\n super((config = config || {}));\n this.name = config.name || \"\";\n for (const bl of config.beatLengths || []) {\n if (typeof bl === \"number\") {\n this.beatLengths.push(TSU.Num.Frac(bl));\n } else {\n this.beatLengths.push(bl);\n }\n }\n for (const bc of config.beatCounts || []) {\n this.beatCounts.push(bc);\n }\n while (this.beatCounts.length < this.beatLengths.length) {\n this.beatCounts.push(1);\n }\n }\n\n debugValue(): any {\n return { ...super.debugValue(), name: name, beatLengths: this.beatLengths };\n }\n\n equals(another: this): boolean {\n if (!super.equals(another)) return false;\n if (this.beatLengths.length != another.beatLengths.length) return false;\n if (this.beatCounts.length != another.beatCounts.length) return false;\n for (let i = 0; i < this.beatLengths.length; i++) {\n if (!this.beatLengths[i].equals(another.beatLengths[i])) return false;\n }\n for (let i = 0; i < this.beatCounts.length; i++) {\n if (this.beatCounts[i] != another.beatCounts[i]) return false;\n }\n return true;\n }\n\n copyTo(another: this): void {\n super.copyTo(another);\n another.name = this.name;\n another.beatLengths = [...this.beatLengths];\n another.beatCounts = [...this.beatCounts];\n }\n\n instanceCount(beatIndex: number): number {\n if (beatIndex > this.beatCounts.length) {\n // by default each beat has 1 instance?\n return 1;\n } else {\n return this.beatCounts[beatIndex];\n }\n }\n\n get beatCount(): number {\n return this.beatLengths.length;\n }\n\n get totalBeatCount(): number {\n let out = 0;\n for (let i = 0; i < this.beatLengths.length; i++) {\n out += this.beatCounts[i] || 1;\n }\n return out;\n }\n\n /**\n * Total duration (of time) across all beats in this bar.\n */\n get duration(): Fraction {\n let total = ZERO;\n for (let i = 0; i < this.beatLengths.length; i++) {\n total = total.plus(this.beatLengths[i].timesNum(this.beatCounts[i] || 1));\n }\n return total;\n }\n}\n\n// Describes the cycle pattern\nexport class Cycle extends TimedEntity {\n readonly TYPE: string = \"Cycle\";\n\n name: string;\n bars: Bar[];\n\n static readonly DEFAULT = new Cycle({\n name: \"Adi Thalam\",\n bars: [\n new Bar({ name: \"Laghu\", beatLengths: [1, 1, 1, 1] }),\n new Bar({ name: \"Dhrutam\", beatLengths: [1, 1] }),\n new Bar({ name: \"Dhrutam\", beatLengths: [1, 1] }),\n ],\n });\n\n constructor(config: null | { name?: string; bars?: Bar[] } = null) {\n super((config = config || {}));\n this.name = config.name || \"\";\n this.bars = config.bars || [];\n }\n\n debugValue(): any {\n return { ...super.debugValue(), name: name, bars: this.bars.map((p) => p.debugValue()) };\n }\n\n children(): Entity[] {\n return this.bars;\n }\n\n equals(another: this): boolean {\n if (!super.equals(another)) {\n return false;\n }\n if (this.bars.length != another.bars.length) return false;\n for (let i = 0; i < this.bars.length; i++) {\n if (!this.bars[i].equals(another.bars[i])) return false;\n }\n return true;\n }\n\n /**\n * Given a global beat index returns four values [cycle,bar,beat,instance] where:\n *\n * cycle - The nth cycle in which the beat lies. Since the global beat\n * index can be greater the number of beats in this cycle this\n * allows us to wrap around. Similarly if beatindex is less than\n * 0 then we can also go behind a cycle.\n * bar - The mth bar in the nth cycle which the offset exists\n * beat - The beat within the mth bar in the nth cycle where the\n * offset lies\n * instance - The beat instance where the offset lies.\n * startOffset - Offset of the beat at this global index.\n */\n getAtIndex(globalIndex: number): [number, CyclePosition, Fraction] {\n let cycle = 0;\n while (globalIndex < 0) {\n globalIndex += this.totalBeatCount;\n cycle--;\n }\n if (globalIndex >= this.totalBeatCount) {\n cycle = Math.floor(globalIndex / this.totalBeatCount);\n }\n globalIndex = globalIndex % this.totalBeatCount;\n let offset = ZERO;\n for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {\n const bar = this.bars[barIndex];\n if (globalIndex >= bar.totalBeatCount) {\n globalIndex -= bar.totalBeatCount;\n offset = offset.plus(bar.duration);\n } else {\n // this is the bar!\n for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {\n const beatLength = bar.beatLengths[beatIndex];\n const beatCount = bar.beatCounts[beatIndex] || 1;\n if (globalIndex >= beatCount) {\n globalIndex -= beatCount;\n offset = offset.plus(beatLength.timesNum(beatCount));\n } else {\n // this is it\n const instance = globalIndex;\n return [cycle, [barIndex, beatIndex, instance], offset.plus(beatLength.timesNum(instance))];\n }\n }\n }\n }\n throw new Error(\"Should not be here!\");\n }\n\n /**\n * Given a global offset returns five values [cycle, bar,beat,instance,offset] where:\n *\n * cycle - The nth cycle in which the beat lies. Since the global offset can be\n * greater the duration of the cycle this allows us to wrap around.\n * Similarly if globalOffset is less than 0 then we can also go behind a cycle.\n * bar - The mth bar in the nth cycle which the offset exists\n * beat - The beat within the mth bar in the nth cycle where the offset lies\n * instance - The beat instance where the offset lies.\n * startOffset - The note offset within the beat where the global offset lies.\n * globalIndex - The beat index within the entire cycle and not just within the bar.\n */\n getPosition(globalOffset: Fraction): [number, CyclePosition, Fraction, number] {\n const duration = this.duration;\n let cycleNum = 0;\n if (globalOffset.isLT(ZERO)) {\n while (globalOffset.isLT(ZERO)) {\n cycleNum--;\n globalOffset = globalOffset.plus(duration);\n }\n } else if (globalOffset.isGTE(duration)) {\n const realOffset = globalOffset.mod(duration);\n globalOffset = globalOffset.minus(realOffset).divby(duration);\n TSU.assert(globalOffset.isWhole);\n cycleNum = globalOffset.floor;\n globalOffset = realOffset;\n }\n\n // here globalOffset is positive and >= 0 and < this.duration\n let globalIndex = 0;\n for (let barIndex = 0; barIndex < this.bars.length; barIndex++) {\n const bar = this.bars[barIndex];\n const barDuration = bar.duration;\n if (globalOffset.isGTE(barDuration)) {\n globalOffset = globalOffset.minus(barDuration);\n } else {\n // this is the bar!\n for (let beatIndex = 0; beatIndex < bar.beatCount; beatIndex++) {\n const beatLength = bar.beatLengths[beatIndex];\n const beatCount = bar.beatCounts[beatIndex] || 1;\n for (let instance = 0; instance < beatCount; instance++, globalIndex++) {\n if (globalOffset.isGTE(beatLength)) {\n globalOffset = globalOffset.minus(beatLength);\n } else {\n // this is it\n return [cycleNum, [barIndex, beatIndex, instance], globalOffset, globalIndex];\n }\n }\n }\n }\n globalIndex += bar.totalBeatCount;\n }\n\n throw new Error(\"Should not be here!\");\n }\n\n *iterateBeats(startBar = 0, startBeat = 0, startInstance = 0): CycleIterator {\n let barIndex = startBar;\n let beatIndex = startBeat;\n let instanceIndex = startInstance;\n while (true) {\n const currBar = this.bars[barIndex];\n yield [[barIndex, beatIndex, instanceIndex], currBar.beatLengths[beatIndex]];\n instanceIndex++;\n if (!currBar.beatCounts[beatIndex] || instanceIndex >= currBar.beatCounts[beatIndex]) {\n instanceIndex = 0;\n beatIndex++;\n if (beatIndex >= currBar.beatLengths.length) {\n beatIndex = 0;\n barIndex++;\n if (barIndex >= this.bars.length) {\n barIndex = 0;\n }\n }\n }\n }\n }\n\n copyTo(another: this): void {\n super.copyTo(another);\n another.name = this.name;\n another.bars = this.bars.map((x) => x.clone());\n }\n\n get beatCount(): number {\n let out = 0;\n for (const bar of this.bars) out += bar.beatCount;\n return out;\n }\n\n get totalBeatCount(): number {\n let out = 0;\n for (const bar of this.bars) out += bar.totalBeatCount;\n return out;\n }\n\n /**\n * Total duration (of time) across all bars in this cycle.\n */\n get duration(): Fraction {\n return this.bars.reduce((x, y) => x.plus(y.duration), ZERO);\n }\n}\n"]}
|
package/lib/cjs/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":";;;AAMA,MAAa,MAAM;IASjB,YAAY,SAAc,IAAI;QARrB,SAAI,GAAW,QAAQ,CAAC;QAIxB,SAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAK/B,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QACtB,IA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C,WAAmB,EAAE,CAAC;IACzC,CAAC;;AA/IH,wBAgJC;AA5IgB,cAAO,GAAG,CAAC,AAAJ,CAAK;AAkJ7B,MAAsB,WAAY,SAAQ,MAAM;IAAhD;;QACW,SAAI,GAAW,aAAa,CAAC;IAWxC,CAAC;IAHC,MAAM,CAAC,OAAa;QAClB,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzE,CAAC;CACF;AAZD,kCAYC","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 readonly TYPE: string = \"Entity\";\n\n // readonly TYPE:string = \"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 * 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 readonly TYPE: string = \"TimedEntity\";\n\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/grids.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
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
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.GridLayoutGroup = exports.RowAlign = exports.ColAlign = exports.AlignedLine = exports.GridRow = exports.GridCell = exports.GridCellEvent = exports.GridModel = void 0;
|
|
27
37
|
const TSU = __importStar(require("@panyam/tsutils"));
|
|
@@ -156,7 +166,7 @@ var GridCellEvent;
|
|
|
156
166
|
GridCellEvent["REMOVED"] = "CellRemoved";
|
|
157
167
|
GridCellEvent["UPDATED"] = "CellUpdated";
|
|
158
168
|
GridCellEvent["MOVED"] = "CellMoved";
|
|
159
|
-
})(GridCellEvent
|
|
169
|
+
})(GridCellEvent || (exports.GridCellEvent = GridCellEvent = {}));
|
|
160
170
|
class GridCell {
|
|
161
171
|
constructor(gridRow, colIndex, value = null) {
|
|
162
172
|
this.gridRow = gridRow;
|
package/lib/cjs/grids.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grids.js","sourceRoot":"","sources":["../../src/grids.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC;iBAC1C;gBAGD,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,SAAS,EAAE;oBACtC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;wBAC5B,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;qBACnC;iBACF;aACF;YACD,SAAS,GAAG,SAAS,CAAC;SACvB;IACH,CAAC;CACF;AAvMD,0CAuMC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\n// import * as kiwi from \"@lume/kiwi\";\n\n/**\n * A generic way to host child views in a grid (very similar to gridbag\n * layout) This allows us to have a framework for hosting BeatViews instead\n * of mucking about with beat rows and beat columns etc.\n *\n * Grid \"cells\" can be referred by cell indexes. Additionally we want our\n * grid rows and columns to have names (like in Spreadsheets) so that even\n * when rows and columns are inserted, though indexes may change, the\n * \"addresses\" will be fixed and immovable. This helps us do things like\n * insert a new new column (say for markers) and not have to worry other\n * columns index changes impacting us.\n */\nexport class GridModel extends TSU.Events.EventEmitter {\n private static idCounter = 0;\n readonly uuid = GridModel.idCounter++;\n lastUpdatedAt = 0;\n // cells = new SparseArray<SparseArray<GridCell>>();\n rows: GridRow[] = [];\n rowAligns = new Map<number, RowAlign>();\n colAligns = new Map<number, ColAlign>();\n\n debugValue() {\n const out = {\n rows: this.rows.map((r) => r.debugValue()),\n lastUpdatedAt: this.lastUpdatedAt,\n } as any;\n return out;\n }\n\n get firstRow(): number {\n for (const gr of this.rows) {\n if (gr.numCells > 0) return gr.rowIndex;\n }\n return -1;\n }\n\n get firstCol(): number {\n let minCol = -1;\n for (const gr of this.rows) {\n const fc = gr.firstCol;\n if (fc >= 0) {\n if (minCol < 0 || fc < minCol) {\n minCol = fc;\n }\n }\n }\n return minCol;\n }\n\n cellsInRow(row: number): GridCell[] {\n const out = [] as GridCell[];\n const gr = this.rows[row];\n if (gr) {\n for (const cell of gr.cells) {\n if (cell?.value) out.push(cell);\n }\n }\n return out;\n }\n\n cellsInCol(col: number): GridCell[] {\n const out = [] as GridCell[];\n for (const gr of this.rows) {\n const cell = gr.cellAt(col);\n if (cell?.value) out.push(cell);\n }\n return out;\n }\n\n addRowAlign(align: RowAlign): void {\n this.rowAligns.set(align.uuid, align);\n }\n\n addColAlign(align: ColAlign): void {\n this.colAligns.set(align.uuid, align);\n }\n\n addRows(insertBefore = -1, numRows = 1): this {\n if (insertBefore < 0) {\n insertBefore = this.rows.length;\n }\n let next = this.rows[insertBefore] || null;\n const prev = this.rows[insertBefore - 1] || null;\n for (let i = numRows - 1; i >= 0; i--) {\n const newRow = new GridRow(this, insertBefore + i);\n this.rows.splice(insertBefore, 0, newRow);\n if (next != null) {\n newRow.defaultRowAlign.addSuccessor(next.defaultRowAlign);\n }\n if (i == 0 && insertBefore > 0) {\n prev.defaultRowAlign.addSuccessor(newRow.defaultRowAlign);\n }\n next = newRow;\n }\n for (let i = insertBefore + numRows; i < this.rows.length; i++) {\n this.rows[i].rowIndex += numRows;\n }\n return this;\n }\n\n getRow(row: number): GridRow {\n if (row >= this.rows.length) {\n this.addRows(-1, 1 + row - this.rows.length);\n }\n return this.rows[row];\n }\n\n setValue(row: number, col: number, value: any, cellCreator?: (row: GridRow, col: number) => GridCell): any {\n const grow = this.getRow(row);\n if (!cellCreator) {\n cellCreator = (row: GridRow, col: number) => {\n return new GridCell(row, col);\n };\n }\n if (value == null) {\n const out = grow.clearCellAt(col);\n if (out != null) {\n this.eventHub?.emit(GridCellEvent.CLEARED, this, {\n loc: out.location,\n });\n }\n return out;\n } else {\n const cell = grow.cellAt(col, cellCreator) as GridCell;\n const oldValue = cell.value;\n this.eventHub?.emit(GridCellEvent.UPDATED, this, {\n loc: cell.location,\n cell: cell,\n oldValue: cell.value,\n });\n cell.value = value;\n return oldValue;\n }\n }\n\n protected eventHubChanged(): void {\n console.log(\"Event Hub Changed for GridModel\");\n }\n}\n\nexport interface GridCellView {\n readonly cell: GridCell;\n x: number;\n y: number;\n width: number;\n height: number;\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout: boolean,\n ): [number | null, number | null, number | null, number | null];\n readonly needsLayout: boolean;\n readonly minSize: TSU.Geom.Size;\n readonly bbox: TSU.Geom.Rect;\n}\n\nexport enum GridCellEvent {\n ADDED = \"CellAdded\",\n CLEARED = \"CellCleared\",\n REMOVED = \"CellRemoved\",\n UPDATED = \"CellUpdated\",\n MOVED = \"CellMoved\",\n}\n\n/**\n * Interface for a view for a given cell in the grid.\n */\nexport class GridCell {\n private static idCounter = 0;\n readonly uuid = GridCell.idCounter++;\n cellView: GridCellView | null;\n private _rowAlign: RowAlign;\n private _colAlign: ColAlign;\n\n constructor(public gridRow: GridRow, public colIndex: number, public value: any = null) {\n this.rowAlign = gridRow.defaultRowAlign;\n }\n\n get rowAlign(): RowAlign {\n return this._rowAlign;\n }\n\n set rowAlign(val: RowAlign) {\n val.addCell(this);\n this._rowAlign = val;\n }\n\n get colAlign(): ColAlign {\n return this._colAlign;\n }\n\n set colAlign(val: ColAlign) {\n val.addCell(this);\n this._colAlign = val;\n }\n\n get location(): string {\n return this.gridRow.rowIndex + \":\" + this.colIndex;\n }\n\n get grid(): GridModel {\n return this.gridRow.grid;\n }\n\n get rowIndex(): number {\n return this.gridRow.rowIndex;\n }\n\n debugValue() {\n const out = {\n r: this.gridRow.rowIndex,\n c: this.colIndex,\n value: this.value,\n y: this.rowAlign.coordOffset,\n h: this.rowAlign.maxLength,\n } as any;\n if (this.colAlign) {\n out.x = this.colAlign.coordOffset;\n out.w = this.colAlign.maxLength;\n }\n return out;\n }\n}\n\n/**\n * Represents a row of grid cells in a GridModel\n */\nexport class GridRow {\n cells: (null | GridCell)[] = [];\n // The default vertical alignment manager for all cells in this row\n defaultRowAlign: RowAlign;\n\n constructor(public grid: GridModel, public rowIndex: number) {\n this.defaultRowAlign = new RowAlign();\n this.grid.addRowAlign(this.defaultRowAlign);\n }\n\n get firstCol() {\n for (let i = 0; i < this.cells.length; i++) {\n if (this.cells[i]?.value) {\n return i;\n }\n }\n return -1;\n }\n\n get numCols() {\n return this.cells.length;\n }\n\n /**\n * Returns the number of cells that contain values.\n */\n get numCells() {\n let i = 0;\n for (const cell of this.cells) {\n if (cell != null && cell.value != null) i++;\n }\n return i;\n }\n\n cellAt(col: number, creator?: (row: GridRow, col: number) => GridCell): GridCell | null {\n let out = this.cells[col] || null;\n if (!out && creator) {\n this.cells[col] = out = creator(this, col);\n out.gridRow = this;\n out.colIndex = col;\n if (out.rowAlign) {\n this.grid.addRowAlign(out.rowAlign);\n }\n if (out.colAlign) {\n this.grid.addColAlign(out.colAlign);\n }\n }\n return out;\n }\n\n // Clears the cell at the given column.\n // Note this is not the same as \"removing\" a cell.\n // Removing a cell needs all cells to the \"right\" to be shifted left.\n // We wont support removing yet.\n clearCellAt(col: number): GridCell | null {\n const out = this.cells[col] || null;\n if (out) {\n this.cells[col] = null;\n }\n return out;\n }\n\n debugValue() {\n return {\n r: this.rowIndex,\n cells: this.cells.filter((c) => c).map((c) => c?.debugValue()),\n };\n }\n}\n\nexport abstract class AlignedLine {\n private static idCounter = 0;\n readonly uuid = AlignedLine.idCounter++;\n needsLayout = false;\n protected _coordOffset = 0;\n protected _maxLength = 0;\n paddingBefore = 15;\n paddingAfter = 15;\n // All the cells that belong in this column\n cells: GridCell[] = [];\n getCellView: (value: any) => GridCellView;\n\n abstract setOffset(val: number): void;\n abstract evalMaxLength(changedCells: GridCell[]): number;\n\n get coordOffset(): number {\n return this._coordOffset;\n }\n\n /**\n * Return the maximum width of a particular column.\n */\n get maxLength(): number {\n return this._maxLength + this.paddingBefore + this.paddingAfter;\n }\n\n setMaxLength(length: number) {\n this._maxLength = length;\n }\n\n setPadding(before: number, after: number): void {\n if (before >= 0) {\n this.paddingBefore = before;\n }\n if (after >= 0) {\n this.paddingAfter = after;\n }\n }\n\n addCell(cell: GridCell): this {\n if (this.beforeAddingCell(cell)) {\n this.cells.push(cell);\n }\n return this;\n }\n\n protected abstract beforeAddingCell(cell: GridCell): boolean;\n\n removeCell(cell: GridCell): this {\n if (this.beforeRemovingCell(cell)) {\n for (let i = 0; i < this.cells.length; i++) {\n if (this.cells[i].uuid == cell.uuid) {\n this.cells.splice(i, 1);\n break;\n }\n }\n }\n return this;\n }\n\n protected abstract beforeRemovingCell(cell: GridCell): boolean;\n\n // The \"neighboring\" columns that depend on this column to be placed\n // before they are placed\n prevLines = [] as this[];\n nextLines = [] as this[];\n addSuccessor(next: this): void {\n // Set nextCol as a successor of this col\n // TODO - Ensure no cycles\n for (const c of this.nextLines) {\n if (c == next) return;\n }\n this.nextLines.push(next);\n next.prevLines.push(this);\n }\n\n /* TODO: Disabling only to improve test coverage as this method is\n * not used.\n * When we have mutable grids where we can insert/remove neighbors\n * we can enable this again.\n */\n /*\n removeSuccessor(next: this): void {\n // Set nextCol as a successor of this col\n // TODO - Ensure no cycles\n for (let i = 0; i < this.nextLines.length; i++) {\n if (this.nextLines[i] == next) {\n this.nextLines.splice(i, 1);\n break;\n }\n }\n for (let i = 0; i < next.prevLines.length; i++) {\n if (next.prevLines[i] == this) {\n next.prevLines.splice(i, 1);\n break;\n }\n }\n }\n */\n}\n\nexport class ColAlign extends AlignedLine {\n setOffset(val: number): void {\n this._coordOffset = val;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n if (this._maxLength <= 0) {\n // this hasnt been evaluated yet so do it!\n this.evalMaxLength();\n }\n cellView.setBounds(val, null, this.maxLength, null, true);\n }\n }\n }\n\n evalMaxLength(changedCells: GridCell[] = []): number {\n this._maxLength = 0;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n this._maxLength = Math.max(cellView.minSize.width, this._maxLength);\n }\n }\n return this._maxLength;\n }\n\n protected beforeAddingCell(cell: GridCell): boolean {\n if (cell.colAlign && cell.colAlign != this) {\n cell.colAlign.removeCell(cell);\n }\n return cell.colAlign != this;\n }\n\n beforeRemovingCell(cell: GridCell): boolean {\n return cell.colAlign == this;\n }\n}\n\nexport class RowAlign extends AlignedLine {\n /**\n * Sets the Y coordinate of all cells in this row.\n */\n setOffset(val: number): void {\n this._coordOffset = val;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n if (this._maxLength <= 0) {\n // this hasnt been evaluated yet so do it!\n this.evalMaxLength();\n }\n cellView.setBounds(null, val, null, this.maxLength, true);\n }\n }\n }\n\n evalMaxLength(changedCells: GridCell[] = []): number {\n this._maxLength = 0;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n this._maxLength = Math.max(cellView.minSize.height, this._maxLength);\n }\n }\n return this._maxLength;\n }\n\n protected beforeAddingCell(cell: GridCell): boolean {\n if (cell.rowAlign && cell.rowAlign != this) {\n cell.rowAlign.removeCell(cell);\n }\n return cell.rowAlign != this;\n }\n\n beforeRemovingCell(cell: GridCell): boolean {\n return cell.rowAlign == this;\n }\n}\n\n/**\n * The layout manager for a collection of GridViews bound by common\n * alignment objects.\n */\nexport class GridLayoutGroup {\n // rowAligns = new Map<number, RowAlign>();\n // colAligns = new Map<number, ColAlign>();\n gridModels = [] as GridModel[];\n\n private eventHandler = (event: TSU.Events.TEvent) => {\n this.applyModelEvents(event.payload);\n };\n\n addGridModel(gridModel: GridModel): boolean {\n gridModel.eventHub?.on(TSU.Events.EventHub.BATCH_EVENTS, this.eventHandler);\n this.gridModels.push(gridModel);\n return true;\n }\n\n startingRowAligns(): RowAlign[] {\n const out = [] as RowAlign[];\n const visited = {} as any;\n for (const gm of this.gridModels) {\n for (const cell of gm.cellsInRow(gm.firstRow)) {\n if (cell.rowAlign && !visited[cell.rowAlign.uuid]) {\n visited[cell.rowAlign.uuid] = true;\n out.push(cell.rowAlign);\n }\n }\n }\n return out;\n }\n\n startingColAligns(): ColAlign[] {\n const out = [] as ColAlign[];\n const visited = {} as any;\n for (const gm of this.gridModels) {\n for (const cell of gm.cellsInCol(gm.firstCol)) {\n if (cell.colAlign && !visited[cell.colAlign.uuid]) {\n visited[cell.colAlign.uuid] = true;\n out.push(cell.colAlign);\n }\n }\n }\n return out;\n }\n\n removeGridModel(gridModel: GridModel): void {\n gridModel.eventHub?.removeOn(TSU.Events.EventHub.BATCH_EVENTS, this.eventHandler);\n }\n\n getCellView: (cell: GridCell) => GridCellView;\n\n get startingRows(): RowAlign[] {\n return this.startingRowAligns();\n }\n\n get startingCols(): ColAlign[] {\n return this.startingColAligns();\n }\n\n /**\n * Forces a full refresh.\n */\n refreshLayout() {\n const changedRowAligns = {} as any;\n const changedColAligns = {} as any;\n\n for (const rowAlign of this.startingRowAligns()) {\n if (!(rowAlign.uuid in changedRowAligns)) {\n changedRowAligns[rowAlign.uuid] = {\n align: rowAlign,\n cells: [],\n };\n }\n }\n\n for (const colAlign of this.startingColAligns()) {\n if (!(colAlign.uuid in changedColAligns)) {\n changedColAligns[colAlign.uuid] = {\n align: colAlign,\n cells: [],\n };\n }\n }\n\n this.doBfsLayout(this.startingRows, changedRowAligns);\n this.doBfsLayout(this.startingCols, changedColAligns);\n }\n\n /**\n * As the grid model changes (cell content changed, cleared etc) we need\n * to refresh our layout based on this.\n * As a first step the new height and width of all changed cells is\n * evaluted to see which rows and/or columns are affected (and need to be\n * resized/repositioned).\n */\n protected applyModelEvents(events: TSU.Events.TEvent[]) {\n const [changedRowAligns, changedColAligns] = this.changesForEvents(events);\n this.doBfsLayout(this.startingRows, changedRowAligns);\n this.doBfsLayout(this.startingCols, changedColAligns);\n }\n\n protected changesForEvents(events: TSU.Events.TEvent[]): [any, any] {\n // Step 1 - topologically sort RowAligns of changed cells\n // Step 2 - topologically sort ColAligns of changed cells\n // Step 3 -\n const cellVisited = {} as any;\n const changedRowAligns = {} as any;\n const changedColAligns = {} as any;\n // Going in reverse means we only get the latest event affecting a cell\n // instead of going through every change.\n // Later on we can revisit this if the events are edge triggered instead\n // of level triggered\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i];\n const loc = event.payload.loc;\n if (cellVisited[loc]) continue;\n cellVisited[loc] = true;\n const [row, col] = loc.split(\":\").map((x: string) => parseInt(x));\n const gridModel = event.source;\n const cell = gridModel.getRow(row).cellAt(col);\n if (cell) {\n // TODO - For now we are marking both row and col as having\n // changed for a cell. We can optimize this to only row or\n // col based on whether height or width has changed.\n if (!(cell.rowAlign.uuid in changedRowAligns)) {\n changedRowAligns[cell.rowAlign.uuid] = {\n align: cell.rowAlign,\n cells: [],\n };\n }\n changedRowAligns[cell.rowAlign.uuid][\"cells\"].push(cell);\n\n if (!(cell.colAlign.uuid in changedColAligns)) {\n changedColAligns[cell.colAlign.uuid] = {\n align: cell.colAlign,\n cells: [],\n };\n }\n changedColAligns[cell.colAlign.uuid][\"cells\"].push(cell);\n }\n }\n return [changedRowAligns, changedColAligns];\n }\n\n protected ensureGetCellView(align: AlignedLine) {\n if (!align.getCellView) {\n if (!this.getCellView) {\n return null;\n }\n align.getCellView = this.getCellView;\n }\n return align.getCellView;\n }\n\n // 1. start from the starting lines and do a BF traversal\n // 2. If a line not visited (ie laid out):\n // if it is in the changedAlign list then reval its length (w/h)\n // set its offset and length if either width or offset has changed\n // offset can be thought of changed if the preceding line's offset has changed\n // first do above for rows\n protected doBfsLayout<T extends AlignedLine>(startingLines: T[], changedAligns: any) {\n // Eval max lengths for all changed aligns\n if (!this.getCellView) return;\n for (const alignId in changedAligns) {\n const val = changedAligns[alignId];\n this.ensureGetCellView(val.align);\n val.align.evalMaxLength(val.cells);\n }\n let lineQueue = [] as [null | T, T][];\n const visitedLines = {} as any;\n for (const line of startingLines) lineQueue.push([null, line]);\n const lineOffsetChanged = {} as any;\n while (lineQueue.length > 0) {\n const nextQueue = [] as [null | T, T][];\n for (let i = 0; i < lineQueue.length; i++) {\n const [prevLineAlign, lineAlign] = lineQueue[i];\n visitedLines[lineAlign.uuid] = true;\n let newOffset = lineAlign.coordOffset;\n let lineChanged = lineAlign.uuid in changedAligns;\n if (prevLineAlign) {\n if (lineOffsetChanged[prevLineAlign.uuid]) {\n newOffset = prevLineAlign.coordOffset + prevLineAlign.maxLength;\n lineChanged = true;\n }\n }\n if (lineChanged) {\n this.ensureGetCellView(lineAlign);\n lineAlign.setOffset(newOffset);\n lineOffsetChanged[lineAlign.uuid] = true;\n }\n\n // Add next neighbors now\n for (const next of lineAlign.nextLines) {\n if (!visitedLines[next.uuid]) {\n nextQueue.push([lineAlign, next]);\n }\n }\n }\n lineQueue = nextQueue;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"grids.js","sourceRoot":"","sources":["../../src/grids.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAevC,MAAa,SAAU,SAAQ,GAAG,CAAC,MAAM,CAAC,YAAY;IAAtD;;QAEW,SAAI,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QACtC,kBAAa,GAAG,CAAC,CAAC;QAElB,SAAI,GAAc,EAAE,CAAC;QACrB,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QACxC,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAuH1C,CAAC;IArHC,UAAU;QACR,MAAM,GAAG,GAAG;YACV,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;YAC1C,aAAa,EAAE,IAAI,CAAC,aAAa;SAC3B,CAAC;QACT,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,QAAQ;QACV,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAC3B,IAAI,EAAE,CAAC,QAAQ,GAAG,CAAC;gBAAE,OAAO,EAAE,CAAC,QAAQ,CAAC;QAC1C,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IAED,IAAI,QAAQ;QACV,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;QAChB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,C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,SAAS,CAAC,SAAS,EAAE,CAAC;oBACvC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;wBAC7B,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;oBACpC,CAAC;gBACH,CAAC;YACH,CAAC;YACD,SAAS,GAAG,SAAS,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AAvMD,0CAuMC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\n// import * as kiwi from \"@lume/kiwi\";\n\n/**\n * A generic way to host child views in a grid (very similar to gridbag\n * layout) This allows us to have a framework for hosting BeatViews instead\n * of mucking about with beat rows and beat columns etc.\n *\n * Grid \"cells\" can be referred by cell indexes. Additionally we want our\n * grid rows and columns to have names (like in Spreadsheets) so that even\n * when rows and columns are inserted, though indexes may change, the\n * \"addresses\" will be fixed and immovable. This helps us do things like\n * insert a new new column (say for markers) and not have to worry other\n * columns index changes impacting us.\n */\nexport class GridModel extends TSU.Events.EventEmitter {\n private static idCounter = 0;\n readonly uuid = GridModel.idCounter++;\n lastUpdatedAt = 0;\n // cells = new SparseArray<SparseArray<GridCell>>();\n rows: GridRow[] = [];\n rowAligns = new Map<number, RowAlign>();\n colAligns = new Map<number, ColAlign>();\n\n debugValue() {\n const out = {\n rows: this.rows.map((r) => r.debugValue()),\n lastUpdatedAt: this.lastUpdatedAt,\n } as any;\n return out;\n }\n\n get firstRow(): number {\n for (const gr of this.rows) {\n if (gr.numCells > 0) return gr.rowIndex;\n }\n return -1;\n }\n\n get firstCol(): number {\n let minCol = -1;\n for (const gr of this.rows) {\n const fc = gr.firstCol;\n if (fc >= 0) {\n if (minCol < 0 || fc < minCol) {\n minCol = fc;\n }\n }\n }\n return minCol;\n }\n\n cellsInRow(row: number): GridCell[] {\n const out = [] as GridCell[];\n const gr = this.rows[row];\n if (gr) {\n for (const cell of gr.cells) {\n if (cell?.value) out.push(cell);\n }\n }\n return out;\n }\n\n cellsInCol(col: number): GridCell[] {\n const out = [] as GridCell[];\n for (const gr of this.rows) {\n const cell = gr.cellAt(col);\n if (cell?.value) out.push(cell);\n }\n return out;\n }\n\n addRowAlign(align: RowAlign): void {\n this.rowAligns.set(align.uuid, align);\n }\n\n addColAlign(align: ColAlign): void {\n this.colAligns.set(align.uuid, align);\n }\n\n addRows(insertBefore = -1, numRows = 1): this {\n if (insertBefore < 0) {\n insertBefore = this.rows.length;\n }\n let next = this.rows[insertBefore] || null;\n const prev = this.rows[insertBefore - 1] || null;\n for (let i = numRows - 1; i >= 0; i--) {\n const newRow = new GridRow(this, insertBefore + i);\n this.rows.splice(insertBefore, 0, newRow);\n if (next != null) {\n newRow.defaultRowAlign.addSuccessor(next.defaultRowAlign);\n }\n if (i == 0 && insertBefore > 0) {\n prev.defaultRowAlign.addSuccessor(newRow.defaultRowAlign);\n }\n next = newRow;\n }\n for (let i = insertBefore + numRows; i < this.rows.length; i++) {\n this.rows[i].rowIndex += numRows;\n }\n return this;\n }\n\n getRow(row: number): GridRow {\n if (row >= this.rows.length) {\n this.addRows(-1, 1 + row - this.rows.length);\n }\n return this.rows[row];\n }\n\n setValue(row: number, col: number, value: any, cellCreator?: (row: GridRow, col: number) => GridCell): any {\n const grow = this.getRow(row);\n if (!cellCreator) {\n cellCreator = (row: GridRow, col: number) => {\n return new GridCell(row, col);\n };\n }\n if (value == null) {\n const out = grow.clearCellAt(col);\n if (out != null) {\n this.eventHub?.emit(GridCellEvent.CLEARED, this, {\n loc: out.location,\n });\n }\n return out;\n } else {\n const cell = grow.cellAt(col, cellCreator) as GridCell;\n const oldValue = cell.value;\n this.eventHub?.emit(GridCellEvent.UPDATED, this, {\n loc: cell.location,\n cell: cell,\n oldValue: cell.value,\n });\n cell.value = value;\n return oldValue;\n }\n }\n\n protected eventHubChanged(): void {\n console.log(\"Event Hub Changed for GridModel\");\n }\n}\n\nexport interface GridCellView {\n readonly cell: GridCell;\n x: number;\n y: number;\n width: number;\n height: number;\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout: boolean,\n ): [number | null, number | null, number | null, number | null];\n readonly needsLayout: boolean;\n readonly minSize: TSU.Geom.Size;\n readonly bbox: TSU.Geom.Rect;\n}\n\nexport enum GridCellEvent {\n ADDED = \"CellAdded\",\n CLEARED = \"CellCleared\",\n REMOVED = \"CellRemoved\",\n UPDATED = \"CellUpdated\",\n MOVED = \"CellMoved\",\n}\n\n/**\n * Interface for a view for a given cell in the grid.\n */\nexport class GridCell {\n private static idCounter = 0;\n readonly uuid = GridCell.idCounter++;\n cellView: GridCellView | null;\n private _rowAlign: RowAlign;\n private _colAlign: ColAlign;\n\n constructor(public gridRow: GridRow, public colIndex: number, public value: any = null) {\n this.rowAlign = gridRow.defaultRowAlign;\n }\n\n get rowAlign(): RowAlign {\n return this._rowAlign;\n }\n\n set rowAlign(val: RowAlign) {\n val.addCell(this);\n this._rowAlign = val;\n }\n\n get colAlign(): ColAlign {\n return this._colAlign;\n }\n\n set colAlign(val: ColAlign) {\n val.addCell(this);\n this._colAlign = val;\n }\n\n get location(): string {\n return this.gridRow.rowIndex + \":\" + this.colIndex;\n }\n\n get grid(): GridModel {\n return this.gridRow.grid;\n }\n\n get rowIndex(): number {\n return this.gridRow.rowIndex;\n }\n\n debugValue() {\n const out = {\n r: this.gridRow.rowIndex,\n c: this.colIndex,\n value: this.value,\n y: this.rowAlign.coordOffset,\n h: this.rowAlign.maxLength,\n } as any;\n if (this.colAlign) {\n out.x = this.colAlign.coordOffset;\n out.w = this.colAlign.maxLength;\n }\n return out;\n }\n}\n\n/**\n * Represents a row of grid cells in a GridModel\n */\nexport class GridRow {\n cells: (null | GridCell)[] = [];\n // The default vertical alignment manager for all cells in this row\n defaultRowAlign: RowAlign;\n\n constructor(public grid: GridModel, public rowIndex: number) {\n this.defaultRowAlign = new RowAlign();\n this.grid.addRowAlign(this.defaultRowAlign);\n }\n\n get firstCol() {\n for (let i = 0; i < this.cells.length; i++) {\n if (this.cells[i]?.value) {\n return i;\n }\n }\n return -1;\n }\n\n get numCols() {\n return this.cells.length;\n }\n\n /**\n * Returns the number of cells that contain values.\n */\n get numCells() {\n let i = 0;\n for (const cell of this.cells) {\n if (cell != null && cell.value != null) i++;\n }\n return i;\n }\n\n cellAt(col: number, creator?: (row: GridRow, col: number) => GridCell): GridCell | null {\n let out = this.cells[col] || null;\n if (!out && creator) {\n this.cells[col] = out = creator(this, col);\n out.gridRow = this;\n out.colIndex = col;\n if (out.rowAlign) {\n this.grid.addRowAlign(out.rowAlign);\n }\n if (out.colAlign) {\n this.grid.addColAlign(out.colAlign);\n }\n }\n return out;\n }\n\n // Clears the cell at the given column.\n // Note this is not the same as \"removing\" a cell.\n // Removing a cell needs all cells to the \"right\" to be shifted left.\n // We wont support removing yet.\n clearCellAt(col: number): GridCell | null {\n const out = this.cells[col] || null;\n if (out) {\n this.cells[col] = null;\n }\n return out;\n }\n\n debugValue() {\n return {\n r: this.rowIndex,\n cells: this.cells.filter((c) => c).map((c) => c?.debugValue()),\n };\n }\n}\n\nexport abstract class AlignedLine {\n private static idCounter = 0;\n readonly uuid = AlignedLine.idCounter++;\n needsLayout = false;\n protected _coordOffset = 0;\n protected _maxLength = 0;\n paddingBefore = 15;\n paddingAfter = 15;\n // All the cells that belong in this column\n cells: GridCell[] = [];\n getCellView: (value: any) => GridCellView;\n\n abstract setOffset(val: number): void;\n abstract evalMaxLength(changedCells: GridCell[]): number;\n\n get coordOffset(): number {\n return this._coordOffset;\n }\n\n /**\n * Return the maximum width of a particular column.\n */\n get maxLength(): number {\n return this._maxLength + this.paddingBefore + this.paddingAfter;\n }\n\n setMaxLength(length: number) {\n this._maxLength = length;\n }\n\n setPadding(before: number, after: number): void {\n if (before >= 0) {\n this.paddingBefore = before;\n }\n if (after >= 0) {\n this.paddingAfter = after;\n }\n }\n\n addCell(cell: GridCell): this {\n if (this.beforeAddingCell(cell)) {\n this.cells.push(cell);\n }\n return this;\n }\n\n protected abstract beforeAddingCell(cell: GridCell): boolean;\n\n removeCell(cell: GridCell): this {\n if (this.beforeRemovingCell(cell)) {\n for (let i = 0; i < this.cells.length; i++) {\n if (this.cells[i].uuid == cell.uuid) {\n this.cells.splice(i, 1);\n break;\n }\n }\n }\n return this;\n }\n\n protected abstract beforeRemovingCell(cell: GridCell): boolean;\n\n // The \"neighboring\" columns that depend on this column to be placed\n // before they are placed\n prevLines = [] as this[];\n nextLines = [] as this[];\n addSuccessor(next: this): void {\n // Set nextCol as a successor of this col\n // TODO - Ensure no cycles\n for (const c of this.nextLines) {\n if (c == next) return;\n }\n this.nextLines.push(next);\n next.prevLines.push(this);\n }\n\n /* TODO: Disabling only to improve test coverage as this method is\n * not used.\n * When we have mutable grids where we can insert/remove neighbors\n * we can enable this again.\n */\n /*\n removeSuccessor(next: this): void {\n // Set nextCol as a successor of this col\n // TODO - Ensure no cycles\n for (let i = 0; i < this.nextLines.length; i++) {\n if (this.nextLines[i] == next) {\n this.nextLines.splice(i, 1);\n break;\n }\n }\n for (let i = 0; i < next.prevLines.length; i++) {\n if (next.prevLines[i] == this) {\n next.prevLines.splice(i, 1);\n break;\n }\n }\n }\n */\n}\n\nexport class ColAlign extends AlignedLine {\n setOffset(val: number): void {\n this._coordOffset = val;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n if (this._maxLength <= 0) {\n // this hasnt been evaluated yet so do it!\n this.evalMaxLength();\n }\n cellView.setBounds(val, null, this.maxLength, null, true);\n }\n }\n }\n\n evalMaxLength(changedCells: GridCell[] = []): number {\n this._maxLength = 0;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n this._maxLength = Math.max(cellView.minSize.width, this._maxLength);\n }\n }\n return this._maxLength;\n }\n\n protected beforeAddingCell(cell: GridCell): boolean {\n if (cell.colAlign && cell.colAlign != this) {\n cell.colAlign.removeCell(cell);\n }\n return cell.colAlign != this;\n }\n\n beforeRemovingCell(cell: GridCell): boolean {\n return cell.colAlign == this;\n }\n}\n\nexport class RowAlign extends AlignedLine {\n /**\n * Sets the Y coordinate of all cells in this row.\n */\n setOffset(val: number): void {\n this._coordOffset = val;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n if (this._maxLength <= 0) {\n // this hasnt been evaluated yet so do it!\n this.evalMaxLength();\n }\n cellView.setBounds(null, val, null, this.maxLength, true);\n }\n }\n }\n\n evalMaxLength(changedCells: GridCell[] = []): number {\n this._maxLength = 0;\n for (const cell of this.cells) {\n if (cell.value) {\n const cellView = this.getCellView(cell);\n this._maxLength = Math.max(cellView.minSize.height, this._maxLength);\n }\n }\n return this._maxLength;\n }\n\n protected beforeAddingCell(cell: GridCell): boolean {\n if (cell.rowAlign && cell.rowAlign != this) {\n cell.rowAlign.removeCell(cell);\n }\n return cell.rowAlign != this;\n }\n\n beforeRemovingCell(cell: GridCell): boolean {\n return cell.rowAlign == this;\n }\n}\n\n/**\n * The layout manager for a collection of GridViews bound by common\n * alignment objects.\n */\nexport class GridLayoutGroup {\n // rowAligns = new Map<number, RowAlign>();\n // colAligns = new Map<number, ColAlign>();\n gridModels = [] as GridModel[];\n\n private eventHandler = (event: TSU.Events.TEvent) => {\n this.applyModelEvents(event.payload);\n };\n\n addGridModel(gridModel: GridModel): boolean {\n gridModel.eventHub?.on(TSU.Events.EventHub.BATCH_EVENTS, this.eventHandler);\n this.gridModels.push(gridModel);\n return true;\n }\n\n startingRowAligns(): RowAlign[] {\n const out = [] as RowAlign[];\n const visited = {} as any;\n for (const gm of this.gridModels) {\n for (const cell of gm.cellsInRow(gm.firstRow)) {\n if (cell.rowAlign && !visited[cell.rowAlign.uuid]) {\n visited[cell.rowAlign.uuid] = true;\n out.push(cell.rowAlign);\n }\n }\n }\n return out;\n }\n\n startingColAligns(): ColAlign[] {\n const out = [] as ColAlign[];\n const visited = {} as any;\n for (const gm of this.gridModels) {\n for (const cell of gm.cellsInCol(gm.firstCol)) {\n if (cell.colAlign && !visited[cell.colAlign.uuid]) {\n visited[cell.colAlign.uuid] = true;\n out.push(cell.colAlign);\n }\n }\n }\n return out;\n }\n\n removeGridModel(gridModel: GridModel): void {\n gridModel.eventHub?.removeOn(TSU.Events.EventHub.BATCH_EVENTS, this.eventHandler);\n }\n\n getCellView: (cell: GridCell) => GridCellView;\n\n get startingRows(): RowAlign[] {\n return this.startingRowAligns();\n }\n\n get startingCols(): ColAlign[] {\n return this.startingColAligns();\n }\n\n /**\n * Forces a full refresh.\n */\n refreshLayout() {\n const changedRowAligns = {} as any;\n const changedColAligns = {} as any;\n\n for (const rowAlign of this.startingRowAligns()) {\n if (!(rowAlign.uuid in changedRowAligns)) {\n changedRowAligns[rowAlign.uuid] = {\n align: rowAlign,\n cells: [],\n };\n }\n }\n\n for (const colAlign of this.startingColAligns()) {\n if (!(colAlign.uuid in changedColAligns)) {\n changedColAligns[colAlign.uuid] = {\n align: colAlign,\n cells: [],\n };\n }\n }\n\n this.doBfsLayout(this.startingRows, changedRowAligns);\n this.doBfsLayout(this.startingCols, changedColAligns);\n }\n\n /**\n * As the grid model changes (cell content changed, cleared etc) we need\n * to refresh our layout based on this.\n * As a first step the new height and width of all changed cells is\n * evaluted to see which rows and/or columns are affected (and need to be\n * resized/repositioned).\n */\n protected applyModelEvents(events: TSU.Events.TEvent[]) {\n const [changedRowAligns, changedColAligns] = this.changesForEvents(events);\n this.doBfsLayout(this.startingRows, changedRowAligns);\n this.doBfsLayout(this.startingCols, changedColAligns);\n }\n\n protected changesForEvents(events: TSU.Events.TEvent[]): [any, any] {\n // Step 1 - topologically sort RowAligns of changed cells\n // Step 2 - topologically sort ColAligns of changed cells\n // Step 3 -\n const cellVisited = {} as any;\n const changedRowAligns = {} as any;\n const changedColAligns = {} as any;\n // Going in reverse means we only get the latest event affecting a cell\n // instead of going through every change.\n // Later on we can revisit this if the events are edge triggered instead\n // of level triggered\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i];\n const loc = event.payload.loc;\n if (cellVisited[loc]) continue;\n cellVisited[loc] = true;\n const [row, col] = loc.split(\":\").map((x: string) => parseInt(x));\n const gridModel = event.source;\n const cell = gridModel.getRow(row).cellAt(col);\n if (cell) {\n // TODO - For now we are marking both row and col as having\n // changed for a cell. We can optimize this to only row or\n // col based on whether height or width has changed.\n if (!(cell.rowAlign.uuid in changedRowAligns)) {\n changedRowAligns[cell.rowAlign.uuid] = {\n align: cell.rowAlign,\n cells: [],\n };\n }\n changedRowAligns[cell.rowAlign.uuid][\"cells\"].push(cell);\n\n if (!(cell.colAlign.uuid in changedColAligns)) {\n changedColAligns[cell.colAlign.uuid] = {\n align: cell.colAlign,\n cells: [],\n };\n }\n changedColAligns[cell.colAlign.uuid][\"cells\"].push(cell);\n }\n }\n return [changedRowAligns, changedColAligns];\n }\n\n protected ensureGetCellView(align: AlignedLine) {\n if (!align.getCellView) {\n if (!this.getCellView) {\n return null;\n }\n align.getCellView = this.getCellView;\n }\n return align.getCellView;\n }\n\n // 1. start from the starting lines and do a BF traversal\n // 2. If a line not visited (ie laid out):\n // if it is in the changedAlign list then reval its length (w/h)\n // set its offset and length if either width or offset has changed\n // offset can be thought of changed if the preceding line's offset has changed\n // first do above for rows\n protected doBfsLayout<T extends AlignedLine>(startingLines: T[], changedAligns: any) {\n // Eval max lengths for all changed aligns\n if (!this.getCellView) return;\n for (const alignId in changedAligns) {\n const val = changedAligns[alignId];\n this.ensureGetCellView(val.align);\n val.align.evalMaxLength(val.cells);\n }\n let lineQueue = [] as [null | T, T][];\n const visitedLines = {} as any;\n for (const line of startingLines) lineQueue.push([null, line]);\n const lineOffsetChanged = {} as any;\n while (lineQueue.length > 0) {\n const nextQueue = [] as [null | T, T][];\n for (let i = 0; i < lineQueue.length; i++) {\n const [prevLineAlign, lineAlign] = lineQueue[i];\n visitedLines[lineAlign.uuid] = true;\n let newOffset = lineAlign.coordOffset;\n let lineChanged = lineAlign.uuid in changedAligns;\n if (prevLineAlign) {\n if (lineOffsetChanged[prevLineAlign.uuid]) {\n newOffset = prevLineAlign.coordOffset + prevLineAlign.maxLength;\n lineChanged = true;\n }\n }\n if (lineChanged) {\n this.ensureGetCellView(lineAlign);\n lineAlign.setOffset(newOffset);\n lineOffsetChanged[lineAlign.uuid] = true;\n }\n\n // Add next neighbors now\n for (const next of lineAlign.nextLines) {\n if (!visitedLines[next.uuid]) {\n nextQueue.push([lineAlign, next]);\n }\n }\n }\n lineQueue = nextQueue;\n }\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.Carnatic = exports.Utils = void 0;
|
|
30
40
|
__exportStar(require("./entity"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
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.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
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
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.DurationIterator = exports.WindowIterator = exports.AtomIterator = exports.FlatAtom = void 0;
|
|
27
37
|
const TSU = __importStar(require("@panyam/tsutils"));
|
package/lib/cjs/iterators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/iterators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,qCAAuC;AACvC,iCAAgE;AAKhE,MAAa,QAAS,SAAQ,oBAAW;IAQvC,YAAmB,IAAc,EAAE,SAAc,IAAI;QACnD,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QADd,SAAI,GAAJ,IAAI,CAAU;QAPxB,SAAI,GAAG,UAAU,CAAC;QASzB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,gBAAgB,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC;IACnF,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED,UAAU;QACR,MAAM,GAAG,mCACJ,KAAK,C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1B,OAAO,IAAI,CAAC;SACb;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;IACnC,CAAC;IASD,GAAG,CAAC,QAA0B;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC;QAC/B,MAAM,GAAG,GAAe,EAAE,CAAC;QAC3B,IAAI,SAAS,GAAG,QAAQ,CAAC;QACzB,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;YACnE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,IAAI,IAAI,IAAI,EAAE;gBAEhB,MAAM;aACP;iBAAM;gBACL,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACf,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;oBACrC,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;iBAC5C;qBAAM;oBAGL,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,IAAI,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;CACF;AA/CD,4CA+CC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { TimedEntity } from \"./entity\";\nimport { Atom, LeafAtom, Space, Group, AtomType } from \"./core\";\n\ntype Fraction = TSU.Num.Fraction;\n// type FlatAtom2 = [atom: Atom, duration: TSU.Num.Fraction, offset: TSU.Num.Fraction];\n\nexport class FlatAtom extends TimedEntity {\n readonly TYPE = \"FlatAtom\";\n\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 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"]}
|
|
1
|
+
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/iterators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,qCAAuC;AACvC,iCAAgE;AAKhE,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AE,CAAC;YAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;YACnE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;gBAEjB,MAAM;YACR,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACf,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;oBACtC,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC7C,CAAC;qBAAM,CAAC;oBAGN,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAC,IAAI,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;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACF;AA/CD,4CA+CC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { TimedEntity } from \"./entity\";\nimport { Atom, LeafAtom, Space, Group, AtomType } from \"./core\";\n\ntype Fraction = TSU.Num.Fraction;\n// type FlatAtom2 = [atom: Atom, duration: TSU.Num.Fraction, offset: TSU.Num.Fraction];\n\nexport class FlatAtom extends TimedEntity {\n readonly TYPE = \"FlatAtom\";\n\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 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.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
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
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.LayoutParams = void 0;
|
|
27
37
|
const TSU = __importStar(require("@panyam/tsutils"));
|
package/lib/cjs/layouts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layouts.js","sourceRoot":"","sources":["../../src/layouts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,mCAA4D;AAG5D,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AAEnC,MAAa,YAAY;IAavB,YAAY,MAAY;QAXf,SAAI,GAAG,YAAY,CAAC,OAAO,EAAE,CAAC;QAYrC,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC;QAC7C,IAAI,OAAO,IAAI,MAAM;YAAE,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QACjD,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE;YAC7C,IAAI,CAAC,KAAK,GAAG,aAAK,CAAC,OAAO,CAAC;SAC5B;QAED,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B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CAAC,CAAC;QAC9D,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;QAClG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACvC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/F,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACzD,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACnF,CAAC;;AAzMH,oCA0MC;AAzMgB,oBAAO,GAAG,CAAC,CAAC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Cycle, CyclePosition, CycleCursor } from \"./cycle\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\n\nexport class LayoutParams {\n private static counter = 0;\n readonly uuid = LayoutParams.counter++;\n beatDuration: number;\n cycle: Cycle;\n protected _lineBreaks: number[];\n private _rowStartOffsets: Fraction[];\n private _rowEndOffsets: Fraction[];\n private _rowDurations: Fraction[];\n private _totalLayoutDuration;\n private _beatLayouts: [CyclePosition, Fraction][][];\n private _totalBeats: number;\n\n constructor(config?: any) {\n config = config || {};\n this.beatDuration = config.beatDuration || 1;\n if (\"cycle\" in config) this.cycle = config.cycle;\n if (!this.cycle || this.cycle.duration.isZero) {\n this.cycle = Cycle.DEFAULT;\n }\n\n this._rowStartOffsets = [];\n this._rowEndOffsets = [];\n this._rowDurations = [];\n this._totalLayoutDuration = ZERO;\n this._totalBeats = 0;\n this._beatLayouts = [];\n this.lineBreaks = config.lineBreaks || config.layout || [];\n }\n\n equals(another: this): boolean {\n return (\n // super.equals(another) &&\n this.beatDuration == another.beatDuration &&\n this.cycle.equals(another.cycle) &&\n this.lineBreaksEqual(another._lineBreaks)\n );\n }\n\n lineBreaksEqual(another: number[]): boolean {\n return this._lineBreaks.length == another.length && this._lineBreaks.every((x, i) => x == another[i]);\n }\n\n debugValue(): any {\n return {\n // ...super.debugValue(),\n cycle: this.cycle?.debugValue(),\n beatDuration: this.beatDuration,\n lineBreaks: this._lineBreaks,\n };\n }\n\n /**\n * Returns the \"location\" of a beat within a layout.\n *\n * Lines are broken into beats of notes and those beats are aligned as per\n * the specs in the LayoutParams (breaks). For example if the breaks param\n * stipulates [5, 5, 4] then we have 5 beats in the first 2 lines and 4 in\n * the last line.\n *\n * If a line contains say 50 beats (B1 - B50), then it is laid out as:\n *\n * C0 C1 C2 C3 C4\n * ---------------------\n * L0 | B1 B2 B3 B4 B5\n * L1 | B6 B7 B8 B9 B10\n * L2 | B11 B12 B13 B14\n * L0 | B15 B16 B17 B18 B19\n * L1 | B20 B21 B22 B23 B24\n * L2 | B25 B26 B27 B28\n * L0 | B29 B30 B31 B32 B33\n * L1 | B34 B35 B36 B37 B38\n * L2 | B39 B40 B41 B42\n * L0 | B43 B44 B45 B46 B47\n * L1 | B48 B49 B50\n *\n * This methods returns the triple: [layoutLine, layoutColumn, rowOffset]\n * where\n *\n * layoutLine: The particular line in the layout break spec this index falls in.\n * *Note*: Since lines can start with negative offsets, we can\n * even return a layoutLine that is towards the end and then go\n * back to 0, eg 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 ...\n * (eg returns L0 or L1 ... Ln)\n * layoutColumn: The column within the layoutLine line where this beat falls.\n * (eg C0 - C4 above - or depending on how many columns exist\n * in the particular layout line).\n * rowOffset: The note offset of the beat from the start of the row/line\n * (not from the start of the cycle).\n *\n * Note the beatIndex can also be negative so we can return a beat\n * starting from before the cycle starting point.\n *\n * To calculate the \"real\" line globally simply do:\n *\n * realLine = lineBreaks.length * Math.floor(beatIndex / this.totalBeats) + layoutLine;\n *\n * Some examples here are (using B1-B50 above):\n */\n getBeatLocation(beat: {\n index: number;\n barIndex: number;\n beatIndex: number;\n instance: number;\n }): [number, number, Fraction] {\n const modIndex = beat.index % this.totalBeats;\n let total = 0;\n for (let i = 0; i < this._lineBreaks.length; i++) {\n if (modIndex < total + this._lineBreaks[i]) {\n // TODO: What is the right offset here?\n let offset = ZERO;\n if (modIndex > total) {\n const cursor = new CycleCursor(this.cycle, beat.barIndex, beat.beatIndex, beat.instance);\n let [, duration] = cursor.prev;\n for (let i = total; i < modIndex; i++) {\n [, duration] = cursor.prev;\n offset = offset.plus(duration.timesNum(this.beatDuration));\n }\n }\n return [i, modIndex - total, offset];\n }\n total += this._lineBreaks[i];\n }\n throw new Error(\"Invalid beat index: \" + beat.index);\n return [-1, -1, ZERO];\n }\n\n /**\n * Return the line layout - ie number of beats in each line - as a\n * repeating pattern.\n *\n * For example 4,2,4 indicates that the notes in our song should be\n * laid out 4 beats in line 1, 2 beats in line 2, 4 beats in line 3 and\n * 4 beats in line 4 and so on as long as there are more notes available\n * in this line.\n */\n get lineBreaks(): number[] {\n if (!this._lineBreaks || this._lineBreaks.length == 0) {\n // trigger a refresh\n this.lineBreaks = [this.cycle.beatCount];\n }\n return this._lineBreaks;\n }\n\n /**\n * Sets the line layout pattern.\n */\n set lineBreaks(val: number[]) {\n this._lineBreaks = val;\n this.refreshLayout();\n }\n\n /**\n * Returns the number of beats in each line based on the line layout\n * after taking beatDuration into account.\n */\n get beatLayouts(): ReadonlyArray<ReadonlyArray<[CyclePosition, Fraction]>> {\n if (!this._beatLayouts || this._beatLayouts.length < this.lineBreaks.length) {\n this.refreshLayout();\n }\n return this._beatLayouts;\n }\n\n /**\n * Total duration of all beats across all lines in our line layout.\n */\n get totalBeats(): number {\n this.beatLayouts;\n return this._totalBeats;\n }\n\n /**\n * Total duration of all beats across all lines in our line layout.\n */\n get totalLayoutDuration(): Fraction {\n this.beatLayouts;\n return this._totalLayoutDuration;\n }\n\n protected refreshLayout(): void {\n const cycleIter = this.cycle.iterateBeats();\n const akb = this.beatDuration;\n this._beatLayouts = this.lineBreaks.map((numBeats, index) => {\n const beats: [CyclePosition, Fraction][] = [];\n // see what the beat lengths are here\n for (let i = 0; i < numBeats; i++) {\n const nextCP = cycleIter.next().value;\n nextCP[1] = nextCP[1].timesNum(akb);\n beats.push(nextCP);\n }\n return beats;\n });\n this._totalBeats = this.lineBreaks.reduce((a, b) => a + b, 0);\n this._rowDurations = this._beatLayouts.map((beats) => beats.reduce((x, y) => x.plus(y[1]), ZERO));\n this._rowDurations.forEach((rd, index) => {\n this._rowStartOffsets[index] = index == 0 ? ZERO : this._rowStartOffsets[index - 1].plus(rd);\n });\n this._rowEndOffsets = this._rowDurations.map((rd, index) => {\n return this._rowStartOffsets[index].plus(rd);\n });\n this._totalLayoutDuration = this._rowDurations.reduce((x, y) => x.plus(y), ZERO);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"layouts.js","sourceRoot":"","sources":["../../src/layouts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,mCAA4D;AAG5D,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;AAEnC,MAAa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ACzD,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACnF,CAAC;;AAzMH,oCA0MC;AAzMgB,oBAAO,GAAG,CAAC,AAAJ,CAAK","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Cycle, CyclePosition, CycleCursor } from \"./cycle\";\n\ntype Fraction = TSU.Num.Fraction;\nconst ZERO = TSU.Num.Fraction.ZERO;\n\nexport class LayoutParams {\n private static counter = 0;\n readonly uuid = LayoutParams.counter++;\n beatDuration: number;\n cycle: Cycle;\n protected _lineBreaks: number[];\n private _rowStartOffsets: Fraction[];\n private _rowEndOffsets: Fraction[];\n private _rowDurations: Fraction[];\n private _totalLayoutDuration;\n private _beatLayouts: [CyclePosition, Fraction][][];\n private _totalBeats: number;\n\n constructor(config?: any) {\n config = config || {};\n this.beatDuration = config.beatDuration || 1;\n if (\"cycle\" in config) this.cycle = config.cycle;\n if (!this.cycle || this.cycle.duration.isZero) {\n this.cycle = Cycle.DEFAULT;\n }\n\n this._rowStartOffsets = [];\n this._rowEndOffsets = [];\n this._rowDurations = [];\n this._totalLayoutDuration = ZERO;\n this._totalBeats = 0;\n this._beatLayouts = [];\n this.lineBreaks = config.lineBreaks || config.layout || [];\n }\n\n equals(another: this): boolean {\n return (\n // super.equals(another) &&\n this.beatDuration == another.beatDuration &&\n this.cycle.equals(another.cycle) &&\n this.lineBreaksEqual(another._lineBreaks)\n );\n }\n\n lineBreaksEqual(another: number[]): boolean {\n return this._lineBreaks.length == another.length && this._lineBreaks.every((x, i) => x == another[i]);\n }\n\n debugValue(): any {\n return {\n // ...super.debugValue(),\n cycle: this.cycle?.debugValue(),\n beatDuration: this.beatDuration,\n lineBreaks: this._lineBreaks,\n };\n }\n\n /**\n * Returns the \"location\" of a beat within a layout.\n *\n * Lines are broken into beats of notes and those beats are aligned as per\n * the specs in the LayoutParams (breaks). For example if the breaks param\n * stipulates [5, 5, 4] then we have 5 beats in the first 2 lines and 4 in\n * the last line.\n *\n * If a line contains say 50 beats (B1 - B50), then it is laid out as:\n *\n * C0 C1 C2 C3 C4\n * ---------------------\n * L0 | B1 B2 B3 B4 B5\n * L1 | B6 B7 B8 B9 B10\n * L2 | B11 B12 B13 B14\n * L0 | B15 B16 B17 B18 B19\n * L1 | B20 B21 B22 B23 B24\n * L2 | B25 B26 B27 B28\n * L0 | B29 B30 B31 B32 B33\n * L1 | B34 B35 B36 B37 B38\n * L2 | B39 B40 B41 B42\n * L0 | B43 B44 B45 B46 B47\n * L1 | B48 B49 B50\n *\n * This methods returns the triple: [layoutLine, layoutColumn, rowOffset]\n * where\n *\n * layoutLine: The particular line in the layout break spec this index falls in.\n * *Note*: Since lines can start with negative offsets, we can\n * even return a layoutLine that is towards the end and then go\n * back to 0, eg 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 ...\n * (eg returns L0 or L1 ... Ln)\n * layoutColumn: The column within the layoutLine line where this beat falls.\n * (eg C0 - C4 above - or depending on how many columns exist\n * in the particular layout line).\n * rowOffset: The note offset of the beat from the start of the row/line\n * (not from the start of the cycle).\n *\n * Note the beatIndex can also be negative so we can return a beat\n * starting from before the cycle starting point.\n *\n * To calculate the \"real\" line globally simply do:\n *\n * realLine = lineBreaks.length * Math.floor(beatIndex / this.totalBeats) + layoutLine;\n *\n * Some examples here are (using B1-B50 above):\n */\n getBeatLocation(beat: {\n index: number;\n barIndex: number;\n beatIndex: number;\n instance: number;\n }): [number, number, Fraction] {\n const modIndex = beat.index % this.totalBeats;\n let total = 0;\n for (let i = 0; i < this._lineBreaks.length; i++) {\n if (modIndex < total + this._lineBreaks[i]) {\n // TODO: What is the right offset here?\n let offset = ZERO;\n if (modIndex > total) {\n const cursor = new CycleCursor(this.cycle, beat.barIndex, beat.beatIndex, beat.instance);\n let [, duration] = cursor.prev;\n for (let i = total; i < modIndex; i++) {\n [, duration] = cursor.prev;\n offset = offset.plus(duration.timesNum(this.beatDuration));\n }\n }\n return [i, modIndex - total, offset];\n }\n total += this._lineBreaks[i];\n }\n throw new Error(\"Invalid beat index: \" + beat.index);\n return [-1, -1, ZERO];\n }\n\n /**\n * Return the line layout - ie number of beats in each line - as a\n * repeating pattern.\n *\n * For example 4,2,4 indicates that the notes in our song should be\n * laid out 4 beats in line 1, 2 beats in line 2, 4 beats in line 3 and\n * 4 beats in line 4 and so on as long as there are more notes available\n * in this line.\n */\n get lineBreaks(): number[] {\n if (!this._lineBreaks || this._lineBreaks.length == 0) {\n // trigger a refresh\n this.lineBreaks = [this.cycle.beatCount];\n }\n return this._lineBreaks;\n }\n\n /**\n * Sets the line layout pattern.\n */\n set lineBreaks(val: number[]) {\n this._lineBreaks = val;\n this.refreshLayout();\n }\n\n /**\n * Returns the number of beats in each line based on the line layout\n * after taking beatDuration into account.\n */\n get beatLayouts(): ReadonlyArray<ReadonlyArray<[CyclePosition, Fraction]>> {\n if (!this._beatLayouts || this._beatLayouts.length < this.lineBreaks.length) {\n this.refreshLayout();\n }\n return this._beatLayouts;\n }\n\n /**\n * Total duration of all beats across all lines in our line layout.\n */\n get totalBeats(): number {\n this.beatLayouts;\n return this._totalBeats;\n }\n\n /**\n * Total duration of all beats across all lines in our line layout.\n */\n get totalLayoutDuration(): Fraction {\n this.beatLayouts;\n return this._totalLayoutDuration;\n }\n\n protected refreshLayout(): void {\n const cycleIter = this.cycle.iterateBeats();\n const akb = this.beatDuration;\n this._beatLayouts = this.lineBreaks.map((numBeats, index) => {\n const beats: [CyclePosition, Fraction][] = [];\n // see what the beat lengths are here\n for (let i = 0; i < numBeats; i++) {\n const nextCP = cycleIter.next().value;\n nextCP[1] = nextCP[1].timesNum(akb);\n beats.push(nextCP);\n }\n return beats;\n });\n this._totalBeats = this.lineBreaks.reduce((a, b) => a + b, 0);\n this._rowDurations = this._beatLayouts.map((beats) => beats.reduce((x, y) => x.plus(y[1]), ZERO));\n this._rowDurations.forEach((rd, index) => {\n this._rowStartOffsets[index] = index == 0 ? ZERO : this._rowStartOffsets[index - 1].plus(rd);\n });\n this._rowEndOffsets = this._rowDurations.map((rd, index) => {\n return this._rowStartOffsets[index].plus(rd);\n });\n this._totalLayoutDuration = this._rowDurations.reduce((x, y) => x.plus(y), ZERO);\n }\n}\n"]}
|