Skip to content

Commit 381498f

Browse files
committed
fix: correct piano note selection logic
1 parent 2ced8a8 commit 381498f

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# majiccode.github.io
2+
3+
Toy website with just some experiments, doodles if you will..

pages/piano.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ if (canvas) {
155155
function getCanvasPosition(e) {
156156
const rect = canvas.getBoundingClientRect();
157157
const x = e.clientX - rect.left + canvas.parentElement.scrollLeft;
158-
const y = e.clientY - rect.top;
158+
const y = e.clientY - rect.top + canvas.parentElement.scrollTop;
159159
return { x, y };
160160
}
161161

@@ -167,7 +167,7 @@ if (canvas) {
167167
const adjustedX = x - NOTE_LABEL_WIDTH;
168168

169169
// Support quarter note resolution (0.25 beats) for syncopation
170-
const beatPos = Math.round((adjustedX / GRID_WIDTH) * 4) / 4;
170+
const beatPos = Math.floor((adjustedX / GRID_WIDTH) * 4) / 4;
171171
const noteIndex = Math.floor(y / NOTE_HEIGHT);
172172

173173
const key = `${noteIndex}-${beatPos}`;

0 commit comments

Comments
 (0)