fix: brush draw pitch revisit by comparing lastDrawnPitch
This commit is contained in:
@@ -5117,10 +5117,10 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
|
|||||||
startOffsetPitch: snapToScaleRef.current ? snapPitchToScale(pitch, selectedScaleRef.current) : pitch,
|
startOffsetPitch: snapToScaleRef.current ? snapPitchToScale(pitch, selectedScaleRef.current) : pitch,
|
||||||
drawNoteId: noteId,
|
drawNoteId: noteId,
|
||||||
drawDuration: initialDur,
|
drawDuration: initialDur,
|
||||||
visitedPitches: snapToScaleRef.current ? [snapPitchToScale(pitch, selectedScaleRef.current)] : [pitch],
|
|
||||||
initialBeat: start,
|
initialBeat: start,
|
||||||
initialPitch: snapToScaleRef.current ? snapPitchToScale(pitch, selectedScaleRef.current) : pitch,
|
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
|
// Play the note with SoundFont
|
||||||
if (window.SonicSF) {
|
if (window.SonicSF) {
|
||||||
@@ -5206,9 +5206,9 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (draggedNote.mode === 'draw') {
|
if (draggedNote.mode === 'draw') {
|
||||||
const visited = draggedNote.visitedPitches || [];
|
|
||||||
const snappedPitch = snapToScaleRef.current ? snapPitchToScale(pitch, selectedScaleRef.current) : pitch;
|
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 noteBeats = draggedNote.noteStartBeats || [];
|
||||||
const defaultDur = getSnapDuration(snapVal);
|
const defaultDur = getSnapDuration(snapVal);
|
||||||
if (pitchChanged) {
|
if (pitchChanged) {
|
||||||
@@ -5223,7 +5223,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
const newNote = {
|
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,
|
pitch: snappedPitch,
|
||||||
start_beat: beat,
|
start_beat: beat,
|
||||||
duration_beats: defaultDur,
|
duration_beats: defaultDur,
|
||||||
@@ -5233,7 +5233,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
|
|||||||
setNotes(prev => [...prev, newNote]);
|
setNotes(prev => [...prev, newNote]);
|
||||||
setSelectedNoteIds(prev => [...prev, newNote.id]);
|
setSelectedNoteIds(prev => [...prev, newNote.id]);
|
||||||
draggedNote.brushIds = [...brushIds, newNote.id];
|
draggedNote.brushIds = [...brushIds, newNote.id];
|
||||||
draggedNote.visitedPitches = [...visited, snappedPitch];
|
draggedNote.lastDrawnPitch = snappedPitch;
|
||||||
draggedNote.noteStartBeats = [...noteBeats, beat];
|
draggedNote.noteStartBeats = [...noteBeats, beat];
|
||||||
} else {
|
} else {
|
||||||
const brushIds = draggedNote.brushIds || [];
|
const brushIds = draggedNote.brushIds || [];
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -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.
|
- **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`
|
- **Các file ảnh hưởng:** `app/static/js/app.jsx`
|
||||||
- **Ghi chú/Test (nếu có):** `npm run build` pass.
|
- **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.
|
||||||
|
|||||||
Reference in New Issue
Block a user