Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
621 changes: 621 additions & 0 deletions crates/opentake-ops/src/command.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/opentake-ops/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub use engines::{
// --- Command layer ---
pub use command::{
apply, ClipEntry, ClipProperties, EditCommand, EditError, EditResult, KeyframePayload,
KeyframeProperty, RenameEntry, TextEntry,
KeyframeProperty, KeyframeValue, RenameEntry, TextEntry,
};
pub use editor_state::{DocSnapshot, EditorState};
pub use id::{IdGen, SeqIdGen};
Expand Down
129 changes: 128 additions & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use opentake_core::{AppCore, CmdError, EditCommand};

use opentake_ops::{
ClipEntry, ClipMove, ClipProperties, FrameRange, KeyframePayload, KeyframeProperty,
RenameEntry, TextEntry,
KeyframeValue, RenameEntry, TextEntry,
};

use opentake_domain::{
Expand Down Expand Up @@ -291,6 +291,13 @@ pub enum EditRequest {
frame: i32,
},
#[serde(rename_all = "camelCase")]
UpsertKeyframe {
clip_id: String,
property: KeyframePropertyDto,
frame: i32,
value: KeyframeValueDto,
},
#[serde(rename_all = "camelCase")]
RemoveKeyframe {
clip_id: String,
property: KeyframePropertyDto,
Expand Down Expand Up @@ -378,6 +385,8 @@ pub enum EditRequest {
DeleteFolder { folder_ids: Vec<String> },
#[serde(rename_all = "camelCase")]
SwapMedia { clip_id: String, media_ref: String },
#[serde(rename_all = "camelCase")]
ResetTransform { clip_ids: Vec<String> },
}

impl EditRequest {
Expand Down Expand Up @@ -439,6 +448,17 @@ impl EditRequest {
property: property.into(),
frame,
},
EditRequest::UpsertKeyframe {
clip_id,
property,
frame,
value,
} => EditCommand::UpsertKeyframe {
clip_id,
property: property.into(),
frame,
value: value.into_value(),
},
EditRequest::RemoveKeyframe {
clip_id,
property,
Expand Down Expand Up @@ -550,6 +570,7 @@ impl EditRequest {
EditRequest::SwapMedia { clip_id, media_ref } => {
EditCommand::SwapMedia { clip_id, media_ref }
}
EditRequest::ResetTransform { clip_ids } => EditCommand::ResetTransform { clip_ids },
})
}
}
Expand Down Expand Up @@ -837,6 +858,27 @@ impl KeyframePayloadDto {
}
}

/// An explicit single-value payload for [`EditRequest::UpsertKeyframe`]. Mirrors
/// [`KeyframePayloadDto`]'s `kind`-tagging, but carries one value (not a whole
/// replacement track) to upsert at the command's `frame`.
#[derive(Debug, Deserialize)]
#[serde(tag = "kind", rename_all = "camelCase")]
pub enum KeyframeValueDto {
Scalar { value: f64 },
Pair { value: AnimPair },
Crop { value: Crop },
}

impl KeyframeValueDto {
fn into_value(self) -> KeyframeValue {
match self {
KeyframeValueDto::Scalar { value } => KeyframeValue::Scalar(value),
KeyframeValueDto::Pair { value } => KeyframeValue::Pair(value),
KeyframeValueDto::Crop { value } => KeyframeValue::Crop(value),
}
}
}

#[cfg(test)]
mod edit_request_serde_tests {
use super::EditRequest;
Expand Down Expand Up @@ -933,6 +975,74 @@ mod edit_request_serde_tests {
}
}

#[test]
fn deserializes_upsert_keyframe_scalar_and_maps_to_command() {
// camelCase clipId/frame must deserialize (the recurring DTO camelCase
// trap), and the "scalar" kind must map onto KeyframeValue::Scalar.
let request = serde_json::from_str::<EditRequest>(
r#"{"type":"upsertKeyframe","clipId":"clip-1","property":"opacity","frame":110,"value":{"kind":"scalar","value":0.25}}"#,
)
.expect("upsertKeyframe scalar camelCase");

match request.into_command().expect("upsertKeyframe command") {
EditCommand::UpsertKeyframe {
clip_id,
property,
frame,
value,
} => {
assert_eq!(clip_id, "clip-1");
assert_eq!(property, opentake_ops::KeyframeProperty::Opacity);
assert_eq!(frame, 110);
assert!(matches!(value, opentake_ops::KeyframeValue::Scalar(v) if v == 0.25));
}
other => panic!("expected UpsertKeyframe, got {other:?}"),
}
}

#[test]
fn deserializes_upsert_keyframe_pair_and_crop_and_maps_to_command() {
let pair_request = serde_json::from_str::<EditRequest>(
r#"{"type":"upsertKeyframe","clipId":"clip-1","property":"position","frame":10,"value":{"kind":"pair","value":{"a":0.3,"b":0.7}}}"#,
)
.expect("upsertKeyframe pair camelCase");
match pair_request
.into_command()
.expect("upsertKeyframe pair command")
{
EditCommand::UpsertKeyframe {
property, value, ..
} => {
assert_eq!(property, opentake_ops::KeyframeProperty::Position);
match value {
opentake_ops::KeyframeValue::Pair(p) => {
assert_eq!(p.a, 0.3);
assert_eq!(p.b, 0.7);
}
other => panic!("expected Pair value, got {other:?}"),
}
}
other => panic!("expected UpsertKeyframe, got {other:?}"),
}

let crop_request = serde_json::from_str::<EditRequest>(
r#"{"type":"upsertKeyframe","clipId":"clip-1","property":"crop","frame":10,"value":{"kind":"crop","value":{"left":0.1,"top":0.2,"right":0.3,"bottom":0.4}}}"#,
)
.expect("upsertKeyframe crop camelCase");
match crop_request
.into_command()
.expect("upsertKeyframe crop command")
{
EditCommand::UpsertKeyframe {
property, value, ..
} => {
assert_eq!(property, opentake_ops::KeyframeProperty::Crop);
assert!(matches!(value, opentake_ops::KeyframeValue::Crop(_)));
}
other => panic!("expected UpsertKeyframe, got {other:?}"),
}
}

#[test]
fn deserializes_effect_commands_and_maps_to_ops_variants() {
let grade = serde_json::from_str::<EditRequest>(
Expand Down Expand Up @@ -978,6 +1088,23 @@ mod edit_request_serde_tests {
}
}

/// Guards the IPC boundary (`AGENTS.md` camelCase discipline): the
/// multiword `clipIds` field must deserialize on the wire exactly like the
/// other multi-clip commands (`setColorGrade` et al.).
#[test]
fn deserializes_reset_transform_camelcase_and_maps_to_ops_variant() {
let req = serde_json::from_str::<EditRequest>(
r#"{"type":"resetTransform","clipIds":["clip-1","clip-2"]}"#,
)
.expect("resetTransform camelCase");
match req.into_command().expect("resetTransform command") {
EditCommand::ResetTransform { clip_ids } => {
assert_eq!(clip_ids, vec!["clip-1", "clip-2"]);
}
other => panic!("expected ResetTransform, got {other:?}"),
}
}

#[test]
fn deserializes_media_library_commands_and_maps_to_ops_variants() {
let rename_media = serde_json::from_str::<EditRequest>(
Expand Down
Loading
Loading