Keyframes: moving keys keeps subframe spacing (#1012)
keys.move and the nudges snapped each key's destination to the nearest frame, so moving keys a Quick Offset had staggered onto subframes put them back on frames: four keys at 0, 1/3, 2/3 and 1 frame, moved one frame, came out at 1, 1, 2 and 2. Layer bars kept theirs, because layer.timing snaps the move, not the times. The move is now rounded to whole frames and every key translated by it. layer_shift turns a comp-time move into a layer-time move through the layer's start and stretch (reversed too) without a round trip through comp time; keys.quickOffset uses it as well. Test: moving_staggered_keys_keeps_their_subframe_spacing (Quick Offset, then keys.move and keys.nudgeForward; fails before: 1/3 frame lands on a frame).
This commit is contained in:
@@ -9,7 +9,7 @@ use effectcraft_project::LayerId;
|
||||
use effectcraft_time::{TICKS_PER_SECOND, Tick};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::prop::{key_gesture, move_key_refs};
|
||||
use super::prop::{key_gesture, layer_shift, move_key_refs};
|
||||
use super::{CommandSpec, b_p, bad, f_p, has_keys, has_layers, layers_p, merge_p};
|
||||
use crate::{EngineError, Result, Session, cmd};
|
||||
|
||||
@@ -110,11 +110,8 @@ fn keys(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
st.selected_keys = move_key_refs(comp, &from, |l, t| {
|
||||
let Some(d) = by_layer.get(&l.id) else { return Ok(t) };
|
||||
let what = format!("a key of \"{}\"", l.name);
|
||||
let at = l.layer_time(shifted(l.comp_time(t), *d, NAME, &what)?);
|
||||
if at < Tick::MIN || at > Tick::MAX {
|
||||
return Err(bad(NAME, format!("{what} would move out of range")));
|
||||
}
|
||||
Ok(at)
|
||||
shifted(l.start_time, *d, NAME, &what)?;
|
||||
shifted(t, layer_shift(l, *d), NAME, &what)
|
||||
})?;
|
||||
Ok(json!({"keys": st.selected_keys.len(), "layers": order.iter().map(|id| json!({"layer": id.0, "offset": by_layer.get(id).copied().unwrap_or_default().seconds()})).collect::<Vec<_>>()}))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user