FIX: sửa lỗi chuyển từ tab PIANO ROLL TAB sang MAIN SESSION và SECTION-TAB thì bị câm

This commit is contained in:
2026-08-07 09:35:40 +07:00
parent 8cdf2942b9
commit 4c820bfa77
4 changed files with 111 additions and 7 deletions
+52 -2
View File
@@ -14840,6 +14840,31 @@ const App = () => {
if (prevSub && prevSub.isPlaying) {
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
// b CÂM. Resume startTrackPlayback(offset + elapsed tht) ch khi
// trưc đó m tab lúc main đang play (mainResumeRef đã set).
const _resume = mainResumeRef.current;
mainResumeRef.current = null;
if (_resume && prevSub.type === 'PIANO_ROLL' && (activeTab === 'main' || (activeTab && activeTab.startsWith('session_')))) {
try {
const _elapsed = getAudioContext().currentTime - _resume.audioTime;
const _resumeAt = _resume.offset + _elapsed;
console.log('[Resume] main play từ', _resumeAt.toFixed(2), 's (offset', _resume.offset.toFixed(2), '+ elapsed', _elapsed.toFixed(2), ')');
stopAllPlayback();
startOffsetTimeRef.current = _resumeAt;
startAudioTimeRef.current = getAudioContext().currentTime;
startTrackPlayback(_resumeAt);
setIsPlaying(true);
} catch (e) { console.warn('[Resume] error:', e); }
}
} else if (prevSub && prevSub.type === 'PIANO_ROLL') {
// Ri PIANO ROLL tab KHÔNG play: main/section play ngm vn chy (âm
// tiếp tc t nhiên không cn resume) clear resume point.
// KHÔNG clear khi prevTab = main/session (đang DI CHUYN VÀO piano
// roll mainResumeRef va set bi handleEditMidiInTab clear nhm
// đây làm resume chết quay li main/section b CÂM).
mainResumeRef.current = null;
}
}
}, [activeTab]);
@@ -15562,6 +15587,11 @@ const App = () => {
const isDraggingSubTabRef = useRef(false);
const handlePlayPauseRef = useRef(null);
const currentTimeRef = useRef(currentTime);
// Resume main/session play khi ri PIANO ROLL tab: m piano roll lúc main
// đang play bm Space (play piano roll) stopAllPlayback dng main
// quay li MAIN/SECTION CÂM. Lưu {offset, audioTime} lúc m tab khi
// ri tab resume startTrackPlayback(offset + elapsed tht).
const mainResumeRef = useRef(null);
currentTimeRef.current = currentTime;
// Keyboard Shortcuts
@@ -16424,7 +16454,15 @@ const App = () => {
// m PIANO ROLL tab KHÔNG đưc dng âm (user: dblclick m tab lúc main
// play âm main phi tiếp tc). Nhánh play sub-tab t stopAllPlayback
// trưc khi play nên không xung đt route.
if (!isPlaying) stopAllPlayback();
if (isPlaying) {
// Lưu đim resume: nếu user bm Space trong piano roll (play piano roll
// stopAllPlayback dng main) khi quay li MAIN/SECTION resume main
// t đúng v trí âm (offset + elapsed tht) hết câm.
mainResumeRef.current = { offset: startOffsetTimeRef.current, audioTime: getAudioContext().currentTime };
} else {
mainResumeRef.current = null;
stopAllPlayback();
}
const ctx = getAudioContext();
const silentBuffer = ctx.createBuffer(1, 128, ctx.sampleRate);
@@ -18425,7 +18463,19 @@ const App = () => {
const isSubTab = subTabsRef.current.some(sub => sub.id === activeTabRef.current);
if (isSubTab) {
const st = subTabsRef.current.find(s => s.id === activeTabRef.current);
if (!st || !st.isPlaying || !st.buffer) return;
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.
animationFrameIdRef.current = requestAnimationFrame(updatePlayhead);
return;
}
const context = getAudioContext();
const speedFactor = st.speed || 1.0;
const elapsed = context.currentTime - startAudioTimeRef.current;
File diff suppressed because one or more lines are too long