sync letter delays after recording

This commit is contained in:
themancalledjakob 2024-03-07 11:13:31 +01:00
parent 05c6f3f5f9
commit be11f015b9

View file

@ -4,6 +4,7 @@ import {
toCssClass,
flattenObject,
deFlattenObject,
getNestedProperty,
} from './utils.js';
const LiveBuffer = function() {
@ -394,6 +395,38 @@ const Record = function(tp) {
liveUpdater.immediateUpdate(layer, merged);
};
/// @brief = copies letterDelay value from audio mapping to the recorded value.
///
/// @param layer - a layer object
/// @param propPaths - two dimensional array of strings
///
/// @return
const syncLetterDelays = (layer, propPaths) => {
propPaths.forEach((path) => {
const oldLetterDelay = getNestedProperty(layer.theatreObject.value.letterDelays, path, true);
const isOriginalSequenced = tp.isSequenced(path, layer);
const isLetterDelaySequenced = tp.isSequenced(["letterDelays", path], layer);
// we use audio.getSavedMapping(), because mapping may be removed directly after recording
const mapping = getNestedProperty(audio.getSavedMapping(), [layer.id()].concat(path), true);
const newLetterDelay = (() => {
if (typeof mapping['letterDelay'] === 'undefined') {
return false;
}
return mapping['letterDelay'];
})();
if (newLetterDelay !== oldLetterDelay &&
!isLetterDelaySequenced &&
newLetterDelay !== false) {
const prop = getNestedProperty(layer.theatreObject.props.letterDelays, path);
tp.studio.transaction(({
set
}) => {
set(prop, newLetterDelay);
});
}
});
};
const startRecording = () => {
isRecording = STARTING_RECORDING;
console.log('Record::startRecording');
@ -499,10 +532,10 @@ const Record = function(tp) {
}
});
//setTimeout(() => {
const kf = clone(keyframes);
promises.push(() => {
return new Promise((subResolve) => {
tp.addKeyframes(layer, keyframes).then(() => {
syncLetterDelays(layer, keyframes.map(k => k.path));
layer.updateValuesViaTheatre(true);
subResolve();
});