vibe-editor 0.0.1 → 0.0.2
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 +5 -0
- package/package.json +3 -3
- package/src/scripts/js/Core.js +14 -14
- package/src/scripts/js/VIBE.js +3 -1
- package/src/scripts/js/assets/mei_template.js +2 -2
- package/src/scripts/js/datastructures/ScoreGraph copy.js +432 -0
- package/src/scripts/js/datastructures/ScoreGraph.js +92 -47
- package/src/scripts/js/datastructures/ScoreGraph_deprecated.js +432 -0
- package/src/scripts/js/datastructures/ScoreNode.js +4 -0
- package/src/scripts/js/entry.js +2 -2
- package/src/scripts/js/gui/Annotations.js +4 -3
- package/src/scripts/js/gui/HarmonyLabel.js +1 -1
- package/src/scripts/js/gui/ScoreManipulator.js +7 -7
- package/src/scripts/js/gui/Tabbar.js +9 -8
- package/src/scripts/js/gui/TempoLabel.js +1 -1
- package/src/scripts/js/gui/Toolbar.js +1 -1
- package/src/scripts/js/handlers/AnnotationChangeHandler.js +3 -3
- package/src/scripts/js/handlers/ClickModeHandler.js +10 -3
- package/src/scripts/js/handlers/CustomAnnotationShapeDrawer.js +2 -2
- package/src/scripts/js/handlers/CustomToolbarHandler.js +4 -4
- package/src/scripts/js/handlers/InsertModeHandler.js +7 -4
- package/src/scripts/js/handlers/KeyModeHandler.js +40 -17
- package/src/scripts/js/handlers/LabelHandler.js +3 -2
- package/src/scripts/js/handlers/NoteDragHandler.js +1 -1
- package/src/scripts/js/handlers/ScoreManipulatorHandler.js +11 -0
- package/src/scripts/js/handlers/SideBarHandler.js +1 -1
- package/src/scripts/js/handlers/TooltipHandler.js +1 -1
- package/src/scripts/js/utils/MEIOperations.js +28 -25
- package/src/scripts/js/utils/Mouse2SVG.js +10 -8
- package/src/scripts/js/utils/ReactWrapper.js +1 -1
- package/src/scripts/js/utils/SVGEditor.js +15 -5
- package/src/scripts/js/utils/mappings.js +17 -14
@@ -11,50 +11,95 @@ class ScoreGraph {
|
|
11
11
|
this.container = document.getElementById(containerId);
|
12
12
|
this.vrvSVG = cq.getVrvSVG(containerId);
|
13
13
|
this.interactionOverlay = cq.getInteractOverlay(containerId);
|
14
|
-
this.populate(xmlDoc
|
14
|
+
this.populate(xmlDoc);
|
15
15
|
}
|
16
16
|
/**
|
17
|
-
*
|
18
|
-
*
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
var
|
24
|
-
|
25
|
-
|
17
|
+
* Populate scoreGraoh according to mei
|
18
|
+
* Determine left and right relations between elements (up and down won't be considered anymore since the keyboard interaction (arrowup/arrowdown) always should result in a transposition)
|
19
|
+
*/
|
20
|
+
populate(xmlDoc) {
|
21
|
+
this.graph = new Map();
|
22
|
+
//Collect all layers grouped by staff and layer index.
|
23
|
+
var groupedLayers = {};
|
24
|
+
xmlDoc.querySelectorAll("staff").forEach(s => s.querySelectorAll("layer").forEach(l => {
|
25
|
+
const sn = s.getAttribute("n");
|
26
|
+
const ln = l.getAttribute("n");
|
27
|
+
if (!groupedLayers[sn]) {
|
28
|
+
groupedLayers[sn] = {};
|
26
29
|
}
|
27
|
-
if (
|
28
|
-
|
29
|
-
return dn;
|
30
|
-
}
|
30
|
+
if (!groupedLayers[sn][ln]) {
|
31
|
+
groupedLayers[sn][ln] = new Array();
|
31
32
|
}
|
33
|
+
groupedLayers[sn][ln].push(l);
|
34
|
+
}));
|
35
|
+
//Collect Clef, meter and key to beginning of Graph
|
36
|
+
//Elements must be parsed from rendered svg
|
37
|
+
var groupedStaffDefs = {};
|
38
|
+
cq.getContainer(this.containerId).querySelectorAll("#vrvSVG .measure[n='1'] .staff").forEach(sd => {
|
39
|
+
const n = sd.getAttribute("n");
|
40
|
+
if (!groupedStaffDefs[n]) {
|
41
|
+
groupedStaffDefs[n] = new Array();
|
42
|
+
}
|
43
|
+
const clef = sd.querySelector(".clef");
|
44
|
+
if (clef)
|
45
|
+
groupedStaffDefs[n].push(clef);
|
46
|
+
const keySig = sd.querySelector(".keySig");
|
47
|
+
if (keySig)
|
48
|
+
groupedStaffDefs[n].push(keySig);
|
49
|
+
const meterSig = sd.querySelector(".meterSig");
|
50
|
+
if (meterSig)
|
51
|
+
groupedStaffDefs[n].push(meterSig);
|
32
52
|
});
|
33
|
-
|
34
|
-
var
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
//iterate through all layers to add and connect score nodes
|
54
|
+
var prevNode;
|
55
|
+
for (const sn in groupedLayers) {
|
56
|
+
for (const ln in groupedLayers[sn]) {
|
57
|
+
const staffDef = groupedStaffDefs[sn];
|
58
|
+
var lastStaffDefId;
|
59
|
+
if (staffDef) {
|
60
|
+
staffDef.forEach(sd => {
|
61
|
+
lastStaffDefId = sd.id;
|
62
|
+
this.graph.set(sd.id, new ScoreNode_1.default(sd.id));
|
63
|
+
const currentNode = this.graph.get(sd.id);
|
64
|
+
if (prevNode) {
|
65
|
+
prevNode.setRight(currentNode);
|
66
|
+
currentNode.setLeft(prevNode);
|
67
|
+
}
|
68
|
+
prevNode = currentNode;
|
69
|
+
});
|
70
|
+
}
|
71
|
+
prevNode = null;
|
72
|
+
const layer = groupedLayers[sn][ln];
|
73
|
+
layer.forEach((l, layerIdx) => {
|
74
|
+
l.querySelectorAll(":scope > note, rest, mRest, chord, keySig, clef, meterSig").forEach((el, elementIdx) => {
|
75
|
+
var _a;
|
76
|
+
this.graph.set(el.id, new ScoreNode_1.default(el.id));
|
77
|
+
const currentNode = this.graph.get(el.id);
|
78
|
+
if (prevNode) {
|
79
|
+
prevNode.setRight(currentNode);
|
80
|
+
currentNode.setLeft(prevNode);
|
81
|
+
}
|
82
|
+
else {
|
83
|
+
currentNode.setLeft(this.graph.get(lastStaffDefId));
|
84
|
+
if (layerIdx === 0 && elementIdx === 0) {
|
85
|
+
(_a = this.graph.get(lastStaffDefId)) === null || _a === void 0 ? void 0 : _a.setRight(currentNode);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
prevNode = currentNode;
|
89
|
+
});
|
90
|
+
});
|
48
91
|
}
|
49
92
|
}
|
93
|
+
console.log("ScoreGraph", this.graph);
|
50
94
|
}
|
51
95
|
/**
|
96
|
+
* @deprecated
|
52
97
|
* Populate scoreGraoh according to mei
|
53
98
|
* Add midi timeCode
|
54
99
|
* @param xmlDoc
|
55
100
|
* @param miditimes
|
56
101
|
*/
|
57
|
-
|
102
|
+
populate_old(xmlDoc, miditimes) {
|
58
103
|
var _a, _b, _c;
|
59
104
|
this.graph = new Map();
|
60
105
|
this.midiTimes = miditimes;
|
@@ -104,23 +149,23 @@ class ScoreGraph {
|
|
104
149
|
}
|
105
150
|
});
|
106
151
|
elements.push(...documentNodes);
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
152
|
+
elements.forEach((el, idx) => {
|
153
|
+
var currentNode = this.graph.get(el.id);
|
154
|
+
var prevSibling = idx === 0 ? null : this.graph.get(elements[idx - 1].id);
|
155
|
+
var nextSibling = idx === elements.length - 1 ? null : this.graph.get(elements[idx + 1].id);
|
156
|
+
if (idx > 0) {
|
157
|
+
currentNode.setLeft(prevSibling);
|
158
|
+
}
|
159
|
+
else { // empty Node at beginning of Layer
|
160
|
+
this.graph.set("BOL" + i.toString(), new ScoreNode_1.default("BOL" + i.toString()));
|
161
|
+
this.graph.get("BOL" + i.toString()).setLeft(null);
|
162
|
+
this.graph.get("BOL" + i.toString()).setUp(null);
|
163
|
+
this.graph.get("BOL" + i.toString()).setDown(null);
|
164
|
+
this.graph.get("BOL" + i.toString()).setRight(currentNode);
|
165
|
+
currentNode.setLeft(this.graph.get("BOL" + i.toString()));
|
166
|
+
}
|
167
|
+
currentNode.setRight(nextSibling);
|
168
|
+
});
|
124
169
|
});
|
125
170
|
}
|
126
171
|
}
|
@@ -0,0 +1,432 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const ScoreNode_1 = require("./ScoreNode");
|
4
|
+
const cq = require("../utils/convenienceQueries");
|
5
|
+
const meiNodeSelector = "note, rest, mRest, chord, layer";
|
6
|
+
const documentNodeSelector = ".clef, .meterSig, .keySig, .note, .rest, .mRest, .chord"; //, .layer"
|
7
|
+
const documentNodeSelector2 = ".clef, .meterSig, .keySig, .layer .note, .layer .rest, .layer .mRest, .layer .chord"; //, :scope > .layer"
|
8
|
+
class ScoreGraph {
|
9
|
+
constructor(xmlDoc, containerId, miditimes) {
|
10
|
+
this.containerId = containerId;
|
11
|
+
this.container = document.getElementById(containerId);
|
12
|
+
this.vrvSVG = cq.getVrvSVG(containerId);
|
13
|
+
this.interactionOverlay = cq.getInteractOverlay(containerId);
|
14
|
+
this.populate(xmlDoc, miditimes);
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* @deprecated
|
18
|
+
* Use function populate instead
|
19
|
+
* @param xmlDoc
|
20
|
+
*/
|
21
|
+
altPop(xmlDoc) {
|
22
|
+
var documentNodes = Array.from(cq.getVrvSVG(this.containerId).querySelectorAll(documentNodeSelector));
|
23
|
+
var documentNodes = documentNodes.filter(dn => {
|
24
|
+
if (!dn.classList.contains("note")) {
|
25
|
+
return dn;
|
26
|
+
}
|
27
|
+
if (dn.classList.contains("note")) {
|
28
|
+
if (dn.closest(".chord") === null) {
|
29
|
+
return dn;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
});
|
33
|
+
var nodeCoodrs = new Map();
|
34
|
+
var root = cq.getVrvSVG(this.containerId);
|
35
|
+
var rootBBox = root.getBoundingClientRect();
|
36
|
+
documentNodes.forEach(dn => {
|
37
|
+
var dnx = dn.getBoundingClientRect().x - rootBBox.x - root.scrollLeft - window.pageXOffset;
|
38
|
+
var dny = dn.getBoundingClientRect().y - rootBBox.y - root.scrollTop - window.pageYOffset;
|
39
|
+
nodeCoodrs.set(dn, { x: dnx, y: dny });
|
40
|
+
});
|
41
|
+
for (const [key, value] of nodeCoodrs.entries()) {
|
42
|
+
var closestLeft;
|
43
|
+
var closestRight;
|
44
|
+
var closestTop;
|
45
|
+
var closestDown;
|
46
|
+
for (const [key, value] of nodeCoodrs.entries()) {
|
47
|
+
//TODO
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
* Populate scoreGraoh according to mei
|
53
|
+
* Add midi timeCode
|
54
|
+
* @param xmlDoc
|
55
|
+
* @param miditimes
|
56
|
+
*/
|
57
|
+
populate(xmlDoc, miditimes) {
|
58
|
+
var _a, _b, _c;
|
59
|
+
this.graph = new Map();
|
60
|
+
this.midiTimes = miditimes;
|
61
|
+
xmlDoc.querySelectorAll(meiNodeSelector).forEach(e => {
|
62
|
+
if ((e.tagName === "note" && e.closest("chord") !== null)) { // || (e.tagName === "layer" && e.children.length > 0)){
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
this.graph.set(e.id, new ScoreNode_1.default(e.id));
|
66
|
+
});
|
67
|
+
cq.getVrvSVG(this.containerId).querySelectorAll(documentNodeSelector).forEach(e => {
|
68
|
+
if ((e.classList.contains("note") && e.closest(".chord") !== null)) {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
this.graph.set(e.id, new ScoreNode_1.default(e.id));
|
72
|
+
});
|
73
|
+
var layerCount = 0;
|
74
|
+
xmlDoc.querySelectorAll("layer").forEach(l => {
|
75
|
+
if (parseInt(l.getAttribute("n")) > layerCount) {
|
76
|
+
layerCount = parseInt(l.getAttribute("n"));
|
77
|
+
}
|
78
|
+
});
|
79
|
+
var staffCount = 0;
|
80
|
+
xmlDoc.querySelectorAll("staff").forEach(l => {
|
81
|
+
if (parseInt(l.getAttribute("n")) > staffCount) {
|
82
|
+
staffCount = parseInt(l.getAttribute("n"));
|
83
|
+
}
|
84
|
+
});
|
85
|
+
// Assign left/right nodes
|
86
|
+
var layerArray;
|
87
|
+
for (var s = 0; s < staffCount; s++) {
|
88
|
+
for (var i = 0; i < layerCount; i++) {
|
89
|
+
layerArray = Array.from(xmlDoc.querySelectorAll("staff[n=\"" + (s + 1).toString() + "\"] > layer[n=\"" + (i + 1).toString() + "\"]"));
|
90
|
+
var elements = new Array();
|
91
|
+
layerArray.forEach(l => {
|
92
|
+
if (cq.getVrvSVG(this.containerId).querySelector("#" + l.id) === null)
|
93
|
+
return;
|
94
|
+
let staff = cq.getVrvSVG(this.containerId).querySelector("#" + l.id).closest(".measure").querySelector(".staff[n='" + l.closest("staff").getAttribute("n") + "']");
|
95
|
+
var documentNodes = Array.from(staff.querySelectorAll(documentNodeSelector2));
|
96
|
+
var documentNodes = documentNodes.filter(dn => {
|
97
|
+
if (!dn.classList.contains("note")) {
|
98
|
+
return dn;
|
99
|
+
}
|
100
|
+
if (dn.classList.contains("note")) {
|
101
|
+
if (dn.closest(".chord") === null) {
|
102
|
+
return dn;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
});
|
106
|
+
elements.push(...documentNodes);
|
107
|
+
elements.forEach((el, idx) => {
|
108
|
+
var currentNode = this.graph.get(el.id);
|
109
|
+
var prevSibling = idx === 0 ? null : this.graph.get(elements[idx - 1].id);
|
110
|
+
var nextSibling = idx === elements.length - 1 ? null : this.graph.get(elements[idx + 1].id);
|
111
|
+
if (idx > 0) {
|
112
|
+
currentNode.setLeft(prevSibling);
|
113
|
+
}
|
114
|
+
else { // empty Node at beginning of Layer
|
115
|
+
this.graph.set("BOL" + i.toString(), new ScoreNode_1.default("BOL" + i.toString()));
|
116
|
+
this.graph.get("BOL" + i.toString()).setLeft(null);
|
117
|
+
this.graph.get("BOL" + i.toString()).setUp(null);
|
118
|
+
this.graph.get("BOL" + i.toString()).setDown(null);
|
119
|
+
this.graph.get("BOL" + i.toString()).setRight(currentNode);
|
120
|
+
currentNode.setLeft(this.graph.get("BOL" + i.toString()));
|
121
|
+
}
|
122
|
+
currentNode.setRight(nextSibling);
|
123
|
+
});
|
124
|
+
});
|
125
|
+
}
|
126
|
+
}
|
127
|
+
//Assign up/down nodes
|
128
|
+
if (this.midiTimes) {
|
129
|
+
// miditimes contain svg Elements (not mei Elements!!!)
|
130
|
+
// first: direct up/down references
|
131
|
+
for (const [key, value] of this.midiTimes.entries()) {
|
132
|
+
var originArr = value;
|
133
|
+
var arr = new Array();
|
134
|
+
originArr.forEach(el => {
|
135
|
+
var chord = el.closest(".chord");
|
136
|
+
if (chord !== null && arr.indexOf(chord) === -1) {
|
137
|
+
arr.push(chord);
|
138
|
+
}
|
139
|
+
else if (chord === null) {
|
140
|
+
arr.push(el);
|
141
|
+
}
|
142
|
+
});
|
143
|
+
arr.forEach((note, idx) => {
|
144
|
+
var current = note;
|
145
|
+
var upSibling = idx === 0 ? null : this.graph.get(arr[idx - 1].id);
|
146
|
+
var downSibling = idx === arr.length - 1 ? null : this.graph.get(arr[idx + 1].id);
|
147
|
+
var currentNode = this.graph.get(current.id);
|
148
|
+
if (typeof currentNode.getTimeCode() === "undefined") {
|
149
|
+
currentNode.setTimeCode(key);
|
150
|
+
}
|
151
|
+
currentNode.setUp(upSibling);
|
152
|
+
currentNode.setDown(downSibling);
|
153
|
+
});
|
154
|
+
}
|
155
|
+
}
|
156
|
+
//DEAL WITH MRESTS
|
157
|
+
var staves = cq.getVrvSVG(this.containerId).querySelectorAll(".staff");
|
158
|
+
for (var i = 0; i < staves.length - 1; i++) {
|
159
|
+
var staffElements = staves[i].querySelectorAll(documentNodeSelector);
|
160
|
+
var emptyElements = staves[i + 1].querySelectorAll(".clef, .meterSig, .keySig, .mRest, .layer");
|
161
|
+
staffElements.forEach((se, idx) => {
|
162
|
+
var gn = this.graph.get(se.id);
|
163
|
+
if ((gn === null || gn === void 0 ? void 0 : gn.getDown()) === null || (gn === null || gn === void 0 ? void 0 : gn.getDown()) == undefined) {
|
164
|
+
var tempIdx = idx;
|
165
|
+
if (idx >= emptyElements.length) {
|
166
|
+
tempIdx = emptyElements.length - 1;
|
167
|
+
}
|
168
|
+
var gnEmpty = this.graph.get(emptyElements[tempIdx].id);
|
169
|
+
if ((gnEmpty === null || gnEmpty === void 0 ? void 0 : gnEmpty.getUp()) === null || (gnEmpty === null || gnEmpty === void 0 ? void 0 : gnEmpty.getUp()) == undefined) {
|
170
|
+
gn === null || gn === void 0 ? void 0 : gn.setDown(gnEmpty);
|
171
|
+
gnEmpty === null || gnEmpty === void 0 ? void 0 : gnEmpty.setUp(gn);
|
172
|
+
}
|
173
|
+
}
|
174
|
+
});
|
175
|
+
}
|
176
|
+
//extra iteration for Beginning of Layer
|
177
|
+
var currBol = null;
|
178
|
+
var prevBol = null;
|
179
|
+
for (const [key, value] of this.graph.entries()) {
|
180
|
+
if (key.indexOf("BOL") !== -1) {
|
181
|
+
currBol = value;
|
182
|
+
var bolIdx = key[key.length - 1];
|
183
|
+
if (bolIdx !== "0") {
|
184
|
+
currBol.setUp(prevBol);
|
185
|
+
if (prevBol !== null) {
|
186
|
+
prevBol.setDown(currBol);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
prevBol = value;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
//if there are no direct up/down references, assign closest references
|
193
|
+
for (const [key, value] of this.graph.entries()) {
|
194
|
+
var currentNode = value;
|
195
|
+
var leftNode = currentNode.getLeft();
|
196
|
+
var rightNode = currentNode.getRight();
|
197
|
+
if (currentNode.getUp() == undefined) {
|
198
|
+
currentNode.setUp(null);
|
199
|
+
}
|
200
|
+
if (currentNode.getDown() == undefined) {
|
201
|
+
currentNode.setDown(null);
|
202
|
+
}
|
203
|
+
// Get closest Node for UP reference
|
204
|
+
//check left
|
205
|
+
var closestTimeUp = 10 ** 10;
|
206
|
+
var upSet = null;
|
207
|
+
if (this.targetNodeIsLeftOrRight(currentNode, currentNode.getUp()) && leftNode !== null) {
|
208
|
+
if (leftNode.getUp() !== null && typeof leftNode.getDown() !== "undefined") {
|
209
|
+
closestTimeUp = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.getTimeCode()) - ((_a = leftNode === null || leftNode === void 0 ? void 0 : leftNode.getUp()) === null || _a === void 0 ? void 0 : _a.getTimeCode()) || 0;
|
210
|
+
upSet = leftNode === null || leftNode === void 0 ? void 0 : leftNode.getUp();
|
211
|
+
}
|
212
|
+
}
|
213
|
+
//check right
|
214
|
+
if (this.targetNodeIsLeftOrRight(currentNode, currentNode.getUp()) && rightNode !== null) {
|
215
|
+
if (rightNode.getUp() !== null && typeof rightNode.getDown() !== "undefined") {
|
216
|
+
if ((((_b = rightNode.getUp()) === null || _b === void 0 ? void 0 : _b.getTimeCode()) - (currentNode === null || currentNode === void 0 ? void 0 : currentNode.getTimeCode())) < closestTimeUp) {
|
217
|
+
upSet = rightNode === null || rightNode === void 0 ? void 0 : rightNode.getUp();
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
if (upSet !== null && upSet !== currentNode && !this.targetNodeIsLeftOrRight(currentNode, upSet)) {
|
222
|
+
currentNode.setUp(upSet);
|
223
|
+
}
|
224
|
+
// Get closest Node for DOWN reference
|
225
|
+
// check left
|
226
|
+
var closestTimeDown = 10 ** 10;
|
227
|
+
var downSet = null;
|
228
|
+
if (this.targetNodeIsLeftOrRight(currentNode, currentNode.getDown()) && leftNode !== null) {
|
229
|
+
if (leftNode.getDown() !== null && typeof leftNode.getDown() !== "undefined") {
|
230
|
+
closestTimeDown = (currentNode === null || currentNode === void 0 ? void 0 : currentNode.getTimeCode()) - ((_c = leftNode === null || leftNode === void 0 ? void 0 : leftNode.getDown()) === null || _c === void 0 ? void 0 : _c.getTimeCode()) || 0;
|
231
|
+
downSet = leftNode.getDown();
|
232
|
+
}
|
233
|
+
}
|
234
|
+
// check right
|
235
|
+
if (this.targetNodeIsLeftOrRight(currentNode, currentNode.getDown()) && rightNode !== null) {
|
236
|
+
if (rightNode.getDown() !== null && rightNode.getDown() != undefined) {
|
237
|
+
if ((rightNode.getDown().getTimeCode() - currentNode.getTimeCode()) < closestTimeDown) {
|
238
|
+
downSet = rightNode.getDown();
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}
|
242
|
+
if (downSet !== null && downSet !== currentNode && !this.targetNodeIsLeftOrRight(currentNode, downSet)) {
|
243
|
+
currentNode.setDown(downSet);
|
244
|
+
}
|
245
|
+
}
|
246
|
+
}
|
247
|
+
targetNodeIsLeftOrRight(startNode, targetNode) {
|
248
|
+
return this.targetIsNodeRight(startNode, targetNode) || this.targetIsNodeLeft(startNode, targetNode);
|
249
|
+
}
|
250
|
+
targetIsNodeLeft(startNode, targetNode) {
|
251
|
+
var tempNode = startNode;
|
252
|
+
var isLeft = false;
|
253
|
+
while (tempNode !== null) {
|
254
|
+
if (tempNode !== null) {
|
255
|
+
if (tempNode == undefined) {
|
256
|
+
return isLeft;
|
257
|
+
}
|
258
|
+
tempNode = tempNode.getLeft();
|
259
|
+
}
|
260
|
+
if (tempNode === targetNode) {
|
261
|
+
isLeft = true;
|
262
|
+
}
|
263
|
+
}
|
264
|
+
return isLeft;
|
265
|
+
}
|
266
|
+
targetIsNodeRight(startNode, targetNode) {
|
267
|
+
var tempNode = startNode;
|
268
|
+
var isRight = false;
|
269
|
+
while (tempNode !== null) {
|
270
|
+
if (tempNode !== null) {
|
271
|
+
if (tempNode == undefined) {
|
272
|
+
return isRight;
|
273
|
+
}
|
274
|
+
tempNode = tempNode.getRight();
|
275
|
+
}
|
276
|
+
if (tempNode === targetNode) {
|
277
|
+
isRight = true;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
return isRight;
|
281
|
+
}
|
282
|
+
getCurrentNode() {
|
283
|
+
return this.currentNode;
|
284
|
+
}
|
285
|
+
setCurrentNodeById(id) {
|
286
|
+
var _a, _b;
|
287
|
+
if (id == undefined)
|
288
|
+
return;
|
289
|
+
var lastNode = this.currentNode;
|
290
|
+
this.currentNode = this.graph.get(id) || this.graph.get((_b = (_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.closest(".chord")) === null || _b === void 0 ? void 0 : _b.id) || lastNode;
|
291
|
+
if (this.currentNode == undefined) {
|
292
|
+
console.log(lastNode);
|
293
|
+
throw new Error("CurrentNode undefined although id is given: " + id);
|
294
|
+
}
|
295
|
+
}
|
296
|
+
setContainerId(containerId) {
|
297
|
+
this.containerId = containerId;
|
298
|
+
}
|
299
|
+
nextUp() {
|
300
|
+
var _a;
|
301
|
+
if (this.currentNode != undefined && ((_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getUp()) !== null) {
|
302
|
+
this.currentNode = this.currentNode.getUp();
|
303
|
+
}
|
304
|
+
return this.currentNode;
|
305
|
+
}
|
306
|
+
nextDown() {
|
307
|
+
var _a;
|
308
|
+
if (this.currentNode != undefined && ((_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getDown()) !== null) {
|
309
|
+
this.currentNode = this.currentNode.getDown();
|
310
|
+
}
|
311
|
+
return this.currentNode;
|
312
|
+
}
|
313
|
+
nextRight() {
|
314
|
+
var _a;
|
315
|
+
if (this.currentNode != undefined && ((_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getRight()) !== null) {
|
316
|
+
this.currentNode = this.currentNode.getRight();
|
317
|
+
}
|
318
|
+
return this.currentNode;
|
319
|
+
}
|
320
|
+
nextLeft() {
|
321
|
+
var _a;
|
322
|
+
if (this.currentNode != undefined && ((_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getLeft()) !== null) {
|
323
|
+
this.currentNode = this.currentNode.getLeft();
|
324
|
+
}
|
325
|
+
return this.currentNode;
|
326
|
+
}
|
327
|
+
nextMeasureRight() {
|
328
|
+
while (this.getCurrentNode().getRight().getDocElement().closest(".measure").id ===
|
329
|
+
this.getCurrentNode().getDocElement().closest(".measure").id) {
|
330
|
+
this.nextRight();
|
331
|
+
}
|
332
|
+
return this.currentNode;
|
333
|
+
}
|
334
|
+
nextMeasureLeft() {
|
335
|
+
while (this.getCurrentNode().getLeft().getDocElement().closest(".measure").id ===
|
336
|
+
this.getCurrentNode().getDocElement().closest(".measure").id) {
|
337
|
+
this.nextLeft();
|
338
|
+
}
|
339
|
+
return this.currentNode;
|
340
|
+
}
|
341
|
+
/**
|
342
|
+
* Go to next Element with given classname.
|
343
|
+
* Whatever comes first according to the classNames array.
|
344
|
+
* @param classNames
|
345
|
+
* @param direction
|
346
|
+
* @returns
|
347
|
+
*/
|
348
|
+
getNextClass(classNames, direction) {
|
349
|
+
var _a;
|
350
|
+
if (typeof classNames === "string")
|
351
|
+
classNames = [classNames];
|
352
|
+
var currentId = (_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getId();
|
353
|
+
if ([null, undefined].some(id => id == currentId))
|
354
|
+
return;
|
355
|
+
var nextIsNull = false;
|
356
|
+
do {
|
357
|
+
switch (direction) {
|
358
|
+
case "ArrowLeft":
|
359
|
+
case "left":
|
360
|
+
this.nextLeft();
|
361
|
+
break;
|
362
|
+
case "ArrowRight":
|
363
|
+
case "right":
|
364
|
+
this.nextRight();
|
365
|
+
break;
|
366
|
+
case "ArrowUp":
|
367
|
+
case "up":
|
368
|
+
this.nextUp();
|
369
|
+
break;
|
370
|
+
case "ArrowDown":
|
371
|
+
case "down":
|
372
|
+
this.nextDown();
|
373
|
+
break;
|
374
|
+
default:
|
375
|
+
console.error(direction + " is not allowed. Use left, right, up or down");
|
376
|
+
return;
|
377
|
+
}
|
378
|
+
nextIsNull = [null, undefined].some(n => this.currentNode == n);
|
379
|
+
} while (!classNames.some(cn => { var _a, _b; return (_b = (_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getDocElement()) === null || _b === void 0 ? void 0 : _b.classList.contains(cn); }) && !nextIsNull);
|
380
|
+
if (nextIsNull) {
|
381
|
+
this.setCurrentNodeById(currentId);
|
382
|
+
}
|
383
|
+
return this.currentNode;
|
384
|
+
}
|
385
|
+
/**
|
386
|
+
* Find node based on class Names. Will not change state and pointers of the graph.
|
387
|
+
* To change this.currentNode, use getNextClass instead.
|
388
|
+
* @param classNames
|
389
|
+
* @param direction
|
390
|
+
* @returns
|
391
|
+
*/
|
392
|
+
lookUp(classNames, direction) {
|
393
|
+
var _a;
|
394
|
+
if (typeof classNames === "string")
|
395
|
+
classNames = [classNames];
|
396
|
+
var currentId = (_a = this.currentNode) === null || _a === void 0 ? void 0 : _a.getId();
|
397
|
+
if ([null, undefined].some(id => id == currentId))
|
398
|
+
return;
|
399
|
+
var isNull = false;
|
400
|
+
var node = this.currentNode;
|
401
|
+
do {
|
402
|
+
switch (direction) {
|
403
|
+
case "ArrowLeft":
|
404
|
+
case "left":
|
405
|
+
node = node.getLeft();
|
406
|
+
break;
|
407
|
+
case "ArrowRight":
|
408
|
+
case "right":
|
409
|
+
node = node.getRight();
|
410
|
+
break;
|
411
|
+
case "ArrowUp":
|
412
|
+
case "up":
|
413
|
+
node = node.getUp();
|
414
|
+
break;
|
415
|
+
case "ArrowDown":
|
416
|
+
case "down":
|
417
|
+
node = node.getDown();
|
418
|
+
break;
|
419
|
+
default:
|
420
|
+
console.error(direction + " is not allowed. Use left, right, up or down");
|
421
|
+
return;
|
422
|
+
}
|
423
|
+
isNull = [null, undefined].some(n => node == n);
|
424
|
+
} while (!classNames.some(cn => { var _a; return (_a = node === null || node === void 0 ? void 0 : node.getDocElement()) === null || _a === void 0 ? void 0 : _a.classList.contains(cn); }) && !isNull);
|
425
|
+
return node;
|
426
|
+
}
|
427
|
+
//Check if ScoreGraph is at beginning of layer
|
428
|
+
isBOL() {
|
429
|
+
return this.currentNode.getLeft() === null && this.currentNode.getId().indexOf("BOL") !== -1;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
exports.default = ScoreGraph;
|
package/src/scripts/js/entry.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import VIBE from "./VIBE.js"
|
2
2
|
|
3
3
|
export default function createEditor(container, options, meiCallback){
|
4
|
-
return new
|
4
|
+
return new VIBE(container, options, meiCallback)
|
5
5
|
}
|
@@ -10,12 +10,12 @@ class Annotations {
|
|
10
10
|
this.clickHarmonyBtnHandler = (function clickHarmonyBtnHandler(e) {
|
11
11
|
//e.preventDefault()
|
12
12
|
this.removeTextListeners();
|
13
|
-
e.target.dispatchEvent(new Event("annotationButtonClicked"))
|
13
|
+
//e.target.dispatchEvent(new Event("annotationButtonClicked"))
|
14
14
|
}).bind(this);
|
15
15
|
this.clickAnnotTextHandler = (function clickAnnotTextHandler(e) {
|
16
16
|
//e.preventDefault()
|
17
17
|
this.resetTextListeners();
|
18
|
-
e.target.dispatchEvent(new Event("annotationButtonClicked"))
|
18
|
+
//e.target.dispatchEvent(new Event("annotationButtonClicked"))
|
19
19
|
}).bind(this);
|
20
20
|
////HANDLERS////
|
21
21
|
this.clickHandler = (function clickHandler(e) {
|
@@ -248,6 +248,7 @@ class Annotations {
|
|
248
248
|
switch (selectedButton) {
|
249
249
|
case "linkedAnnotButton":
|
250
250
|
case "staticTextButton":
|
251
|
+
this.container.classList.remove("harmonyMode");
|
251
252
|
this.createTextAnnotation(e, selectedButton);
|
252
253
|
break;
|
253
254
|
case "harmonyAnnotButton":
|
@@ -291,7 +292,7 @@ class Annotations {
|
|
291
292
|
var posy = pt.y; //matrixTransform(rootMatrix).y //e.pageY - this.rootBBox.y - window.pageYOffset
|
292
293
|
var annotationTarget = this.m2s.findScoreTarget(posx, posy, false);
|
293
294
|
var textGroup = document.createElementNS(constants_1.constants._SVGNS_, "g");
|
294
|
-
textGroup.setAttribute("id", random_1.uuidv4());
|
295
|
+
textGroup.setAttribute("id", (0, random_1.uuidv4)());
|
295
296
|
textGroup.setAttribute("targetId", annotationTarget.id);
|
296
297
|
var text = document.createElementNS(constants_1.constants._SVGNS_, "svg");
|
297
298
|
if (isLinked)
|
@@ -41,7 +41,7 @@ class HarmonyLabel {
|
|
41
41
|
}
|
42
42
|
createElement(inputString) {
|
43
43
|
this.element = this.currentMEI.createElement("harm");
|
44
|
-
this.element.setAttribute("id", random_1.uuidv4());
|
44
|
+
this.element.setAttribute("id", (0, random_1.uuidv4)());
|
45
45
|
this.element.setAttribute("place", "below");
|
46
46
|
Array.from(this.element.children).forEach(c => {
|
47
47
|
c.remove();
|