vibe-editor 0.0.3 → 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.
Files changed (87) hide show
  1. package/package.json +65 -61
  2. package/src/scripts/js/Core.js +32 -13
  3. package/src/scripts/js/entry.js +6 -5
  4. package/src/scripts/js/gui/Annotations.js +28 -13
  5. package/src/scripts/js/gui/ScoreManipulator.js +13 -11
  6. package/src/scripts/js/gui/Tabbar.js +14 -5
  7. package/src/scripts/js/gui/Toolbar.js +1 -1
  8. package/src/scripts/js/handlers/AnnotationChangeHandler.js +16 -4
  9. package/src/scripts/js/handlers/CustomAnnotationShapeDrawer.js +2 -2
  10. package/src/scripts/js/handlers/InsertModeHandler.js +7 -7
  11. package/src/scripts/js/handlers/KeyModeHandler.js +1 -1
  12. package/src/scripts/js/handlers/LabelHandler.js +1 -1
  13. package/src/scripts/js/handlers/NoteDragHandler.js +1 -1
  14. package/src/scripts/js/handlers/PhantomElementHandler.js +3 -10
  15. package/src/scripts/js/handlers/{SideBarHandler.js → SidebarHandler.js} +1 -1
  16. package/src/scripts/js/handlers/TooltipHandler.js +1 -1
  17. package/src/scripts/js/handlers/WindowHandler.js +7 -7
  18. package/src/scripts/js/scripts/Core.js +932 -0
  19. package/src/scripts/js/scripts/MusicProcessor.js +810 -0
  20. package/src/scripts/js/scripts/VIBE.js +219 -0
  21. package/src/scripts/js/{assets → scripts/assets}/mei_template.js +2 -2
  22. package/src/scripts/js/scripts/datastructures/MeasureMatrix.js +156 -0
  23. package/src/scripts/js/scripts/gui/Annotations.js +549 -0
  24. package/src/scripts/js/scripts/gui/Cursor.js +203 -0
  25. package/src/scripts/js/{gui → scripts/gui}/HarmonyLabel.js +1 -1
  26. package/src/scripts/js/scripts/gui/PhantomElement.js +132 -0
  27. package/src/scripts/js/scripts/gui/ScoreManipulator.js +188 -0
  28. package/src/scripts/js/scripts/gui/Tabbar.js +705 -0
  29. package/src/scripts/js/{gui → scripts/gui}/TempoLabel.js +1 -1
  30. package/src/scripts/js/{gui/Toolbar copy.js → scripts/gui/Toolbar.js} +15 -11
  31. package/src/scripts/js/scripts/handlers/AnnotationChangeHandler.js +650 -0
  32. package/src/scripts/js/scripts/handlers/ClickModeHandler.js +535 -0
  33. package/src/scripts/js/{gui → scripts/handlers}/CustomAnnotationShapeDrawer.js +34 -17
  34. package/src/scripts/js/{handlers/ModHandler.js → scripts/handlers/CustomToolbarHandler.js} +54 -66
  35. package/src/scripts/js/scripts/handlers/GlobalKeyboardHandler.js +372 -0
  36. package/src/scripts/js/scripts/handlers/Handler.js +2 -0
  37. package/src/scripts/js/{handlers/InsertModeHandler_deprecated.js → scripts/handlers/InsertModeHandler.js} +117 -164
  38. package/src/scripts/js/scripts/handlers/KeyModeHandler.js +405 -0
  39. package/src/scripts/js/scripts/handlers/LabelHandler.js +463 -0
  40. package/src/scripts/js/scripts/handlers/NoteDragHandler.js +97 -0
  41. package/src/scripts/js/scripts/handlers/PhantomElementHandler.js +168 -0
  42. package/src/scripts/js/scripts/handlers/ScoreManipulatorHandler.js +233 -0
  43. package/src/scripts/js/scripts/handlers/SidebarHandler.js +506 -0
  44. package/src/scripts/js/scripts/handlers/TooltipHandler.js +132 -0
  45. package/src/scripts/js/scripts/handlers/WindowHandler.js +278 -0
  46. package/src/scripts/js/scripts/utils/MEIOperations.js +2121 -0
  47. package/src/scripts/js/{utils/Mouse2MEI.js → scripts/utils/Mouse2SVG.js} +225 -57
  48. package/src/scripts/js/{utils → scripts/utils}/ReactWrapper.js +1 -1
  49. package/src/scripts/js/scripts/utils/SVGEditor.js +453 -0
  50. package/src/scripts/js/scripts/utils/Types.js +2 -0
  51. package/src/scripts/js/{utils/VerovioWrapper copy.js → scripts/utils/VerovioWrapper.js} +35 -21
  52. package/src/scripts/js/scripts/utils/coordinates.js +54 -0
  53. package/src/scripts/js/utils/MEIOperations.js +22 -22
  54. package/src/scripts/js/utils/Mouse2SVG.js +13 -6
  55. package/src/scripts/js/utils/SVGEditor.js +2 -2
  56. package/src/scripts/js/utils/VerovioWrapper.js +4 -4
  57. package/src/scripts/js/utils/coordinates.js +26 -2
  58. package/src/scripts/js/.DS_Store +0 -0
  59. package/src/scripts/js/MusicPlayer.js +0 -572
  60. package/src/scripts/js/datastructures/ScoreGraph copy.js +0 -432
  61. package/src/scripts/js/gui/CustomAnnotationDrawer.js +0 -114
  62. package/src/scripts/js/handlers/AnnotationDragHandler.js +0 -113
  63. package/src/scripts/js/handlers/AnnotationLineHandler.js +0 -113
  64. package/src/scripts/js/handlers/ArticulationHandler.js +0 -20
  65. package/src/scripts/js/handlers/HarmonyHandler.js +0 -282
  66. package/src/scripts/js/handlers/InsertModeHandler copy.js +0 -423
  67. package/src/scripts/js/handlers/KeyModeHandler copy.js +0 -407
  68. package/src/scripts/js/handlers/KeyModeHandler_deprecated.js +0 -411
  69. package/src/scripts/js/handlers/NoteDragHandler copy.js +0 -148
  70. package/src/scripts/js/handlers/NoteDragHandler_deprecated.js +0 -150
  71. package/src/scripts/js/handlers/SelectionHandler.js +0 -262
  72. package/src/scripts/js/utils/RectWrapper.js +0 -10
  73. package/src/scripts/js/utils/SVGFiller.js +0 -245
  74. package/src/scripts/js/utils/VerovioWrapperLocal.js +0 -156
  75. package/src/scripts/js/utils/firefoxBBoxes.js +0 -143
  76. package/src/styles/vibe.css +0 -785
  77. /package/src/scripts/js/{constants.js → scripts/constants.js} +0 -0
  78. /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreGraph.js +0 -0
  79. /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreGraph_deprecated.js +0 -0
  80. /package/src/scripts/js/{datastructures → scripts/datastructures}/ScoreNode.js +0 -0
  81. /package/src/scripts/js/{gui → scripts/gui}/Label.js +0 -0
  82. /package/src/scripts/js/{handlers → scripts/handlers}/DeleteHandler.js +0 -0
  83. /package/src/scripts/js/{utils → scripts/utils}/DOMCreator.js +0 -0
  84. /package/src/scripts/js/{utils → scripts/utils}/MEIConverter.js +0 -0
  85. /package/src/scripts/js/{utils → scripts/utils}/convenienceQueries.js +0 -0
  86. /package/src/scripts/js/{utils → scripts/utils}/mappings.js +0 -0
  87. /package/src/scripts/js/{utils → scripts/utils}/random.js +0 -0
