Simplify qrunweb renderer and update screenshot utility
This commit is contained in:
@@ -160,401 +160,261 @@ header h1 { font-size: 16px; font-weight: 600; letter-spacing: 0.05em; }
|
|||||||
fetch('show.json').then(r => r.json()).then(render);
|
fetch('show.json').then(r => r.json()).then(render);
|
||||||
|
|
||||||
function render(data) {
|
function render(data) {
|
||||||
const blockMap = new Map(data.blocks.map(b => [b.id, b]));
|
const blocks = new Map(data.blocks.map(b => [b.id, b]));
|
||||||
const CUE_TRACK = '_cue';
|
const getTrack = id => blocks.get(id).type === 'cue' ? '_cue' : blocks.get(id).track;
|
||||||
const trackIds = [CUE_TRACK, ...data.tracks.map(t => t.id)];
|
const trackIds = ['_cue', ...data.tracks.map(t => t.id)];
|
||||||
|
|
||||||
function ref(b, s) { return b + ':' + s; }
|
const startSigs = new Map();
|
||||||
|
data.triggers.forEach(t => t.source.signal === 'START' && startSigs.set(t.source.block, t.targets));
|
||||||
|
|
||||||
const triggerSourceSet = new Set();
|
const isChain = t => {
|
||||||
const startSignalMap = new Map();
|
if (t.source.signal !== 'END' || t.targets.length !== 1) return false;
|
||||||
data.triggers.forEach(t => {
|
return t.targets[0].hook === 'START' && getTrack(t.source.block) === getTrack(t.targets[0].block);
|
||||||
triggerSourceSet.add(ref(t.source.block, t.source.signal));
|
};
|
||||||
if (t.source.signal === 'START') startSignalMap.set(t.source.block, t.targets);
|
|
||||||
});
|
|
||||||
|
|
||||||
function blockTrack(bid) {
|
const expand = (tgts) => {
|
||||||
const b = blockMap.get(bid);
|
const res = new Map();
|
||||||
return b.type === 'cue' ? CUE_TRACK : b.track;
|
const q = [...tgts];
|
||||||
|
while(q.length) {
|
||||||
|
const {block, hook} = q.shift();
|
||||||
|
if (!res.has(block)) { res.set(block, hook); if (hook === 'START' && startSigs.has(block)) q.push(...startSigs.get(block)); }
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
function isChain(trigger) {
|
let active = new Map(), pending = new Set(), rows = [], noTitle = new Set();
|
||||||
const src = trigger.source;
|
|
||||||
if (src.signal !== 'END' || trigger.targets.length !== 1) return false;
|
|
||||||
return trigger.targets[0].hook === 'START' &&
|
|
||||||
blockTrack(src.block) === blockTrack(trigger.targets[0].block);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('header-status').innerHTML =
|
const addRow = (cells, cls = '') => {
|
||||||
'<span><span class="status-dot"></span>QLab Connected</span>' +
|
const last = rows[rows.length-1];
|
||||||
'<span>Show: ' + data.show + '</span>' +
|
if (last && last.rowClass === cls) {
|
||||||
'<span>Cue: ' + data.blocks.filter(b => b.type === 'cue').length + '</span>';
|
let merge = true;
|
||||||
|
for (let i=0; i<cells.length; i++) {
|
||||||
const active = new Map();
|
if ((cells[i].event||cells[i].cueLabel) && (last.cells[i].event||last.cells[i].cueLabel)) { merge = false; break; }
|
||||||
const pendingEnds = new Set();
|
|
||||||
const noTitleAfter = new Set();
|
|
||||||
const rows = [];
|
|
||||||
|
|
||||||
function mid(tid) {
|
|
||||||
const a = active.get(tid);
|
|
||||||
return a ? { blockId: a, segment: 'mid' } : { empty: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
function addRow(cells, rowClass) {
|
|
||||||
rowClass = rowClass || '';
|
|
||||||
if (rows.length > 0) {
|
|
||||||
const last = rows[rows.length - 1];
|
|
||||||
if (last.rowClass === rowClass) {
|
|
||||||
let canMerge = true;
|
|
||||||
for (let i = 0; i < cells.length; i++) {
|
|
||||||
if ((cells[i].event || cells[i].cueLabel) && (last.cells[i].event || last.cells[i].cueLabel)) {
|
|
||||||
canMerge = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (canMerge) {
|
|
||||||
for (let i = 0; i < cells.length; i++) {
|
|
||||||
if (cells[i].event || cells[i].cueLabel) last.cells[i] = cells[i];
|
|
||||||
}
|
}
|
||||||
|
if (merge) {
|
||||||
|
cells.forEach((c, i) => { if (c.event||c.cueLabel) last.cells[i] = c; });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
rows.push({ cells, rowClass: cls });
|
||||||
rows.push({ cells, rowClass });
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function flush() {
|
const mid = tid => active.has(tid) ? { blockId: active.get(tid), segment: 'mid' } : { empty: true };
|
||||||
if (pendingEnds.size === 0) return;
|
const mkCells = evs => trackIds.map(tid => evs.get(tid) || mid(tid));
|
||||||
|
|
||||||
const toEnd = [...pendingEnds].filter(bid => !triggerSourceSet.has(ref(bid, 'END')));
|
const flush = () => {
|
||||||
if (toEnd.length === 0) return;
|
const toEnd = [...pending].filter(bid => !data.triggers.some(t => t.source.block === bid && t.source.signal === 'END'));
|
||||||
|
if (!toEnd.length) return;
|
||||||
|
const evs = new Map();
|
||||||
|
toEnd.forEach(bid => evs.set(getTrack(bid), { blockId: bid, segment: 'end', event: 'END' }));
|
||||||
|
addRow(mkCells(evs));
|
||||||
|
toEnd.forEach(bid => { active.delete(getTrack(bid)); pending.delete(bid); });
|
||||||
|
};
|
||||||
|
|
||||||
const cells = trackIds.map(tid => {
|
for (let i = 0; i < data.triggers.length; i++) {
|
||||||
const e = toEnd.find(bid => blockTrack(bid) === tid);
|
const t = data.triggers[i];
|
||||||
return e ? { blockId: e, segment: 'end', event: 'END' } : mid(tid);
|
if (t.source.signal === 'START') continue;
|
||||||
});
|
|
||||||
addRow(cells);
|
|
||||||
toEnd.forEach(bid => { active.delete(blockTrack(bid)); pendingEnds.delete(bid); });
|
|
||||||
}
|
|
||||||
|
|
||||||
function expandTargets(targetMap) {
|
if (isChain(t)) {
|
||||||
const toExpand = [...targetMap.entries()].filter(([_, hook]) => hook === 'START');
|
if (startSigs.has(t.targets[0].block)) {
|
||||||
toExpand.forEach(([bid]) => {
|
|
||||||
const extras = startSignalMap.get(bid);
|
|
||||||
if (extras) extras.forEach(et => { if (!targetMap.has(et.block)) targetMap.set(et.block, et.hook); });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyTargets(targetMap, tid, isCue) {
|
|
||||||
const entry = [...targetMap.entries()].find(([bid]) => blockTrack(bid) === tid);
|
|
||||||
if (!entry) return null;
|
|
||||||
const [bid, hook] = entry;
|
|
||||||
const isHook = !isCue;
|
|
||||||
if (hook === 'START') {
|
|
||||||
active.set(tid, bid);
|
|
||||||
return { blockId: bid, segment: 'start', event: 'START', isHook };
|
|
||||||
}
|
|
||||||
if (hook === 'END') return { blockId: bid, segment: 'end', event: 'END', isHook, directEnd: true };
|
|
||||||
if (hook === 'FADE_OUT') {
|
|
||||||
pendingEnds.add(bid);
|
|
||||||
return { blockId: bid, segment: 'mid', event: 'FADE_OUT' };
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function processChainBatch(chains) {
|
|
||||||
flush();
|
flush();
|
||||||
const chainEnds = [];
|
const s = t.source.block, tgt = t.targets[0].block, tid = getTrack(tgt);
|
||||||
for (const trigger of chains) {
|
|
||||||
const src = trigger.source.block;
|
const ends = new Map();
|
||||||
const tid = blockTrack(src);
|
if (active.get(tid) === s || pending.has(s)) {
|
||||||
if (active.get(tid) === src || pendingEnds.has(src)) {
|
pending.delete(s); active.delete(tid);
|
||||||
pendingEnds.delete(src);
|
ends.set(tid, { blockId: s, segment: 'end', event: 'END' });
|
||||||
chainEnds.push({ block: src, track: tid });
|
|
||||||
active.delete(tid);
|
|
||||||
}
|
}
|
||||||
}
|
if (ends.size) addRow(mkCells(ends));
|
||||||
if (chainEnds.length > 0) {
|
|
||||||
const endCells = trackIds.map(t => {
|
|
||||||
const e = chainEnds.find(ce => ce.track === t);
|
|
||||||
return e ? { blockId: e.block, segment: 'end', event: 'END' } : mid(t);
|
|
||||||
});
|
|
||||||
addRow(endCells);
|
|
||||||
}
|
|
||||||
const chainStarts = new Map();
|
|
||||||
const combinedTargets = new Map();
|
|
||||||
for (const trigger of chains) {
|
|
||||||
const tgt = trigger.targets[0].block;
|
|
||||||
const tid = blockTrack(tgt);
|
|
||||||
active.set(tid, tgt);
|
active.set(tid, tgt);
|
||||||
const targetMap = new Map();
|
const sideEffects = new Map(), starts = new Map();
|
||||||
const extras = startSignalMap.get(tgt);
|
expand(startSigs.get(tgt)).forEach((h, b) => sideEffects.set(b, h));
|
||||||
if (extras) extras.forEach(et => targetMap.set(et.block, et.hook));
|
starts.set(tid, { blockId: tgt, segment: 'start', event: 'START', isSignal: true });
|
||||||
expandTargets(targetMap);
|
|
||||||
chainStarts.set(tid, { blockId: tgt, hasTargets: targetMap.size > 0 });
|
noTitle.add(rows.length-1);
|
||||||
for (const [bid, hook] of targetMap) {
|
sideEffects.forEach((h, b) => {
|
||||||
if (!combinedTargets.has(bid)) combinedTargets.set(bid, hook);
|
const ttid = getTrack(b);
|
||||||
}
|
if (starts.has(ttid)) return;
|
||||||
}
|
if (h === 'START') { active.set(ttid, b); starts.set(ttid, { blockId: b, segment: 'start', event: 'START', isHook: true }); }
|
||||||
const hasAnyTargets = [...chainStarts.values()].some(cs => cs.hasTargets);
|
else if (h === 'END') { starts.set(ttid, { blockId: b, segment: 'end', event: 'END', isHook: true }); active.delete(ttid); }
|
||||||
noTitleAfter.add(rows.length - 1);
|
else if (h === 'FADE_OUT') { starts.set(ttid, { blockId: b, segment: 'mid', event: 'FADE_OUT' }); pending.add(b); }
|
||||||
const directEnds = [];
|
|
||||||
const startCells = trackIds.map(t => {
|
|
||||||
const cs = chainStarts.get(t);
|
|
||||||
if (cs) return { blockId: cs.blockId, segment: 'start', event: 'START', isSignal: cs.hasTargets };
|
|
||||||
const cell = applyTargets(combinedTargets, t, false);
|
|
||||||
if (cell) { if (cell.directEnd) { directEnds.push(cell.blockId); delete cell.directEnd; } return cell; }
|
|
||||||
return mid(t);
|
|
||||||
});
|
});
|
||||||
addRow(startCells, hasAnyTargets ? 'sig-row' : '');
|
addRow(mkCells(starts), sideEffects.size ? 'sig-row' : '');
|
||||||
directEnds.forEach(bid => active.delete(blockTrack(bid)));
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
function processTrigger(trigger) {
|
let batch = [t], tracks = new Set([getTrack(t.source.block)]), j = i + 1;
|
||||||
const src = trigger.source;
|
while (j < data.triggers.length) {
|
||||||
const isCue = src.signal === 'GO';
|
const c = data.triggers[j];
|
||||||
|
if (c.source.signal === 'START') { j++; continue; }
|
||||||
|
if (!isChain(c) || tracks.has(getTrack(c.source.block)) || startSigs.has(c.targets[0].block)) break;
|
||||||
|
tracks.add(getTrack(c.source.block)); batch.push(c); j++;
|
||||||
|
}
|
||||||
|
|
||||||
flush();
|
flush();
|
||||||
|
const ends = new Map();
|
||||||
const rowClass = isCue ? 'cue-row' : 'sig-row';
|
batch.forEach(c => {
|
||||||
|
const s = c.source.block, tid = getTrack(s);
|
||||||
const targetMap = new Map();
|
if (active.get(tid) === s || pending.has(s)) {
|
||||||
trigger.targets.forEach(t => targetMap.set(t.block, t.hook));
|
pending.delete(s); active.delete(tid);
|
||||||
expandTargets(targetMap);
|
ends.set(tid, { blockId: s, segment: 'end', event: 'END' });
|
||||||
|
|
||||||
const directEnds = [];
|
|
||||||
|
|
||||||
const cells = trackIds.map(tid => {
|
|
||||||
if (isCue && tid === CUE_TRACK)
|
|
||||||
return { cueLabel: blockMap.get(src.block).name };
|
|
||||||
|
|
||||||
if (!isCue && blockTrack(src.block) === tid) {
|
|
||||||
const seg = src.signal === 'END' ? 'end' : 'mid';
|
|
||||||
return { blockId: src.block, segment: seg, event: src.signal, isSignal: true };
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
if (ends.size) addRow(mkCells(ends));
|
||||||
|
|
||||||
const cell = applyTargets(targetMap, tid, isCue);
|
const starts = new Map(), sideEffects = new Map();
|
||||||
if (cell) { if (cell.directEnd) { directEnds.push(cell.blockId); delete cell.directEnd; } return cell; }
|
batch.forEach(c => {
|
||||||
|
const tgt = c.targets[0].block, tid = getTrack(tgt);
|
||||||
|
active.set(tid, tgt);
|
||||||
|
const hasSigs = startSigs.has(tgt);
|
||||||
|
if (hasSigs) expand(startSigs.get(tgt)).forEach((h, b) => sideEffects.set(b, h));
|
||||||
|
starts.set(tid, { blockId: tgt, segment: 'start', event: 'START', isSignal: hasSigs });
|
||||||
|
});
|
||||||
|
noTitle.add(rows.length-1);
|
||||||
|
|
||||||
return mid(tid);
|
sideEffects.forEach((h, b) => {
|
||||||
|
const tid = getTrack(b);
|
||||||
|
if (starts.has(tid)) return;
|
||||||
|
if (h === 'START') { active.set(tid, b); starts.set(tid, { blockId: b, segment: 'start', event: 'START', isHook: true }); }
|
||||||
|
else if (h === 'END') { starts.set(tid, { blockId: b, segment: 'end', event: 'END', isHook: true }); active.delete(tid); }
|
||||||
|
else if (h === 'FADE_OUT') { starts.set(tid, { blockId: b, segment: 'mid', event: 'FADE_OUT' }); pending.add(b); }
|
||||||
});
|
});
|
||||||
|
|
||||||
addRow(cells, rowClass);
|
addRow(mkCells(starts), sideEffects.size ? 'sig-row' : '');
|
||||||
|
i = j - 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
directEnds.forEach(bid => active.delete(blockTrack(bid)));
|
flush();
|
||||||
|
const isCue = t.source.signal === 'GO';
|
||||||
|
const tgts = new Map();
|
||||||
|
t.targets.forEach(tx => tgts.set(tx.block, tx.hook));
|
||||||
|
expand(t.targets).forEach((h, b) => tgts.set(b, h));
|
||||||
|
|
||||||
|
const evs = new Map(), directEnds = [];
|
||||||
|
if (isCue) evs.set('_cue', { cueLabel: blocks.get(t.source.block).name });
|
||||||
|
else if (getTrack(t.source.block) !== '_cue') evs.set(getTrack(t.source.block), { blockId: t.source.block, segment: t.source.signal === 'END' ? 'end' : 'mid', event: t.source.signal, isSignal: true });
|
||||||
|
|
||||||
|
tgts.forEach((h, b) => {
|
||||||
|
const tid = getTrack(b);
|
||||||
|
if (evs.has(tid)) return;
|
||||||
|
if (h === 'START') { active.set(tid, b); evs.set(tid, { blockId: b, segment: 'start', event: 'START', isHook: !isCue }); }
|
||||||
|
else if (h === 'END') { evs.set(tid, { blockId: b, segment: 'end', event: 'END', isHook: !isCue, directEnd: true }); }
|
||||||
|
else if (h === 'FADE_OUT') { evs.set(tid, { blockId: b, segment: 'mid', event: 'FADE_OUT' }); pending.add(b); }
|
||||||
|
});
|
||||||
|
|
||||||
|
const cells = mkCells(evs);
|
||||||
|
evs.forEach((c, tid) => { if(c.directEnd) { directEnds.push(c.blockId); delete c.directEnd; } });
|
||||||
|
addRow(cells, isCue ? 'cue-row' : 'sig-row');
|
||||||
|
directEnds.forEach(b => active.delete(getTrack(b)));
|
||||||
|
|
||||||
if (!isCue) {
|
if (!isCue) {
|
||||||
if (src.signal === 'FADE_OUT') pendingEnds.add(src.block);
|
if (t.source.signal === 'FADE_OUT') pending.add(t.source.block);
|
||||||
if (src.signal === 'END') {
|
if (t.source.signal === 'END') { active.delete(getTrack(t.source.block)); pending.delete(t.source.block); }
|
||||||
active.delete(blockTrack(src.block));
|
|
||||||
pendingEnds.delete(src.block);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let triggerIdx = 0;
|
|
||||||
while (triggerIdx < data.triggers.length) {
|
|
||||||
const t = data.triggers[triggerIdx];
|
|
||||||
if (t.source.signal === 'START') { triggerIdx++; continue; }
|
|
||||||
if (isChain(t)) {
|
|
||||||
if (startSignalMap.has(t.targets[0].block)) {
|
|
||||||
processChainBatch([t]);
|
|
||||||
triggerIdx++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const batch = [t];
|
|
||||||
const batchTracks = new Set([blockTrack(t.source.block)]);
|
|
||||||
let j = triggerIdx + 1;
|
|
||||||
while (j < data.triggers.length) {
|
|
||||||
if (data.triggers[j].source.signal === 'START') { j++; continue; }
|
|
||||||
if (!isChain(data.triggers[j])) break;
|
|
||||||
if (batchTracks.has(blockTrack(data.triggers[j].source.block))) break;
|
|
||||||
if (startSignalMap.has(data.triggers[j].targets[0].block)) break;
|
|
||||||
batchTracks.add(blockTrack(data.triggers[j].source.block));
|
|
||||||
batch.push(data.triggers[j]);
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
processChainBatch(batch);
|
|
||||||
triggerIdx = j;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
processTrigger(t);
|
|
||||||
triggerIdx++;
|
|
||||||
}
|
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
const stillActive = [];
|
const activeEvs = new Map();
|
||||||
for (const [tid, bid] of active) {
|
[...active].forEach(([tid, bid]) => { if (tid !== '_cue') activeEvs.set(tid, { blockId: bid, segment: 'mid', infinity: true }); });
|
||||||
if (tid !== CUE_TRACK) stillActive.push(bid);
|
if (activeEvs.size) addRow(mkCells(activeEvs));
|
||||||
}
|
|
||||||
if (stillActive.length > 0) {
|
|
||||||
const cells = trackIds.map(tid => {
|
|
||||||
const bid = stillActive.find(b => blockTrack(b) === tid);
|
|
||||||
return bid ? { blockId: bid, segment: 'mid', infinity: true } : mid(tid);
|
|
||||||
});
|
|
||||||
addRow(cells);
|
|
||||||
}
|
|
||||||
|
|
||||||
const blockOpenEnd = new Map();
|
const ranges = new Map();
|
||||||
const blockCloseStart = new Map();
|
rows.forEach((row, rIdx) => row.cells.forEach(c => {
|
||||||
const blockRange = new Map();
|
if (!c.blockId) return;
|
||||||
rows.forEach((row, idx) => {
|
const r = ranges.get(c.blockId) || { first: rIdx, last: rIdx, start: -1, end: Infinity };
|
||||||
row.cells.forEach(cell => {
|
r.last = rIdx;
|
||||||
if (!cell.blockId) return;
|
if (c.event === 'START') r.start = Math.max(r.start, rIdx);
|
||||||
const bid = cell.blockId;
|
if (['END', 'FADE_OUT'].includes(c.event)) r.end = Math.min(r.end, rIdx);
|
||||||
if (!blockRange.has(bid)) blockRange.set(bid, { first: idx, last: idx });
|
ranges.set(c.blockId, r);
|
||||||
else blockRange.get(bid).last = idx;
|
}));
|
||||||
if (cell.event === 'START') blockOpenEnd.set(bid, Math.max(blockOpenEnd.get(bid) || -1, idx));
|
|
||||||
if (cell.event === 'FADE_OUT' || cell.event === 'END') blockCloseStart.set(bid, Math.min(blockCloseStart.get(bid) || Infinity, idx));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const titlesToPlace = [];
|
const titles = [...ranges.entries()].filter(([bid]) => blocks.get(bid).type !== 'cue').map(([bid, r]) => {
|
||||||
for (const [bid, range] of blockRange) {
|
const s = r.start >= 0 ? r.start : r.first, e = r.end !== Infinity ? r.end : r.last;
|
||||||
if (blockMap.get(bid).type === 'cue') continue;
|
return { bid, track: getTrack(bid), s, e: r.end !== Infinity ? r.end - 1 : e, pos: Math.floor((s + (r.end !== Infinity ? r.end - 1 : e)) / 2) };
|
||||||
const openEnd = blockOpenEnd.get(bid) || range.first;
|
}).sort((a,b) => a.pos - b.pos);
|
||||||
const closeStart = blockCloseStart.has(bid) ? blockCloseStart.get(bid) : Infinity;
|
|
||||||
let afterRow;
|
|
||||||
if (closeStart === Infinity) {
|
|
||||||
afterRow = openEnd;
|
|
||||||
} else if (openEnd + 1 <= closeStart - 1) {
|
|
||||||
afterRow = Math.floor((openEnd + closeStart - 1) / 2);
|
|
||||||
} else {
|
|
||||||
afterRow = openEnd;
|
|
||||||
}
|
|
||||||
titlesToPlace.push({ bid, track: blockTrack(bid), afterRow, validFrom: openEnd, validTo: closeStart === Infinity ? range.last : closeStart - 1 });
|
|
||||||
}
|
|
||||||
titlesToPlace.sort((a, b) => a.afterRow - b.afterRow);
|
|
||||||
|
|
||||||
const titleGroups = [];
|
const groups = [];
|
||||||
titlesToPlace.forEach(t => {
|
titles.forEach(t => {
|
||||||
let best = -1;
|
let best = -1, bestDist = Infinity;
|
||||||
let bestDist = Infinity;
|
for (let i = 0; i < groups.length; i++) {
|
||||||
for (let i = 0; i < titleGroups.length; i++) {
|
const g = groups[i];
|
||||||
const group = titleGroups[i];
|
const iS = Math.max(g.s, t.s), iE = Math.min(g.e, t.e);
|
||||||
const iFrom = Math.max(group.validFrom, t.validFrom);
|
if (iS > iE || g.titles.some(gt => gt.track === t.track)) continue;
|
||||||
const iTo = Math.min(group.validTo, t.validTo);
|
let cand = g.pos; if (cand < iS || cand > iE) cand = Math.floor((iS + iE) / 2);
|
||||||
if (iFrom > iTo) continue;
|
if (noTitle.has(cand)) {
|
||||||
if (group.titles.some(gt => gt.track === t.track)) continue;
|
let f = false; for (let r = cand + 1; r <= iE; r++) { if (!noTitle.has(r)) { cand = r; f = true; break; } }
|
||||||
let candidate = group.afterRow;
|
if (!f) continue;
|
||||||
if (candidate < iFrom || candidate > iTo) candidate = Math.floor((iFrom + iTo) / 2);
|
|
||||||
if (noTitleAfter.has(candidate)) {
|
|
||||||
let found = false;
|
|
||||||
for (let r = candidate + 1; r <= iTo; r++) {
|
|
||||||
if (!noTitleAfter.has(r)) { candidate = r; found = true; break; }
|
|
||||||
}
|
}
|
||||||
if (!found) continue;
|
const dist = Math.abs(cand - t.pos);
|
||||||
}
|
|
||||||
const dist = Math.abs(candidate - t.afterRow);
|
|
||||||
if (dist < bestDist) { best = i; bestDist = dist; }
|
if (dist < bestDist) { best = i; bestDist = dist; }
|
||||||
}
|
}
|
||||||
if (best >= 0) {
|
if (best >= 0) {
|
||||||
const group = titleGroups[best];
|
const g = groups[best];
|
||||||
group.validFrom = Math.max(group.validFrom, t.validFrom);
|
g.s = Math.max(g.s, t.s); g.e = Math.min(g.e, t.e);
|
||||||
group.validTo = Math.min(group.validTo, t.validTo);
|
if (g.pos < g.s || g.pos > g.e) g.pos = Math.floor((g.s + g.e) / 2);
|
||||||
if (group.afterRow < group.validFrom || group.afterRow > group.validTo) {
|
if (noTitle.has(g.pos)) { for (let r = g.pos + 1; r <= g.e; r++) if (!noTitle.has(r)) { g.pos = r; break; } }
|
||||||
group.afterRow = Math.floor((group.validFrom + group.validTo) / 2);
|
g.titles.push(t);
|
||||||
}
|
|
||||||
if (noTitleAfter.has(group.afterRow)) {
|
|
||||||
for (let r = group.afterRow + 1; r <= group.validTo; r++) {
|
|
||||||
if (!noTitleAfter.has(r)) { group.afterRow = r; break; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
group.titles.push({ bid: t.bid, track: t.track });
|
|
||||||
} else {
|
} else {
|
||||||
let pos = t.afterRow;
|
let p = t.pos; if (noTitle.has(p)) { for (let r = p + 1; r <= t.e; r++) if (!noTitle.has(r)) { p = r; break; } }
|
||||||
if (noTitleAfter.has(pos)) {
|
groups.push({ pos: p, s: t.s, e: t.e, titles: [t] });
|
||||||
for (let r = pos + 1; r <= t.validTo; r++) {
|
|
||||||
if (!noTitleAfter.has(r)) { pos = r; break; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
titleGroups.push({ afterRow: pos, validFrom: t.validFrom, validTo: t.validTo, titles: [{ bid: t.bid, track: t.track }] });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
titleGroups.sort((a, b) => a.afterRow - b.afterRow);
|
groups.sort((a,b) => a.pos - b.pos);
|
||||||
|
|
||||||
const finalRows = [];
|
const finalRows = [];
|
||||||
let tgIdx = 0;
|
let gIdx = 0;
|
||||||
rows.forEach((row, idx) => {
|
rows.forEach((r, i) => {
|
||||||
finalRows.push(row);
|
finalRows.push(r);
|
||||||
while (tgIdx < titleGroups.length && titleGroups[tgIdx].afterRow === idx) {
|
while (gIdx < groups.length && groups[gIdx].pos === i) {
|
||||||
const group = titleGroups[tgIdx];
|
const g = groups[gIdx];
|
||||||
const titleCells = trackIds.map((tid, colIdx) => {
|
finalRows.push({ cells: trackIds.map((tid, col) => {
|
||||||
const t = group.titles.find(gt => gt.track === tid);
|
const t = g.titles.find(gt => gt.track === tid);
|
||||||
if (t) return { blockId: t.bid, segment: 'mid', title: blockMap.get(t.bid).name };
|
if (t) return { blockId: t.bid, segment: 'mid', title: blocks.get(t.bid).name };
|
||||||
const prev = row.cells[colIdx];
|
const p = r.cells[col];
|
||||||
if (prev.blockId && prev.segment !== 'end') return { blockId: prev.blockId, segment: 'mid' };
|
return p.blockId && p.segment !== 'end' ? { blockId: p.blockId, segment: 'mid' } : { empty: true };
|
||||||
return { empty: true };
|
}) });
|
||||||
});
|
gIdx++;
|
||||||
finalRows.push({ cells: titleCells, rowClass: '' });
|
|
||||||
tgIdx++;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('header-status').innerHTML =
|
||||||
|
`<span><span class="status-dot"></span>QLab Connected</span>` +
|
||||||
|
`<span>Show: ${data.show}</span>` +
|
||||||
|
`<span>Cue: ${data.blocks.filter(b => b.type === 'cue').length}</span>`;
|
||||||
|
|
||||||
const timeline = document.getElementById('timeline');
|
const timeline = document.getElementById('timeline');
|
||||||
const trackNames = { [CUE_TRACK]: 'Cue' };
|
timeline.style.gridTemplateColumns = `repeat(${trackIds.length}, 140px)`;
|
||||||
data.tracks.forEach(t => { trackNames[t.id] = t.name; });
|
|
||||||
timeline.style.gridTemplateColumns = 'repeat(' + trackIds.length + ', 140px)';
|
|
||||||
|
|
||||||
trackIds.forEach(tid => {
|
trackIds.forEach(tid => {
|
||||||
const th = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
th.className = 'track-header';
|
el.className = 'track-header';
|
||||||
th.textContent = trackNames[tid];
|
el.textContent = tid === '_cue' ? 'Cue' : (data.tracks.find(t => t.id === tid)||{}).name;
|
||||||
timeline.appendChild(th);
|
timeline.appendChild(el);
|
||||||
});
|
});
|
||||||
|
|
||||||
finalRows.forEach(row => {
|
finalRows.forEach(row => row.cells.forEach(c => {
|
||||||
row.cells.forEach(cell => {
|
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
let cls = 'cell';
|
div.className = 'cell ' + (row.rowClass || '');
|
||||||
if (row.rowClass) cls += ' ' + row.rowClass;
|
if (c.cueLabel) {
|
||||||
|
div.innerHTML = `<div class="cue-label">${c.cueLabel}</div>`;
|
||||||
if (cell.cueLabel) {
|
} else if (c.title) {
|
||||||
div.className = cls;
|
div.innerHTML = `<div class="block block-mid ${blocks.get(c.blockId).type}"><div class="title">${c.title}</div></div>`;
|
||||||
const label = document.createElement('div');
|
} else if (c.blockId) {
|
||||||
label.className = 'cue-label';
|
const b = blocks.get(c.blockId);
|
||||||
label.textContent = cell.cueLabel;
|
const seg = c.infinity ? 'mid' : (c.segment || 'mid');
|
||||||
div.appendChild(label);
|
div.className += c.infinity ? ' infinity-cell' : '';
|
||||||
} else if (cell.empty) {
|
let inner = `<div class="block block-${seg} ${b.type}">`;
|
||||||
div.className = cls;
|
if (c.event) {
|
||||||
} else if (cell.title) {
|
let hCls = 'hook' + (c.isSignal ? ' sig' : (c.isHook ? ' hk' : ''));
|
||||||
div.className = cls;
|
inner += `<div class="${hCls}">${c.event.replace('_', ' ')}</div>`;
|
||||||
const block = document.createElement('div');
|
|
||||||
block.className = 'block block-mid ' + blockMap.get(cell.blockId).type;
|
|
||||||
const t = document.createElement('div');
|
|
||||||
t.className = 'title';
|
|
||||||
t.textContent = cell.title;
|
|
||||||
block.appendChild(t);
|
|
||||||
div.appendChild(block);
|
|
||||||
} else if (cell.infinity) {
|
|
||||||
div.className = cls + ' infinity-cell';
|
|
||||||
const block = document.createElement('div');
|
|
||||||
block.className = 'block block-mid ' + blockMap.get(cell.blockId).type;
|
|
||||||
div.appendChild(block);
|
|
||||||
const marker = document.createElement('div');
|
|
||||||
marker.className = 'infinity-marker';
|
|
||||||
marker.innerHTML = '∿∿∿';
|
|
||||||
div.appendChild(marker);
|
|
||||||
} else {
|
|
||||||
div.className = cls;
|
|
||||||
const seg = cell.segment || 'mid';
|
|
||||||
const block = document.createElement('div');
|
|
||||||
block.className = 'block block-' + seg + ' ' + blockMap.get(cell.blockId).type;
|
|
||||||
if (cell.event) {
|
|
||||||
const hook = document.createElement('div');
|
|
||||||
let hookCls = 'hook';
|
|
||||||
if (cell.isSignal) hookCls += ' sig';
|
|
||||||
else if (cell.isHook) hookCls += ' hk';
|
|
||||||
hook.className = hookCls;
|
|
||||||
hook.textContent = cell.event.replace('_', ' ');
|
|
||||||
block.appendChild(hook);
|
|
||||||
}
|
}
|
||||||
div.appendChild(block);
|
inner += `</div>`;
|
||||||
|
if (c.infinity) inner += `<div class="infinity-marker">∿∿∿</div>`;
|
||||||
|
div.innerHTML = inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeline.appendChild(div);
|
timeline.appendChild(div);
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
exec go run ./cmd/qrunweb/ "--run-and-exit=shot-scraper http://localhost:8080/ -o /tmp/timeline.png --width 1000 --height ${1:-1200}"
|
exec go run ./cmd/qrunweb/ "--run-and-exit=shot-scraper http://localhost:8080/ -o ${2:-/tmp/timeline.png} --width 1000 --height ${1:-1200}"
|
||||||
|
|||||||
Reference in New Issue
Block a user