From be11f015b995cb626719e2fa9a61ed3866829305 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Thu, 7 Mar 2024 11:13:31 +0100 Subject: [PATCH] sync letter delays after recording --- bin/em/variabletime/web/js/record.js | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/bin/em/variabletime/web/js/record.js b/bin/em/variabletime/web/js/record.js index 5e50c68..708115e 100644 --- a/bin/em/variabletime/web/js/record.js +++ b/bin/em/variabletime/web/js/record.js @@ -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(); });