notations 0.0.43 → 0.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/lib/cjs/beats.d.ts +111 -0
- package/lib/cjs/beats.js +527 -0
- package/lib/cjs/beats.js.map +1 -0
- package/lib/cjs/carnatic/LineView.d.ts +20 -0
- package/lib/cjs/carnatic/LineView.js +73 -0
- package/lib/cjs/carnatic/LineView.js.map +1 -0
- package/lib/cjs/carnatic/NotationView.d.ts +31 -0
- package/lib/cjs/carnatic/NotationView.js +254 -0
- package/lib/cjs/carnatic/NotationView.js.map +1 -0
- package/lib/cjs/carnatic/atomviews.d.ts +14 -7
- package/lib/cjs/carnatic/atomviews.js +175 -138
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/beatviews.d.ts +10 -14
- package/lib/cjs/carnatic/beatviews.js +58 -109
- package/lib/cjs/carnatic/beatviews.js.map +1 -1
- package/lib/cjs/carnatic/embelishments.d.ts +38 -32
- package/lib/cjs/carnatic/embelishments.js +39 -20
- package/lib/cjs/carnatic/embelishments.js.map +1 -1
- package/lib/cjs/carnatic/index.d.ts +2 -0
- package/lib/cjs/carnatic/index.js +7 -1
- package/lib/cjs/carnatic/index.js.map +1 -1
- package/lib/cjs/commands.js +5 -1
- package/lib/cjs/commands.js.map +1 -1
- package/lib/cjs/core.d.ts +15 -73
- package/lib/cjs/core.js +201 -565
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/cycle.d.ts +47 -0
- package/lib/cjs/cycle.js +496 -0
- package/lib/cjs/cycle.js.map +1 -0
- package/lib/cjs/entity.d.ts +24 -0
- package/lib/cjs/entity.js +135 -0
- package/lib/cjs/entity.js.map +1 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.js +8 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/iterators.d.ts +14 -2
- package/lib/cjs/iterators.js +82 -6
- package/lib/cjs/iterators.js.map +1 -1
- package/lib/cjs/layouts.d.ts +7 -106
- package/lib/cjs/layouts.js +9 -479
- package/lib/cjs/layouts.js.map +1 -1
- package/lib/cjs/loader.d.ts +2 -1
- package/lib/cjs/loader.js +36 -27
- package/lib/cjs/loader.js.map +1 -1
- package/lib/cjs/notation.d.ts +3 -1
- package/lib/cjs/notation.js +6 -4
- package/lib/cjs/notation.js.map +1 -1
- package/lib/cjs/parser.js +10 -5
- package/lib/cjs/parser.js.map +1 -1
- package/lib/cjs/shapes.d.ts +35 -14
- package/lib/cjs/shapes.js +158 -44
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/cjs/utils.d.ts +2 -1
- package/lib/cjs/utils.js +9 -4
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/beats.d.ts +111 -0
- package/lib/esm/beats.js +501 -0
- package/lib/esm/beats.js.map +1 -0
- package/lib/esm/carnatic/LineView.d.ts +20 -0
- package/lib/esm/carnatic/LineView.js +47 -0
- package/lib/esm/carnatic/LineView.js.map +1 -0
- package/lib/esm/carnatic/NotationView.d.ts +31 -0
- package/lib/esm/carnatic/NotationView.js +228 -0
- package/lib/esm/carnatic/NotationView.js.map +1 -0
- package/lib/esm/carnatic/atomviews.d.ts +14 -7
- package/lib/esm/carnatic/atomviews.js +170 -137
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/beatviews.d.ts +10 -14
- package/lib/esm/carnatic/beatviews.js +54 -109
- package/lib/esm/carnatic/beatviews.js.map +1 -1
- package/lib/esm/carnatic/embelishments.d.ts +38 -32
- package/lib/esm/carnatic/embelishments.js +33 -18
- package/lib/esm/carnatic/embelishments.js.map +1 -1
- package/lib/esm/carnatic/index.d.ts +2 -0
- package/lib/esm/carnatic/index.js +2 -0
- package/lib/esm/carnatic/index.js.map +1 -1
- package/lib/esm/core.d.ts +15 -73
- package/lib/esm/core.js +192 -560
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/cycle.d.ts +47 -0
- package/lib/esm/cycle.js +470 -0
- package/lib/esm/cycle.js.map +1 -0
- package/lib/esm/entity.d.ts +24 -0
- package/lib/esm/entity.js +132 -0
- package/lib/esm/entity.js.map +1 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/iterators.d.ts +14 -2
- package/lib/esm/iterators.js +73 -1
- package/lib/esm/iterators.js.map +1 -1
- package/lib/esm/layouts.d.ts +7 -106
- package/lib/esm/layouts.js +1 -475
- package/lib/esm/layouts.js.map +1 -1
- package/lib/esm/loader.d.ts +2 -1
- package/lib/esm/loader.js +27 -23
- package/lib/esm/loader.js.map +1 -1
- package/lib/esm/notation.d.ts +3 -1
- package/lib/esm/notation.js +3 -1
- package/lib/esm/notation.js.map +1 -1
- package/lib/esm/parser.js +5 -4
- package/lib/esm/parser.js.map +1 -1
- package/lib/esm/shapes.d.ts +35 -14
- package/lib/esm/shapes.js +152 -42
- package/lib/esm/shapes.js.map +1 -1
- package/lib/esm/utils.d.ts +2 -1
- package/lib/esm/utils.js +3 -2
- package/lib/esm/utils.js.map +1 -1
- package/package.json +33 -28
- package/styles/NotationView.scss +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
# Notations
|
|
3
|
+
|
|
4
|
+
Notations is a Typescript library for rendering Carnatic music. Notations comes with:
|
|
5
|
+
|
|
6
|
+
1. An API for representing and rendering carnatic music.
|
|
7
|
+
2. A DSL and an accompanying parser for representing music in a simpler and intuitive way.
|
|
8
|
+
|
|
9
|
+
# Getting Started
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
# Install Typescript
|
|
15
|
+
npm i typescript
|
|
16
|
+
|
|
17
|
+
# Install the library (in a folder that already contains your package.json file).
|
|
18
|
+
npm install --save notations
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Example
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
import { NotationView } from notations;
|
|
26
|
+
|
|
27
|
+
const element = document.getElementById("mydiv");
|
|
28
|
+
const notationView = new NotationView(element);
|
|
29
|
+
notationView.add(new Note("Ga"), new Space(),
|
|
30
|
+
new Note("Ga"), new Space(),
|
|
31
|
+
new Note("Ri"), new Space(),
|
|
32
|
+
new Note("Ri"), new Space(),
|
|
33
|
+
new Note("Sa"), new Note("Sa"),
|
|
34
|
+
new Note("Ri"), new Note("Ri"),
|
|
35
|
+
new Note("Ga"), new Note("Ga"),
|
|
36
|
+
new Note("Ri"), new Note("Ri"));
|
|
37
|
+
```
|
|
38
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as TSU from "@panyam/tsutils";
|
|
2
|
+
import { Line, Atom, Role } from "./";
|
|
3
|
+
import { CycleIterator } from "./cycle";
|
|
4
|
+
import { FlatAtom, WindowIterator } from "./iterators";
|
|
5
|
+
import { LayoutParams } from "./layouts";
|
|
6
|
+
declare type Fraction = TSU.Num.Fraction;
|
|
7
|
+
interface BeatViewDelegate {
|
|
8
|
+
viewForBeat(beat: Beat): BeatView;
|
|
9
|
+
}
|
|
10
|
+
export interface BeatView {
|
|
11
|
+
readonly beat: Beat;
|
|
12
|
+
readonly needsLayout: boolean;
|
|
13
|
+
readonly minSize: TSU.Geom.Size;
|
|
14
|
+
readonly bbox: TSU.Geom.Rect;
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
refreshLayout(): void;
|
|
20
|
+
setStyles(config: any): void;
|
|
21
|
+
}
|
|
22
|
+
export declare class Beat {
|
|
23
|
+
readonly index: number;
|
|
24
|
+
readonly role: Role;
|
|
25
|
+
readonly offset: Fraction;
|
|
26
|
+
readonly duration: Fraction;
|
|
27
|
+
readonly barIndex: number;
|
|
28
|
+
readonly beatIndex: number;
|
|
29
|
+
readonly instance: number;
|
|
30
|
+
readonly prevBeat: null | Beat;
|
|
31
|
+
nextBeat: null | Beat;
|
|
32
|
+
private static idCounter;
|
|
33
|
+
layoutLine: number;
|
|
34
|
+
layoutColumn: number;
|
|
35
|
+
readonly uuid: number;
|
|
36
|
+
atom: Atom;
|
|
37
|
+
protected atomIsPlaceholder: boolean;
|
|
38
|
+
constructor(index: number, role: Role, offset: Fraction, duration: Fraction, barIndex: number, beatIndex: number, instance: number, prevBeat: null | Beat, nextBeat: null | Beat);
|
|
39
|
+
debugValue(): any;
|
|
40
|
+
get endOffset(): Fraction;
|
|
41
|
+
get filled(): boolean;
|
|
42
|
+
get remaining(): Fraction;
|
|
43
|
+
add(atom: Atom): boolean;
|
|
44
|
+
ensureUniformSpaces(atoms: FlatAtom[], slotsPerBeat?: number): void;
|
|
45
|
+
}
|
|
46
|
+
export declare class BeatLayout {
|
|
47
|
+
readonly layoutParams: LayoutParams;
|
|
48
|
+
bcolNextList: Map<string, Set<string>>;
|
|
49
|
+
beatColumns: Map<string, BeatColumn>;
|
|
50
|
+
startingColumns: BeatColumn[];
|
|
51
|
+
columnForBeat: Map<number, BeatColumn>;
|
|
52
|
+
constructor(layoutParams: LayoutParams);
|
|
53
|
+
getBeatColumn(offset: Fraction, duration: Fraction): BeatColumn;
|
|
54
|
+
protected static keyFor(offset: Fraction, duration: Fraction): string;
|
|
55
|
+
protected addSuccessor(prev: BeatColumn, next: BeatColumn): void;
|
|
56
|
+
addBeat(beat: Beat): BeatColumn;
|
|
57
|
+
neighborsOf(beatColumn: BeatColumn): BeatColumn[];
|
|
58
|
+
readonly DEBUG = false;
|
|
59
|
+
evalColumnSizes(beatViewDelegate: BeatViewDelegate): void;
|
|
60
|
+
roleSpacing: number;
|
|
61
|
+
rowSpacing: number;
|
|
62
|
+
layoutBeatsForLine(line: Line, allRoleBeats: Beat[][], beatViewDelegate: BeatViewDelegate): void;
|
|
63
|
+
}
|
|
64
|
+
export declare class BeatRow {
|
|
65
|
+
readonly layoutLine: number;
|
|
66
|
+
rowIndex: number;
|
|
67
|
+
protected _y: number;
|
|
68
|
+
protected _maxHeight: number;
|
|
69
|
+
needsLayout: boolean;
|
|
70
|
+
rowSpacing: number;
|
|
71
|
+
beats: Beat[];
|
|
72
|
+
constructor(layoutLine: number, rowIndex: number);
|
|
73
|
+
get y(): number;
|
|
74
|
+
set y(val: number);
|
|
75
|
+
add(beat: Beat): void;
|
|
76
|
+
}
|
|
77
|
+
export declare class BeatColumn {
|
|
78
|
+
readonly offset: Fraction;
|
|
79
|
+
readonly duration: Fraction;
|
|
80
|
+
protected _x: number;
|
|
81
|
+
protected _maxWidth: number;
|
|
82
|
+
needsLayout: boolean;
|
|
83
|
+
atomSpacing: number;
|
|
84
|
+
paddingLeft: number;
|
|
85
|
+
paddingRight: number;
|
|
86
|
+
beats: Beat[];
|
|
87
|
+
constructor(offset: Fraction, duration: Fraction);
|
|
88
|
+
get x(): number;
|
|
89
|
+
setX(val: number, beatViewDelegate: BeatViewDelegate): void;
|
|
90
|
+
get maxWidth(): number;
|
|
91
|
+
setPadding(left: number, right: number): void;
|
|
92
|
+
evalMaxWidth(beatViewDelegate: BeatViewDelegate): number;
|
|
93
|
+
add(beat: Beat): void;
|
|
94
|
+
}
|
|
95
|
+
export declare class BeatsBuilder {
|
|
96
|
+
readonly role: Role;
|
|
97
|
+
readonly layoutParams: LayoutParams;
|
|
98
|
+
readonly startOffset: Fraction;
|
|
99
|
+
readonly beats: Beat[];
|
|
100
|
+
readonly startIndex: number;
|
|
101
|
+
readonly beatOffset: Fraction;
|
|
102
|
+
cycleIter: CycleIterator;
|
|
103
|
+
windowIter: WindowIterator;
|
|
104
|
+
onAtomAdded: (atom: Atom, beat: Beat) => void;
|
|
105
|
+
onBeatAdded: (beat: Beat) => void;
|
|
106
|
+
onBeatFilled: (beat: Beat) => void;
|
|
107
|
+
constructor(role: Role, layoutParams: LayoutParams, startOffset?: Fraction);
|
|
108
|
+
protected addBeat(): Beat;
|
|
109
|
+
addAtoms(...atoms: Atom[]): void;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
package/lib/cjs/beats.js
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __values = (this && this.__values) || function(o) {
|
|
26
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
27
|
+
if (m) return m.call(o);
|
|
28
|
+
if (o && typeof o.length === "number") return {
|
|
29
|
+
next: function () {
|
|
30
|
+
if (o && i >= o.length) o = void 0;
|
|
31
|
+
return { value: o && o[i++], done: !o };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
35
|
+
};
|
|
36
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
37
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
38
|
+
if (!m) return o;
|
|
39
|
+
var i = m.call(o), r, ar = [], e;
|
|
40
|
+
try {
|
|
41
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
42
|
+
}
|
|
43
|
+
catch (error) { e = { error: error }; }
|
|
44
|
+
finally {
|
|
45
|
+
try {
|
|
46
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
47
|
+
}
|
|
48
|
+
finally { if (e) throw e.error; }
|
|
49
|
+
}
|
|
50
|
+
return ar;
|
|
51
|
+
};
|
|
52
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
53
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
54
|
+
if (ar || !(i in from)) {
|
|
55
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
56
|
+
ar[i] = from[i];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.BeatsBuilder = exports.BeatColumn = exports.BeatRow = exports.BeatLayout = exports.Beat = void 0;
|
|
63
|
+
var TSU = __importStar(require("@panyam/tsutils"));
|
|
64
|
+
var _1 = require("./");
|
|
65
|
+
var iterators_1 = require("./iterators");
|
|
66
|
+
var ZERO = TSU.Num.Fraction.ZERO;
|
|
67
|
+
var ONE = TSU.Num.Fraction.ONE;
|
|
68
|
+
var Beat = (function () {
|
|
69
|
+
function Beat(index, role, offset, duration, barIndex, beatIndex, instance, prevBeat, nextBeat) {
|
|
70
|
+
this.index = index;
|
|
71
|
+
this.role = role;
|
|
72
|
+
this.offset = offset;
|
|
73
|
+
this.duration = duration;
|
|
74
|
+
this.barIndex = barIndex;
|
|
75
|
+
this.beatIndex = beatIndex;
|
|
76
|
+
this.instance = instance;
|
|
77
|
+
this.prevBeat = prevBeat;
|
|
78
|
+
this.nextBeat = nextBeat;
|
|
79
|
+
this.layoutLine = -1;
|
|
80
|
+
this.layoutColumn = -1;
|
|
81
|
+
this.uuid = Beat.idCounter++;
|
|
82
|
+
this.atomIsPlaceholder = false;
|
|
83
|
+
}
|
|
84
|
+
Beat.prototype.debugValue = function () {
|
|
85
|
+
return {
|
|
86
|
+
index: this.index,
|
|
87
|
+
role: this.role.name,
|
|
88
|
+
offset: this.offset.toString(),
|
|
89
|
+
duration: this.duration.toString(),
|
|
90
|
+
barIndex: this.barIndex,
|
|
91
|
+
beatIndex: this.beatIndex,
|
|
92
|
+
instance: this.instance,
|
|
93
|
+
atom: this.atom.debugValue(),
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
Object.defineProperty(Beat.prototype, "endOffset", {
|
|
97
|
+
get: function () {
|
|
98
|
+
return this.offset.plus(this.duration);
|
|
99
|
+
},
|
|
100
|
+
enumerable: false,
|
|
101
|
+
configurable: true
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(Beat.prototype, "filled", {
|
|
104
|
+
get: function () {
|
|
105
|
+
return this.remaining.isZero;
|
|
106
|
+
},
|
|
107
|
+
enumerable: false,
|
|
108
|
+
configurable: true
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(Beat.prototype, "remaining", {
|
|
111
|
+
get: function () {
|
|
112
|
+
return this.atom ? this.duration.minus(this.atom.duration, true) : this.duration;
|
|
113
|
+
},
|
|
114
|
+
enumerable: false,
|
|
115
|
+
configurable: true
|
|
116
|
+
});
|
|
117
|
+
Beat.prototype.add = function (atom) {
|
|
118
|
+
if (this.remaining.cmp(atom.duration) < 0) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (!this.atom) {
|
|
122
|
+
this.atom = atom;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
if (!this.atomIsPlaceholder) {
|
|
126
|
+
this.atomIsPlaceholder = true;
|
|
127
|
+
this.atom = new _1.Group(this.atom).setDuration(ONE, true);
|
|
128
|
+
}
|
|
129
|
+
this.atom.addAtoms(true, atom);
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
};
|
|
133
|
+
Beat.prototype.ensureUniformSpaces = function (atoms, slotsPerBeat) {
|
|
134
|
+
if (slotsPerBeat === void 0) { slotsPerBeat = 1; }
|
|
135
|
+
var lcm = 1;
|
|
136
|
+
var gcd = 0;
|
|
137
|
+
atoms.forEach(function (a, index) {
|
|
138
|
+
a.duration = a.duration.factorized;
|
|
139
|
+
var currDen = a.duration.den;
|
|
140
|
+
if (currDen != 1) {
|
|
141
|
+
lcm *= currDen;
|
|
142
|
+
if (gcd == 0) {
|
|
143
|
+
gcd = a.duration.den;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
gcd = TSU.Num.gcdof(gcd, currDen);
|
|
147
|
+
lcm /= gcd;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
var baseDur = new TSU.Num.Fraction(1, lcm);
|
|
152
|
+
var currOffset = this.offset;
|
|
153
|
+
for (var i = 0; i < atoms.length;) {
|
|
154
|
+
var fa = atoms[i];
|
|
155
|
+
var numSpaces = lcm == 1 ? fa.duration.num - 1 : lcm / fa.duration.den - 1;
|
|
156
|
+
fa.duration = baseDur;
|
|
157
|
+
currOffset = currOffset.plus(baseDur);
|
|
158
|
+
i++;
|
|
159
|
+
for (var j = 0; j < numSpaces; j++, i++) {
|
|
160
|
+
var space = new _1.Space(baseDur);
|
|
161
|
+
space.isContinuation = true;
|
|
162
|
+
atoms.splice(i, 0, new iterators_1.FlatAtom(space));
|
|
163
|
+
atoms.splice(i, 0, new iterators_1.FlatAtom(space));
|
|
164
|
+
currOffset = currOffset.plus(baseDur);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
Beat.idCounter = 0;
|
|
169
|
+
return Beat;
|
|
170
|
+
}());
|
|
171
|
+
exports.Beat = Beat;
|
|
172
|
+
var BeatLayout = (function () {
|
|
173
|
+
function BeatLayout(layoutParams) {
|
|
174
|
+
this.layoutParams = layoutParams;
|
|
175
|
+
this.bcolNextList = new Map();
|
|
176
|
+
this.beatColumns = new Map();
|
|
177
|
+
this.startingColumns = [];
|
|
178
|
+
this.columnForBeat = new Map();
|
|
179
|
+
this.DEBUG = false;
|
|
180
|
+
this.roleSpacing = 10;
|
|
181
|
+
this.rowSpacing = 15;
|
|
182
|
+
}
|
|
183
|
+
BeatLayout.prototype.getBeatColumn = function (offset, duration) {
|
|
184
|
+
var e_1, _a;
|
|
185
|
+
var key = BeatLayout.keyFor(offset, duration);
|
|
186
|
+
var bcol = this.beatColumns.get(key) || null;
|
|
187
|
+
if (!bcol) {
|
|
188
|
+
bcol = new BeatColumn(offset, duration);
|
|
189
|
+
this.beatColumns.set(key, bcol);
|
|
190
|
+
if (bcol.offset.isZero) {
|
|
191
|
+
this.startingColumns.push(bcol);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
var endOffset = offset.plus(duration);
|
|
195
|
+
try {
|
|
196
|
+
for (var _b = __values(this.beatColumns.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
197
|
+
var other = _c.value;
|
|
198
|
+
if (other.offset.plus(other.duration).equals(offset)) {
|
|
199
|
+
this.addSuccessor(other, bcol);
|
|
200
|
+
}
|
|
201
|
+
else if (other.offset.equals(endOffset)) {
|
|
202
|
+
this.addSuccessor(bcol, other);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
207
|
+
finally {
|
|
208
|
+
try {
|
|
209
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
210
|
+
}
|
|
211
|
+
finally { if (e_1) throw e_1.error; }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return bcol;
|
|
216
|
+
};
|
|
217
|
+
BeatLayout.keyFor = function (offset, duration) {
|
|
218
|
+
return offset.factorized.toString() + ":" + duration.factorized.toString();
|
|
219
|
+
};
|
|
220
|
+
BeatLayout.prototype.addSuccessor = function (prev, next) {
|
|
221
|
+
TSU.assert(prev.offset.plus(prev.duration).equals(next.offset), "BeatColumns are not adjacent to each other");
|
|
222
|
+
var prevKey = BeatLayout.keyFor(prev.offset, prev.duration);
|
|
223
|
+
var nextKey = BeatLayout.keyFor(next.offset, next.duration);
|
|
224
|
+
var nextset = this.bcolNextList.get(prevKey) || null;
|
|
225
|
+
if (!nextset) {
|
|
226
|
+
nextset = new Set();
|
|
227
|
+
this.bcolNextList.set(prevKey, nextset);
|
|
228
|
+
}
|
|
229
|
+
nextset.add(nextKey);
|
|
230
|
+
};
|
|
231
|
+
BeatLayout.prototype.addBeat = function (beat) {
|
|
232
|
+
var lp = this.layoutParams;
|
|
233
|
+
var _a = __read(lp.getBeatLocation(beat), 3), layoutLine = _a[0], layoutColumn = _a[1], rowOffset = _a[2];
|
|
234
|
+
var bcol = this.getBeatColumn(rowOffset, beat.duration);
|
|
235
|
+
bcol.add(beat);
|
|
236
|
+
this.columnForBeat.set(beat.uuid, bcol);
|
|
237
|
+
beat.layoutLine = layoutLine;
|
|
238
|
+
beat.layoutColumn = layoutColumn;
|
|
239
|
+
return bcol;
|
|
240
|
+
};
|
|
241
|
+
BeatLayout.prototype.neighborsOf = function (beatColumn) {
|
|
242
|
+
var e_2, _a;
|
|
243
|
+
var out = [];
|
|
244
|
+
var endOffset = beatColumn.offset.plus(beatColumn.duration);
|
|
245
|
+
try {
|
|
246
|
+
for (var _b = __values(this.beatColumns.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
247
|
+
var other = _c.value;
|
|
248
|
+
if (endOffset.equals(other.offset)) {
|
|
249
|
+
out.push(other);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
254
|
+
finally {
|
|
255
|
+
try {
|
|
256
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
257
|
+
}
|
|
258
|
+
finally { if (e_2) throw e_2.error; }
|
|
259
|
+
}
|
|
260
|
+
return out;
|
|
261
|
+
};
|
|
262
|
+
BeatLayout.prototype.evalColumnSizes = function (beatViewDelegate) {
|
|
263
|
+
var e_3, _a, e_4, _b;
|
|
264
|
+
var queue = __spreadArray([], __read(this.startingColumns), false);
|
|
265
|
+
var xForOffsets = {};
|
|
266
|
+
while (queue.length > 0) {
|
|
267
|
+
var nextQueue = [];
|
|
268
|
+
try {
|
|
269
|
+
for (var queue_1 = (e_3 = void 0, __values(queue)), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
|
|
270
|
+
var bcol = queue_1_1.value;
|
|
271
|
+
var offset = bcol.offset.factorized;
|
|
272
|
+
var colWidth = bcol.evalMaxWidth(beatViewDelegate);
|
|
273
|
+
var currX = 0;
|
|
274
|
+
if (!bcol.offset.isZero) {
|
|
275
|
+
TSU.assert(offset.toString() in xForOffsets, "Cannot find x for given offset");
|
|
276
|
+
currX = xForOffsets[offset.toString()];
|
|
277
|
+
}
|
|
278
|
+
bcol.setX(currX, beatViewDelegate);
|
|
279
|
+
var endOffset = offset.plus(bcol.duration, true);
|
|
280
|
+
xForOffsets[endOffset.toString()] = Math.max(xForOffsets[endOffset.toString()] || 0, currX + colWidth + bcol.paddingLeft + bcol.paddingRight);
|
|
281
|
+
try {
|
|
282
|
+
for (var _c = (e_4 = void 0, __values(this.beatColumns.values())), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
283
|
+
var other = _d.value;
|
|
284
|
+
if (endOffset.equals(other.offset)) {
|
|
285
|
+
nextQueue.push(other);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
290
|
+
finally {
|
|
291
|
+
try {
|
|
292
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
293
|
+
}
|
|
294
|
+
finally { if (e_4) throw e_4.error; }
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
299
|
+
finally {
|
|
300
|
+
try {
|
|
301
|
+
if (queue_1_1 && !queue_1_1.done && (_a = queue_1.return)) _a.call(queue_1);
|
|
302
|
+
}
|
|
303
|
+
finally { if (e_3) throw e_3.error; }
|
|
304
|
+
}
|
|
305
|
+
queue = nextQueue;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
BeatLayout.prototype.layoutBeatsForLine = function (line, allRoleBeats, beatViewDelegate) {
|
|
309
|
+
var lp = this.layoutParams;
|
|
310
|
+
var currBeats = line.roles.map(function (l, index) { return allRoleBeats[index][0]; });
|
|
311
|
+
var currY = this.roleSpacing;
|
|
312
|
+
var numDone = 0;
|
|
313
|
+
do {
|
|
314
|
+
numDone = 0;
|
|
315
|
+
for (var currRole = 0; currRole < currBeats.length; currRole++) {
|
|
316
|
+
var currBeat = currBeats[currRole];
|
|
317
|
+
if (currBeat) {
|
|
318
|
+
var temp = currBeat;
|
|
319
|
+
var numBeatsInRow = lp.lineBreaks[currBeat.layoutLine];
|
|
320
|
+
var maxHeight = 0;
|
|
321
|
+
var currX = 15;
|
|
322
|
+
for (var i = currBeat.layoutColumn; i < numBeatsInRow && currBeat; i++, currBeat = currBeat.nextBeat, numDone++) {
|
|
323
|
+
var beatView = beatViewDelegate.viewForBeat(currBeat);
|
|
324
|
+
beatView.y = currY;
|
|
325
|
+
if (this.DEBUG) {
|
|
326
|
+
beatView.x = currX;
|
|
327
|
+
beatView.refreshLayout();
|
|
328
|
+
currX += beatView.width;
|
|
329
|
+
}
|
|
330
|
+
maxHeight = Math.max(maxHeight, beatView.minSize.height);
|
|
331
|
+
}
|
|
332
|
+
currBeat = temp;
|
|
333
|
+
for (var i = currBeat.layoutColumn; i < numBeatsInRow && currBeat; i++, currBeat = currBeat.nextBeat, numDone++) {
|
|
334
|
+
var beatView = beatViewDelegate.viewForBeat(currBeat);
|
|
335
|
+
beatView.height = maxHeight;
|
|
336
|
+
}
|
|
337
|
+
currY += maxHeight;
|
|
338
|
+
currY += this.roleSpacing;
|
|
339
|
+
}
|
|
340
|
+
currBeats[currRole] = currBeat;
|
|
341
|
+
}
|
|
342
|
+
currY += this.rowSpacing;
|
|
343
|
+
} while (numDone > 0);
|
|
344
|
+
};
|
|
345
|
+
return BeatLayout;
|
|
346
|
+
}());
|
|
347
|
+
exports.BeatLayout = BeatLayout;
|
|
348
|
+
var BeatRow = (function () {
|
|
349
|
+
function BeatRow(layoutLine, rowIndex) {
|
|
350
|
+
this.layoutLine = layoutLine;
|
|
351
|
+
this.rowIndex = rowIndex;
|
|
352
|
+
this._y = 0;
|
|
353
|
+
this._maxHeight = 0;
|
|
354
|
+
this.needsLayout = false;
|
|
355
|
+
this.rowSpacing = 5;
|
|
356
|
+
this.beats = [];
|
|
357
|
+
}
|
|
358
|
+
Object.defineProperty(BeatRow.prototype, "y", {
|
|
359
|
+
get: function () {
|
|
360
|
+
return this._y;
|
|
361
|
+
},
|
|
362
|
+
set: function (val) {
|
|
363
|
+
this._y = val;
|
|
364
|
+
this.needsLayout = true;
|
|
365
|
+
},
|
|
366
|
+
enumerable: false,
|
|
367
|
+
configurable: true
|
|
368
|
+
});
|
|
369
|
+
BeatRow.prototype.add = function (beat) {
|
|
370
|
+
this.beats.push(beat);
|
|
371
|
+
this.needsLayout = true;
|
|
372
|
+
};
|
|
373
|
+
return BeatRow;
|
|
374
|
+
}());
|
|
375
|
+
exports.BeatRow = BeatRow;
|
|
376
|
+
var BeatColumn = (function () {
|
|
377
|
+
function BeatColumn(offset, duration) {
|
|
378
|
+
this.offset = offset;
|
|
379
|
+
this.duration = duration;
|
|
380
|
+
this._x = 0;
|
|
381
|
+
this._maxWidth = 0;
|
|
382
|
+
this.needsLayout = false;
|
|
383
|
+
this.atomSpacing = 5;
|
|
384
|
+
this.paddingLeft = 15;
|
|
385
|
+
this.paddingRight = 15;
|
|
386
|
+
this.beats = [];
|
|
387
|
+
offset = offset.factorized;
|
|
388
|
+
duration = duration.factorized;
|
|
389
|
+
}
|
|
390
|
+
Object.defineProperty(BeatColumn.prototype, "x", {
|
|
391
|
+
get: function () {
|
|
392
|
+
return this._x;
|
|
393
|
+
},
|
|
394
|
+
enumerable: false,
|
|
395
|
+
configurable: true
|
|
396
|
+
});
|
|
397
|
+
BeatColumn.prototype.setX = function (val, beatViewDelegate) {
|
|
398
|
+
var e_5, _a;
|
|
399
|
+
this._x = val;
|
|
400
|
+
try {
|
|
401
|
+
for (var _b = __values(this.beats), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
402
|
+
var beat = _c.value;
|
|
403
|
+
var beatView = beatViewDelegate.viewForBeat(beat);
|
|
404
|
+
beatView.x = val + this.paddingLeft;
|
|
405
|
+
beatView.width = this._maxWidth;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
409
|
+
finally {
|
|
410
|
+
try {
|
|
411
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
412
|
+
}
|
|
413
|
+
finally { if (e_5) throw e_5.error; }
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
Object.defineProperty(BeatColumn.prototype, "maxWidth", {
|
|
417
|
+
get: function () {
|
|
418
|
+
return this._maxWidth + this.paddingLeft + this.paddingRight;
|
|
419
|
+
},
|
|
420
|
+
enumerable: false,
|
|
421
|
+
configurable: true
|
|
422
|
+
});
|
|
423
|
+
BeatColumn.prototype.setPadding = function (left, right) {
|
|
424
|
+
if (left >= 0) {
|
|
425
|
+
this.paddingLeft = left;
|
|
426
|
+
}
|
|
427
|
+
if (right >= 0) {
|
|
428
|
+
this.paddingRight = right;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
BeatColumn.prototype.evalMaxWidth = function (beatViewDelegate) {
|
|
432
|
+
var e_6, _a;
|
|
433
|
+
this._maxWidth = 0;
|
|
434
|
+
try {
|
|
435
|
+
for (var _b = __values(this.beats), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
436
|
+
var beat = _c.value;
|
|
437
|
+
var beatView = beatViewDelegate.viewForBeat(beat);
|
|
438
|
+
var minSize = beatView.minSize;
|
|
439
|
+
if (minSize.width > this._maxWidth) {
|
|
440
|
+
this._maxWidth = minSize.width;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
445
|
+
finally {
|
|
446
|
+
try {
|
|
447
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
448
|
+
}
|
|
449
|
+
finally { if (e_6) throw e_6.error; }
|
|
450
|
+
}
|
|
451
|
+
return this._maxWidth;
|
|
452
|
+
};
|
|
453
|
+
BeatColumn.prototype.add = function (beat) {
|
|
454
|
+
this.beats.push(beat);
|
|
455
|
+
this.needsLayout = true;
|
|
456
|
+
};
|
|
457
|
+
return BeatColumn;
|
|
458
|
+
}());
|
|
459
|
+
exports.BeatColumn = BeatColumn;
|
|
460
|
+
var BeatsBuilder = (function () {
|
|
461
|
+
function BeatsBuilder(role, layoutParams, startOffset) {
|
|
462
|
+
if (startOffset === void 0) { startOffset = ZERO; }
|
|
463
|
+
this.role = role;
|
|
464
|
+
this.layoutParams = layoutParams;
|
|
465
|
+
this.startOffset = startOffset;
|
|
466
|
+
this.beats = [];
|
|
467
|
+
var _a = __read(layoutParams.cycle.getPosition(startOffset), 4), _b = __read(_a[1], 3), bar = _b[0], beat = _b[1], instance = _b[2], beatOffset = _a[2], index = _a[3];
|
|
468
|
+
this.cycleIter = layoutParams.cycle.iterateBeats(bar, beat, instance);
|
|
469
|
+
this.windowIter = new iterators_1.WindowIterator();
|
|
470
|
+
this.beatOffset = beatOffset;
|
|
471
|
+
this.startIndex = index;
|
|
472
|
+
}
|
|
473
|
+
BeatsBuilder.prototype.addBeat = function () {
|
|
474
|
+
var numBeats = this.beats.length;
|
|
475
|
+
var lastBeat = numBeats == 0 ? null : this.beats[numBeats - 1];
|
|
476
|
+
var nextCP = this.cycleIter.next().value;
|
|
477
|
+
var apb = this.layoutParams.beatDuration;
|
|
478
|
+
var newBeat = new Beat(lastBeat == null ? this.startIndex : lastBeat.index + 1, this.role, lastBeat == null ? this.startOffset.minus(this.beatOffset).timesNum(apb, true) : lastBeat.endOffset, nextCP[1].timesNum(apb), nextCP[0][0], nextCP[0][1], nextCP[0][2], lastBeat, null);
|
|
479
|
+
if (lastBeat == null && this.beatOffset.isGT(ZERO)) {
|
|
480
|
+
newBeat.add(new _1.Space(this.beatOffset.timesNum(apb)));
|
|
481
|
+
}
|
|
482
|
+
if (lastBeat)
|
|
483
|
+
lastBeat.nextBeat = newBeat;
|
|
484
|
+
this.beats.push(newBeat);
|
|
485
|
+
if (this.onBeatAdded)
|
|
486
|
+
this.onBeatAdded(newBeat);
|
|
487
|
+
return newBeat;
|
|
488
|
+
};
|
|
489
|
+
BeatsBuilder.prototype.addAtoms = function () {
|
|
490
|
+
var _a, e_7, _b;
|
|
491
|
+
var atoms = [];
|
|
492
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
493
|
+
atoms[_i] = arguments[_i];
|
|
494
|
+
}
|
|
495
|
+
(_a = this.windowIter).push.apply(_a, __spreadArray([], __read(atoms), false));
|
|
496
|
+
while (this.windowIter.hasMore) {
|
|
497
|
+
var currBeat = this.beats[this.beats.length - 1];
|
|
498
|
+
if (this.beats.length == 0 || currBeat.filled) {
|
|
499
|
+
currBeat = this.addBeat();
|
|
500
|
+
}
|
|
501
|
+
var _c = __read(this.windowIter.get(currBeat.remaining), 2), remAtoms = _c[0], filled = _c[1];
|
|
502
|
+
TSU.assert(remAtoms.length > 0, "Atleast one element should have been available here");
|
|
503
|
+
try {
|
|
504
|
+
for (var remAtoms_1 = (e_7 = void 0, __values(remAtoms)), remAtoms_1_1 = remAtoms_1.next(); !remAtoms_1_1.done; remAtoms_1_1 = remAtoms_1.next()) {
|
|
505
|
+
var atom = remAtoms_1_1.value;
|
|
506
|
+
TSU.assert(currBeat.add(atom), "Should return true as we are already using a duration iterator here");
|
|
507
|
+
if (this.onAtomAdded)
|
|
508
|
+
this.onAtomAdded(atom, currBeat);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
512
|
+
finally {
|
|
513
|
+
try {
|
|
514
|
+
if (remAtoms_1_1 && !remAtoms_1_1.done && (_b = remAtoms_1.return)) _b.call(remAtoms_1);
|
|
515
|
+
}
|
|
516
|
+
finally { if (e_7) throw e_7.error; }
|
|
517
|
+
}
|
|
518
|
+
if (currBeat.filled) {
|
|
519
|
+
if (this.onBeatFilled)
|
|
520
|
+
this.onBeatFilled(currBeat);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
return BeatsBuilder;
|
|
525
|
+
}());
|
|
526
|
+
exports.BeatsBuilder = BeatsBuilder;
|
|
527
|
+
//# sourceMappingURL=beats.js.map
|