diff --git a/src/control.js b/src/control.js index e33679c..94b83a2 100644 --- a/src/control.js +++ b/src/control.js @@ -204,10 +204,10 @@ let sceneImgTarget = -1, sceneCueTarget = -1; // track/cue awaiting an image let activeCues = [], firedCue = -1; // cue schedule for the playing track function serializePlaylist() { - return playlist.map(t => ({ path: t.path, name: t.name, key: t.key || null, cues: t.cues || [], isVideo: !!t.isVideo })); + return playlist.map(t => ({ path: t.path, name: t.name, key: t.key || null, cues: t.cues || [], isVideo: !!t.isVideo, gap: t.gap || 0 })); } function normalizeTrack(t) { - return { path: t.path, name: t.name || baseName(t.path), key: t.key || null, cues: migrateCues(Array.isArray(t.cues) ? t.cues : []), isVideo: !!t.isVideo }; + return { path: t.path, name: t.name || baseName(t.path), key: t.key || null, cues: migrateCues(Array.isArray(t.cues) ? t.cues : []), isVideo: !!t.isVideo, gap: t.gap || 0 }; } function savePlaylistState() { if (djv.savePlaylist) djv.savePlaylist(serializePlaylist()); @@ -273,10 +273,13 @@ function migrateCues(cues) { // Runtime: re-evaluate which element is active per channel and diff-apply it. let lastScene = { effect: null, text: null, image: null }; +let userTrackBlend = 'normal'; // playlist-video blend chosen by the user +let sentTrackBlend = null; // last blend pushed to the output (auto or manual) function startCues(tr) { tr.cues = migrateCues(tr.cues || []); activeCues = tr.cues.slice().sort((a, b) => a.time - b.time); + sentTrackBlend = null; // re-evaluate auto-blend for the new track // `undefined` (not null) forces advanceCues to APPLY every channel once, so a // stale text/image from the previous track is cleared even when the new scene // has nothing active at t=0. @@ -295,6 +298,15 @@ function sceneActive(type, t) { function advanceCues(t) { const ef = sceneActive('effect', t); if (ef !== lastScene.effect) { lastScene.effect = ef; if (ef && EFFECTS.list[ef.effectIndex]) applyEffect(EFFECTS.list[ef.effectIndex]); } + // Auto-blend: on a video track, when a scene effect is active, blend the video + // ('screen') so the effect shows through underneath. Only when the user left + // the blend at the default 'normal' — a manual choice is always respected. + const curTr = playlist[currentIndex]; + if (curTr && curTr.isVideo) { + const effOn = !!(ef && ef.effectIndex != null && EFFECTS.list[ef.effectIndex]); + const wantBlend = (effOn && userTrackBlend === 'normal') ? 'screen' : userTrackBlend; + if (wantBlend !== sentTrackBlend) { sentTrackBlend = wantBlend; send({ type: 'trackVideoBlend', value: wantBlend }); } + } const tx = sceneActive('text', t); if (tx !== lastScene.text) { lastScene.text = tx; applyTextEl(tx); } const im = sceneActive('image', t); @@ -344,7 +356,7 @@ function probePaths(paths) { function addTracks(items) { // items: array of { path, name } const start = playlist.length; - items.forEach(it => { if (it.path) playlist.push({ path: it.path, name: it.name || baseName(it.path), key: null, cues: [], isVideo: !!it.isVideo }); }); + items.forEach(it => { if (it.path) playlist.push({ path: it.path, name: it.name || baseName(it.path), key: null, cues: [], isVideo: !!it.isVideo, gap: 0 }); }); renderPlaylist(); savePlaylistState(); probePaths(items.map(it => it.path)); @@ -354,6 +366,7 @@ function addTracks(items) { function playIndex(i) { if (i < 0 || i >= playlist.length) return; + clearGap(); currentIndex = i; isPlaying = true; ended = false; @@ -374,6 +387,31 @@ function nextTrack() { return true; } +// Inter-track gap: after a track ends, keep its scene timeline running for +// `secs` seconds (so scene elements scheduled past the song length show as an +// intermission) while the audio is silent, then advance to the next track. +let gapTimer = null, gapRemain = 0; +function clearGap() { if (gapTimer) { clearInterval(gapTimer); gapTimer = null; } gapRemain = 0; } +function startGap(tr, secs) { + clearGap(); + send({ type: 'tickerText', text: '' }); // any live ticker handled by scene cues below + const base = playDur || playCur || 0; + const t0 = Date.now(); + gapRemain = secs; + const tick = () => { + const elapsed = (Date.now() - t0) / 1000; + gapRemain = Math.max(0, secs - elapsed); + advanceCues(base + elapsed); // drive scene elements placed after the song end + renderPlaylist(); + if (elapsed >= secs) { + clearGap(); + if (!nextTrack()) { isPlaying = false; ended = true; $('#btn-play').textContent = '▶ Play'; renderPlaylist(); } + } + }; + gapTimer = setInterval(tick, 200); + tick(); +} + function removeTrack(i) { playlist.splice(i, 1); if (i === currentIndex) currentIndex = -1; @@ -501,6 +539,10 @@ function buildSceneEditor(tr, i, li) { '' + '' + '' + + '' + + '