casparcg-state
Version:
Node.js Javascript/Typescript library for keeping and resolving a given state of CasparCG into commands for casparcg-connection.
113 lines • 5.05 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveMixerState = void 0;
const mixer_1 = require("../mixer");
const util_1 = require("../util");
const _ = require("underscore");
const casparcg_connection_1 = require("casparcg-connection");
function resolveMixerState(oldState, newState, channel, layer) {
const newChannel = (0, util_1.getChannel)(newState, channel);
const oldLayer = (0, util_1.getLayer)(oldState, channel, layer);
const newLayer = (0, util_1.getLayer)(newState, channel, layer);
const diffCmds = {
cmds: [],
};
const bundledCmds = {};
if (!newLayer.mixer)
newLayer.mixer = new mixer_1.Mixer();
if (!oldLayer.mixer)
oldLayer.mixer = new mixer_1.Mixer();
const pushMixerCommand = (attr, command, subValue) => {
const diff = (0, util_1.compareMixerValues)(newLayer, oldLayer, attr, _.isArray(subValue) ? subValue : undefined);
if (diff) {
const options = {};
options.channel = newChannel.channelNo;
if (newLayer.layerNo !== -1) {
options.layer = newLayer.layerNo;
}
let o = mixer_1.Mixer.getValue((newLayer.mixer || {})[attr]);
if (newLayer.mixer && _.has(newLayer.mixer, attr) && !_.isUndefined(o)) {
(0, util_1.setMixerTransition)(options, newChannel, oldLayer, newLayer.mixer, false);
}
else {
(0, util_1.setMixerTransition)(options, newChannel, oldLayer, newLayer.mixer, true);
o = mixer_1.Mixer.getDefaultValues(attr);
}
if (_.isArray(subValue)) {
_.each(subValue, (sv) => {
options[sv] = o[sv];
});
}
else if (_.isString(subValue)) {
if (_.isObject(o) && o._transition) {
options[subValue] = o._value;
}
else {
options[subValue] = o;
}
}
if (newLayer && newLayer.mixer && newLayer.mixer.bundleWithCommands) {
// options['bundleWithCommands'] = newLayer.mixer.bundleWithCommands
const key = newLayer.mixer.bundleWithCommands + '';
if (!bundledCmds[key])
bundledCmds[key] = [];
options['defer'] = true;
bundledCmds[key].push((0, util_1.addContext)({ command, params: options }, `Bundle: ${diff}`, newLayer));
}
else {
(0, util_1.addCommands)(diffCmds, (0, util_1.addContext)({ command, params: options }, `Mixer: ${diff}`, newLayer || oldLayer));
}
}
};
pushMixerCommand('anchor', casparcg_connection_1.Commands.MixerAnchor, ['x', 'y']);
pushMixerCommand('blendmode', casparcg_connection_1.Commands.MixerBlend, 'value');
pushMixerCommand('brightness', casparcg_connection_1.Commands.MixerBrightness, 'value');
pushMixerCommand('chroma', casparcg_connection_1.Commands.MixerChroma, [
'enable',
'targetHue',
'hueWidth',
'minSaturation',
'minBrightness',
'softness',
'spillSuppress',
'spillSuppressSaturation',
'showMask',
]);
pushMixerCommand('clip', casparcg_connection_1.Commands.MixerClip, ['x', 'y', 'width', 'height']);
pushMixerCommand('contrast', casparcg_connection_1.Commands.MixerContrast, 'value');
pushMixerCommand('crop', casparcg_connection_1.Commands.MixerCrop, ['left', 'top', 'right', 'bottom']);
pushMixerCommand('fill', casparcg_connection_1.Commands.MixerFill, ['x', 'y', 'xScale', 'yScale']);
// grid
pushMixerCommand('keyer', casparcg_connection_1.Commands.MixerKeyer, 'keyer');
pushMixerCommand('levels', casparcg_connection_1.Commands.MixerLevels, [
'minInput',
'maxInput',
'gamma',
'minOutput',
'maxOutput',
]);
if (newLayer.layerNo === -1) {
pushMixerCommand('mastervolume', casparcg_connection_1.Commands.MixerMastervolume, 'value');
}
// mipmap
pushMixerCommand('opacity', casparcg_connection_1.Commands.MixerOpacity, 'value');
pushMixerCommand('perspective', casparcg_connection_1.Commands.MixerPerspective, [
'topLeftX',
'topLeftY',
'topRightX',
'topRightY',
'bottomRightX',
'bottomRightY',
'bottomLeftX',
'bottomLeftY',
]);
pushMixerCommand('rotation', casparcg_connection_1.Commands.MixerRotation, 'value');
pushMixerCommand('saturation', casparcg_connection_1.Commands.MixerSaturation, 'value');
if (newLayer.layerNo === -1) {
pushMixerCommand('straightAlpha', casparcg_connection_1.Commands.MixerStraightAlphaOutput, 'value');
}
pushMixerCommand('volume', casparcg_connection_1.Commands.MixerVolume, 'value');
return { commands: diffCmds, bundledCmds };
}
exports.resolveMixerState = resolveMixerState;
//# sourceMappingURL=mixer.js.map
;