fix: brush draw pitch revisit by comparing lastDrawnPitch

This commit is contained in:
2026-07-26 10:55:21 +07:00
parent bc0c2d3279
commit 27d9556a9d
3 changed files with 13 additions and 8 deletions
+6 -6
View File
@@ -5117,10 +5117,10 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
startOffsetPitch: snapToScaleRef.current ? snapPitchToScale(pitch, selectedScaleRef.current) : pitch,
drawNoteId: noteId,
drawDuration: initialDur,
visitedPitches: snapToScaleRef.current ? [snapPitchToScale(pitch, selectedScaleRef.current)] : [pitch],
initialBeat: start,
initialPitch: snapToScaleRef.current ? snapPitchToScale(pitch, selectedScaleRef.current) : pitch,
noteStartBeats: [start]
noteStartBeats: [start],
lastDrawnPitch: snapToScaleRef.current ? snapPitchToScale(pitch, selectedScaleRef.current) : pitch
});
// Play the note with SoundFont
if (window.SonicSF) {
@@ -5206,9 +5206,9 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
return;
}
if (draggedNote.mode === 'draw') {
const visited = draggedNote.visitedPitches || [];
const snappedPitch = snapToScaleRef.current ? snapPitchToScale(pitch, selectedScaleRef.current) : pitch;
const pitchChanged = !visited.includes(snappedPitch);
const lastPitch = draggedNote.lastDrawnPitch !== undefined ? draggedNote.lastDrawnPitch : draggedNote.startOffsetPitch;
const pitchChanged = snappedPitch !== lastPitch;
const noteBeats = draggedNote.noteStartBeats || [];
const defaultDur = getSnapDuration(snapVal);
if (pitchChanged) {
@@ -5223,7 +5223,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
}));
}
const newNote = {
id: 'note_' + Date.now() + Math.random().toString(36).substr(2, 8) + '_' + (visited.length + 1),
id: 'note_' + Date.now() + Math.random().toString(36).substr(2, 8) + '_' + (noteBeats.length + 1),
pitch: snappedPitch,
start_beat: beat,
duration_beats: defaultDur,
@@ -5233,7 +5233,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
setNotes(prev => [...prev, newNote]);
setSelectedNoteIds(prev => [...prev, newNote.id]);
draggedNote.brushIds = [...brushIds, newNote.id];
draggedNote.visitedPitches = [...visited, snappedPitch];
draggedNote.lastDrawnPitch = snappedPitch;
draggedNote.noteStartBeats = [...noteBeats, beat];
} else {
const brushIds = draggedNote.brushIds || [];
File diff suppressed because one or more lines are too long
+5
View File
@@ -205,3 +205,8 @@
- **Tóm tắt thay đổi:** (1) Thêm `noteStartBeats` array trong `draggedNote` — track start beat của từng note. Khi tạo note mới (pitchChanged), fix duration của note trước đó thành `beat - prevNoteBeat`. Khi extend (cùng pitch), chỉ extend note cuối với `beat - lastNoteBeat` (không extend toàn bộ stroke). (2) Khởi tạo `noteStartBeats: [start]` trong setDraggedNote. Fix lỗi note cuối có duration dài bằng toàn bộ brush stroke.
- **Các file ảnh hưởng:** `app/static/js/app.jsx`
- **Ghi chú/Test (nếu có):** `npm run build` pass.
### [2026-07-26 10:55] Task: Fix brush draw pitch revisit by comparing lastDrawnPitch
- **Tóm tắt thay đổi:** Thay `!visited.includes(snappedPitch)` bằng `snappedPitch !== lastDrawnPitch`. Bug cũ: khi vẽ C→D→C, visited.includes(C) = true → không tạo note mới → note D cũ bị extend. Fix: so sánh với pitch của note cuối cùng, cho phép vẽ tiếp khi pitch thay đổi dù đã visit trước đó. Bỏ `visitedPitches` (không còn dùng).
- **Các file ảnh hưởng:** `app/static/js/app.jsx`
- **Ghi chú/Test (nếu có):** `npm run build` pass.