FIX: sửa lỗi chuyển từ tab PIANO ROLL TAB sang MAIN SESSION/SECTION-TAB không đồng bộ playhead

This commit is contained in:
2026-08-07 10:12:18 +07:00
parent 4c820bfa77
commit bca661bffd
4 changed files with 80 additions and 23 deletions
+32 -10
View File
@@ -14838,7 +14838,12 @@ const App = () => {
if (prevTab !== activeTab) {
const prevSub = subTabsRef.current.find(s => s.id === prevTab);
if (prevSub && prevSub.isPlaying) {
try { stopAllPlayback(); } catch (e) {}
// PIANO ROLL tab: KHÔNG stop âm khi ri tab (SF notes đã schedule
// tiếp tc kêu t nhiên user: chuyn tab qua li KHÔNG đưc câm).
// Audio sub-tab (buffer source riêng): vn stop như cũ.
if (prevSub.type !== 'PIANO_ROLL') {
try { stopAllPlayback(); } catch (e) {}
}
setSubTabs(prev => prev.map(s => s.id === prevTab ? { ...s, isPlaying: false } : s));
// Resume main/session play khi ri PIANO ROLL tab đã play (Space):
// play piano roll stopAllPlayback dng main quay li MAIN/SECTION
@@ -14857,6 +14862,17 @@ const App = () => {
startTrackPlayback(_resumeAt);
setIsPlaying(true);
} catch (e) { console.warn('[Resume] error:', e); }
} else if (prevSub.type === 'PIANO_ROLL' && (activeTab === 'main' || (activeTab && activeTab.startsWith('session_')))) {
// Play THUN piano roll (main chưa tng play mainResumeRef null):
// ri tab KHÔNG stop âm (0415) NHƯNG isPlaying=false nhánh
// main updatePlayhead `if (!isPlaying) return` playhead NGNG dù
// âm piano roll còn kêu (user: playhead không đng b/ngng khi
// chuyn tab). setIsPlaying(true): playhead main/section chy theo
// elapsed (startOffsetTimeRef/startAudioTimeRef đang là ca piano
// roll play đng b vi âm đang phát). Hết bài (projectEnd)
// nhánh main t stop.
console.log('[Playhead] tiếp tục theo piano roll (không stop âm) — activeTab=' + activeTab);
setIsPlaying(true);
}
} else if (prevSub && prevSub.type === 'PIANO_ROLL') {
// Ri PIANO ROLL tab KHÔNG play: main/section play ngm vn chy (âm
@@ -15936,7 +15952,12 @@ const App = () => {
const handler = e => {
// Bypass global hotkeys when typing inside input/textarea/contentEditable elements
if (e.target && (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.isContentEditable)) {
return;
// PIANO ROLL tab: Space LUÔN play/stop (user yêu cu transport phi
// capture đưc k c khi có input đang focus trong tab) các phím
// khác vn bypass đ gõ liu bình thưng.
if (!(e.key === ' ' || e.code === 'Space') || !activeTabRef.current || !activeTabRef.current.startsWith('midi_')) {
return;
}
}
const ctrl = e.ctrlKey || e.metaKey;
const alt = e.altKey;
@@ -18465,14 +18486,15 @@ const App = () => {
const st = subTabsRef.current.find(s => s.id === activeTabRef.current);
if (!st || !st.buffer) return;
if (!st.isPlaying) {
// PIANO ROLL / sub-tab KHÔNG play (mi m, đang edit): playhead ca
// MAIN/SECTION KHÔNG đưc tiếp tc di chuyn (yêu cu user) KHÔNG
// setCurrentTime. Loop phi TIP TC (rAF) đ khi quay li tab playhead
// không nhy vt sai lch. KHÔNG check projectEnd đây: projectEnd
// tính theo activeTab piano roll tab (sub-tab) projectEnd = 1s
// updatedTime (elapsed tht) >= 1 stopAllPlayback NGAY CÂM + panic
// notes. Âm main đã schedule hết t startTrackPlayback t hết đúng
// lúc; khi quay li MAIN nhánh main t stop ti projectEnd tht.
// PIANO ROLL / sub-tab KHÔNG play: playhead theo MAIN/SECTION nếu đang
// play (đng b v trí âm THT user: di chuyn tab qua li quay
// li piano roll tab playhead phi chy theo âm đang phát); không
// có play nào đng yên (chế đ edit). Loop luôn tiếp tc (rAF).
if (isPlaying) {
const context = getAudioContext();
const _ph = startOffsetTimeRef.current + (context.currentTime - startAudioTimeRef.current);
setSubTabs(prev => prev.map(s => s.id === st.id ? { ...s, currentTime: _ph } : s));
}
animationFrameIdRef.current = requestAnimationFrame(updatePlayhead);
return;
}