vibe-editor 0.0.0
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/LICENSE +21 -0
- package/README.md +51 -0
- package/package.json +56 -0
- package/src/fonts/bravura/FONTLOG.txt +243 -0
- package/src/fonts/bravura/OFL-FAQ.txt +369 -0
- package/src/fonts/bravura/OFL.txt +94 -0
- package/src/fonts/bravura/bravura-text.md +153 -0
- package/src/fonts/bravura/bravura_metadata.json +34718 -0
- package/src/fonts/bravura/eot/Bravura.eot +0 -0
- package/src/fonts/bravura/eot/BravuraText.eot +0 -0
- package/src/fonts/bravura/otf/Bravura.otf +0 -0
- package/src/fonts/bravura/otf/BravuraText.otf +0 -0
- package/src/fonts/bravura/svg/Bravura.svg +3517 -0
- package/src/fonts/bravura/svg/BravuraText.svg +18879 -0
- package/src/fonts/bravura/woff/Bravura.woff +0 -0
- package/src/fonts/bravura/woff/BravuraText.woff +0 -0
- package/src/fonts/colaborate/ColabBol-webfont.eot +0 -0
- package/src/fonts/colaborate/ColabBol-webfont.svg +976 -0
- package/src/fonts/colaborate/ColabBol-webfont.ttf +0 -0
- package/src/fonts/colaborate/ColabBol-webfont.woff +0 -0
- package/src/fonts/colaborate/ColabLig-webfont.eot +0 -0
- package/src/fonts/colaborate/ColabLig-webfont.svg +976 -0
- package/src/fonts/colaborate/ColabLig-webfont.ttf +0 -0
- package/src/fonts/colaborate/ColabLig-webfont.woff +0 -0
- package/src/fonts/colaborate/ColabMed-webfont.eot +0 -0
- package/src/fonts/colaborate/ColabMed-webfont.svg +976 -0
- package/src/fonts/colaborate/ColabMed-webfont.ttf +0 -0
- package/src/fonts/colaborate/ColabMed-webfont.woff +0 -0
- package/src/fonts/colaborate/ColabReg-webfont.eot +0 -0
- package/src/fonts/colaborate/ColabReg-webfont.svg +976 -0
- package/src/fonts/colaborate/ColabReg-webfont.ttf +0 -0
- package/src/fonts/colaborate/ColabReg-webfont.woff +0 -0
- package/src/fonts/colaborate/ColabThi-webfont.eot +0 -0
- package/src/fonts/colaborate/ColabThi-webfont.svg +970 -0
- package/src/fonts/colaborate/ColabThi-webfont.ttf +0 -0
- package/src/fonts/colaborate/ColabThi-webfont.woff +0 -0
- package/src/images/GUI/.DS_Store +0 -0
- package/src/images/GUI/backward-fast-solid.svg +1 -0
- package/src/images/GUI/bars-solid.svg +1 -0
- package/src/images/GUI/caret-left-solid.svg +1 -0
- package/src/images/GUI/caret-right-solid.svg +1 -0
- package/src/images/GUI/edit-solid.svg +1 -0
- package/src/images/GUI/pause-solid.svg +1 -0
- package/src/images/GUI/play-solid.svg +1 -0
- package/src/images/GUI/triplet.svg +21 -0
- package/src/images/GUI/zoomin.svg +1 -0
- package/src/images/GUI/zoomout.svg +1 -0
- package/src/images/bravura_notes/.DS_Store +0 -0
- package/src/images/bravura_notes/16th.svg +1 -0
- package/src/images/bravura_notes/32th.svg +1 -0
- package/src/images/bravura_notes/alterDDown.svg +1 -0
- package/src/images/bravura_notes/alterDUp.svg +1 -0
- package/src/images/bravura_notes/alterDown.svg +1 -0
- package/src/images/bravura_notes/alterNeutral.svg +1 -0
- package/src/images/bravura_notes/alterUp.svg +1 -0
- package/src/images/bravura_notes/beams.svg +1 -0
- package/src/images/bravura_notes/eigth.svg +1 -0
- package/src/images/bravura_notes/full.svg +1 -0
- package/src/images/bravura_notes/half.svg +1 -0
- package/src/images/bravura_notes/oneDot.svg +1 -0
- package/src/images/bravura_notes/pauseNote.svg +1 -0
- package/src/images/bravura_notes/quarter.svg +1 -0
- package/src/images/bravura_notes/tie.svg +1 -0
- package/src/images/bravura_notes/twoDot.svg +1 -0
- package/src/scripts/js/.DS_Store +0 -0
- package/src/scripts/js/Core.js +887 -0
- package/src/scripts/js/MusicPlayer.js +572 -0
- package/src/scripts/js/MusicProcessor.js +652 -0
- package/src/scripts/js/VerovioScoreEditor.js +183 -0
- package/src/scripts/js/assets/mei_template.js +161 -0
- package/src/scripts/js/constants.js +20 -0
- package/src/scripts/js/datastructures/MeasureMatrix.js +235 -0
- package/src/scripts/js/datastructures/ScoreGraph.js +432 -0
- package/src/scripts/js/datastructures/ScoreNode.js +78 -0
- package/src/scripts/js/entry.js +4 -0
- package/src/scripts/js/gui/Annotations.js +456 -0
- package/src/scripts/js/gui/Cursor.js +203 -0
- package/src/scripts/js/gui/CustomAnnotationDrawer.js +114 -0
- package/src/scripts/js/gui/CustomAnnotationShapeDrawer.js +114 -0
- package/src/scripts/js/gui/HarmonyLabel.js +104 -0
- package/src/scripts/js/gui/Label.js +2 -0
- package/src/scripts/js/gui/PhantomElement.js +132 -0
- package/src/scripts/js/gui/ScoreManipulator.js +156 -0
- package/src/scripts/js/gui/Tabbar.js +675 -0
- package/src/scripts/js/gui/TempoLabel.js +60 -0
- package/src/scripts/js/gui/Toolbar copy.js +614 -0
- package/src/scripts/js/gui/Toolbar.js +618 -0
- package/src/scripts/js/handlers/AnnotationChangeHandler.js +567 -0
- package/src/scripts/js/handlers/AnnotationDragHandler.js +113 -0
- package/src/scripts/js/handlers/AnnotationLineHandler.js +113 -0
- package/src/scripts/js/handlers/ArticulationHandler.js +20 -0
- package/src/scripts/js/handlers/ClickModeHandler.js +265 -0
- package/src/scripts/js/handlers/CustomAnnotationShapeDrawer.js +131 -0
- package/src/scripts/js/handlers/CustomToolbarHandler.js +297 -0
- package/src/scripts/js/handlers/DeleteHandler.js +102 -0
- package/src/scripts/js/handlers/GlobalKeyboardHandler.js +367 -0
- package/src/scripts/js/handlers/Handler.js +2 -0
- package/src/scripts/js/handlers/HarmonyHandler.js +282 -0
- package/src/scripts/js/handlers/InsertModeHandler copy.js +423 -0
- package/src/scripts/js/handlers/InsertModeHandler.js +380 -0
- package/src/scripts/js/handlers/InsertModeHandler_deprecated.js +424 -0
- package/src/scripts/js/handlers/KeyModeHandler copy.js +407 -0
- package/src/scripts/js/handlers/KeyModeHandler.js +456 -0
- package/src/scripts/js/handlers/KeyModeHandler_deprecated.js +411 -0
- package/src/scripts/js/handlers/LabelHandler.js +461 -0
- package/src/scripts/js/handlers/ModHandler.js +311 -0
- package/src/scripts/js/handlers/NoteDragHandler copy.js +148 -0
- package/src/scripts/js/handlers/NoteDragHandler.js +97 -0
- package/src/scripts/js/handlers/NoteDragHandler_deprecated.js +150 -0
- package/src/scripts/js/handlers/PhantomElementHandler.js +168 -0
- package/src/scripts/js/handlers/ScoreManipulatorHandler.js +135 -0
- package/src/scripts/js/handlers/SelectionHandler.js +218 -0
- package/src/scripts/js/handlers/SideBarHandler.js +499 -0
- package/src/scripts/js/handlers/TooltipHandler.js +132 -0
- package/src/scripts/js/handlers/WindowHandler.js +257 -0
- package/src/scripts/js/utils/DOMCreator.js +174 -0
- package/src/scripts/js/utils/MEIConverter.js +64 -0
- package/src/scripts/js/utils/MEIOperations.js +2112 -0
- package/src/scripts/js/utils/Mouse2MEI.js +735 -0
- package/src/scripts/js/utils/Mouse2SVG.js +737 -0
- package/src/scripts/js/utils/SVGEditor.js +352 -0
- package/src/scripts/js/utils/SVGFiller.js +245 -0
- package/src/scripts/js/utils/Types.js +2 -0
- package/src/scripts/js/utils/VerovioWrapper copy.js +156 -0
- package/src/scripts/js/utils/VerovioWrapper.js +165 -0
- package/src/scripts/js/utils/VerovioWrapperLocal.js +156 -0
- package/src/scripts/js/utils/convenienceQueries.js +37 -0
- package/src/scripts/js/utils/coordinates.js +54 -0
- package/src/scripts/js/utils/firefoxBBoxes.js +143 -0
- package/src/scripts/js/utils/mappings.js +332 -0
- package/src/scripts/js/utils/random.js +45 -0
- package/src/styles/VerovioScoreEditor.css +694 -0
@@ -0,0 +1,456 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const mappings_1 = require("../utils/mappings");
|
4
|
+
const random_1 = require("../utils/random");
|
5
|
+
const cq = require("../utils/convenienceQueries");
|
6
|
+
const meiOperation = require("../utils/MEIOperations");
|
7
|
+
const marked = "marked";
|
8
|
+
class KeyModeHandler {
|
9
|
+
constructor(containerId) {
|
10
|
+
/**
|
11
|
+
* Event handler for inserting Notes
|
12
|
+
*/
|
13
|
+
this.noteInputHandler = (function noteInputHandler(e) {
|
14
|
+
this.noteInput(e);
|
15
|
+
}).bind(this);
|
16
|
+
this.midiHandler = (function midiHandler(e) {
|
17
|
+
e.preventDefault();
|
18
|
+
this.midiInput(e.detail);
|
19
|
+
}).bind(this);
|
20
|
+
this.pressedHandler = (function pressedHandler(e) {
|
21
|
+
this.assignKeys(e);
|
22
|
+
}).bind(this);
|
23
|
+
/**
|
24
|
+
* Event Handler for any Keyboard input (except inserting)
|
25
|
+
*/
|
26
|
+
this.keyInputHandler = (function keyInputHandler(e) {
|
27
|
+
if (!cq.hasActiveElement(this.containerId))
|
28
|
+
return;
|
29
|
+
if (e.ctrlKey || e.metaKey)
|
30
|
+
return; //prevent confusion with global keyboard functionalities
|
31
|
+
if (this.interactionOverlay.querySelector("div[contenteditable=true]") !== null)
|
32
|
+
return; // prevent navigating in scrore, when label editor is open
|
33
|
+
if (this.scoreGraph.getCurrentNode() == undefined)
|
34
|
+
return;
|
35
|
+
if (e.shiftKey && e.key.includes("Arrow")) {
|
36
|
+
e.preventDefault();
|
37
|
+
this.navigateSelection(e.key);
|
38
|
+
}
|
39
|
+
else if (e.key.includes("Arrow")) {
|
40
|
+
e.preventDefault();
|
41
|
+
this.endSelection();
|
42
|
+
this.navigateCursor(e.key);
|
43
|
+
}
|
44
|
+
else if (["Delete", "Backspace"].indexOf(e.key) > -1) {
|
45
|
+
e.preventDefault();
|
46
|
+
//this.deleteByKey(e.key)
|
47
|
+
}
|
48
|
+
}).bind(this);
|
49
|
+
/**
|
50
|
+
* Set Cursor to new position after pasting
|
51
|
+
*/
|
52
|
+
this.pastedHandler = (function pastedHandler(e) {
|
53
|
+
var _a;
|
54
|
+
console.log("PASTED ", e);
|
55
|
+
this.scoreGraph.setCurrentNodeById(e.detail);
|
56
|
+
this.cursor.definePosById((_a = this.scoreGraph.getCurrentNode()) === null || _a === void 0 ? void 0 : _a.getId());
|
57
|
+
}).bind(this);
|
58
|
+
this.setContainerId(containerId);
|
59
|
+
}
|
60
|
+
setListeners() {
|
61
|
+
document.addEventListener("keydown", this.pressedHandler);
|
62
|
+
document.addEventListener("keyup", this.pressedHandler);
|
63
|
+
document.addEventListener('keydown', this.noteInputHandler);
|
64
|
+
document.addEventListener('keydown', this.keyInputHandler);
|
65
|
+
document.addEventListener("pasted", this.pastedHandler);
|
66
|
+
document.addEventListener("midiin", this.midiHandler);
|
67
|
+
}
|
68
|
+
removeListeners() {
|
69
|
+
document.removeEventListener("keydown", this.pressedHandler);
|
70
|
+
document.removeEventListener("keyup", this.pressedHandler);
|
71
|
+
document.removeEventListener('keydown', this.noteInputHandler);
|
72
|
+
document.removeEventListener('keydown', this.keyInputHandler);
|
73
|
+
document.removeEventListener("pasted", this.pastedHandler);
|
74
|
+
document.removeEventListener("midiin", this.midiHandler);
|
75
|
+
}
|
76
|
+
resetListeners() {
|
77
|
+
this.removeListeners();
|
78
|
+
this.setListeners();
|
79
|
+
}
|
80
|
+
noteInput(e) {
|
81
|
+
var _a;
|
82
|
+
if (e.shiftKey || e.metaKey)
|
83
|
+
return;
|
84
|
+
if (this.container.querySelector("[contenteditable=true]"))
|
85
|
+
return;
|
86
|
+
var currentNode = this.scoreGraph.getCurrentNode();
|
87
|
+
if (document.getElementById(currentNode.getId()) === null)
|
88
|
+
return;
|
89
|
+
if (!cq.hasActiveElement(this.containerId))
|
90
|
+
return;
|
91
|
+
if (this.musicPlayer.getIsPlaying() === true) {
|
92
|
+
return;
|
93
|
+
} // getIsPlaying could also be undefined
|
94
|
+
if (mappings_1.keyCodeNoteMap.has(e.code)) {
|
95
|
+
e.preventDefault();
|
96
|
+
var pname = mappings_1.keyCodeNoteMap.get(e.code);
|
97
|
+
var oct = mappings_1.octToNum.get((_a = this.container.querySelector("#octaveGroupKM .selected")) === null || _a === void 0 ? void 0 : _a.id) || "4";
|
98
|
+
const newNote = this.createNewNote(pname, oct, null);
|
99
|
+
if (newNote == undefined)
|
100
|
+
return;
|
101
|
+
this.processNewNote(newNote);
|
102
|
+
// var noteExists: Boolean = false
|
103
|
+
// var noteToDelete: Element
|
104
|
+
// if (document.getElementById(currentNode.getId()).closest(".chord") !== null) {
|
105
|
+
// var chordNotes = Array.from(document.getElementById(currentNode.getId()).closest(".chord").querySelectorAll(".note"))
|
106
|
+
// chordNotes.forEach((n: Element) => {
|
107
|
+
// var meiNote = this.m2s.getCurrentMei().getElementById(n.id)
|
108
|
+
// var sameOct = meiNote.getAttribute("oct") === newNote.oct
|
109
|
+
// var samePname = meiNote.getAttribute("pname") === newNote.pname
|
110
|
+
// if (sameOct && samePname) {
|
111
|
+
// noteExists = true
|
112
|
+
// noteToDelete = n
|
113
|
+
// }
|
114
|
+
// })
|
115
|
+
// }
|
116
|
+
// if (!noteExists) {
|
117
|
+
// // check if new note should replace a rest
|
118
|
+
// if (this.scoreGraph.getCurrentNode().getDocElement().classList.contains("rest")) {
|
119
|
+
// newNote.relPosX = "left";
|
120
|
+
// newNote.nearestNoteId = this.scoreGraph.getCurrentNode().getId()
|
121
|
+
// } else if (!this.scoreGraph.getCurrentNode()?.getDocElement().classList.contains("mRest") && this.scoreGraph.lookUp(["note", "rest", "mRest"], "right") == null && newNote.chordElement == undefined) {
|
122
|
+
// //check if new Measure must be created
|
123
|
+
// meiOperation.addMeasure(this.m2s.getCurrentMei())
|
124
|
+
// var currentStaff = this.m2s.getCurrentMei().getElementById(newNote.staffId)
|
125
|
+
// var staffN = currentStaff.getAttribute("n")
|
126
|
+
// newNote.staffId = currentStaff.closest("measure").nextElementSibling.querySelector("staff[n=\"" + staffN + "\"]").id
|
127
|
+
// newNote.relPosX = "left"
|
128
|
+
// newNote.nearestNoteId = this.m2s.getCurrentMei().querySelector("#" + newNote.staffId).querySelector("mRest").id
|
129
|
+
// } else {
|
130
|
+
// //or if ne note must be rendered into the next bar
|
131
|
+
// var oldStaffId = newNote.staffId
|
132
|
+
// if (this.m2s.getCurrentMei().querySelector("#" + newNote.nearestNoteId) === null) return
|
133
|
+
// if (this.m2s.getCurrentMei().querySelector("#" + newNote.nearestNoteId).tagName !== "mRest") {
|
134
|
+
// newNote.staffId = this.m2s.getCurrentMei().getElementById(this.scoreGraph.getNextClass(["note", "rest", "mRest"], "right")?.getId())?.closest("staff").id || newNote.staffId
|
135
|
+
// }
|
136
|
+
// if (oldStaffId !== newNote.staffId) {
|
137
|
+
// newNote.relPosX = "left"
|
138
|
+
// newNote.nearestNoteId = this.scoreGraph.getCurrentNode()?.getId()
|
139
|
+
// }
|
140
|
+
// }
|
141
|
+
// this.insertCallback(newNote, true).then(() => {
|
142
|
+
// //this.m2s.update();
|
143
|
+
// this.resetListeners()
|
144
|
+
// var currentTargetId;
|
145
|
+
// if (newNote.chordElement != undefined) {
|
146
|
+
// currentTargetId = this.vrvSVG.querySelector("#" + newNote.chordElement.id).closest(".chord").id // new chord with own ID is created, if note is added
|
147
|
+
// } else {
|
148
|
+
// currentTargetId = newNote.id
|
149
|
+
// }
|
150
|
+
// this.scoreGraph.setCurrentNodeById(currentTargetId)
|
151
|
+
// this.musicPlayer.generateTone(newNote)
|
152
|
+
// }).catch(() => {
|
153
|
+
// //alert("your bar is too small")
|
154
|
+
// })
|
155
|
+
// } else {
|
156
|
+
// this.deleteCallback([noteToDelete]).then(() => {
|
157
|
+
// //this.m2s.update();
|
158
|
+
// this.resetListeners()
|
159
|
+
// this.scoreGraph.setCurrentNodeById(newNote.chordElement?.id)
|
160
|
+
// })
|
161
|
+
// }
|
162
|
+
}
|
163
|
+
}
|
164
|
+
processNewNote(newNote) {
|
165
|
+
var _a, _b, _c, _d;
|
166
|
+
var currentNode = this.scoreGraph.getCurrentNode();
|
167
|
+
var noteExists = false;
|
168
|
+
var noteToDelete;
|
169
|
+
if (document.getElementById(currentNode.getId()).closest(".chord") !== null) {
|
170
|
+
var chordNotes = Array.from(document.getElementById(currentNode.getId()).closest(".chord").querySelectorAll(".note"));
|
171
|
+
chordNotes.forEach((n) => {
|
172
|
+
var meiNote = this.m2s.getCurrentMei().getElementById(n.id);
|
173
|
+
var sameOct = meiNote.getAttribute("oct") === newNote.oct;
|
174
|
+
var samePname = meiNote.getAttribute("pname") === newNote.pname;
|
175
|
+
if (sameOct && samePname) {
|
176
|
+
noteExists = true;
|
177
|
+
noteToDelete = n;
|
178
|
+
}
|
179
|
+
});
|
180
|
+
}
|
181
|
+
if (!noteExists) {
|
182
|
+
// check if new note should replace a rest
|
183
|
+
if (this.scoreGraph.getCurrentNode().getDocElement().classList.contains("rest")) {
|
184
|
+
newNote.relPosX = "left";
|
185
|
+
newNote.nearestNoteId = this.scoreGraph.getCurrentNode().getId();
|
186
|
+
}
|
187
|
+
else if (!((_a = this.scoreGraph.getCurrentNode()) === null || _a === void 0 ? void 0 : _a.getDocElement().classList.contains("mRest")) && this.scoreGraph.lookUp(["note", "rest", "mRest"], "right") == null && newNote.chordElement == undefined) {
|
188
|
+
//check if new Measure must be created
|
189
|
+
meiOperation.addMeasure(this.m2s.getCurrentMei());
|
190
|
+
var currentStaff = this.m2s.getCurrentMei().getElementById(newNote.staffId);
|
191
|
+
var staffN = currentStaff.getAttribute("n");
|
192
|
+
newNote.staffId = currentStaff.closest("measure").nextElementSibling.querySelector("staff[n=\"" + staffN + "\"]").id;
|
193
|
+
newNote.relPosX = "left";
|
194
|
+
newNote.nearestNoteId = this.m2s.getCurrentMei().querySelector("#" + newNote.staffId).querySelector("mRest").id;
|
195
|
+
}
|
196
|
+
else {
|
197
|
+
//or if ne note must be rendered into the next bar
|
198
|
+
var oldStaffId = newNote.staffId;
|
199
|
+
if (this.m2s.getCurrentMei().querySelector("#" + newNote.nearestNoteId) === null)
|
200
|
+
return;
|
201
|
+
if (this.m2s.getCurrentMei().querySelector("#" + newNote.nearestNoteId).tagName !== "mRest") {
|
202
|
+
newNote.staffId = ((_c = this.m2s.getCurrentMei().getElementById((_b = this.scoreGraph.getNextClass(["note", "rest", "mRest"], "right")) === null || _b === void 0 ? void 0 : _b.getId())) === null || _c === void 0 ? void 0 : _c.closest("staff").id) || newNote.staffId;
|
203
|
+
}
|
204
|
+
if (oldStaffId !== newNote.staffId) {
|
205
|
+
newNote.relPosX = "left";
|
206
|
+
newNote.nearestNoteId = (_d = this.scoreGraph.getCurrentNode()) === null || _d === void 0 ? void 0 : _d.getId();
|
207
|
+
}
|
208
|
+
}
|
209
|
+
this.insertCallback(newNote, true).then(() => {
|
210
|
+
//this.m2s.update();
|
211
|
+
this.resetListeners();
|
212
|
+
var currentTargetId;
|
213
|
+
if (newNote.chordElement != undefined) {
|
214
|
+
currentTargetId = this.vrvSVG.querySelector("#" + newNote.chordElement.id).closest(".chord").id; // new chord with own ID is created, if note is added
|
215
|
+
}
|
216
|
+
else {
|
217
|
+
currentTargetId = newNote.id;
|
218
|
+
}
|
219
|
+
this.scoreGraph.setCurrentNodeById(currentTargetId);
|
220
|
+
this.musicPlayer.generateTone(newNote);
|
221
|
+
}).catch(() => {
|
222
|
+
//alert("your bar is too small")
|
223
|
+
});
|
224
|
+
}
|
225
|
+
else {
|
226
|
+
this.deleteCallback([noteToDelete]).then(() => {
|
227
|
+
var _a;
|
228
|
+
//this.m2s.update();
|
229
|
+
this.resetListeners();
|
230
|
+
this.scoreGraph.setCurrentNodeById((_a = newNote.chordElement) === null || _a === void 0 ? void 0 : _a.id);
|
231
|
+
});
|
232
|
+
}
|
233
|
+
}
|
234
|
+
midiInput(midiArray) {
|
235
|
+
var [_, midiNum, velocity] = midiArray;
|
236
|
+
var noteName = mappings_1.midiToNote.get(midiNum);
|
237
|
+
if (noteName == undefined)
|
238
|
+
return;
|
239
|
+
if (velocity === 0)
|
240
|
+
return;
|
241
|
+
var pname = noteName.slice(0, 1);
|
242
|
+
var accid = noteName.length === 3 ? noteName.slice(1, 2) : undefined;
|
243
|
+
var oct = noteName.match(/\d/g)[0].toString();
|
244
|
+
var newNote = this.createNewNote(pname, oct, { accid: accid });
|
245
|
+
if (newNote == undefined)
|
246
|
+
return;
|
247
|
+
this.processNewNote(newNote);
|
248
|
+
}
|
249
|
+
assignKeys(e) {
|
250
|
+
var b = false;
|
251
|
+
if (e.type === "keydown") {
|
252
|
+
b = true;
|
253
|
+
}
|
254
|
+
else if (e.type === "keyup") {
|
255
|
+
b = false;
|
256
|
+
}
|
257
|
+
switch (e.key) {
|
258
|
+
case "Shift":
|
259
|
+
this.shiftDown = b;
|
260
|
+
break;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
/**
|
264
|
+
* create a newNote
|
265
|
+
* @param pname pitch name
|
266
|
+
* @param oct octave
|
267
|
+
* @param options
|
268
|
+
* @returns
|
269
|
+
*/
|
270
|
+
createNewNote(pname, oct, options) {
|
271
|
+
var _a, _b, _c, _d;
|
272
|
+
//get relevant staffinfo
|
273
|
+
var nearestNodeId = (_a = this.scoreGraph.getCurrentNode()) === null || _a === void 0 ? void 0 : _a.getId();
|
274
|
+
if (nearestNodeId == undefined)
|
275
|
+
return;
|
276
|
+
var closestStaff = ((_b = this.m2s.getCurrentMei().getElementById(nearestNodeId)) === null || _b === void 0 ? void 0 : _b.closest("staff")) || this.m2s.getCurrentMei().querySelector("measure > staff"); //asume first measure first staff
|
277
|
+
var closestMeasure = closestStaff.closest("measure");
|
278
|
+
var closestStaffIdx = parseInt(closestStaff.getAttribute("n")) - 1;
|
279
|
+
var closestMeasureIdx = parseInt(closestMeasure.getAttribute("n")) - 1;
|
280
|
+
var keysig = this.m2s.getMeasureMatrix().get(closestMeasureIdx, closestStaffIdx).keysig;
|
281
|
+
var accids = mappings_1.keysigToNotes.get(keysig);
|
282
|
+
var accid;
|
283
|
+
if (options === null) {
|
284
|
+
accids = accids.filter((s) => { return s === pname; });
|
285
|
+
if (accids.length === 1) {
|
286
|
+
accid = keysig.charAt(1);
|
287
|
+
}
|
288
|
+
}
|
289
|
+
else if (options === null || options === void 0 ? void 0 : options.accid) {
|
290
|
+
accid = options.accid;
|
291
|
+
//should the note be enharmonically swapped?
|
292
|
+
//midi inputs are only given as sharps
|
293
|
+
var increment = pname === "g" ? -6 : 1; //- 6 is for jumping back to a; oct stays the same
|
294
|
+
if (keysig.includes("f") && accids.includes(String.fromCharCode(pname.charCodeAt(0) + increment))) {
|
295
|
+
accid = "f";
|
296
|
+
pname = String.fromCharCode(pname.charCodeAt(0) + increment);
|
297
|
+
}
|
298
|
+
}
|
299
|
+
var targetChord;
|
300
|
+
//if(this.container.querySelector("#chordButton")?.classList.contains("selected")){
|
301
|
+
if (this.shiftDown) {
|
302
|
+
targetChord = this.vrvSVG.querySelector("#" + nearestNodeId);
|
303
|
+
if ((targetChord === null || targetChord === void 0 ? void 0 : targetChord.closest(".chord")) !== null) {
|
304
|
+
targetChord = targetChord.closest(".chord");
|
305
|
+
}
|
306
|
+
}
|
307
|
+
this.setContainerId(this.containerId);
|
308
|
+
var newNote = {
|
309
|
+
pname: pname,
|
310
|
+
id: random_1.uuidv4(),
|
311
|
+
dur: this.m2s.getDurationNewNote(),
|
312
|
+
dots: this.m2s.getDotsNewNote(),
|
313
|
+
oct: oct,
|
314
|
+
keysig: keysig,
|
315
|
+
accid: accid,
|
316
|
+
nearestNoteId: nearestNodeId,
|
317
|
+
relPosX: "right",
|
318
|
+
staffId: (_c = this.vrvSVG.querySelector("#" + nearestNodeId)) === null || _c === void 0 ? void 0 : _c.closest(".staff").id,
|
319
|
+
chordElement: targetChord,
|
320
|
+
rest: (_d = this.container.querySelector("#pauseNote")) === null || _d === void 0 ? void 0 : _d.classList.contains("selected")
|
321
|
+
};
|
322
|
+
return newNote;
|
323
|
+
}
|
324
|
+
/**
|
325
|
+
* Navigate through Scoregraph with Arrow Keys
|
326
|
+
* @param direction Key Code for Arrows
|
327
|
+
*/
|
328
|
+
navigateCursor(direction) {
|
329
|
+
var _a, _b, _c;
|
330
|
+
var prevNode = this.scoreGraph.getCurrentNode();
|
331
|
+
switch (direction) {
|
332
|
+
case "ArrowLeft":
|
333
|
+
(_a = document.querySelectorAll(".lastAdded")) === null || _a === void 0 ? void 0 : _a.forEach(la => la.classList.remove("lastAdded"));
|
334
|
+
this.scoreGraph.nextLeft();
|
335
|
+
break;
|
336
|
+
case "ArrowRight":
|
337
|
+
(_b = document.querySelectorAll(".lastAdded")) === null || _b === void 0 ? void 0 : _b.forEach(la => la.classList.remove("lastAdded"));
|
338
|
+
this.scoreGraph.nextRight();
|
339
|
+
break;
|
340
|
+
default:
|
341
|
+
return;
|
342
|
+
}
|
343
|
+
if (this.scoreGraph.getCurrentNode() == undefined)
|
344
|
+
return;
|
345
|
+
this.container.querySelectorAll(".marked").forEach(m => m.classList.remove("marked"));
|
346
|
+
(_c = this.container.querySelector("#" + prevNode.getId())) === null || _c === void 0 ? void 0 : _c.classList.remove("lastAdded");
|
347
|
+
var currEl = this.container.querySelector("#" + this.scoreGraph.getCurrentNode().getId());
|
348
|
+
currEl.classList.add("marked");
|
349
|
+
if (currEl.closest(".chord") !== null) {
|
350
|
+
currEl.querySelectorAll(".note, .notehead").forEach(n => n.classList.add("marked"));
|
351
|
+
}
|
352
|
+
}
|
353
|
+
/**
|
354
|
+
* End selection in Keyboardmode
|
355
|
+
*/
|
356
|
+
endSelection() {
|
357
|
+
this.startSelect = undefined;
|
358
|
+
if (this.selectRect !== null && typeof this.selectRect !== "undefined") {
|
359
|
+
this.selectRect.remove();
|
360
|
+
this.vrvSVG.querySelectorAll(".marked").forEach(m => {
|
361
|
+
m.classList.remove("marked");
|
362
|
+
});
|
363
|
+
}
|
364
|
+
this.selectRect = undefined;
|
365
|
+
}
|
366
|
+
/**
|
367
|
+
*
|
368
|
+
* @param elementId Id of the current Element to be set in the ScoreGrap
|
369
|
+
*/
|
370
|
+
setCurrentNodeScoreGraph(elementId = null) {
|
371
|
+
// if(this.scoreGraph.getCurrentNode() == undefined || elementId === null){
|
372
|
+
// var nextEl = this.cursor.getNextElement()
|
373
|
+
// if(nextEl == undefined) return
|
374
|
+
// if(nextEl.classList.contains("staff")){
|
375
|
+
// nextEl = nextEl.querySelector(".layer")
|
376
|
+
// }
|
377
|
+
// this.scoreGraph.setCurrentNodeById(nextEl.id)
|
378
|
+
// }else if(elementId !== null){
|
379
|
+
// this.scoreGraph.setCurrentNodeById(elementId)
|
380
|
+
// }
|
381
|
+
this.scoreGraph.setCurrentNodeById(elementId);
|
382
|
+
return this;
|
383
|
+
}
|
384
|
+
/**
|
385
|
+
* Delete next element depending on Keyboad input (Backspace: left, Delete: right)
|
386
|
+
* @param key "Backspace" or "Delete"
|
387
|
+
*/
|
388
|
+
deleteByKey(key) {
|
389
|
+
var _a, _b;
|
390
|
+
var elementToDelete;
|
391
|
+
var currNodeId;
|
392
|
+
var isFocusedChord = ((_a = this.container.querySelector("#chordButton")) === null || _a === void 0 ? void 0 : _a.classList.contains("selected")) ? true : false;
|
393
|
+
if (isFocusedChord) {
|
394
|
+
key = "Backspace";
|
395
|
+
}
|
396
|
+
switch (key) {
|
397
|
+
case "Delete":
|
398
|
+
//elementToDelete = this.vrvSVG.querySelector("#" + this.scoreGraph.getCurrentNode().getRight().getId())
|
399
|
+
//break;
|
400
|
+
case "Backspace":
|
401
|
+
elementToDelete = this.vrvSVG.querySelector("#" + this.scoreGraph.getCurrentNode().getId());
|
402
|
+
if (this.scoreGraph.getCurrentNode().isLayer()) {
|
403
|
+
elementToDelete = this.vrvSVG.querySelector("#" + this.scoreGraph.getCurrentNode().getLeft().getId());
|
404
|
+
this.navigateCursor("ArrowLeft");
|
405
|
+
}
|
406
|
+
if (!((_b = this.scoreGraph.getCurrentNode().getLeft()) === null || _b === void 0 ? void 0 : _b.isBOL())) {
|
407
|
+
this.navigateCursor("ArrowLeft");
|
408
|
+
}
|
409
|
+
else {
|
410
|
+
this.navigateCursor("ArrowRight");
|
411
|
+
}
|
412
|
+
break;
|
413
|
+
}
|
414
|
+
currNodeId = this.scoreGraph.getCurrentNode().getId();
|
415
|
+
// if(this.vrvSVG.querySelector(".marked") === null){
|
416
|
+
// this.deleteCallback([elementToDelete]).then(() => {
|
417
|
+
// this.m2s.update();
|
418
|
+
// this.resetListeners()
|
419
|
+
// this.cursor.definePosById(currNodeId)
|
420
|
+
// })
|
421
|
+
// }
|
422
|
+
}
|
423
|
+
///// GETTER / SETTER////////////////
|
424
|
+
setm2s(m2s) {
|
425
|
+
this.m2s = m2s;
|
426
|
+
return this;
|
427
|
+
}
|
428
|
+
setMusicProcessor(musicPlayer) {
|
429
|
+
this.musicPlayer = musicPlayer;
|
430
|
+
return this;
|
431
|
+
}
|
432
|
+
setScoreGraph(scoreGraph) {
|
433
|
+
this.scoreGraph = scoreGraph;
|
434
|
+
return this;
|
435
|
+
}
|
436
|
+
setCurrentMEI(mei) {
|
437
|
+
this.currentMEI = mei;
|
438
|
+
return this;
|
439
|
+
}
|
440
|
+
setContainerId(id) {
|
441
|
+
this.containerId = id;
|
442
|
+
this.vrvSVG = cq.getVrvSVG(id);
|
443
|
+
this.interactionOverlay = cq.getInteractOverlay(id);
|
444
|
+
this.container = document.getElementById(id);
|
445
|
+
return this;
|
446
|
+
}
|
447
|
+
setInsertCallback(insertCallback) {
|
448
|
+
this.insertCallback = insertCallback;
|
449
|
+
return this;
|
450
|
+
}
|
451
|
+
setDeleteCallback(deleteCallback) {
|
452
|
+
this.deleteCallback = deleteCallback;
|
453
|
+
return this;
|
454
|
+
}
|
455
|
+
}
|
456
|
+
exports.default = KeyModeHandler;
|