@@ -1,411 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Cursor_1 = require("../gui/Cursor");
4
- const mappings_1 = require("../utils/mappings");
5
- const random_1 = require("../utils/random");
6
- const cq = require("../utils/convenienceQueries");
7
- const marked = "marked";
8
- /**
9
- * @deprecated
10
- */
11
- class KeyModeHandler {
12
- constructor(containerId) {
13
- /**
14
- * Event handler for inserting Notes
15
- */
16
- this.keyModeHandler = (function keyModeHandler(e) {
17
- var _a;
18
- if (!cq.hasActiveElement(this.containerId))
19
- return;
20
- if (this.musicPlayer.getIsPlaying() === true) {
21
- return;
22
- } // getIsPlaying could also be undefined
23
- if (mappings_1.keyCodeNoteMap.has(e.code) && typeof this.cursor != undefined) {
24
- e.preventDefault();
25
- var pname = mappings_1.keyCodeNoteMap.get(e.code);
26
- var oct = mappings_1.octToNum.get((_a = this.container.querySelector("#octaveGroupKM .selected")) === null || _a === void 0 ? void 0 : _a.id) || "4";
27
- const newNote = this.createNewNote(pname, oct, null);
28
- if (newNote == undefined)
29
- return;
30
- var noteExists = false;
31
- var noteToDelete;
32
- if (this.cursor.nextElement.classList.contains("chord")) {
33
- var chordNotes = Array.from(this.cursor.nextElement.querySelectorAll(".note"));
34
- chordNotes.forEach((n) => {
35
- var meiNote = this.m2m.getCurrentMei().getElementById(n.id);
36
- var sameOct = meiNote.getAttribute("oct") === newNote.oct;
37
- var samePname = meiNote.getAttribute("pname") === newNote.pname;
38
- if (sameOct && samePname) {
39
- noteExists = true;
40
- noteToDelete = n;
41
- }
42
- });
43
- }
44
- if (!noteExists) {
45
- var replace = this.container.querySelector("#insertToggle").checked;
46
- this.insertCallback(newNote, replace).then(() => {
47
- this.m2m.update();
48
- this.resetListeners();
49
- var currentTargetId;
50
- if (newNote.chordElement != undefined) {
51
- currentTargetId = this.rootSVG.querySelector("#" + newNote.chordElement.id).closest(".chord").id; // new chord with own ID is created, if note is added
52
- }
53
- else {
54
- currentTargetId = newNote.id;
55
- }
56
- this.scoreGraph.setCurrentNodeById(currentTargetId);
57
- if (this.scoreGraph.getCurrentNode() != undefined) {
58
- this.cursor.definePosById(this.scoreGraph.getCurrentNode().getId());
59
- }
60
- this.musicPlayer.generateTone(newNote);
61
- }).catch(() => {
62
- //alert("your bar is too small")
63
- });
64
- }
65
- else {
66
- this.deleteCallback([noteToDelete]).then(() => {
67
- var _a;
68
- this.m2m.update();
69
- this.resetListeners();
70
- this.scoreGraph.setCurrentNodeById(newNote.chordElement.id);
71
- this.cursor.definePosById((_a = this.scoreGraph.getCurrentNode()) === null || _a === void 0 ? void 0 : _a.getId());
72
- });
73
- }
74
- }
75
- }).bind(this);
76
- this.pressedHandler = (function pressedHandler(e) {
77
- this.assignKeys(e);
78
- }).bind(this);
79
- /**
80
- * Event Handler for any Keyboard input (except inserting)
81
- */
82
- this.keyInputHandler = (function keyInputHandler(e) {
83
- var _a, _b;
84
- if (!cq.hasActiveElement(this.containerId))
85
- return;
86
- if (e.ctrlKey || e.metaKey)
87
- return; //prevent confusion with global keyboard functionalities
88
- if (this.interactionOverlay.querySelector("div[contenteditable=true]") !== null)
89
- return; // prevent navigating in scrore, when label editor is open
90
- //this.setCurrentNodeScoreGraph()
91
- if (this.scoreGraph.getCurrentNode() == undefined) {
92
- (_a = this.scoreGraph) === null || _a === void 0 ? void 0 : _a.setCurrentNodeById((_b = this.cursor) === null || _b === void 0 ? void 0 : _b.getNextElement().id);
93
- }
94
- if (e.shiftKey && e.key.includes("Arrow")) {
95
- e.preventDefault();
96
- this.navigateSelection(e.key);
97
- }
98
- else if (e.key.includes("Arrow")) {
99
- e.preventDefault();
100
- this.endSelection();
101
- this.navigateCursor(e.key);
102
- }
103
- else if (["Delete", "Backspace"].indexOf(e.key) > -1) {
104
- e.preventDefault();
105
- //this.deleteByKey(e.key)
106
- }
107
- }).bind(this);
108
- /**
109
- * Set Cursor to new position after pasting
110
- */
111
- this.pastedHandler = (function pastedHandler(e) {
112
- var _a;
113
- console.log("PASTED ", e);
114
- this.scoreGraph.setCurrentNodeById(e.detail);
115
- this.cursor.definePosById((_a = this.scoreGraph.getCurrentNode()) === null || _a === void 0 ? void 0 : _a.getId());
116
- }).bind(this);
117
- this.setContainerId(containerId);
118
- this.cursor = new Cursor_1.default(containerId);
119
- }
120
- setListeners() {
121
- document.addEventListener("keydown", this.pressedHandler);
122
- document.addEventListener("keyup", this.pressedHandler);
123
- document.addEventListener('keydown', this.keyModeHandler);
124
- document.addEventListener('keydown', this.keyInputHandler);
125
- document.addEventListener("pasted", this.pastedHandler);
126
- this.cursor.setClickListener();
127
- }
128
- removeListeners() {
129
- document.removeEventListener("keydown", this.pressedHandler);
130
- document.removeEventListener("keyup", this.pressedHandler);
131
- document.removeEventListener('keydown', this.keyModeHandler);
132
- document.removeEventListener('keydown', this.keyInputHandler);
133
- document.removeEventListener("pasted", this.pastedHandler);
134
- this.cursor.flashStop();
135
- this.cursor.removeClickListener();
136
- }
137
- resetListeners() {
138
- this.removeListeners();
139
- this.setListeners();
140
- }
141
- assignKeys(e) {
142
- var b = false;
143
- if (e.type === "keydown") {
144
- b = true;
145
- }
146
- else if (e.type === "keyup") {
147
- b = false;
148
- }
149
- switch (e.key) {
150
- case "Shift":
151
- this.shiftDown = b;
152
- break;
153
- }
154
- }
155
- /**
156
- * create a newNote
157
- * @param pname pitch name
158
- * @param oct octave
159
- * @param options
160
- * @returns
161
- */
162
- createNewNote(pname, oct, options) {
163
- var _a, _b;
164
- //get relevant staffinfo
165
- this.setCurrentNodeScoreGraph();
166
- var nearestNodeId = (_a = this.scoreGraph.getCurrentNode()) === null || _a === void 0 ? void 0 : _a.getId();
167
- if (nearestNodeId == undefined)
168
- return;
169
- var closestStaff = ((_b = this.m2m.getCurrentMei().getElementById(nearestNodeId)) === null || _b === void 0 ? void 0 : _b.closest("staff")) || this.m2m.getCurrentMei().querySelector("measure > staff"); //asume first measure first staff
170
- var closestMeasure = closestStaff.closest("measure");
171
- var closestStaffIdx = parseInt(closestStaff.getAttribute("n")) - 1;
172
- var closestMeasureIdx = parseInt(closestMeasure.getAttribute("n")) - 1;
173
- var keysig = this.m2m.getMeasureMatrix().get(closestMeasureIdx, closestStaffIdx).keysig;
174
- var accids;
175
- var accid;
176
- if (keysig == undefined) {
177
- accids = mappings_1.keysigToNotes.get(keysig);
178
- accids = accids.filter((s) => { return s === pname; });
179
- if (accids.length === 1) {
180
- accid = keysig.charAt(1);
181
- }
182
- }
183
- var targetChord;
184
- //if(this.container.querySelector("#chordButton")?.classList.contains("selected")){
185
- if (this.shiftDown) {
186
- targetChord = this.rootSVG.querySelector("#" + nearestNodeId);
187
- if ((targetChord === null || targetChord === void 0 ? void 0 : targetChord.closest(".chord")) !== null) {
188
- targetChord = targetChord.closest(".chord");
189
- }
190
- }
191
- var relPosX = this.cursor.isBOL() ? "left" : "right";
192
- this.setContainerId(this.containerId);
193
- var newNote = {
194
- pname: pname,
195
- id: random_1.uuidv4(),
196
- dur: this.m2m.getDurationNewNote(),
197
- dots: this.m2m.getDotsNewNote(),
198
- oct: oct,
199
- keysig: keysig,
200
- accid: accid,
201
- nearestNoteId: nearestNodeId,
202
- relPosX: relPosX,
203
- staffId: this.rootSVG.querySelector("#" + nearestNodeId).closest(".staff").id,
204
- chordElement: targetChord,
205
- rest: this.container.querySelector("#pauseNote").classList.contains("selected")
206
- };
207
- return newNote;
208
- }
209
- /**
210
- * Navigate through Scoregraph with Arrow Keys
211
- * @param direction Key Code for Arrows
212
- */
213
- navigateCursor(direction) {
214
- var _a, _b, _c, _d, _e;
215
- var prevNode = this.scoreGraph.getCurrentNode();
216
- var container = document.getElementById(this.containerId);
217
- //this.rootSVG.querySelectorAll(".marked").forEach(m => m.classList.remove("marked"))
218
- var cbs = (_a = container.querySelector("#chordButton")) === null || _a === void 0 ? void 0 : _a.classList.contains("selected");
219
- if (cbs) {
220
- this.scoreGraph.nextClass(["chord", "note"], direction);
221
- }
222
- else {
223
- switch (direction) {
224
- case "ArrowLeft":
225
- (_b = document.querySelectorAll(".lastAdded")) === null || _b === void 0 ? void 0 : _b.forEach(la => la.classList.remove("lastAdded"));
226
- this.scoreGraph.nextLeft();
227
- break;
228
- case "ArrowRight":
229
- (_c = document.querySelectorAll(".lastAdded")) === null || _c === void 0 ? void 0 : _c.forEach(la => la.classList.remove("lastAdded"));
230
- this.scoreGraph.nextRight();
231
- break;
232
- // case "ArrowUp":
233
- // this.scoreGraph.nextUp()
234
- // break;
235
- // case "ArrowDown":
236
- // this.scoreGraph.nextDown()
237
- // break;
238
- }
239
- }
240
- if (this.scoreGraph.getCurrentNode() == undefined)
241
- return;
242
- (_d = this.rootSVG.querySelector("#" + prevNode.getId())) === null || _d === void 0 ? void 0 : _d.classList.remove("marked");
243
- this.cursor.definePosById(this.scoreGraph.getCurrentNode().getId());
244
- (_e = this.rootSVG.querySelector("#" + this.scoreGraph.getCurrentNode().getId())) === null || _e === void 0 ? void 0 : _e.classList.add("marked");
245
- if (this.scoreGraph.getCurrentNode().getId().indexOf("BOL") === -1) {
246
- this.setCurrentNodeScoreGraph(this.scoreGraph.getCurrentNode().getId());
247
- }
248
- }
249
- // navigateSelection(direction: string){
250
- // if(typeof this.startSelect === "undefined"){
251
- // this.startSelect = document.getElementById(this.scoreGraph.getCurrentNode().getId()).getBoundingClientRect()
252
- // }
253
- // this.navigateCursor(direction)
254
- // if(this.selectRect == undefined){
255
- // this.selectRect = document.createElementNS(c._SVGNS_, "rect")
256
- // this.selectRect.setAttribute("id", "keyModeSelectRect")
257
- // document.getElementById("canvasG").appendChild(this.selectRect)
258
- // }
259
- // var cursorPos = this.cursor.getPos() //document.getElementById("cursor").getBoundingClientRect()
260
- // var startSelectX = coord.adjustToPage(this.startSelect.left, "x")
261
- // var cursorX = cursorPos.x
262
- // var startSelectY = coord.adjustToPage(this.startSelect.top, "y") + window.pageYOffset
263
- // var cursorY = cursorPos.y //+ window.pageYOffset
264
- // if(cursorX < startSelectX){ // draw rect to right
265
- // this.selectRect.setAttribute("x", cursorX.toString())
266
- // this.selectRect.setAttribute("width", Math.abs(cursorX - startSelectX).toString())
267
- // }else{ // else right
268
- // this.selectRect.setAttribute("x", startSelectX.toString())
269
- // this.selectRect.setAttribute("width", Math.abs(coord.adjustToPage(this.startSelect.left, "x") - cursorX).toString())
270
- // }
271
- // if(cursorY < startSelectY){ // draw rect to top
272
- // this.selectRect.setAttribute("y", cursorY.toString())
273
- // //this.selectRect.setAttribute("height", Math.abs(cursorPos.y - coord.adjustToPage(this.startSelect.top, "y")).toString())
274
- // this.selectRect.setAttribute("height", Math.abs(cursorY - startSelectY).toString())
275
- // //console.log(cursorY, startSelectY, this.selectRect.getAttribute("height"))
276
- // }else{ // else bottom
277
- // this.selectRect.setAttribute("y", startSelectY.toString())
278
- // this.selectRect.setAttribute("height", Math.abs(coord.adjustToPage(this.startSelect.bottom, "y") - cursorY).toString())
279
- // //this.selectRect.setAttribute("height", Math.abs(coord.adjustToPage(this.startSelect.top, "y") - coord.adjustToPage(cursorPos.y, "y")).toString())
280
- // //console.log(cursorY, startSelectY, this.selectRect.getAttribute("height"))
281
- // }
282
- // var rectBBox = this.selectRect.getBoundingClientRect()
283
- // var rx = rectBBox.x + window.pageXOffset //accomodate for scrolling
284
- // var ry = rectBBox.y + window.pageYOffset
285
- // this.m2m.getNoteBBoxes().forEach(bb => {
286
- // var note = document.getElementById(bb.id)
287
- // let stem = note.querySelector(".stem") as HTMLElement
288
- // if( bb.x >= rx &&
289
- // bb.x <= rx + rectBBox.width &&
290
- // bb.y >= ry &&
291
- // bb.y <= ry + rectBBox.height) {
292
- // note.classList.add(marked)
293
- // if(stem !== null) stem.classList.add(marked)
294
- // var chord = note.closest(".chord")
295
- // if(chord !== null){
296
- // if(!chord.classList.contains(marked)) chord.classList.add(marked)
297
- // }
298
- // }else{
299
- // note.classList.remove(marked)
300
- // if(stem !== null) stem.classList.remove(marked)
301
- // var chord = note.closest(".chord")
302
- // if(chord !== null) chord.classList.remove(marked)
303
- // }
304
- // })
305
- // }
306
- /**
307
- * End selection in Keyboardmode
308
- */
309
- endSelection() {
310
- this.startSelect = undefined;
311
- if (this.selectRect !== null && typeof this.selectRect !== "undefined") {
312
- this.selectRect.remove();
313
- this.rootSVG.querySelectorAll(".marked").forEach(m => {
314
- m.classList.remove("marked");
315
- });
316
- }
317
- this.selectRect = undefined;
318
- }
319
- /**
320
- *
321
- * @param elementId Id of the current Element to be set in the ScoreGrap
322
- */
323
- setCurrentNodeScoreGraph(elementId = null) {
324
- if (this.scoreGraph.getCurrentNode() == undefined || elementId === null) {
325
- var nextEl = this.cursor.getNextElement();
326
- if (nextEl == undefined)
327
- return;
328
- if (nextEl.classList.contains("staff")) {
329
- nextEl = nextEl.querySelector(".layer");
330
- }
331
- this.scoreGraph.setCurrentNodeById(nextEl.id);
332
- }
333
- else if (elementId !== null) {
334
- this.scoreGraph.setCurrentNodeById(elementId);
335
- }
336
- return this;
337
- }
338
- /**
339
- * Delete next element depending on Keyboad input (Backspace: left, Delete: right)
340
- * @param key "Backspace" or "Delete"
341
- */
342
- deleteByKey(key) {
343
- var _a, _b;
344
- var elementToDelete;
345
- var currNodeId;
346
- var isFocusedChord = ((_a = this.container.querySelector("#chordButton")) === null || _a === void 0 ? void 0 : _a.classList.contains("selected")) ? true : false;
347
- if (isFocusedChord) {
348
- key = "Backspace";
349
- }
350
- switch (key) {
351
- case "Delete":
352
- //elementToDelete = this.rootSVG.querySelector("#" + this.scoreGraph.getCurrentNode().getRight().getId())
353
- //break;
354
- case "Backspace":
355
- elementToDelete = this.rootSVG.querySelector("#" + this.scoreGraph.getCurrentNode().getId());
356
- if (this.scoreGraph.getCurrentNode().isLayer()) {
357
- elementToDelete = this.rootSVG.querySelector("#" + this.scoreGraph.getCurrentNode().getLeft().getId());
358
- this.navigateCursor("ArrowLeft");
359
- }
360
- if (!((_b = this.scoreGraph.getCurrentNode().getLeft()) === null || _b === void 0 ? void 0 : _b.isBOL())) {
361
- this.navigateCursor("ArrowLeft");
362
- }
363
- else {
364
- this.navigateCursor("ArrowRight");
365
- }
366
- break;
367
- }
368
- currNodeId = this.scoreGraph.getCurrentNode().getId();
369
- // if(this.rootSVG.querySelector(".marked") === null){
370
- // this.deleteCallback([elementToDelete]).then(() => {
371
- // this.m2m.update();
372
- // this.resetListeners()
373
- // this.cursor.definePosById(currNodeId)
374
- // })
375
- // }
376
- }
377
- ///// GETTER / SETTER////////////////
378
- setM2M(m2m) {
379
- this.m2m = m2m;
380
- this.cursor.setM2M(m2m);
381
- return this;
382
- }
383
- setMusicPlayer(musicPlayer) {
384
- this.musicPlayer = musicPlayer;
385
- return this;
386
- }
387
- setScoreGraph(scoreGraph) {
388
- this.scoreGraph = scoreGraph;
389
- return this;
390
- }
391
- setCurrentMEI(mei) {
392
- this.currentMEI = mei;
393
- return this;
394
- }
395
- setContainerId(id) {
396
- this.containerId = id;
397
- this.rootSVG = cq.getRootSVG(id);
398
- this.interactionOverlay = cq.getInteractOverlay(id);
399
- this.container = document.getElementById(id);
400
- return this;
401
- }
402
- setInsertCallback(insertCallback) {
403
- this.insertCallback = insertCallback;
404
- return this;
405
- }
406
- setDeleteCallback(deleteCallback) {
407
- this.deleteCallback = deleteCallback;
408
- return this;
409
- }
410
- }
411
- exports.default = KeyModeHandler;
@@ -1,148 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- const MeasureMatrix_1 = require("../datastructures/MeasureMatrix");
3
- const d3 = require("d3");
4
- const coordinates = require("../utils/coordinates");
5
- const cq = require("../utils/convenienceQueries");
6
- //@ts-ignore
7
- //const $ = H5P.jQuery;
8
- /**
9
- * Class that handles insert mode, events, and actions.
10
- */
11
- class NoteDragHandler {
12
- constructor(containerId) {
13
- this.wasDragged = false;
14
- this.setContainerId(containerId);
15
- this.dragInit();
16
- this.noteDraggedEvent = new Event("noteDragged");
17
- }
18
- setListeners() {
19
- }
20
- removeListeners() {
21
- }
22
- resetListeners() {
23
- this.removeListeners();
24
- this.setListeners();
25
- }
26
- /**
27
- * Initialize the dragging action and handler for selected elements.
28
- */
29
- dragInit() {
30
- // Adding listeners
31
- const dragBehaviour = d3.drag()
32
- .on('start', dragStarted.bind(this))
33
- .on('drag', this.dragging.bind(this))
34
- .on('end', this.dragEnded.bind(this));
35
- this.notes = document.querySelectorAll(".note, .notehead"); //d3.select("#" + this.containerId).selectAll(".note, .notehead");
36
- this.draggedOverlayElement = null;
37
- this.notes.call(dragBehaviour);
38
- // Drag effects
39
- function dragStarted() {
40
- var _a;
41
- this.draggedOverlayElement = d3.event.sourceEvent.currentTarget;
42
- this.draggedRootSVGElement = (_a = this.rootSVG.querySelector("#" + this.draggedOverlayElement.getAttribute("refId"))) === null || _a === void 0 ? void 0 : _a.closest(".note");
43
- this.dragStartCoords = [d3.event.x, d3.event.y]; //coordinates.transformToDOMMatrixCoordinates(d3.event.sourceEvent.clientX, d3.event.sourceEvent.clientY, document.getElementById(c._ROOTSVGID_))
44
- this.dx = 0; //this.dragStartCoords[0]
45
- this.dy = 0; //this.dragStartCoords[1]
46
- }
47
- }
48
- dragging() {
49
- if (this.draggedOverlayElement === null || this.draggedRootSVGElement === null)
50
- return;
51
- this.dx = d3.event.x;
52
- this.dy = d3.event.y;
53
- var overlayCoords = coordinates.transformToDOMMatrixCoordinates(d3.event.sourceEvent.clientX, d3.event.sourceEvent.clientY, this.interactionOverlay);
54
- var diffY = Math.abs(this.dy - this.dragStartCoords[1]);
55
- if (diffY > 15) {
56
- this.wasDragged = true;
57
- }
58
- //snap while dragging
59
- this.m2m.defineNote(overlayCoords.x, overlayCoords.y, {});
60
- var newNote = [this.m2m.getNewNote().pname, this.m2m.getNewNote().oct];
61
- if (this.oldNote == undefined) {
62
- this.oldNote = newNote;
63
- }
64
- const relativeY = d3.event.y - this.dragStartCoords[1]; //d3.event.y - this.dragStartCoords[1]
65
- const relativeX = 0; //d3.event.x - this.dragStartCoords[0];
66
- //overlay and defscale have completely different viewbox dimensions
67
- var defScaleVBox = this.rootSVG.querySelector(".definition-scale").viewBox.baseVal;
68
- var overlayVBox = this.interactionOverlay.viewBox.baseVal;
69
- this.scaleX = defScaleVBox.width / overlayVBox.width;
70
- this.scaleY = defScaleVBox.height / overlayVBox.height;
71
- var shiftY = 10;
72
- shiftY = relativeY < 0 ? -shiftY : shiftY;
73
- if (!this.oldNote.every((v, i) => v === newNote[i])) {
74
- this.draggedOverlayElement.setAttribute('transform', 'translate(' + [relativeX, relativeY + shiftY] + ')');
75
- this.draggedRootSVGElement.setAttribute('transform', 'translate(' + [relativeX * this.scaleX, (relativeY + shiftY) * this.scaleY] + ')');
76
- this.oldNote = newNote;
77
- }
78
- }
79
- dragEnded() {
80
- if (this.draggedOverlayElement === null || this.draggedRootSVGElement === null)
81
- return;
82
- if (this.wasDragged) {
83
- this.notes.on("drag", null);
84
- this.wasDragged = false;
85
- this.draggedOverlayElement.dispatchEvent(this.noteDraggedEvent);
86
- this.container.querySelector("#" + this.draggedRootSVGElement.id).classList.remove(this.deleteHandler.getDeleteFlag()); //remove flag to delete after dragging
87
- const action = {
88
- action: "drag",
89
- param: { elementId: this.draggedRootSVGElement.id,
90
- //x: this.dx,
91
- //y: this.dy
92
- }
93
- };
94
- this.editCallback(action).then(() => {
95
- var attr = this.elementAttrCallback(this.draggedRootSVGElement.id);
96
- var mm = new MeasureMatrix_1.default();
97
- //mm.populateFromSVG(svg)
98
- mm.populateFromMEI(this.currentMEI);
99
- var staff = this.currentMEI.getElementById(this.draggedRootSVGElement.id).closest("staff");
100
- var measure = staff.closest("measure");
101
- var staffIdx = parseInt(staff.getAttribute("n")) - 1;
102
- var measureIdx = parseInt(measure.getAttribute("n")) - 1;
103
- var dur = this.currentMEI.getElementById(this.draggedRootSVGElement.id).closest("chord") !== null ? this.currentMEI.getElementById(this.draggedRootSVGElement.id).closest("chord").getAttribute("dur") : attr.dur;
104
- let newNote = {
105
- pname: attr.pname,
106
- oct: attr.oct.toString(),
107
- dur: dur,
108
- keysig: mm.get(measureIdx, staffIdx).keysig,
109
- rest: false,
110
- };
111
- this.musicPlayer.generateTone(newNote);
112
- });
113
- }
114
- }
115
- //////////////// GETTER/ SETTER ////////////
116
- setMusicPlayer(musicPlayer) {
117
- this.musicPlayer = musicPlayer;
118
- return this;
119
- }
120
- setCurrentMEI(xmlDoc) {
121
- this.currentMEI = xmlDoc;
122
- return this;
123
- }
124
- setM2M(m2m) {
125
- this.m2m = m2m;
126
- return this;
127
- }
128
- setDeleteHandler(deleteHandler) {
129
- this.deleteHandler = deleteHandler;
130
- return this;
131
- }
132
- setEditCallback(editCallback) {
133
- this.editCallback = editCallback;
134
- return this;
135
- }
136
- setElementAttrCallback(elementAttrCallback) {
137
- this.elementAttrCallback = elementAttrCallback;
138
- return this;
139
- }
140
- setContainerId(id) {
141
- this.containerId = id;
142
- this.container = document.getElementById(id);
143
- this.interactionOverlay = cq.getInteractOverlay(id);
144
- this.rootSVG = cq.getRootSVG(id);
145
- return this;
146
- }
147
- }
148
- exports.default = NoteDragHandler;