vibe-editor 0.0.0 → 0.0.1-dev

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.
Files changed (38) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +12 -9
  3. package/package.json +11 -5
  4. package/src/scripts/js/Core.js +212 -186
  5. package/src/scripts/js/MusicProcessor.js +286 -128
  6. package/src/scripts/js/{VerovioScoreEditor.js → VIBE.js} +62 -28
  7. package/src/scripts/js/assets/mei_template.js +5 -1
  8. package/src/scripts/js/datastructures/MeasureMatrix.js +6 -85
  9. package/src/scripts/js/datastructures/ScoreGraph.js +1 -1
  10. package/src/scripts/js/entry.js +3 -2
  11. package/src/scripts/js/gui/Annotations.js +188 -111
  12. package/src/scripts/js/gui/HarmonyLabel.js +26 -2
  13. package/src/scripts/js/gui/ScoreManipulator.js +61 -31
  14. package/src/scripts/js/gui/Tabbar.js +41 -21
  15. package/src/scripts/js/gui/Toolbar.js +4 -4
  16. package/src/scripts/js/handlers/AnnotationChangeHandler.js +131 -60
  17. package/src/scripts/js/handlers/ClickModeHandler.js +406 -143
  18. package/src/scripts/js/handlers/CustomToolbarHandler.js +26 -24
  19. package/src/scripts/js/handlers/GlobalKeyboardHandler.js +12 -7
  20. package/src/scripts/js/handlers/InsertModeHandler.js +26 -32
  21. package/src/scripts/js/handlers/KeyModeHandler.js +12 -86
  22. package/src/scripts/js/handlers/LabelHandler.js +3 -2
  23. package/src/scripts/js/handlers/PhantomElementHandler.js +1 -1
  24. package/src/scripts/js/handlers/ScoreManipulatorHandler.js +101 -14
  25. package/src/scripts/js/handlers/SelectionHandler.js +80 -36
  26. package/src/scripts/js/handlers/SideBarHandler.js +10 -3
  27. package/src/scripts/js/handlers/WindowHandler.js +25 -4
  28. package/src/scripts/js/utils/DOMCreator.js +1 -1
  29. package/src/scripts/js/utils/MEIConverter.js +13 -1
  30. package/src/scripts/js/utils/MEIOperations.js +180 -187
  31. package/src/scripts/js/utils/Mouse2SVG.js +200 -43
  32. package/src/scripts/js/utils/ReactWrapper.js +46 -0
  33. package/src/scripts/js/utils/RectWrapper.js +10 -0
  34. package/src/scripts/js/utils/SVGEditor.js +94 -3
  35. package/src/scripts/js/utils/VerovioWrapper.js +6 -1
  36. package/src/scripts/js/utils/convenienceQueries.js +2 -0
  37. package/src/scripts/js/utils/mappings.js +322 -56
  38. package/src/styles/VerovioScoreEditor.css +0 -694
@@ -23,25 +23,27 @@ const cq = require("./utils/convenienceQueries");
23
23
  const coordinates = require("./utils/coordinates");
24
24
  const TooltipHandler_1 = require("./handlers/TooltipHandler");
25
25
  /**
26
- * The core component the Editor. This manages the database,
27
- * the verovio toolkit, the cache, and undo/redo stacks.
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.
28
29
  */
