vibe-editor 0.0.4 → 0.0.5
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/package.json +65 -61
- package/src/scripts/js/Core.js +28 -9
- package/src/scripts/js/entry.js +6 -5
- package/src/scripts/js/gui/Annotations.js +27 -12
- package/src/scripts/js/gui/ScoreManipulator.js +6 -4
- package/src/scripts/js/gui/Tabbar.js +13 -4
- package/src/scripts/js/handlers/AnnotationChangeHandler.js +13 -1
- package/src/scripts/js/handlers/InsertModeHandler.js +3 -3
- package/src/scripts/js/handlers/PhantomElementHandler.js +3 -10
- package/src/scripts/js/handlers/WindowHandler.js +7 -7
- package/src/scripts/js/scripts/Core.js +932 -0
- package/src/scripts/js/scripts/MusicProcessor.js +810 -0
- package/src/scripts/js/scripts/VIBE.js +219 -0
- package/src/scripts/js/scripts/datastructures/MeasureMatrix.js +156 -0
- package/src/scripts/js/scripts/gui/Annotations.js +549 -0
- package/src/scripts/js/scripts/gui/Cursor.js +203 -0
- package/src/scripts/js/scripts/gui/PhantomElement.js +132 -0
- package/src/scripts/js/scripts/gui/ScoreManipulator.js +188 -0
- package/src/scripts/js/scripts/gui/Tabbar.js +705 -0
- package/src/scripts/js/{gui/Toolbar copy.js → scripts/gui/Toolbar.js} +15 -11
- package/src/scripts/js/scripts/handlers/AnnotationChangeHandler.js +650 -0
- package/src/scripts/js/scripts/handlers/ClickModeHandler.js +535 -0
- package/src/scripts/js/{gui → scripts/handlers}/CustomAnnotationShapeDrawer.js +34 -17
- package/src/scripts/js/{handlers/ModHandler.js → scripts/handlers/CustomToolbarHandler.js} +54 -66
- package/src/scripts/js/scripts/handlers/GlobalKeyboardHandler.js +372 -0
- package/src/scripts/js/scripts/handlers/Handler.js +2 -0
- package/src/scripts/js/{handlers/InsertModeHandler_deprecated.js → scripts/handlers/InsertModeHandler.js} +117 -164
- package/src/scripts/js/scripts/handlers/KeyModeHandler.js +405 -0
- package/src/scripts/js/scripts/handlers/LabelHandler.js +463 -0
- package/src/scripts/js/scripts/handlers/NoteDragHandler.js +97 -0
- package/src/scripts/js/scripts/handlers/PhantomElementHandler.js +168 -0
- package/src/scripts/js/scripts/handlers/ScoreManipulatorHandler.js +233 -0
- package/src/scripts/js/scripts/handlers/SidebarHandler.js +506 -0
- package/src/scripts/js/scripts/handlers/TooltipHandler.js +132 -0
- package/src/scripts/js/scripts/handlers/WindowHandler.js +278 -0
- package/src/scripts/js/scripts/utils/MEIOperations.js +2121 -0
- package/src/scripts/js/{utils/Mouse2MEI.js → scripts/utils/Mouse2SVG.js} +225 -57
- package/src/scripts/js/scripts/utils/SVGEditor.js +453 -0
- package/src/scripts/js/scripts/utils/Types.js +2 -0
- package/src/scripts/js/{utils/VerovioWrapper copy.js → scripts/utils/VerovioWrapper.js} +35 -21
- package/src/scripts/js/scripts/utils/coordinates.js +54 -0
- package/src/scripts/js/utils/Mouse2SVG.js +11 -4
- package/src/scripts/js/utils/VerovioWrapper.js +4 -4
- package/src/scripts/js/utils/coordinates.js +26 -2
- package/src/scripts/js/.DS_Store +0 -0
- package/src/scripts/js/MusicPlayer.js +0 -572
- package/src/scripts/js/datastructures/ScoreGraph copy.js +0 -432
- package/src/scripts/js/gui/CustomAnnotationDrawer.js +0 -114
- package/src/scripts/js/handlers/AnnotationDragHandler.js +0 -113
- package/src/scripts/js/handlers/AnnotationLineHandler.js +0 -113
- package/src/scripts/js/handlers/ArticulationHandler.js +0 -20
- package/src/scripts/js/handlers/HarmonyHandler.js +0 -282
- package/src/scripts/js/handlers/InsertModeHandler copy.js +0 -423
- package/src/scripts/js/handlers/KeyModeHandler copy.js +0 -407
- package/src/scripts/js/handlers/KeyModeHandler_deprecated.js +0 -411
- package/src/scripts/js/handlers/NoteDragHandler copy.js +0 -148
- package/src/scripts/js/handlers/NoteDragHandler_deprecated.js +0 -150
- package/src/scripts/js/handlers/SelectionHandler.js +0 -262
- package/src/scripts/js/utils/RectWrapper.js +0 -10
- package/src/scripts/js/utils/SVGFiller.js +0 -245
- package/src/scripts/js/utils/VerovioWrapperLocal.js +0 -156
- package/src/scripts/js/utils/firefoxBBoxes.js +0 -143
- package/src/styles/vibe.css +0 -785
- /package/src/scripts/js/{assets → scripts/assets}/mei_template.js +0 -0
- /package/src/scripts/js/{constants.js → scripts/constants.js} +0 -0
- /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreGraph.js +0 -0
- /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreGraph_deprecated.js +0 -0
- /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreNode.js +0 -0
- /package/src/scripts/js/{gui → scripts/gui}/HarmonyLabel.js +0 -0
- /package/src/scripts/js/{gui → scripts/gui}/Label.js +0 -0
- /package/src/scripts/js/{gui → scripts/gui}/TempoLabel.js +0 -0
- /package/src/scripts/js/{handlers → scripts/handlers}/DeleteHandler.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/DOMCreator.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/MEIConverter.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/ReactWrapper.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/convenienceQueries.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/mappings.js +0 -0
- /package/src/scripts/js/{utils → scripts/utils}/random.js +0 -0
@@ -0,0 +1,932 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = void 0;
|
4
|
+
const VerovioWrapper_1 = require("./utils/VerovioWrapper");
|
5
|
+
const random_1 = require("./utils/random");
|
6
|
+
const constants_1 = require("./constants");
|
7
|
+
const InsertModeHandler_1 = require("./handlers/InsertModeHandler");
|
8
|
+
const DeleteHandler_1 = require("./handlers/DeleteHandler");
|
9
|
+
const NoteDragHandler_1 = require("./handlers/NoteDragHandler");
|
10
|
+
const Mouse2SVG_1 = require("./utils/Mouse2SVG");
|
11
|
+
const GlobalKeyboardHandler_1 = require("./handlers/GlobalKeyboardHandler");
|
12
|
+
const MusicProcessor_1 = require("./MusicProcessor");
|
13
|
+
const meiConverter = require("./utils/MEIConverter");
|
14
|
+
const meiOperation = require("./utils/MEIOperations");
|
15
|
+
const mei_template_1 = require("./assets/mei_template");
|
16
|
+
const SVGEditor_1 = require("./utils/SVGEditor");
|
17
|
+
const ScoreGraph_1 = require("./datastructures/ScoreGraph");
|
18
|
+
const WindowHandler_1 = require("./handlers/WindowHandler");
|
19
|
+
const SidebarHandler_1 = require("./handlers/SidebarHandler");
|
20
|
+
const LabelHandler_1 = require("./handlers/LabelHandler");
|
21
|
+
const CustomToolbarHandler_1 = require("./handlers/CustomToolbarHandler");
|
22
|
+
const cq = require("./utils/convenienceQueries");
|
23
|
+
const coordinates = require("./utils/coordinates");
|
24
|
+
const TooltipHandler_1 = require("./handlers/TooltipHandler");
|
25
|
+
/**
|
26
|
+
* The core component the Editor. Manages the rendering with
|
27
|
+
* the verovio toolkit, sets bounding boxes and initializes all the interaction handlers.
|
28
|
+
* After each new load of the score, all handlers are reset and changed parametes (such as annotations or Mouse2SVG-Instance) are dispatched.
|
29
|
+
*/
|
30
|
+
class Core {
|
31
|
+
constructor(containerId) {
|
32
|
+
this.firstStart = true;
|
33
|
+
this.noteInputToggle = "on";
|
34
|
+
this.reloadDataHandler = (function reloadDataHandler() {
|
35
|
+
return this.reloadData();
|
36
|
+
}).bind(this);
|
37
|
+
this.loadDataHandler = (function loadDataHandler(pageURI, data, isUrl, options = null) {
|
38
|
+
return this.loadData(data, isUrl, Object.assign({ changeOnPageNo: pageURI }, options));
|
39
|
+
}).bind(this);
|
40
|
+
/**
|
41
|
+
* Provides AligFunction for Tabbar. alignFunction will be first set, when musicprocessor will instantiated
|
42
|
+
*/
|
43
|
+
this.alignFunctionHandler = (function alignFunctionHandler(file) {
|
44
|
+
var _a, _b;
|
45
|
+
(_a = this.musicProcessor) === null || _a === void 0 ? void 0 : _a.resetListeners();
|
46
|
+
(_b = this.musicProcessor) === null || _b === void 0 ? void 0 : _b.align(file);
|
47
|
+
}).bind(this);
|
48
|
+
/**
|
49
|
+
* Delete array of notes from score
|
50
|
+
*/
|
51
|
+
this.delete = (function d(notes) {
|
52
|
+
return new Promise((resolve) => {
|
53
|
+
this.getMEI("").then(mei => {
|
54
|
+
meiOperation.removeFromMEI(notes, this.currentMEIDoc).then(updatedMEI => {
|
55
|
+
if (updatedMEI != undefined) {
|
56
|
+
this.loadData(updatedMEI, false).then(() => {
|
57
|
+
resolve(true);
|
58
|
+
});
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
resolve(true);
|
62
|
+
}
|
63
|
+
});
|
64
|
+
});
|
65
|
+
});
|
66
|
+
}).bind(this);
|
67
|
+
/**
|
68
|
+
*
|
69
|
+
*/
|
70
|
+
this.insert = (function insert(newNote, replace = false) {
|
71
|
+
this.lastInsertedNoteId = newNote.id;
|
72
|
+
this.container.querySelectorAll(".marked").forEach(m => m.classList.remove("marked"));
|
73
|
+
return new Promise((resolve, reject) => {
|
74
|
+
this.getMEI("").then(mei => {
|
75
|
+
var updatedMEI = meiOperation.addToMEI(newNote, this.currentMEIDoc, replace, this.scoreGraph);
|
76
|
+
if ((updatedMEI === null || updatedMEI === void 0 ? void 0 : updatedMEI.documentElement.innerHTML.indexOf(newNote.id)) === -1) {
|
77
|
+
reject();
|
78
|
+
}
|
79
|
+
if (updatedMEI != undefined) {
|
80
|
+
this.loadData(updatedMEI, false).then(() => {
|
81
|
+
resolve(true);
|
82
|
+
});
|
83
|
+
}
|
84
|
+
else {
|
85
|
+
reject();
|
86
|
+
}
|
87
|
+
});
|
88
|
+
});
|
89
|
+
}).bind(this);
|
90
|
+
/**
|
91
|
+
* Undo the last action performed on a specific page.
|
92
|
+
* @param pageURI - The URI of the selected page.
|
93
|
+
* @returns If the action was undone.
|
94
|
+
*/
|
95
|
+
this.undo = (function undo(pageURI = "") {
|
96
|
+
return new Promise((resolve) => {
|
97
|
+
if (this.container.classList.contains("annotMode")) {
|
98
|
+
this.undoAnnotationStacks.pop();
|
99
|
+
const annotstate = this.undoAnnotationStacks.pop();
|
100
|
+
if (annotstate != undefined) {
|
101
|
+
var annotCanvas = this.container.querySelector("#annotationCanvas");
|
102
|
+
var annotList = this.container.querySelector("#annotList");
|
103
|
+
this.redoAnnotationStacks.push([annotCanvas, annotList]);
|
104
|
+
this.undoAnnotationStacks.push([annotCanvas, annotList]);
|
105
|
+
annotCanvas.replaceWith(annotstate[0]);
|
106
|
+
annotList.replaceWith(annotstate[1]);
|
107
|
+
this.keyboardHandler.resetListeners();
|
108
|
+
this.container.dispatchEvent(new Event("annotationCanvasChanged"));
|
109
|
+
}
|
110
|
+
resolve(true);
|
111
|
+
return;
|
112
|
+
}
|
113
|
+
this.undoMEIStacks.pop(); // get rid of currentMEI, since last in line (=initial) MEI is not accessible through verovio
|
114
|
+
const meistate = this.undoMEIStacks.pop();
|
115
|
+
if (meistate != undefined) {
|
116
|
+
this.redoMEIStacks.push(this.currentMEI);
|
117
|
+
this.loadData(meistate, false).then(() => resolve(true));
|
118
|
+
}
|
119
|
+
else {
|
120
|
+
resolve(false);
|
121
|
+
}
|
122
|
+
});
|
123
|
+
}).bind(this);
|
124
|
+
/**
|
125
|
+
* Redo the last action performed on a page.
|
126
|
+
* @param pageURI - The page URI.
|
127
|
+
* @returns If the action was redone.
|
128
|
+
*/
|
129
|
+
this.redo = (function redo(pageURI = "") {
|
130
|
+
return new Promise((resolve) => {
|
131
|
+
if (this.container.classList.contains("annotMode")) {
|
132
|
+
const annotstate = this.redoAnnotationStacks.pop();
|
133
|
+
if (annotstate != undefined) {
|
134
|
+
var annotCanvas = this.container.querySelector("#annotationCanvas");
|
135
|
+
var annotList = this.container.querySelector("#annotList");
|
136
|
+
this.undoAnnotationStacks.push([annotCanvas, annotList]);
|
137
|
+
annotCanvas.replaceWith(annotstate[0]);
|
138
|
+
annotList.replaceWith(annotstate[1]);
|
139
|
+
this.keyboardHandler.resetListeners();
|
140
|
+
}
|
141
|
+
resolve(true);
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
const meistate = this.redoMEIStacks.pop();
|
145
|
+
if (meistate !== undefined) {
|
146
|
+
this.undoMEIStacks.push(this.currentMEI);
|
147
|
+
this.loadData(meistate, false).then(() => resolve(true));
|
148
|
+
}
|
149
|
+
else {
|
150
|
+
resolve(false);
|
151
|
+
}
|
152
|
+
});
|
153
|
+
}).bind(this);
|
154
|
+
this.getElementAttr = (function getElementAttr(id) {
|
155
|
+
const message = {
|
156
|
+
action: "getElementAttr",
|
157
|
+
elementId: id
|
158
|
+
};
|
159
|
+
return this.verovioWrapper.setMessage(message).attributes;
|
160
|
+
}).bind(this);
|
161
|
+
this.resetLastInsertedNoteId = function () {
|
162
|
+
this.lastInsertedNoteId = undefined;
|
163
|
+
}.bind(this);
|
164
|
+
this.doHideUI = false;
|
165
|
+
this.hideOptions = {};
|
166
|
+
this.styleOptions = {};
|
167
|
+
this.attributeOptions = {};
|
168
|
+
this.containerId = containerId;
|
169
|
+
this.container = document.getElementById(containerId);
|
170
|
+
this.undoMEIStacks = Array();
|
171
|
+
this.redoMEIStacks = new Array();
|
172
|
+
this.undoAnnotationStacks = new Array();
|
173
|
+
//this.undoAnnotationStacks.push(new Array<Element>())
|
174
|
+
this.redoAnnotationStacks = new Array();
|
175
|
+
//this.redoAnnotationStacks.push(new Array<Element>())
|
176
|
+
this.windowHandler = new WindowHandler_1.default();
|
177
|
+
this.svgEditor = new SVGEditor_1.default();
|
178
|
+
}
|
179
|
+
/**
|
180
|
+
* Load data into the verovio toolkit and update the cache.
|
181
|
+
*/
|
182
|
+
loadData(data, isUrl, options = null) {
|
183
|
+
this.verovioWrapper = this.verovioWrapper || new VerovioWrapper_1.default();
|
184
|
+
var waitingFlag = "waiting";
|
185
|
+
if (cq.getVrvSVG(this.containerId) !== null) {
|
186
|
+
document.body.classList.add(waitingFlag);
|
187
|
+
}
|
188
|
+
document.getElementById(this.containerId).dispatchEvent(new Event("loadingStart"));
|
189
|
+
var that = this;
|
190
|
+
this.svgEditor.setContainerId(this.containerId);
|
191
|
+
this.svgEditor.cacheClasses().cacheScales().cacheStyles();
|
192
|
+
//this function renders the pages via the veroviowrapper
|
193
|
+
async function render(pageNo = 1, options = null) {
|
194
|
+
return new Promise((resolve, reject) => {
|
195
|
+
var _a;
|
196
|
+
var message = {
|
197
|
+
id: random_1.uuidv4(),
|
198
|
+
action: 'renderToSVG',
|
199
|
+
pageNo: pageNo
|
200
|
+
};
|
201
|
+
var response;
|
202
|
+
var svg;
|
203
|
+
response = that.verovioWrapper.setMessage(message);
|
204
|
+
svg = response.svg;
|
205
|
+
var svgDoc = new DOMParser().parseFromString(svg, "image/svg+xml");
|
206
|
+
var pageElement = svgDoc.querySelector("svg");
|
207
|
+
var pageId = "vrvPage" + pageNo.toString();
|
208
|
+
pageElement.setAttribute("id", "vrvPage" + pageNo.toString());
|
209
|
+
pageElement.classList.add("page");
|
210
|
+
try {
|
211
|
+
// delete old svg
|
212
|
+
if (cq.getVrvSVG(that.containerId).querySelector("#" + pageId) !== null) {
|
213
|
+
//that.svgEditor.cacheClasses().cacheScales()
|
214
|
+
cq.getVrvSVG(that.containerId).querySelector("#" + pageId).innerHTML = ""; //.remove()
|
215
|
+
}
|
216
|
+
//insert new complete svg
|
217
|
+
//document.querySelector("#" + that.containerId + " #vrvSVG").append(pageElement)
|
218
|
+
cq.getVrvSVG(that.containerId).querySelector("#" + pageId).replaceWith(pageElement);
|
219
|
+
}
|
220
|
+
catch (error) {
|
221
|
+
(_a = document.querySelector("#" + that.containerId + " #vrvSVG")) === null || _a === void 0 ? void 0 : _a.append(pageElement);
|
222
|
+
}
|
223
|
+
that.svgEditor.distributeIds(pageElement.querySelector(".definition-scale"));
|
224
|
+
pageElement.setAttribute("preserveAspectRatio", "xMinYMin meet");
|
225
|
+
var systemHeigth = pageElement.querySelector(".system").getBoundingClientRect().height;
|
226
|
+
systemHeigth += systemHeigth * 0.2;
|
227
|
+
//that.verovioWrapper.setHeightValue(systemHeigth)
|
228
|
+
// if(!options){
|
229
|
+
// options = {}
|
230
|
+
// }
|
231
|
+
// options.widthFactor = (that.container as HTMLElement).clientWidth / screen.availWidth
|
232
|
+
// if (options?.widthFactor) {
|
233
|
+
// console.log("pageW before", that.verovioWrapper.getOptions().pageWidth)
|
234
|
+
// that.verovioWrapper.setWidthValue(
|
235
|
+
// parseFloat(that.verovioWrapper.getOptions().pageWidth) * options.widthFactor
|
236
|
+
// )
|
237
|
+
// console.log("pageW after", that.verovioWrapper.getOptions().pageWidth)
|
238
|
+
// }
|
239
|
+
resolve();
|
240
|
+
});
|
241
|
+
}
|
242
|
+
//END ASYNC FUNCTION RENDER
|
243
|
+
return new Promise((resolve, reject) => {
|
244
|
+
var _a, _b, _c, _d, _e;
|
245
|
+
this.sendDataToVerovio(data, isUrl);
|
246
|
+
var pageGroup = document.createElement("g");
|
247
|
+
pageGroup.setAttribute("id", "vrvSVG");
|
248
|
+
if (cq.getVrvSVG(that.containerId) !== null) {
|
249
|
+
that.svgEditor.cacheClasses().cacheScales();
|
250
|
+
}
|
251
|
+
if (!cq.getVrvSVG(that.containerId))
|
252
|
+
document.querySelector("#" + that.containerId + "> #svgContainer").append(pageGroup);
|
253
|
+
var pageCount = this.verovioWrapper.getToolkit().getPageCount();
|
254
|
+
var renderPromises = new Array();
|
255
|
+
var staffId = (_c = (_b = (_a = this.m2s) === null || _a === void 0 ? void 0 : _a.getLastMouseEnter()) === null || _b === void 0 ? void 0 : _b.staff) === null || _c === void 0 ? void 0 : _c.getAttribute("refId");
|
256
|
+
var optionPage;
|
257
|
+
if ((options === null || options === void 0 ? void 0 : options.changeOnPageNo) != undefined) {
|
258
|
+
if (options.changeOnPageNo === "last") {
|
259
|
+
optionPage = pageCount;
|
260
|
+
}
|
261
|
+
else {
|
262
|
+
optionPage = parseInt(options.changeOnPageNo);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
//remove all pages, that do not exist anymore
|
266
|
+
cq.getVrvSVG(this.containerId).querySelectorAll(":scope > svg").forEach(svg => {
|
267
|
+
if (parseInt(svg.id.match(/\d+/)[0]) > pageCount) {
|
268
|
+
svg.remove();
|
269
|
+
}
|
270
|
+
});
|
271
|
+
var changeOnPage = optionPage || parseInt((_e = (_d = cq.getVrvSVG(this.containerId).querySelector("#" + staffId)) === null || _d === void 0 ? void 0 : _d.closest(".page")) === null || _e === void 0 ? void 0 : _e.id.split("").reverse()[0]);
|
272
|
+
Array.from({ length: pageCount }, (_, index) => index + 1).forEach(pageNo => {
|
273
|
+
if (!isNaN(changeOnPage)) {
|
274
|
+
if (pageNo < changeOnPage)
|
275
|
+
return;
|
276
|
+
}
|
277
|
+
renderPromises.push(setTimeout(function () { render(pageNo, options); }, 1));
|
278
|
+
});
|
279
|
+
//Each page will be redered seperatly
|
280
|
+
Promise.all(renderPromises).then(() => {
|
281
|
+
document.body.classList.remove(waitingFlag);
|
282
|
+
resolve(that.initAfterRender());
|
283
|
+
});
|
284
|
+
});
|
285
|
+
}
|
286
|
+
sendDataToVerovio(data, isUrl) {
|
287
|
+
var d;
|
288
|
+
var u;
|
289
|
+
var type = data === null || data === void 0 ? void 0 : data.constructor.name;
|
290
|
+
switch (type) {
|
291
|
+
case 'String':
|
292
|
+
data = meiConverter.reformatMEI(data);
|
293
|
+
d = data;
|
294
|
+
u = isUrl;
|
295
|
+
break;
|
296
|
+
case 'XMLDocument':
|
297
|
+
data = meiOperation.disableFeatures(["grace", "arpeg"], data); // for Debugging
|
298
|
+
this.svgEditor.copyClassesFromMei(data);
|
299
|
+
d = new XMLSerializer().serializeToString(data);
|
300
|
+
u = false;
|
301
|
+
break;
|
302
|
+
case 'HTMLUnknownElement':
|
303
|
+
d = new XMLSerializer().serializeToString(data);
|
304
|
+
u = false;
|
305
|
+
break;
|
306
|
+
case undefined:
|
307
|
+
d = new mei_template_1.default().emptyMEI();
|
308
|
+
u = false;
|
309
|
+
break;
|
310
|
+
default:
|
311
|
+
console.log("Wrong Datatype: " + type);
|
312
|
+
break;
|
313
|
+
}
|
314
|
+
//just render the data once to make pagecount accessible
|
315
|
+
var message = {
|
316
|
+
id: random_1.uuidv4(),
|
317
|
+
action: 'renderData',
|
318
|
+
mei: d,
|
319
|
+
isUrl: u
|
320
|
+
};
|
321
|
+
this.verovioWrapper.setMessage(message);
|
322
|
+
}
|
323
|
+
/**
|
324
|
+
* Init attributes for the svg, creat svg overlay and distribute/ init handlers.
|
325
|
+
* @returns
|
326
|
+
*/
|
327
|
+
initAfterRender() {
|
328
|
+
var that = this;
|
329
|
+
return new Promise((resolve, reject) => {
|
330
|
+
setTimeout(function () {
|
331
|
+
var _a, _b;
|
332
|
+
that.svgEditor.drawLinesUnderSystems();
|
333
|
+
that.svgEditor.modifyHarm();
|
334
|
+
that.createSVGOverlay(true);
|
335
|
+
that.svgEditor.setXY((_a = that.windowHandler) === null || _a === void 0 ? void 0 : _a.getX(), (_b = that.windowHandler) === null || _b === void 0 ? void 0 : _b.getY());
|
336
|
+
that.getMEI("").then(mei => {
|
337
|
+
var _a;
|
338
|
+
that.currentMEI = mei;
|
339
|
+
that.currentMEIDoc = that.getCurrentMEI(true);
|
340
|
+
that.currentMEIDoc.querySelectorAll("[dur='breve']").forEach(d => d.setAttribute("dur", "0.5"));
|
341
|
+
if (that.currentMEIDoc.querySelector("parsererror")) {
|
342
|
+
try {
|
343
|
+
throw new Error("ParsingError");
|
344
|
+
}
|
345
|
+
catch (error) {
|
346
|
+
console.error("There is a parsingerror in the meiDoc: ", error, that.currentMEIDoc, that.currentMEI);
|
347
|
+
}
|
348
|
+
}
|
349
|
+
that.svgEditor.markOverfilledMeasures(that.currentMEIDoc);
|
350
|
+
that.svgEditor
|
351
|
+
.setContainerId(that.containerId)
|
352
|
+
.loadClasses()
|
353
|
+
.loadStyles()
|
354
|
+
.fillSVG(that.currentMEIDoc)
|
355
|
+
.setActiveLayer()
|
356
|
+
.hideRedundantRests(that.currentMEIDoc);
|
357
|
+
that.undoMEIStacks.push(mei);
|
358
|
+
var lastAddedClass = "lastAdded";
|
359
|
+
// that.container.querySelectorAll("." + lastAddedClass).forEach(m => {
|
360
|
+
// m.classList.replace("lastAdded", "marked") //remove(lastAddedClass)
|
361
|
+
// })
|
362
|
+
if (that.lastInsertedNoteId && ["textmode", "clickmode"].some(mode => that.container.classList.contains(mode))) {
|
363
|
+
//that.container.querySelector("#" + that.lastInsertedNoteId)?.classList.add(lastAddedClass)
|
364
|
+
(_a = that.container.querySelector("#" + that.lastInsertedNoteId)) === null || _a === void 0 ? void 0 : _a.classList.add("marked");
|
365
|
+
}
|
366
|
+
if (that.meiChangedCallback) {
|
367
|
+
that.meiChangedCallback(that.currentMEI);
|
368
|
+
}
|
369
|
+
});
|
370
|
+
//Initialize music processor
|
371
|
+
that.getTimemap().then(timemap => {
|
372
|
+
var _a;
|
373
|
+
that.musicProcessor = that.musicProcessor || new MusicProcessor_1.default(that.containerId);
|
374
|
+
that.musicProcessor
|
375
|
+
.setMEI(that.currentMEIDoc)
|
376
|
+
.setMidi(that.verovioWrapper.renderToMidi())
|
377
|
+
.setTimemap(timemap)
|
378
|
+
.addCanvas()
|
379
|
+
.update();
|
380
|
+
that.scoreGraph = new ScoreGraph_1.default(that.currentMEIDoc, that.containerId, null);
|
381
|
+
//the first condition should only occur at first starting the score editor
|
382
|
+
if (!that.container.querySelector(".lastAdded, .marked")) { //that.scoreGraph.getCurrentNode() == undefined) {
|
383
|
+
that.scoreGraph.setCurrentNodeById(that.container.querySelector("#vrvSVG .staff > .layer.activeLayer :is(.note, .rest, .mRest").id);
|
384
|
+
}
|
385
|
+
else { //second condition always sets lastAdded Note
|
386
|
+
that.scoreGraph.setCurrentNodeById((_a = that.container.querySelector("#vrvSVG :is(.lastAdded, .marked)")) === null || _a === void 0 ? void 0 : _a.id);
|
387
|
+
}
|
388
|
+
that.initializeHandlers();
|
389
|
+
that.musicProcessor.setScoreGraph(that.scoreGraph);
|
390
|
+
document.getElementById(that.containerId).dispatchEvent(new Event("loadingEnd"));
|
391
|
+
that.svg = new XMLSerializer().serializeToString(that.container.querySelector("#svgContainer"));
|
392
|
+
that.svgEditor.loadClasses();
|
393
|
+
console.log(that.currentMEIDoc, that.m2s.getMeasureMatrix());
|
394
|
+
resolve(that.currentMEI);
|
395
|
+
//})
|
396
|
+
});
|
397
|
+
}, 1);
|
398
|
+
});
|
399
|
+
}
|
400
|
+
/**
|
401
|
+
* Load everything if there is already a svg present. Displaying the visuals is not necessary here.
|
402
|
+
* But the MEI has to be loaded with verovio anyway to ensure that options and subsequent loads will have access to the underlying MEI.
|
403
|
+
* Only supposed to be used from Main class for first initialisation.
|
404
|
+
* @param container container with already rendered svg (usually a container with "vibe-container" class)
|
405
|
+
* @param data MEI to be loaded in verovio
|
406
|
+
* @returns
|
407
|
+
*/
|
408
|
+
loadWithExistingSVG(container, data, isUrl) {
|
409
|
+
return new Promise(resolve => {
|
410
|
+
this.container = container;
|
411
|
+
this.containerId = container.id;
|
412
|
+
this.verovioWrapper = this.verovioWrapper || new VerovioWrapper_1.default();
|
413
|
+
var waitingFlag = "waiting";
|
414
|
+
// svg has to be loaded into verovio anyway
|
415
|
+
this.sendDataToVerovio(data, isUrl);
|
416
|
+
this.interactionOverlay = cq.getInteractOverlay(this.containerId);
|
417
|
+
// get most right standing canvas in interactionOverlay
|
418
|
+
let rightMostElement = this.interactionOverlay;
|
419
|
+
let rightCoord = 0;
|
420
|
+
this.container.querySelectorAll("#interactionOverlay > *, #vrvSVG > svg > *").forEach(c => {
|
421
|
+
let bbox = c.getBoundingClientRect();
|
422
|
+
if (bbox.x + bbox.width > rightCoord) {
|
423
|
+
rightCoord = bbox.x + bbox.width;
|
424
|
+
rightMostElement = c;
|
425
|
+
}
|
426
|
+
});
|
427
|
+
var sizeRatio = ((this.container.getBoundingClientRect().width / this.interactionOverlay.getBoundingClientRect().width) + 2) * 100; //rightMostElement.getBoundingClientRect().width * 60
|
428
|
+
if (!sizeRatio || sizeRatio <= 0) {
|
429
|
+
sizeRatio = 100;
|
430
|
+
}
|
431
|
+
this.container.querySelector("#svgContainer").style.width = sizeRatio.toString() + "%";
|
432
|
+
document.getElementById(this.containerId).dispatchEvent(new Event("loadingStart"));
|
433
|
+
this.svgEditor.setContainerId(this.containerId);
|
434
|
+
this.svgEditor.cacheClasses().cacheScales().cacheStyles();
|
435
|
+
this.initializeHandlers(true, false);
|
436
|
+
resolve(this.initAfterRender());
|
437
|
+
});
|
438
|
+
}
|
439
|
+
reloadData() {
|
440
|
+
return this.loadData(this.currentMEI, false);
|
441
|
+
}
|
442
|
+
/**
|
443
|
+
* Initialize Handlers
|
444
|
+
*/
|
445
|
+
initializeHandlers(initNew = false, dispatch = true) {
|
446
|
+
//m2s must be first since all coordinates and interacions are based on positions computed in Mouse2SVG
|
447
|
+
this.m2s = initNew ? new Mouse2SVG_1.Mouse2SVG() : this.m2s || new Mouse2SVG_1.Mouse2SVG();
|
448
|
+
if (!initNew && dispatch) {
|
449
|
+
this.m2s
|
450
|
+
.setContainerId(this.containerId)
|
451
|
+
.setUpdateOverlayCallback(this.createSVGOverlay)
|
452
|
+
.setCurrentMEI(this.currentMEIDoc)
|
453
|
+
.update();
|
454
|
+
}
|
455
|
+
this.insertModeHandler = initNew ? new InsertModeHandler_1.default(this.containerId) : this.insertModeHandler || new InsertModeHandler_1.default(this.containerId);
|
456
|
+
this.deleteHandler = initNew ? new DeleteHandler_1.default(this.containerId) : this.deleteHandler || new DeleteHandler_1.default(this.containerId);
|
457
|
+
this.noteDragHandler = new NoteDragHandler_1.default(this.containerId);
|
458
|
+
this.globalKeyboardHandler = initNew ? new GlobalKeyboardHandler_1.default(this.containerId) : this.globalKeyboardHandler || new GlobalKeyboardHandler_1.default(this.containerId);
|
459
|
+
this.sidebarHandler = initNew ? new SidebarHandler_1.default : this.sidebarHandler || new SidebarHandler_1.default();
|
460
|
+
this.labelHandler = initNew ? new LabelHandler_1.default(this.containerId) : this.labelHandler || new LabelHandler_1.default(this.containerId);
|
461
|
+
this.modHandler = initNew ? new CustomToolbarHandler_1.default(this.containerId) : this.modHandler || new CustomToolbarHandler_1.default(this.containerId);
|
462
|
+
this.tooltipHandler = initNew ? new TooltipHandler_1.default() : this.tooltipHandler || new TooltipHandler_1.default();
|
463
|
+
this.musicProcessor = initNew ? new MusicProcessor_1.default(this.containerId) : this.musicProcessor || new MusicProcessor_1.default(this.containerId);
|
464
|
+
if (dispatch) {
|
465
|
+
this.dispatchFunctions();
|
466
|
+
}
|
467
|
+
}
|
468
|
+
/**
|
469
|
+
* distribute Callback functions for each element which uses some information from of the Core (Handlers, musicProcessor, Callbacks, etc)
|
470
|
+
*/
|
471
|
+
dispatchFunctions() {
|
472
|
+
this.labelHandler
|
473
|
+
.setContainerId(this.containerId)
|
474
|
+
.setCurrentMEI(this.currentMEIDoc)
|
475
|
+
.reset();
|
476
|
+
this.insertModeHandler
|
477
|
+
.setContainerId(this.containerId)
|
478
|
+
.setScoreGraph(this.scoreGraph)
|
479
|
+
.setm2s(this.m2s)
|
480
|
+
.setMusicProcessor(this.musicProcessor)
|
481
|
+
.setDeleteHandler(this.deleteHandler)
|
482
|
+
.setLabelHandler(this.labelHandler)
|
483
|
+
.activateHarmonyMode()
|
484
|
+
//.activateSelectionMode()
|
485
|
+
.setInsertCallback(this.insert)
|
486
|
+
.setDeleteCallback(this.delete)
|
487
|
+
.setLoadDataCallback(this.loadDataHandler)
|
488
|
+
.setUndoAnnotationStacks(this.undoAnnotationStacks)
|
489
|
+
.resetModes()
|
490
|
+
.resetCanvas();
|
491
|
+
this.noteInputSwitch(this.noteInputToggle);
|
492
|
+
this.deleteHandler
|
493
|
+
.setContainerId(this.containerId)
|
494
|
+
.setDeleteCallback(this.delete)
|
495
|
+
.update();
|
496
|
+
this.noteDragHandler
|
497
|
+
.setContainerId(this.containerId)
|
498
|
+
.setCurrentMEI(this.currentMEIDoc)
|
499
|
+
.setInsertCallback(this.insert)
|
500
|
+
.setMusicProcessor(this.musicProcessor)
|
501
|
+
.setm2s(this.m2s)
|
502
|
+
.resetListeners();
|
503
|
+
this.globalKeyboardHandler
|
504
|
+
.setContainerId(this.containerId)
|
505
|
+
.setUndoCallback(this.undo)
|
506
|
+
.setRedoCallback(this.redo)
|
507
|
+
.setCurrentMei(this.currentMEIDoc)
|
508
|
+
.setMusicProcessor(this.musicProcessor)
|
509
|
+
.setHarmonyHandlerCallback(this.labelHandler.setHarmonyLabelHandlerKey)
|
510
|
+
.setLoadDataCallback(this.loadDataHandler)
|
511
|
+
.setScoreGraph(this.scoreGraph)
|
512
|
+
.resetLastInsertedNoteCallback(this.resetLastInsertedNoteId)
|
513
|
+
.resetListeners();
|
514
|
+
this.sidebarHandler
|
515
|
+
.setContainerId(this.containerId)
|
516
|
+
.setCurrentMei(this.currentMEIDoc)
|
517
|
+
.setm2s(this.m2s)
|
518
|
+
.setLoadDataCallback(this.loadDataHandler)
|
519
|
+
.loadMeter()
|
520
|
+
.makeScoreElementsClickable()
|
521
|
+
.resetListeners();
|
522
|
+
this.modHandler
|
523
|
+
.setContainerId(this.containerId)
|
524
|
+
.resetListeners()
|
525
|
+
.setCurrentMEI(this.currentMEIDoc)
|
526
|
+
.setLoadDataCallback(this.loadDataHandler);
|
527
|
+
this.windowHandler
|
528
|
+
.setContainerId(this.containerId)
|
529
|
+
.setm2s(this.m2s)
|
530
|
+
.setCurrentMEI(this.currentMEIDoc)
|
531
|
+
.setLoadDataCallback(this.loadDataHandler)
|
532
|
+
.setSVGReloadCallback(this.reloadDataHandler)
|
533
|
+
.setAnnotations(this.insertModeHandler.getAnnotations())
|
534
|
+
.setInsertModeHandler(this.insertModeHandler)
|
535
|
+
.resetListeners();
|
536
|
+
this.tooltipHandler
|
537
|
+
.setContainerId(this.containerId)
|
538
|
+
.removeListeners()
|
539
|
+
.setListeners();
|
540
|
+
// always start from click mode
|
541
|
+
if (this.firstStart) {
|
542
|
+
this.container.querySelector("#notationTabBtn").click();
|
543
|
+
this.container.querySelector(".voiceBtn").classList.add("selected");
|
544
|
+
this.container.querySelector(".layer").classList.add("activeLayer");
|
545
|
+
this.firstStart = false;
|
546
|
+
}
|
547
|
+
if (this.doHideUI) {
|
548
|
+
this.hideUI(this.hideOptions);
|
549
|
+
}
|
550
|
+
else {
|
551
|
+
this.viewUI(this.hideOptions);
|
552
|
+
}
|
553
|
+
if (Object.entries(this.styleOptions).length > 0) {
|
554
|
+
this.setStyles(this.styleOptions);
|
555
|
+
}
|
556
|
+
if (Object.entries(this.attributeOptions).length > 0) {
|
557
|
+
this.setAttributes(this.attributeOptions);
|
558
|
+
}
|
559
|
+
// experimental react implementation of color picker
|
560
|
+
//this.container.append(ReactWrapper.createColorPicker("reactContainer"))
|
561
|
+
}
|
562
|
+
////// VEROVIO REQUESTS /////////////////
|
563
|
+
/**
|
564
|
+
* Get the MEI for a specific page.
|
565
|
+
* @param pageURI - The URI of the selected page.
|
566
|
+
*/
|
567
|
+
getMEI(pageURI) {
|
568
|
+
return new Promise((resolve, reject) => {
|
569
|
+
const message = {
|
570
|
+
action: "getMEI",
|
571
|
+
id: random_1.uuidv4()
|
572
|
+
};
|
573
|
+
var response;
|
574
|
+
response = this.verovioWrapper.setMessage(message);
|
575
|
+
if (response.mei) {
|
576
|
+
this.currentMEI = response.mei;
|
577
|
+
}
|
578
|
+
else {
|
579
|
+
//console.log(meiConverter.meiToDoc(response.mei))
|
580
|
+
}
|
581
|
+
resolve(response.mei);
|
582
|
+
});
|
583
|
+
}
|
584
|
+
getMidi() {
|
585
|
+
return new Promise((resolve, reject) => {
|
586
|
+
const message = {
|
587
|
+
action: "renderToMidi",
|
588
|
+
id: random_1.uuidv4()
|
589
|
+
};
|
590
|
+
var response = this.verovioWrapper.setMessage(message);
|
591
|
+
if (response.midi) {
|
592
|
+
this.currentMidi = response.midi;
|
593
|
+
resolve(response.midi);
|
594
|
+
}
|
595
|
+
else {
|
596
|
+
reject("fail!");
|
597
|
+
}
|
598
|
+
});
|
599
|
+
}
|
600
|
+
getTimemap() {
|
601
|
+
return new Promise((resolve, reject) => {
|
602
|
+
const timemap = this.verovioWrapper.getTimemap();
|
603
|
+
if (timemap) {
|
604
|
+
resolve(timemap);
|
605
|
+
}
|
606
|
+
else {
|
607
|
+
reject("fail!");
|
608
|
+
}
|
609
|
+
});
|
610
|
+
}
|
611
|
+
/**
|
612
|
+
* Create an overlay of all interative elements over the the score svg.
|
613
|
+
*/
|
614
|
+
createSVGOverlay(loadBBoxes = true) {
|
615
|
+
return new Promise((resolve) => {
|
616
|
+
var _a;
|
617
|
+
document.getElementById(this.containerId).focus();
|
618
|
+
var refSVG = document.getElementById(this.containerId).querySelector("#vrvSVG");
|
619
|
+
this.interactionOverlay = document.getElementById(this.containerId).querySelector("#interactionOverlay");
|
620
|
+
if (!this.interactionOverlay) {
|
621
|
+
var overlay = document.createElementNS(constants_1.constants._SVGNS_, "svg");
|
622
|
+
overlay.setAttribute("id", "interactionOverlay");
|
623
|
+
this.interactionOverlay = overlay;
|
624
|
+
}
|
625
|
+
var svgContainer = document.getElementById(this.containerId).querySelector("#svgContainer");
|
626
|
+
var vrvContainer = cq.getVrvSVG(this.containerId);
|
627
|
+
var root = svgContainer.getBoundingClientRect().height > vrvContainer.getBoundingClientRect().height ? svgContainer : vrvContainer;
|
628
|
+
var rootBBox = root.getBoundingClientRect();
|
629
|
+
var rootWidth = rootBBox.width;
|
630
|
+
var rootHeigth = rootBBox.height;
|
631
|
+
if (!this.interactionOverlay.getAttribute("viewBox")) {
|
632
|
+
this.interactionOverlay.setAttribute("viewBox", ["0", "0", rootWidth.toString(), rootHeigth.toString()].join(" "));
|
633
|
+
}
|
634
|
+
(_a = document.getElementById(this.containerId).querySelector("#interactionOverlay #scoreRects")) === null || _a === void 0 ? void 0 : _a.remove();
|
635
|
+
var scoreRects = document.createElementNS(constants_1.constants._SVGNS_, "svg");
|
636
|
+
scoreRects.setAttribute("id", "scoreRects");
|
637
|
+
//scoreRects.setAttribute("viewBox", ["0", "0", rootWidth.toString(), rootHeigth.toString()].join(" "))
|
638
|
+
Array.from(refSVG.attributes).forEach(a => {
|
639
|
+
if (!["id", "width", "height"].includes(a.name)) {
|
640
|
+
this.interactionOverlay.setAttribute(a.name, a.value);
|
641
|
+
}
|
642
|
+
});
|
643
|
+
this.interactionOverlay.appendChild(scoreRects);
|
644
|
+
refSVG.insertAdjacentElement("beforebegin", this.interactionOverlay);
|
645
|
+
if (loadBBoxes) {
|
646
|
+
var svgBoxes = Array.from(document.getElementById(this.containerId)
|
647
|
+
.querySelectorAll(".definition-scale :is(g,path)")) //".definition-scale path, .definition-scale .bounding-box"))
|
648
|
+
.filter(el => {
|
649
|
+
var condition = !["system", "measure", "layer", "ledgerLines", "flag"].some(cn => el.classList.contains(cn));
|
650
|
+
return condition;
|
651
|
+
});
|
652
|
+
var reorderedBoxes = new Array(); // reorder so that dependent elements are already in array
|
653
|
+
svgBoxes.forEach(sb => {
|
654
|
+
if (sb.querySelector(":scope > use, :scope > rect, :scope > path") === null) {
|
655
|
+
reorderedBoxes.push(sb);
|
656
|
+
}
|
657
|
+
else {
|
658
|
+
reorderedBoxes.unshift(sb);
|
659
|
+
}
|
660
|
+
});
|
661
|
+
// staff always has to be on top of sibling elements, so that one can interact with score elements
|
662
|
+
reorderedBoxes = reorderedBoxes.reverse();
|
663
|
+
async function computeCoords(box, interactionOverlay) {
|
664
|
+
return new Promise((resolve) => {
|
665
|
+
var g = document.createElementNS(constants_1.constants._SVGNS_, "g");
|
666
|
+
var refId = box.id !== "" ? box.id : box.getAttribute("refId");
|
667
|
+
if (refId !== "" && refId !== null) {
|
668
|
+
g.setAttribute("refId", refId);
|
669
|
+
}
|
670
|
+
box.classList.forEach(c => g.classList.add(c));
|
671
|
+
var bbox = box.getBoundingClientRect();
|
672
|
+
var cc = coordinates.getDOMMatrixCoordinates(bbox, interactionOverlay);
|
673
|
+
var rect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
|
674
|
+
rect.setAttribute("x", cc.left.toString());
|
675
|
+
rect.setAttribute("y", cc.top.toString());
|
676
|
+
var w;
|
677
|
+
if (cc.width === 0)
|
678
|
+
w = 2;
|
679
|
+
rect.setAttribute("width", (w === null || w === void 0 ? void 0 : w.toString()) || cc.width.toString());
|
680
|
+
var h;
|
681
|
+
if (cc.height === 0)
|
682
|
+
h = 2;
|
683
|
+
rect.setAttribute("height", (h === null || h === void 0 ? void 0 : h.toString()) || cc.height.toString());
|
684
|
+
g.appendChild(rect);
|
685
|
+
scoreRects.append(g);
|
686
|
+
resolve(true);
|
687
|
+
});
|
688
|
+
}
|
689
|
+
var coordPromises = new Array();
|
690
|
+
reorderedBoxes.forEach(sr => {
|
691
|
+
if (!["g", "path"].includes(sr.tagName.toLowerCase())) {
|
692
|
+
return;
|
693
|
+
}
|
694
|
+
else if (Array.from(sr.classList).some(srcl => srcl.includes("page") || srcl.includes("system"))) {
|
695
|
+
return;
|
696
|
+
}
|
697
|
+
else {
|
698
|
+
coordPromises.push(computeCoords(sr, this.interactionOverlay));
|
699
|
+
}
|
700
|
+
});
|
701
|
+
setTimeout(function () { Promise.all(coordPromises); }, 1);
|
702
|
+
}
|
703
|
+
resolve(true);
|
704
|
+
});
|
705
|
+
}
|
706
|
+
replaceWithRect(el) {
|
707
|
+
if (!["g", "path", "svg"].includes(el.tagName.toLowerCase())) {
|
708
|
+
el.remove();
|
709
|
+
return;
|
710
|
+
}
|
711
|
+
if (el.childElementCount > 0) {
|
712
|
+
Array.from(el.children).forEach(ec => {
|
713
|
+
this.replaceWithRect(ec);
|
714
|
+
});
|
715
|
+
}
|
716
|
+
if ("svg" !== el.tagName.toLowerCase()) {
|
717
|
+
var childCopy = new Array();
|
718
|
+
Array.from(el.children).forEach(ec => childCopy.push(ec.cloneNode(true)));
|
719
|
+
var bbox = el.getBoundingClientRect();
|
720
|
+
var rect = document.createElementNS(constants_1.constants._SVGNS_, "rect");
|
721
|
+
rect.setAttribute("refId", el.id);
|
722
|
+
el.classList.forEach(c => rect.classList.add(c));
|
723
|
+
var cc = coordinates.getDOMMatrixCoordinates(bbox, this.interactionOverlay);
|
724
|
+
rect.setAttribute("x", cc.left.toString());
|
725
|
+
rect.setAttribute("y", cc.top.toString());
|
726
|
+
var w;
|
727
|
+
if (cc.width === 0)
|
728
|
+
w = 2;
|
729
|
+
rect.setAttribute("width", (w === null || w === void 0 ? void 0 : w.toString()) || cc.width.toString());
|
730
|
+
var h;
|
731
|
+
if (cc.height === 0)
|
732
|
+
h = 2;
|
733
|
+
rect.setAttribute("height", (h === null || h === void 0 ? void 0 : h.toString()) || cc.height.toString());
|
734
|
+
childCopy.forEach(cc => rect.appendChild(childCopy.shift()));
|
735
|
+
el.insertAdjacentElement("beforebegin", rect);
|
736
|
+
el.remove();
|
737
|
+
}
|
738
|
+
}
|
739
|
+
/**
|
740
|
+
* hide ui elements, so that no interaction is possible
|
741
|
+
* should be best called after promise of loadData
|
742
|
+
* @param options
|
743
|
+
*/
|
744
|
+
hideUI(options = {}) {
|
745
|
+
var _a, _b, _c;
|
746
|
+
if (Object.entries(options).length === 0) {
|
747
|
+
options = { annotationCanvas: true, labelCanvas: true, canvasMusicPlayer: true, scoreRects: true, manipulatorCanvas: true, sidebarContainer: true, btnToolbar: true, customToolbar: true, groups: true };
|
748
|
+
}
|
749
|
+
for (const [key, value] of Object.entries(options)) {
|
750
|
+
if (value) {
|
751
|
+
if (key === "groups") {
|
752
|
+
((_a = document.getElementById(this.containerId)) === null || _a === void 0 ? void 0 : _a.querySelectorAll("[role=\"group\"]")).forEach(g => g.classList.add("hideUI")); // style.setProperty("display", "none", "important"))
|
753
|
+
}
|
754
|
+
else {
|
755
|
+
(_c = (_b = document.getElementById(this.containerId)) === null || _b === void 0 ? void 0 : _b.querySelector("#" + key)) === null || _c === void 0 ? void 0 : _c.classList.add("hideUI"); //style.setProperty("display", "none", "important")
|
756
|
+
}
|
757
|
+
}
|
758
|
+
}
|
759
|
+
}
|
760
|
+
/**
|
761
|
+
* View Ui elements if they where hidden earlier
|
762
|
+
* @param options
|
763
|
+
*/
|
764
|
+
viewUI(options = {}) {
|
765
|
+
var _a, _b, _c;
|
766
|
+
if (Object.entries(options).length === 0) {
|
767
|
+
options = { annotationCanvas: true, labelCanvas: true, canvasMusicPlayer: true, scoreRects: true, manipulatorCanvas: true, sidebarContainer: true, btnToolbar: true, customToolbar: true, groups: true };
|
768
|
+
}
|
769
|
+
for (const [key, value] of Object.entries(options)) {
|
770
|
+
if (value) {
|
771
|
+
if (key === "groups") {
|
772
|
+
((_a = document.getElementById(this.containerId)) === null || _a === void 0 ? void 0 : _a.querySelectorAll("[role=\"group\"]")).forEach(g => g.classList.remove("hideUI")); // style.setProperty("display", "none", "important"))
|
773
|
+
}
|
774
|
+
else {
|
775
|
+
(_c = (_b = document.getElementById(this.containerId)) === null || _b === void 0 ? void 0 : _b.querySelector("#" + key)) === null || _c === void 0 ? void 0 : _c.classList.remove("hideUI"); //style.setProperty("display", "none", "important")
|
776
|
+
}
|
777
|
+
}
|
778
|
+
}
|
779
|
+
}
|
780
|
+
/**
|
781
|
+
* Note Input will be disabled. All other interactions stay active.
|
782
|
+
*/
|
783
|
+
noteInputSwitch(toggle) {
|
784
|
+
var _a, _b, _c, _d;
|
785
|
+
this.noteInputToggle = toggle;
|
786
|
+
if (toggle === "off") {
|
787
|
+
(_a = this.insertModeHandler) === null || _a === void 0 ? void 0 : _a.disableNoteInput();
|
788
|
+
(_b = this.noteDragHandler) === null || _b === void 0 ? void 0 : _b.removeListeners();
|
789
|
+
}
|
790
|
+
else if (toggle === "on") {
|
791
|
+
(_c = this.insertModeHandler) === null || _c === void 0 ? void 0 : _c.enableNoteInput();
|
792
|
+
(_d = this.noteDragHandler) === null || _d === void 0 ? void 0 : _d.setListeners();
|
793
|
+
}
|
794
|
+
else {
|
795
|
+
console.log(arguments.callee.name, toggle + " has no effect!");
|
796
|
+
}
|
797
|
+
}
|
798
|
+
////////// GETTER/ SETTER
|
799
|
+
/**
|
800
|
+
*
|
801
|
+
* @returns current Mouse2SVG Instance
|
802
|
+
*/
|
803
|
+
getMouse2SVG() {
|
804
|
+
return this.m2s;
|
805
|
+
}
|
806
|
+
getDeleteHandler() {
|
807
|
+
return this.deleteHandler;
|
808
|
+
}
|
809
|
+
getInsertModeHandler() {
|
810
|
+
return this.insertModeHandler;
|
811
|
+
}
|
812
|
+
getCurrentMEI(asDocument = true) {
|
813
|
+
if (asDocument) {
|
814
|
+
var meiDoc = meiConverter.meiToDoc(this.currentMEI);
|
815
|
+
meiDoc = meiConverter.standardizeAccid(meiDoc);
|
816
|
+
return meiDoc;
|
817
|
+
}
|
818
|
+
return this.currentMEI;
|
819
|
+
}
|
820
|
+
/**
|
821
|
+
* Get SVG of the current container.
|
822
|
+
* @param {boolean} [plain=true] - delete classes which would result in coloration of the score
|
823
|
+
* @returns {string} - serialized svg
|
824
|
+
*/
|
825
|
+
getSVG(plain = true) {
|
826
|
+
var svgDom = this.container; //.querySelector("#svgContainer")
|
827
|
+
if (plain) {
|
828
|
+
svgDom.querySelectorAll(".lastAdded, .marked").forEach(sd => {
|
829
|
+
sd.classList.remove("lastAdded");
|
830
|
+
sd.classList.remove("marked");
|
831
|
+
});
|
832
|
+
}
|
833
|
+
return new XMLSerializer().serializeToString(svgDom);
|
834
|
+
}
|
835
|
+
getNoteDragHandler() {
|
836
|
+
return this.noteDragHandler;
|
837
|
+
}
|
838
|
+
getGlobalKeyboardHandler() {
|
839
|
+
return this.globalKeyboardHandler;
|
840
|
+
}
|
841
|
+
getSidebarHandler() {
|
842
|
+
return this.sidebarHandler;
|
843
|
+
}
|
844
|
+
getLabelHandler() {
|
845
|
+
return this.labelHandler;
|
846
|
+
}
|
847
|
+
getModifierHandler() {
|
848
|
+
return this.modHandler;
|
849
|
+
}
|
850
|
+
getWindowHandler() {
|
851
|
+
return this.windowHandler;
|
852
|
+
}
|
853
|
+
getCurrentMidi() {
|
854
|
+
return this.currentMidi;
|
855
|
+
}
|
856
|
+
getMusicProcessor() {
|
857
|
+
return this.musicProcessor;
|
858
|
+
}
|
859
|
+
getScoreGraph() {
|
860
|
+
return this.scoreGraph;
|
861
|
+
}
|
862
|
+
getContainer() {
|
863
|
+
return this.container;
|
864
|
+
}
|
865
|
+
/**
|
866
|
+
* Access Verovio from outside of score editor.
|
867
|
+
* Use getToolkit method to access any method which is not wrapped
|
868
|
+
* @returns VerovioWrapper instance
|
869
|
+
*/
|
870
|
+
getVerovioWrapper() {
|
871
|
+
return this.verovioWrapper;
|
872
|
+
}
|
873
|
+
setMEIChangedCallback(meiChangedCallback) {
|
874
|
+
this.meiChangedCallback = meiChangedCallback;
|
875
|
+
}
|
876
|
+
setHideUI(hide) {
|
877
|
+
this.doHideUI = hide;
|
878
|
+
}
|
879
|
+
setHideOptions(options) {
|
880
|
+
this.hideOptions = options;
|
881
|
+
}
|
882
|
+
/**
|
883
|
+
* Set Attibutes for any element in the result svg as {selector: {attributeName: [values as string]}}.
|
884
|
+
* By default will be concatenated with spaces as value string for this attribute
|
885
|
+
* @param options
|
886
|
+
* @param separator optional separator, default: " "
|
887
|
+
*/
|
888
|
+
setAttributes(options, separator = " ") {
|
889
|
+
var svg = cq.getVrvSVG(this.containerId);
|
890
|
+
for (const [elKey, elValue] of Object.entries(options)) {
|
891
|
+
var element = svg.querySelector(elKey);
|
892
|
+
if (element !== null) {
|
893
|
+
for (const [attrKey, attrValue] of Object.entries(elValue)) {
|
894
|
+
element.setAttribute(attrKey, attrValue.join(separator));
|
895
|
+
}
|
896
|
+
}
|
897
|
+
}
|
898
|
+
}
|
899
|
+
setAttributeOptions(options) {
|
900
|
+
this.attributeOptions = options;
|
901
|
+
return this;
|
902
|
+
}
|
903
|
+
/**
|
904
|
+
* Set Styles for any element in the result svg as {selector: {attributeName: [values as string]}}.
|
905
|
+
* By default will be concatenated with spaces as value string for this attribute
|
906
|
+
* @param options
|
907
|
+
* @param separator optional separator, default: " "
|
908
|
+
*/
|
909
|
+
setStyles(options, separator = " ") {
|
910
|
+
var svg = cq.getVrvSVG(this.containerId);
|
911
|
+
for (const [elKey, elValue] of Object.entries(options)) {
|
912
|
+
var element = svg.querySelector(elKey);
|
913
|
+
if (element !== null) {
|
914
|
+
for (const [styleKey, styleValue] of Object.entries(elValue)) {
|
915
|
+
var importantIdx = styleValue.indexOf("important");
|
916
|
+
if (importantIdx === -1) {
|
917
|
+
element.style.setProperty(styleKey, styleValue.join(separator));
|
918
|
+
}
|
919
|
+
else {
|
920
|
+
var important = styleValue.splice(importantIdx, 1)[0];
|
921
|
+
element.style.setProperty(styleKey, styleValue.join(separator), important);
|
922
|
+
}
|
923
|
+
}
|
924
|
+
}
|
925
|
+
}
|
926
|
+
}
|
927
|
+
setStyleOptions(options) {
|
928
|
+
this.styleOptions = options;
|
929
|
+
return this;
|
930
|
+
}
|
931
|
+
}
|
932
|
+
exports.default = Core;
|