Skip to content

Commit

Permalink
Piano Keys gets stuck (#4179)
Browse files Browse the repository at this point in the history
* Piano key stuck fix

* piano key stuck fix

* format fix

* final fix

* fix
  • Loading branch information
Commanderk3 authored Dec 24, 2024
1 parent abd7088 commit 7be0371
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion js/widgets/musickeyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ function MusicKeyboard(activity) {
*/
let selectedNotes = [];

/**
* String of active note.
* @type {Array}
*/
let activeKey = null;

/**
* Array of row blocks.
* @type {Array}
Expand Down Expand Up @@ -507,6 +513,7 @@ function MusicKeyboard(activity) {
};

element.onmousedown = function () {
activeKey = element;
__startNote(this);
};

Expand Down Expand Up @@ -576,7 +583,18 @@ function MusicKeyboard(activity) {
};

element.onmouseup = function () {
__endNote(this);
if (activeKey === element) {
__endNote(this);
activeKey = null;
} else {
const id = activeKey.id;
if (id.includes("blackRow")) {
activeKey.style.backgroundColor = "black";
} else {
activeKey.style.backgroundColor = "white";
}
activeKey = null;
}
};
};

Expand Down Expand Up @@ -2572,6 +2590,9 @@ function MusicKeyboard(activity) {
mkbKeyboardDiv.style.width = "100%";
mkbKeyboardDiv.style.top = "0px";
mkbKeyboardDiv.style.overflow = "auto";
mkbKeyboardDiv.style.userSelect = 'none';
mkbKeyboardDiv.style.webkitUserSelect = 'none'; // Safari/Chrome
mkbKeyboardDiv.style.msUserSelect = 'none'; // Edge
mkbKeyboardDiv.innerHTML = "";
mkbKeyboardDiv.innerHTML =
' <div id="keyboardHolder2"><table class="white"><tbody><tr id="myrow"></tr></tbody></table><table class="black"><tbody><tr id="myrow2"></tr></tbody></table></div>';
Expand Down

0 comments on commit 7be0371

Please sign in to comment.