29
30
  class Core {
30
31
  constructor(containerId) {
31
32
  this.firstStart = true;
32
33
  this.noteInputToggle = "on";
33
- this.reloadDataFunction = (function reloadData() {
34
- return this.loadData(this.currentMEI, false);
34
+ this.reloadDataHandler = (function reloadDataHandler() {
35
+ return this.reloadData();
35
36
  }).bind(this);
36
- this.loadDataFunction = (function loadDataFunction(pageURI, data, isUrl) {
37
- return this.loadData(data, isUrl, { changeOnPageNo: pageURI });
37
+ this.loadDataHandler = (function loadDataHandler(pageURI, data, isUrl, options = null) {
38
+ return this.loadData(data, isUrl, Object.assign({ changeOnPageNo: pageURI }, options));
38
39
  }).bind(this);
39
40
  /**
40
41
  * Provides AligFunction for Tabbar. alignFunction will be first set, when musicprocessor will instantiated
41
42
  */
42
- this.alignFunctionCall = (function alignFunction(file) {
43
- var _a;
44
- (_a = this.musicProcessor) === null || _a === void 0 ? void 0 : _a.align(file);
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);
45
47
  }).bind(this);
46
48
  /**
47
49
  * Delete array of notes from score
@@ -186,8 +188,11 @@ class Core {
186
188
  document.getElementById(this.containerId).dispatchEvent(new Event("loadingStart"));
187
189
  var that = this;
188
190
  this.svgEditor.setContainerId(this.containerId);
191
+ this.svgEditor.cacheClasses().cacheScales().cacheStyles();
192
+ //this function renders the pages via the veroviowrapper
189
193
  async function render(pageNo = 1, options = null) {
190
194
  return new Promise((resolve, reject) => {
195
+ var _a;
191
196
  var message = {
192
197
  id: random_1.uuidv4(),
193
198
  action: 'renderToSVG',
@@ -205,7 +210,7 @@ class Core {
205
210
  try {
206
211
  // delete old svg
207
212
  if (cq.getVrvSVG(that.containerId).querySelector("#" + pageId) !== null) {
208
- that.svgEditor.cacheClasses().cacheScales();
213
+ //that.svgEditor.cacheClasses().cacheScales()
209
214
  cq.getVrvSVG(that.containerId).querySelector("#" + pageId).innerHTML = ""; //.remove()
210
215
  }
211
216
  //insert new complete svg
@@ -213,59 +218,29 @@ class Core {
213
218
  cq.getVrvSVG(that.containerId).querySelector("#" + pageId).replaceWith(pageElement);
214
219
  }
215
220
  catch (error) {
216
- document.querySelector("#" + that.containerId + " #vrvSVG").append(pageElement);
221
+ (_a = document.querySelector("#" + that.containerId + " #vrvSVG")) === null || _a === void 0 ? void 0 : _a.append(pageElement);
217
222
  }
218
223
  that.svgEditor.distributeIds(pageElement.querySelector(".definition-scale"));
219
224
  pageElement.setAttribute("preserveAspectRatio", "xMinYMin meet");
220
225
  var systemHeigth = pageElement.querySelector(".system").getBoundingClientRect().height;
221
226
  systemHeigth += systemHeigth * 0.2;
222
227
  that.verovioWrapper.setHeightValue(systemHeigth);
228
+ if (options === null || options === void 0 ? void 0 : options.widthFactor) {
229
+ console.log("pageW before", that.verovioWrapper.getOptions().pageWidth);
230
+ that.verovioWrapper.setWidthValue(parseFloat(that.verovioWrapper.getOptions().pageWidth) * options.widthFactor);
231
+ console.log("pageW after", that.verovioWrapper.getOptions().pageWidth);
232
+ }
223
233
  resolve();
224
234
  });
225
235
  }
226
236
  //END ASYNC FUNCTION RENDER
227
237
  return new Promise((resolve, reject) => {
228
238
  var _a, _b, _c, _d, _e;
229
- var d;
230
- var u;
231
- var type = data === null || data === void 0 ? void 0 : data.constructor.name;
232
- switch (type) {
233
- case 'String':
234
- data = meiConverter.reformatMEI(data);
235
- d = data;
236
- u = isUrl;
237
- break;
238
- case 'XMLDocument':
239
- data = meiOperation.disableFeatures(["grace", "arpeg"], data); // for Debugging
240
- that.svgEditor.copyClassesFromMei(data);
241
- d = new XMLSerializer().serializeToString(data);
242
- u = false;
243
- break;
244
- case 'HTMLUnknownElement':
245
- d = new XMLSerializer().serializeToString(data);
246
- u = false;
247
- break;
248
- case undefined:
249
- d = new mei_template_1.default().emptyMEI();
250
- u = false;
251
- break;
252
- default:
253
- reject("Wrong Datatype: " + type);
254
- break;
255
- }
256
- //just render the data once to make pagecount accessible
257
- var message = {
258
- id: random_1.uuidv4(),
259
- action: 'renderData',
260
- mei: d,
261
- isUrl: u
262
- };
263
- this.verovioWrapper.setMessage(message);
239
+ this.sendDataToVerovio(data, isUrl);
264
240
  var pageGroup = document.createElement("g");
265
241
  pageGroup.setAttribute("id", "vrvSVG");
266
242
  if (cq.getVrvSVG(that.containerId) !== null) {
267
243
  that.svgEditor.cacheClasses().cacheScales();
268
- //cq.getVrvSVG(that.containerId).remove()
269
244
  }
270
245
  if (!cq.getVrvSVG(that.containerId))
271
246
  document.querySelector("#" + that.containerId + "> #svgContainer").append(pageGroup);
@@ -295,94 +270,181 @@ class Core {
295
270
  }
296
271
  renderPromises.push(setTimeout(function () { render(pageNo, options); }, 1));
297
272
  });
273
+ //Each page will be redered seperatly
298
274
  Promise.all(renderPromises).then(() => {
299
275
  document.body.classList.remove(waitingFlag);
300
- var that = this;
301
- setTimeout(function () {
276
+ resolve(that.initAfterRender());
277
+ });
278
+ });
279
+ }
280
+ sendDataToVerovio(data, isUrl) {
281
+ var d;
282
+ var u;
283
+ var type = data === null || data === void 0 ? void 0 : data.constructor.name;
284
+ switch (type) {
285
+ case 'String':
286
+ data = meiConverter.reformatMEI(data);
287
+ d = data;
288
+ u = isUrl;
289
+ break;
290
+ case 'XMLDocument':
291
+ data = meiOperation.disableFeatures(["grace", "arpeg"], data); // for Debugging
292
+ this.svgEditor.copyClassesFromMei(data);
293
+ d = new XMLSerializer().serializeToString(data);
294
+ u = false;
295
+ break;
296
+ case 'HTMLUnknownElement':
297
+ d = new XMLSerializer().serializeToString(data);
298
+ u = false;
299
+ break;
300
+ case undefined:
301
+ d = new mei_template_1.default().emptyMEI();
302
+ u = false;
303
+ break;
304
+ default:
305
+ console.log("Wrong Datatype: " + type);
306
+ break;
307
+ }
308
+ //just render the data once to make pagecount accessible
309
+ var message = {
310
+ id: random_1.uuidv4(),
311
+ action: 'renderData',
312
+ mei: d,
313
+ isUrl: u
314
+ };
315
+ this.verovioWrapper.setMessage(message);
316
+ }
317
+ /**
318
+ * Init attributes for the svg, creat svg overlay and distribute/ init handlers.
319
+ * @returns
320
+ */
321
+ initAfterRender() {
322
+ var that = this;
323
+ return new Promise((resolve, reject) => {
324
+ setTimeout(function () {
325
+ var _a, _b;
326
+ that.svgEditor.drawLinesUnderSystems();
327
+ that.svgEditor.modifyHarm();
328
+ that.createSVGOverlay(true);
329
+ 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());
330
+ that.getMEI("").then(mei => {
302
331
  var _a, _b;
303
- that.svgEditor.drawLinesUnderSystems();
304
- that.svgEditor.modifyHarm();
305
- that.createSVGOverlay(true);
306
- 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());
307
- that.getMEI("").then(mei => {
308
- var _a;
309
- that.currentMEI = mei;
310
- that.currentMEIDoc = that.getCurrentMEI(true);
311
- that.svgEditor.markOverfilledMeasures(that.currentMEIDoc);
312
- //console.log(that.currentMEIDoc)
313
- that.svgEditor
314
- .setContainerId(that.containerId)
315
- .loadClasses()
316
- .fillSVG(that.currentMEIDoc);
317
- that.undoMEIStacks.push(mei);
318
- var lastAddedClass = "lastAdded";
319
- document.querySelectorAll("." + lastAddedClass).forEach(m => {
320
- m.classList.remove(lastAddedClass);
321
- });
322
- if (that.lastInsertedNoteId != undefined && ["textmode", "clickmode"].some(mode => that.container.classList.contains(mode))) {
323
- (_a = that.container.querySelector("#" + that.lastInsertedNoteId)) === null || _a === void 0 ? void 0 : _a.classList.add(lastAddedClass);
332
+ that.currentMEI = mei;
333
+ that.currentMEIDoc = that.getCurrentMEI(true);
334
+ that.currentMEIDoc.querySelectorAll("[dur='breve']").forEach(d => d.setAttribute("dur", "0.5"));
335
+ if (that.currentMEIDoc.querySelector("parsererror")) {
336
+ try {
337
+ throw new Error("ParsingError");
324
338
  }
325
- if (that.meiChangedCallback != undefined) {
326
- that.meiChangedCallback(that.currentMEI);
339
+ catch (error) {
340
+ console.error("There is a parsingerror in the meiDoc: ", error, that.currentMEIDoc, that.currentMEI);
327
341
  }
342
+ }
343
+ that.svgEditor.markOverfilledMeasures(that.currentMEIDoc);
344
+ that.svgEditor
345
+ .setContainerId(that.containerId)
346
+ .loadClasses()
347
+ .loadStyles()
348
+ .fillSVG(that.currentMEIDoc)
349
+ .setActiveLayer()
350
+ .hideRedundantRests(that.currentMEIDoc);
351
+ that.undoMEIStacks.push(mei);
352
+ var lastAddedClass = "lastAdded";
353
+ that.container.querySelectorAll("." + lastAddedClass).forEach(m => {
354
+ m.classList.remove(lastAddedClass);
328
355
  });
329
- //musicProcessor stuff
330
- that.getMidi().then(midi => {
331
- that.musicProcessor = that.musicProcessor || new MusicProcessor_1.default(that.containerId);
332
- that.musicProcessor
333
- .setMEI(that.currentMEIDoc)
334
- .setMidi(midi)
335
- .addCanvas();
336
- that.getMidiTimesForSymbols().then(md => {
337
- var _a;
338
- that.musicProcessor.setMidiTimes(md);
339
- that.musicProcessor.update();
340
- that.scoreGraph = new ScoreGraph_1.default(that.currentMEIDoc, that.containerId, md);
341
- //the first condition should only occur at first starting the score editor
342
- if (that.container.querySelector(".lastAdded") === null && that.scoreGraph.getCurrentNode() == undefined) {
343
- that.scoreGraph.setCurrentNodeById(that.container.querySelector(".staff > .layer :is(.note, .rest, .mRest").id);
344
- }
345
- else { //second condition always sets lastAdded Note
346
- that.scoreGraph.setCurrentNodeById((_a = that.container.querySelector(".lastAdded")) === null || _a === void 0 ? void 0 : _a.id);
347
- }
348
- that.initializeHandlers();
349
- that.musicProcessor.setScoreGraph(that.scoreGraph);
350
- document.getElementById(that.containerId).dispatchEvent(new Event("loadingEnd"));
351
- that.svg = new XMLSerializer().serializeToString(that.container.querySelector("#svgContainer"));
352
- console.log(that.currentMEIDoc, that.m2s.getMeasureMatrix());
353
- resolve(that.currentMEI);
354
- });
355
- });
356
- }, 1);
357
- });
356
+ if (that.lastInsertedNoteId && ["textmode", "clickmode"].some(mode => that.container.classList.contains(mode))) {
357
+ (_a = that.container.querySelector("#" + that.lastInsertedNoteId)) === null || _a === void 0 ? void 0 : _a.classList.add(lastAddedClass);
358
+ (_b = that.container.querySelector("#" + that.lastInsertedNoteId)) === null || _b === void 0 ? void 0 : _b.classList.add("marked");
359
+ }
360
+ if (that.meiChangedCallback) {
361
+ that.meiChangedCallback(that.currentMEI);
362
+ }
363
+ });
364
+ //Initialize music processor
365
+ that.getTimemap().then(timemap => {
366
+ var _a;
367
+ that.musicProcessor = that.musicProcessor || new MusicProcessor_1.default(that.containerId);
368
+ that.musicProcessor
369
+ .setMEI(that.currentMEIDoc)
370
+ .setMidi(that.verovioWrapper.renderToMidi())
371
+ .setTimemap(timemap)
372
+ .addCanvas()
373
+ .update();
374
+ that.scoreGraph = new ScoreGraph_1.default(that.currentMEIDoc, that.containerId, null);
375
+ //the first condition should only occur at first starting the score editor
376
+ if (that.container.querySelector(".lastAdded") === null && that.scoreGraph.getCurrentNode() == undefined) {
377
+ that.scoreGraph.setCurrentNodeById(that.container.querySelector(".staff > .layer :is(.note, .rest, .mRest").id);
378
+ }
379
+ else { //second condition always sets lastAdded Note
380
+ that.scoreGraph.setCurrentNodeById((_a = that.container.querySelector(".lastAdded")) === null || _a === void 0 ? void 0 : _a.id);
381
+ }
382
+ that.initializeHandlers();
383
+ that.musicProcessor.setScoreGraph(that.scoreGraph);
384
+ document.getElementById(that.containerId).dispatchEvent(new Event("loadingEnd"));
385
+ that.svg = new XMLSerializer().serializeToString(that.container.querySelector("#svgContainer"));
386
+ that.svgEditor.loadClasses();
387
+ console.log(that.currentMEIDoc, that.m2s.getMeasureMatrix());
388
+ resolve(that.currentMEI);
389
+ //})
390
+ });
391
+ }, 1);
392
+ });
393
+ }
394
+ /**
395
+ * Load everything if there is already a svg present. Displaying the visuals is not necessary here.
396
+ * But the MEI has to be loaded with verovio anyway to ensure that options and subsequent loads will have access to the underlying MEI.
397
+ * Only supposed to be used from Main class for first initialisation.
398
+ * @param container container with already rendered svg (usually a container with "vibe-container" class)
399
+ * @param data MEI to be loaded in verovio
400
+ * @returns
401
+ */
402
+ loadWithExistingSVG(container, data, isUrl) {
403
+ return new Promise(resolve => {
404
+ this.container = container;
405
+ this.containerId = container.id;
406
+ this.verovioWrapper = this.verovioWrapper || new VerovioWrapper_1.default();
407
+ var waitingFlag = "waiting";
408
+ // if (cq.getVrvSVG(this.containerId) !== null) {
409
+ // document.body.classList.add(waitingFlag)
410
+ // }
411
+ // svg has to be loaded into verovio anyway
412
+ this.sendDataToVerovio(data, isUrl);
413
+ document.getElementById(this.containerId).dispatchEvent(new Event("loadingStart"));
414
+ this.svgEditor.setContainerId(this.containerId);
415
+ this.svgEditor.cacheClasses().cacheScales().cacheStyles();
416
+ this.initializeHandlers(true, false);
417
+ resolve(this.initAfterRender());
358
418
  });
359
419
  }
420
+ reloadData() {
421
+ return this.loadData(this.currentMEI, false);
422
+ }
360
423
  /**
361
424
  * Initialize Handlers
362
425
  */
363
- initializeHandlers() {
364
- //must be first!!!
365
- if (this.m2s == undefined) {
366
- this.m2s = new Mouse2SVG_1.Mouse2SVG();
367
- }
368
- else {
369
- //this.m2s.update()
426
+ initializeHandlers(initNew = false, dispatch = true) {
427
+ //m2s must be first since all coordinates and interacions are based on positions computed in Mouse2SVG
428
+ this.m2s = initNew ? new Mouse2SVG_1.Mouse2SVG() : this.m2s || new Mouse2SVG_1.Mouse2SVG();
429
+ if (!initNew && dispatch) {
430
+ this.m2s
431
+ .setContainerId(this.containerId)
432
+ .setUpdateOverlayCallback(this.createSVGOverlay)
433
+ .setCurrentMEI(this.currentMEIDoc)
434
+ .update();
370
435
  }
371
- this.m2s
372
- .setContainerId(this.containerId)
373
- .setUpdateOverlayCallback(this.createSVGOverlay)
374
- .setCurrentMEI(this.currentMEIDoc)
375
- .update();
376
- //.setMouseEnterElementListeners()
377
- this.insertModeHandler = this.insertModeHandler || new InsertModeHandler_1.default(this.containerId);
378
- this.deleteHandler = this.deleteHandler || new DeleteHandler_1.default(this.containerId);
436
+ this.insertModeHandler = initNew ? new InsertModeHandler_1.default(this.containerId) : this.insertModeHandler || new InsertModeHandler_1.default(this.containerId);
437
+ this.deleteHandler = initNew ? new DeleteHandler_1.default(this.containerId) : this.deleteHandler || new DeleteHandler_1.default(this.containerId);
379
438
  this.noteDragHandler = new NoteDragHandler_1.default(this.containerId);
380
- this.globalKeyboardHandler = this.globalKeyboardHandler || new GlobalKeyboardHandler_1.default(this.containerId);
381
- this.sidebarHandler = this.sidebarHandler || new SidebarHandler_1.default();
382
- this.labelHandler = this.labelHandler || new LabelHandler_1.default(this.containerId);
383
- this.modHandler = this.modHandler || new CustomToolbarHandler_1.default(this.containerId);
384
- this.tooltipHandler = this.tooltipHandler || new TooltipHandler_1.default();
385
- this.dispatchFunctions();
439
+ this.globalKeyboardHandler = initNew ? new GlobalKeyboardHandler_1.default(this.containerId) : this.globalKeyboardHandler || new GlobalKeyboardHandler_1.default(this.containerId);
440
+ this.sidebarHandler = initNew ? new SidebarHandler_1.default : this.sidebarHandler || new SidebarHandler_1.default();
441
+ this.labelHandler = initNew ? new LabelHandler_1.default(this.containerId) : this.labelHandler || new LabelHandler_1.default(this.containerId);
442
+ this.modHandler = initNew ? new CustomToolbarHandler_1.default(this.containerId) : this.modHandler || new CustomToolbarHandler_1.default(this.containerId);
443
+ this.tooltipHandler = initNew ? new TooltipHandler_1.default() : this.tooltipHandler || new TooltipHandler_1.default();
444
+ this.musicProcessor = initNew ? new MusicProcessor_1.default(this.containerId) : this.musicProcessor || new MusicProcessor_1.default(this.containerId);
445
+ if (dispatch) {
446
+ this.dispatchFunctions();
447
+ }
386
448
  }
387
449
  /**
388
450
  * distribute Callback functions for each element which uses some information from of the Core (Handlers, musicProcessor, Callbacks, etc)
@@ -400,10 +462,10 @@ class Core {
400
462
  .setDeleteHandler(this.deleteHandler)
401
463
  .setLabelHandler(this.labelHandler)
402
464
  .activateHarmonyMode()
403
- .activateSelectionMode()
465
+ //.activateSelectionMode()
404
466
  .setInsertCallback(this.insert)
405
467
  .setDeleteCallback(this.delete)
406
- .setLoadDataCallback(this.loadDataFunction)
468
+ .setLoadDataCallback(this.loadDataHandler)
407
469
  .setUndoAnnotationStacks(this.undoAnnotationStacks)
408
470
  .resetModes()
409
471
  .resetCanvas();
@@ -426,7 +488,7 @@ class Core {
426
488
  .setCurrentMei(this.currentMEIDoc)
427
489
  .setMusicProcessor(this.musicProcessor)
428
490
  .setHarmonyHandlerCallback(this.labelHandler.setHarmonyLabelHandlerKey)
429
- .setLoadDataCallback(this.loadDataFunction)
491
+ .setLoadDataCallback(this.loadDataHandler)
430
492
  .setScoreGraph(this.scoreGraph)
431
493
  .resetLastInsertedNoteCallback(this.resetLastInsertedNoteId)
432
494
  .resetListeners();
@@ -434,7 +496,7 @@ class Core {
434
496
  .setContainerId(this.containerId)
435
497
  .setCurrentMei(this.currentMEIDoc)
436
498
  .setm2s(this.m2s)
437
- .setLoadDataCallback(this.loadDataFunction)
499
+ .setLoadDataCallback(this.loadDataHandler)
438
500
  .loadMeter()
439
501
  .makeScoreElementsClickable()
440
502
  .resetListeners();
@@ -442,13 +504,13 @@ class Core {
442
504
  .setContainerId(this.containerId)
443
505
  .resetListeners()
444
506
  .setCurrentMEI(this.currentMEIDoc)
445
- .setLoadDataCallback(this.loadDataFunction);
507
+ .setLoadDataCallback(this.loadDataHandler);
446
508
  this.windowHandler
447
509
  .setContainerId(this.containerId)
448
510
  .setm2s(this.m2s)
449
511
  .setCurrentMEI(this.currentMEIDoc)
450
- .setLoadDataCallback(this.loadDataFunction)
451
- .setSVGReloadCallback(this.reloadDataFunction)
512
+ .setLoadDataCallback(this.loadDataHandler)
513
+ .setSVGReloadCallback(this.reloadDataHandler)
452
514
  .setAnnotations(this.insertModeHandler.getAnnotations())
453
515
  .setInsertModeHandler(this.insertModeHandler)
454
516
  .resetListeners();
@@ -459,6 +521,8 @@ class Core {
459
521
  // always start from click mode
460
522
  if (this.firstStart) {
461
523
  this.container.querySelector("#notationTabBtn").click();
524
+ this.container.querySelector(".voiceBtn").classList.add("selected");
525
+ this.container.querySelector(".layer").classList.add("activeLayer");
462
526
  this.firstStart = false;
463
527
  }
464
528
  if (this.doHideUI) {
@@ -473,6 +537,8 @@ class Core {
473
537
  if (Object.entries(this.attributeOptions).length > 0) {
474
538
  this.setAttributes(this.attributeOptions);
475
539
  }
540
+ // experimental react implementation of color picker
541
+ //this.container.append(ReactWrapper.createColorPicker("reactContainer"))
476
542
  }
477
543
  ////// VEROVIO REQUESTS /////////////////
478
544
  /**
@@ -504,7 +570,7 @@ class Core {
504
570
  };
505
571
  var response = this.verovioWrapper.setMessage(message);
506
572
  if (response.midi) {
507
- this.currentMidi = response.mei;
573
+ this.currentMidi = response.midi;
508
574
  resolve(response.midi);
509
575
  }
510
576
  else {
@@ -512,55 +578,15 @@ class Core {
512
578
  }
513
579
  });
514
580
  }
515
- /**
516
- * Get all times (tick position) for each event visible in the score (notes, rests, etc.)
517
- * @returns
518
- */
519
- getMidiTimesForSymbols() {
520
- return new Promise((resolve) => {
521
- var noteTimes = new Map();
522
- var that = this;
523
- var container = cq.getVrvSVG(this.containerId);
524
- var midi = that.verovioWrapper.getMidiJSON();
525
- var tracks = midi.tracks;
526
- tracks.forEach((t, tIdx) => {
527
- var svgNotes = container.querySelectorAll(".staff[n=\"" + (tIdx + 1).toString() + "\"] .note");
528
- var prevNote;
529
- t.notes.forEach((n, nIdx) => {
530
- if (!noteTimes.has(n.ticks)) {
531
- noteTimes.set(n.ticks, new Array());
532
- }
533
- var arr = noteTimes.get(n.ticks);
534
- var currNote = svgNotes[nIdx];
535
- //indicaton, that some rests are in between
536
- //trailing rests are intentionally left out, since there is nothing to play anyway
537
- if ((prevNote === null || prevNote === void 0 ? void 0 : prevNote.midi.ticks) + (prevNote === null || prevNote === void 0 ? void 0 : prevNote.midi.durationTicks) != n.ticks) {
538
- var elements = container.querySelectorAll(".staff[n=\"" + (tIdx + 1).toString() + "\"] .note, .staff[n=\"" + (tIdx + 1).toString() + "\"] .rest");
539
- var elementIds = Array.from(elements).map(e => e.id);
540
- var sliceLeft = prevNote == undefined && n.ticks > 0 ? 0 : undefined;
541
- sliceLeft = prevNote != undefined ? elementIds.findIndex(eid => eid === prevNote.svg.id) + 1 : 0;
542
- var sliceRight = elementIds.findIndex(eid => eid === currNote.id) - 1;
543
- var slicedElementIds = elementIds.slice(sliceLeft, sliceRight);
544
- var currentTickPos = (prevNote === null || prevNote === void 0 ? void 0 : prevNote.midi.ticks) + (prevNote === null || prevNote === void 0 ? void 0 : prevNote.midi.durationTicks) || 0;
545
- slicedElementIds.forEach(id => {
546
- var ratio = meiOperation.getAbsoluteRatio(this.currentMEIDoc.getElementById(id));
547
- var tickDur = 4 * ratio * midi.header.ppq;
548
- if (!noteTimes.has(currentTickPos)) {
549
- noteTimes.set(currentTickPos, new Array());
550
- }
551
- var restArr = noteTimes.get(currentTickPos);
552
- restArr.push(container.querySelector("#" + id));
553
- currentTickPos += tickDur;
554
- });
555
- }
556
- arr.push(currNote);
557
- prevNote = {
558
- midi: n,
559
- svg: svgNotes[nIdx]
560
- };
561
- });
562
- });
563
- resolve(noteTimes);
581
+ getTimemap() {
582
+ return new Promise((resolve, reject) => {
583
+ const timemap = this.verovioWrapper.getTimemap();
584
+ if (timemap) {
585
+ resolve(timemap);
586
+ }
587
+ else {
588
+ reject("fail!");
589
+ }
564
590
  });
565
591
  }
566
592
  /**
@@ -572,7 +598,7 @@ class Core {
572
598
  document.getElementById(this.containerId).focus();
573
599
  var refSVG = document.getElementById(this.containerId).querySelector("#vrvSVG");
574
600
  this.interactionOverlay = document.getElementById(this.containerId).querySelector("#interactionOverlay");
575
- if (this.interactionOverlay === null) {
601
+ if (!this.interactionOverlay) {
576
602
  var overlay = document.createElementNS(constants_1.constants._SVGNS_, "svg");
577
603
  overlay.setAttribute("id", "interactionOverlay");
578
604
  this.interactionOverlay = overlay;
@@ -581,15 +607,15 @@ class Core {
581
607
  var vrvContainer = cq.getVrvSVG(this.containerId);
582
608
  var root = svgContainer.getBoundingClientRect().height > vrvContainer.getBoundingClientRect().height ? svgContainer : vrvContainer;
583
609
  var rootBBox = root.getBoundingClientRect();
584
- var rootWidth = (rootBBox.width).toString();
585
- var rootHeigth = (rootBBox.height).toString();
586
- //if (this.interactionOverlay.getAttribute("viewBox") === null) {
587
- this.interactionOverlay.setAttribute("viewBox", ["0", "0", rootWidth, rootHeigth].join(" "));
588
- //}
610
+ var rootWidth = rootBBox.width;
611
+ var rootHeigth = rootBBox.height;
612
+ if (!this.interactionOverlay.getAttribute("viewBox")) {
613
+ this.interactionOverlay.setAttribute("viewBox", ["0", "0", rootWidth.toString(), rootHeigth.toString()].join(" "));
614
+ }
589
615
  (_a = document.getElementById(this.containerId).querySelector("#interactionOverlay #scoreRects")) === null || _a === void 0 ? void 0 : _a.remove();
590
616
  var scoreRects = document.createElementNS(constants_1.constants._SVGNS_, "svg");
591
617
  scoreRects.setAttribute("id", "scoreRects");
592
- scoreRects.setAttribute("viewBox", ["0", "0", rootWidth, rootHeigth].join(" "));
618
+ //scoreRects.setAttribute("viewBox", ["0", "0", rootWidth.toString(), rootHeigth.toString()].join(" "))
593
619
  Array.from(refSVG.attributes).forEach(a => {
594
620
  if (!["id", "width", "height"].includes(a.name)) {
595
621
  this.interactionOverlay.setAttribute(a.name, a.value);