FIX: sửa lỗi khi quét chọn duration để loop và khi bật nút loop thì tự động giãn ra bar 18

This commit is contained in:
2026-08-03 19:41:42 +07:00
parent 8c1a8ead56
commit ec5fedec33
4 changed files with 48 additions and 21 deletions
+27 -17
View File
@@ -17610,6 +17610,9 @@ const App = () => {
setSelectedTrackId(trackId);
captureSelectionUndo();
clearLocalSelection();
// A fresh region selection re-enables selection-looping (a previous
// Ctrl+click "clear selection" must not keep blocking the new region).
setSelectionCleared(false);
localSelectionAnchorRef.current = time;
setSelectionMode('local');
setLocalSelectionTrackId(trackId);
@@ -22525,24 +22528,31 @@ const App = () => {
setSubTabs(prev => prev.map(s => s.id === activeTab ? { ...s, selectionStart: 0, selectionEnd: loopEndTime } : s));
}
} else {
// Main timeline: auto-derive loop end from tracks
const bpmVal = parseInt(bpm) || 120;
const secPerBar = (60.0 / bpmVal) * 4;
let maxEnd = 0;
activeTracks.forEach(t => {
(t.clips || []).forEach(c => {
const end = (c.startTime || 0) + (c.duration || 0);
if (end > maxEnd) maxEnd = end;
// Main timeline / section tab: if the user already selected a loop
// region, KEEP it only auto-derive (0 content end) when no
// selection exists yet. Previously this always overwrote the
// selection with 0 (contentEnd + 2 bars).
const hasSel = (selectionMode === 'local' && selLeft !== null && selRight !== null && selRight > selLeft)
|| (selectionStart !== null && selectionEnd !== null && selectionEnd > selectionStart);
if (!hasSel) {
const bpmVal = parseInt(bpm) || 120;
const secPerBar = (60.0 / bpmVal) * 4;
let maxEnd = 0;
activeTracks.forEach(t => {
(t.clips || []).forEach(c => {
const end = (c.startTime || 0) + (c.duration || 0);
if (end > maxEnd) maxEnd = end;
});
(t.items || []).forEach(it => {
const end = (it.start || 0) + (it.duration || 4);
if (end > maxEnd) maxEnd = end;
});
});
(t.items || []).forEach(it => {
const end = (it.start || 0) + (it.duration || 4);
if (end > maxEnd) maxEnd = end;
});
});
if (maxEnd > 0) {
const loopEnd = maxEnd + secPerBar * 2;
setSelectionStart(0);
setSelectionEnd(loopEnd);
if (maxEnd > 0) {
const loopEnd = maxEnd + secPerBar * 2;
setSelectionStart(0);
setSelectionEnd(loopEnd);
}
}
}
},
File diff suppressed because one or more lines are too long