UNPKG

timeline-state-resolver

Version:
107 lines 4.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertTimelineStateToQuantelState = exports.getMappedPorts = void 0; const timeline_state_resolver_types_1 = require("timeline-state-resolver-types"); function getMappedPorts(mappings) { const ports = {}; for (const mapping of Object.values(mappings)) { if (mapping && 'portId' in mapping.options && 'channelId' in mapping.options) { if (!ports[mapping.options.portId]) { ports[mapping.options.portId] = { mode: mapping.options.mode || timeline_state_resolver_types_1.QuantelControlMode.QUALITY, channels: [], }; } // push now, sort later ports[mapping.options.portId].channels.push(mapping.options.channelId); // todo: support for multiple channels (these should be unique) } } // now sort in place for (const port of Object.values(ports)) { port.channels = port.channels.sort((a, b) => a - b); } return ports; } exports.getMappedPorts = getMappedPorts; function convertTimelineStateToQuantelState(timelineState, mappings) { const state = { time: timelineState.time, port: {}, }; // create ports from mappings: createPortsFromMappings(state, getMappedPorts(mappings)); // merge timeline layer states into port states for (const [layerName, layer] of Object.entries(timelineState.layers)) { const { foundMapping, isLookahead } = getMappingForLayer(layer, mappings, layerName); if (foundMapping && 'portId' in foundMapping.options && 'channelId' in foundMapping.options) { // mapping exists const port = state.port[foundMapping.options.portId]; if (!port) throw new Error(`Port "${foundMapping.options.portId}" not found`); // port exists const content = layer.content; if (content && (content.title || content.guid)) { // content exists and has title or guid setPortStateFromLayer(port, isLookahead, content, layer); } } } return state; } exports.convertTimelineStateToQuantelState = convertTimelineStateToQuantelState; /** Creates port on state object from mappedPorts */ function createPortsFromMappings(state, mappedPorts) { for (const [portId, port] of Object.entries(mappedPorts)) { state.port[portId] = { channels: port.channels, timelineObjId: '', mode: port.mode, lookahead: false, }; } } /** finds the correct mapping for a layer state and if the state is for a lookahead */ function getMappingForLayer(layerExt, mappings, layerName) { let foundMapping = mappings[layerName]; let isLookahead = false; if (!foundMapping && layerExt.isLookahead && layerExt.lookaheadForLayer) { foundMapping = mappings[layerExt.lookaheadForLayer]; isLookahead = true; } return { foundMapping, isLookahead }; } /** merges a layer state into a port state */ function setPortStateFromLayer(port, isLookahead, content, layer) { // Note on lookaheads: // If there is ONLY a lookahead on a port, it'll be treated as a "paused (real) clip" // If there is a lookahead alongside the a real clip, its fragments will be preloaded if (isLookahead) { port.lookaheadClip = { title: content.title, guid: content.guid, timelineObjId: layer.id, }; } if (isLookahead && port.clip) { // There is already a non-lookahead on the port // Do nothing more with this then } else { const startTime = layer.instance.originalStart || layer.instance.start; port.timelineObjId = layer.id; port.notOnAir = content.notOnAir || isLookahead; port.outTransition = content.outTransition; port.lookahead = isLookahead; port.clip = { title: content.title, guid: content.guid, // clipId // set later pauseTime: content.pauseTime, playing: isLookahead ? false : content.playing ?? true, inPoint: content.inPoint, length: content.length, playTime: (content.noStarttime || isLookahead ? null : startTime) || null, }; } } //# sourceMappingURL=state.js.map