feat(engine,app): timeline markers, work area, cross-track move (M12 P4)

- facade: oakengine_sequence_set_workarea_undoable (enable+range as one
  undo record); marker add/remove/list already existed and are now
  covered by it_timeline (10 new tests: markers, workarea, cross-track)
- fixes: stubs workarea_get honored NULL out-params (is_enabled always
  failed); export tasks honor custom ranges (export_params_pod dropped
  them; oaktask EncodingParams carries has_custom_range)
- app: markers on the ruler (gpui diamond markers), menu
  sequence-add/remove marker, set/clear work area (selected-clip bounds
  or playhead+1), ruler drag previews live and commits one undoable
  record (C++ ruler semantics); export uses the work area when enabled
- cross-track clip moves were already wired; now covered end to end
This commit is contained in:
2026-08-16 16:06:19 +08:00
parent 23e6fa7a5b
commit 92daff1a83
12 changed files with 1205 additions and 23 deletions
+19 -8
View File
@@ -10870,21 +10870,27 @@ pub mod timeline {
out_den: *mut c_int,
enabled: *mut c_int,
) -> c_int {
if in_num.is_null() || in_den.is_null() || out_num.is_null() || out_den.is_null() {
return oaktimeline::error::OAKTIMELINE_E_INVALID;
}
// SAFETY: work-area handles box TimelineWorkArea.
let wa = match unsafe { oaktimeline::handle::get::<oaktimeline::workarea::TimelineWorkArea>(&w) } {
Some(wa) => wa,
None => return oaktimeline::error::OAKTIMELINE_E_INVALID,
};
let range = wa.range();
// SAFETY: valid out pointers.
// Out params may individually be NULL (the header contract); write
// each only when the caller supplied a target.
unsafe {
*in_num = range.in_().numerator() as c_int;
*in_den = range.in_().denominator() as c_int;
*out_num = range.out().numerator() as c_int;
*out_den = range.out().denominator() as c_int;
if !in_num.is_null() {
*in_num = range.in_().numerator() as c_int;
}
if !in_den.is_null() {
*in_den = range.in_().denominator() as c_int;
}
if !out_num.is_null() {
*out_num = range.out().numerator() as c_int;
}
if !out_den.is_null() {
*out_den = range.out().denominator() as c_int;
}
if !enabled.is_null() {
*enabled = if wa.enabled() { 1 } else { 0 };
}
@@ -13699,6 +13705,11 @@ pub mod task {
subtitles_enabled: pod.subtitles_enabled != 0,
export_length_num: pod.export_length_num,
export_length_den: pod.export_length_den,
has_custom_range: pod.has_custom_range != 0,
custom_range_in_num: pod.custom_range_in_num as i32,
custom_range_in_den: pod.custom_range_in_den as i32,
custom_range_out_num: pod.custom_range_out_num as i32,
custom_range_out_den: pod.custom_range_out_den as i32,
};
let _ = color_manager; // the domain ExportTask dropped the manager slot
let inner = oaktask::export::ExportTask::new(viewer_ref, encoding);
+24
View File
@@ -709,6 +709,30 @@ fn export_params_pod(params: *const OakEngineEncodingParams) -> Result<EncodingP
&mut pod.export_length_den,
);
}
// Custom in/out range (work-area export): copied so the export task
// renders exactly [in, out) instead of the whole viewer length.
if unsafe { crate::codec::oakengine_encoding_params_has_custom_range(params) } != 0 {
let mut in_num: i64 = 0;
let mut in_den: i64 = 0;
let mut out_num: i64 = 0;
let mut out_den: i64 = 0;
let rc = unsafe {
crate::codec::oakengine_encoding_params_get_custom_range(
params,
&mut in_num,
&mut in_den,
&mut out_num,
&mut out_den,
)
};
if rc == 0 {
pod.has_custom_range = 1;
pod.custom_range_in_num = in_num;
pod.custom_range_in_den = in_den;
pod.custom_range_out_num = out_num;
pod.custom_range_out_den = out_den;
}
}
if pod.video_enabled != 0 {
let mut video = std::mem::MaybeUninit::<OakVideoParamsPod>::uninit();
@@ -0,0 +1,532 @@
// Oak Video Editor - Non-Linear Video Editor
// Copyright (C) 2026 Oak Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//! Integration tests for the **timeline editing family** (M12 P4): the
//! cross-track move export `oakengine_sequence_move_clip_to_track`, the
//! sequence marker surface (add / remove / list, all undoable), and the
//! sequence work-area surface (set / get / enable / clear, live and
//! undoable). Coverage rules (see the family test charter):
//!
//! 1. no mocks — every call goes through the real facade into the real
//! module crates; the only stubs are the host-provided `oakcore_*`
//! symbols in `tests/common` (no media is decoded, so no FFmpeg);
//! 2. every export under test is exercised on a legal path with the
//! result asserted;
//! 3. illegal inputs (NULL seq, bad track types, out-of-range indices,
//! negative times) always yield a negative error code — never a crash;
//! 4. the undoable exports round-trip through `oakengine_project_undo` /
//! `oakengine_project_redo`.
//!
//! ## Serialization
//!
//! The tests assemble projects and push undo commands on the facade's
//! process-wide undo stack, so every test takes the shared stack lock (the
//! same pattern as `it_export`/`it_undo`).
use super::common;
use std::ffi::{c_char, c_int};
use std::sync::Mutex;
use crate::handle::{OakEngineFootage, OakEngineProject, OakEngineSequence, free_box};
use crate::node::{
oakengine_footage_free, oakengine_project_create, oakengine_project_free,
oakengine_project_import_footage, oakengine_project_new, oakengine_project_redo,
oakengine_project_undo,
};
use crate::timeline::{
oakengine_clip_get_range, oakengine_sequence_add_footage_clip_ex,
oakengine_sequence_add_track, oakengine_sequence_clip_at, oakengine_sequence_clip_count,
oakengine_sequence_get_workarea, oakengine_sequence_marker_add, oakengine_sequence_marker_at,
oakengine_sequence_marker_count, oakengine_sequence_marker_remove,
oakengine_sequence_move_clip_to_track, oakengine_sequence_new, oakengine_sequence_name,
oakengine_sequence_set_video_params, oakengine_sequence_set_workarea,
oakengine_sequence_set_workarea_undoable, oakengine_sequence_workarea_is_enabled,
};
use crate::undo::oakengine_undo_clear;
/// `OAKENGINE_TRACK_TYPE_*` (timeline.h).
const TRACK_VIDEO: c_int = 0;
const TRACK_AUDIO: c_int = 1;
/// Serializes every test here: the facade's global undo stack is shared
/// with the it_undo / it_export / it_storage tests.
static SERIAL: Mutex<()> = Mutex::new(());
/// Both lock guards held by [`serial`].
struct SerialGuard {
/// The [`SERIAL`] lock.
_task: std::sync::MutexGuard<'static, ()>,
/// The facade-wide undo-stack lock.
_stack: std::sync::MutexGuard<'static, ()>,
}
/// Take the [`SERIAL`] lock AND the global undo-stack lock, recovering
/// from any poisoning.
fn serial() -> SerialGuard {
let _task = SERIAL.lock().unwrap_or_else(|e| e.into_inner());
let _stack = super::it_undo::GLOBAL_STACK_LOCK
.lock()
.unwrap_or_else(|e| e.into_inner());
SerialGuard { _task, _stack }
}
/// Reads a NUL-terminated string from a facade two-stage buffer.
unsafe fn read_str(buf: *const c_char) -> String {
if buf.is_null() {
return String::new();
}
let len = (0..4096).find(|&i| unsafe { *buf.add(i) } == 0).unwrap_or(0);
String::from_utf8_lossy(unsafe { std::slice::from_raw_parts(buf as *const u8, len) })
.into_owned()
}
/// A temp file path (per-process so parallel test binaries never collide).
fn temp_path(kind: &str) -> std::path::PathBuf {
std::env::temp_dir().join(format!("oakengine-it-timeline-{kind}-{}.bin", std::process::id()))
}
/// Build a project + sequence with `video_tracks` video tracks, each
/// carrying one clip spanning `0..100` frames (media-in 0), at 25 fps.
/// The source file is a plain byte blob — the module does not probe media.
///
/// Returns `(project, sequence, footage)` — the caller releases the
/// footage with `oakengine_footage_free`, the sequence box with `free_box`,
/// and the project with `oakengine_project_free`.
///
/// # Safety
/// The returned handles must be released by the caller exactly once.
unsafe fn assemble_timeline_sequence(
video_tracks: c_int,
) -> (*mut OakEngineProject, *mut OakEngineSequence, *mut OakEngineFootage) {
unsafe {
// The caller holds the storage-config lock + storage_off_guard for
// the whole body (assembly AND the subsequent command pushes), so no
// lock is taken here (re-locking the same std mutex would deadlock).
let media = temp_path("media");
std::fs::write(&media, b"oak timeline test footage").expect("write the source blob");
let media_c = std::ffi::CString::new(media.to_string_lossy().into_owned()).unwrap();
let project = oakengine_project_create();
assert!(!project.is_null());
assert_eq!(oakengine_project_new(project), 0);
let footage = oakengine_project_import_footage(project, media_c.as_ptr());
assert!(!footage.is_null(), "import the source blob");
let seq = oakengine_sequence_new(project, c"Timeline Test".as_ptr());
assert!(!seq.is_null());
assert_eq!(
oakengine_sequence_set_video_params(seq, 640, 480, 25, 1, 1, 1, 0, 4, 0),
0,
"set the sequence frame rate"
);
for _ in 0..video_tracks {
let track = oakengine_sequence_add_track(seq, TRACK_VIDEO);
assert!(track >= 0, "add the video track");
// Only the first track carries a clip: the move tests need an
// empty destination track (and `oakengine_sequence_add_track`
// returns its index, which is 0 for the first call).
if track == 0 {
let clip = oakengine_sequence_add_footage_clip_ex(seq, footage, TRACK_VIDEO, track, 0, 100, 0);
assert!(!clip.is_null(), "place the clip");
free_box(clip);
}
}
(project, seq, footage)
}
}
/// Release the assembly returned by [`assemble_timeline_sequence`].
///
/// # Safety
/// The handles must be the ones returned by [`assemble_timeline_sequence`].
unsafe fn drop_timeline_sequence(
project: *mut OakEngineProject,
seq: *mut OakEngineSequence,
footage: *mut OakEngineFootage,
) {
unsafe {
if !footage.is_null() {
oakengine_footage_free(footage);
}
free_box::<OakEngineSequence>(seq);
oakengine_project_free(project);
}
}
/// The (in, out) frame range of the clip at `(track, index)`, read back
/// through the facade. `None` when the track has no such clip.
unsafe fn clip_range_of(seq: *mut OakEngineSequence, track: c_int, index: c_int) -> Option<(i64, i64)> {
unsafe {
let clip = oakengine_sequence_clip_at(seq, TRACK_VIDEO, track, index);
if clip.is_null() {
return None;
}
let mut in_ts: i64 = 0;
let mut out_ts: i64 = 0;
let mut media_in: i64 = 0;
assert_eq!(oakengine_clip_get_range(clip, &mut in_ts, &mut out_ts, &mut media_in), 0);
free_box(clip);
Some((in_ts, out_ts))
}
}
// ---------------------------------------------------------------------------
// Cross-track move (oakengine_sequence_move_clip_to_track)
// ---------------------------------------------------------------------------
/// A cross-track move lands the clip on the destination track at the new
/// in point, and the source spot becomes a gap (the source track's clip
/// count drops to zero). One undoable entry: undo restores the clip to its
/// original track/position, redo re-applies the move.
#[test]
fn move_clip_to_track_cross_track_roundtrip() {
let _g = serial();
common::force_link();
unsafe {
// Storage off for the whole body: the assembly and the move both
// push commands (the assembly helper's guard is dropped on return).
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(2);
assert_eq!(oakengine_undo_clear(), 0);
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 0), 1);
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 1), 0);
assert_eq!(clip_range_of(seq, 0, 0), Some((0, 100)));
// Track 0 clip 0 → track 1 at frame 30.
let rc = oakengine_sequence_move_clip_to_track(seq, TRACK_VIDEO, 0, 0, 1, 30);
assert_eq!(rc, 0, "cross-track move succeeds");
assert_eq!(
oakengine_sequence_clip_count(seq, TRACK_VIDEO, 0),
0,
"source spot becomes a gap"
);
assert_eq!(
oakengine_sequence_clip_count(seq, TRACK_VIDEO, 1),
1,
"the clip lands on the destination track"
);
assert_eq!(clip_range_of(seq, 1, 0), Some((30, 130)));
// One undo restores the original layout.
assert_eq!(oakengine_project_undo(project), 0);
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 0), 1);
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 1), 0);
assert_eq!(clip_range_of(seq, 0, 0), Some((0, 100)));
// Redo re-applies the move.
assert_eq!(oakengine_project_redo(project), 0);
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 0), 0);
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 1), 1);
assert_eq!(clip_range_of(seq, 1, 0), Some((30, 130)));
drop_timeline_sequence(project, seq, footage);
}
}
/// Moving to the same track (destination index == source index) is a
/// time-only move, equivalent to `oakengine_sequence_move_clip`.
#[test]
fn move_clip_to_track_same_track_is_time_only() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(2);
assert_eq!(oakengine_undo_clear(), 0);
let rc = oakengine_sequence_move_clip_to_track(seq, TRACK_VIDEO, 0, 0, 0, 40);
assert_eq!(rc, 0, "same-track move succeeds");
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 0), 1);
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 1), 0);
assert_eq!(clip_range_of(seq, 0, 0), Some((40, 140)));
assert_eq!(oakengine_project_undo(project), 0);
assert_eq!(clip_range_of(seq, 0, 0), Some((0, 100)));
drop_timeline_sequence(project, seq, footage);
}
}
/// Illegal inputs never crash: NULL sequence, unknown track types,
/// negative in points, missing clips and out-of-range destination tracks
/// all yield a negative error code.
#[test]
fn move_clip_to_track_rejects_illegal_inputs() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(1);
assert_eq!(oakengine_undo_clear(), 0);
// NULL sequence.
assert!(oakengine_sequence_move_clip_to_track(
std::ptr::null_mut(), TRACK_VIDEO, 0, 0, 1, 10
) < 0);
// Unknown track types.
assert!(oakengine_sequence_move_clip_to_track(seq, 3, 0, 0, 1, 10) < 0);
assert!(oakengine_sequence_move_clip_to_track(seq, -1, 0, 0, 1, 10) < 0);
// Negative destination in point.
assert!(oakengine_sequence_move_clip_to_track(seq, TRACK_VIDEO, 0, 0, 1, -5) < 0);
// Missing clip (index 5 on a one-clip track).
assert!(oakengine_sequence_move_clip_to_track(seq, TRACK_VIDEO, 0, 5, 1, 10) < 0);
assert!(oakengine_sequence_move_clip_to_track(seq, TRACK_VIDEO, 2, 0, 1, 10) < 0);
// Destination track out of range.
assert!(oakengine_sequence_move_clip_to_track(seq, TRACK_VIDEO, 0, 0, 9, 10) < 0);
// The rejections left the sequence untouched.
assert_eq!(oakengine_sequence_clip_count(seq, TRACK_VIDEO, 0), 1);
assert_eq!(clip_range_of(seq, 0, 0), Some((0, 100)));
drop_timeline_sequence(project, seq, footage);
}
}
// ---------------------------------------------------------------------------
// Sequence markers (oakengine_sequence_marker_*)
// ---------------------------------------------------------------------------
/// `oakengine_sequence_marker_add` inserts an undoable marker; the list
/// exposes it through count/at (time in the sequence's frame timebase,
/// name and color round-trip). Undo removes it, redo re-adds it.
#[test]
fn markers_add_list_and_undo_roundtrip() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(0);
assert_eq!(oakengine_undo_clear(), 0);
assert_eq!(oakengine_sequence_marker_count(seq), 0);
let rc = oakengine_sequence_marker_add(seq, 60, c"scene 1".as_ptr());
assert_eq!(rc, 0, "add a marker at frame 60");
assert_eq!(oakengine_sequence_marker_count(seq), 1);
let mut time: i64 = -1;
let mut color: c_int = -1;
let mut name_buf = [0 as c_char; 64];
assert_eq!(
oakengine_sequence_marker_at(
seq, 0, &mut time, name_buf.as_mut_ptr(), 64, &mut color
),
0
);
assert_eq!(time, 60);
assert_eq!(color, 0);
assert_eq!(read_str(name_buf.as_ptr()), "scene 1");
// Undo removes the marker, redo re-adds it.
assert_eq!(oakengine_project_undo(project), 0);
assert_eq!(oakengine_sequence_marker_count(seq), 0);
assert_eq!(oakengine_project_redo(project), 0);
assert_eq!(oakengine_sequence_marker_count(seq), 1);
time = -1;
assert_eq!(oakengine_sequence_marker_at(seq, 0, &mut time, std::ptr::null_mut(), 0, std::ptr::null_mut()), 0);
assert_eq!(time, 60);
drop_timeline_sequence(project, seq, footage);
}
}
/// `oakengine_sequence_marker_remove` removes the marker at a time
/// (undoable); removing from an empty spot is an error that leaves the list
/// intact.
#[test]
fn markers_remove_and_reject_duplicates() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(0);
assert_eq!(oakengine_undo_clear(), 0);
assert_eq!(oakengine_sequence_marker_add(seq, 30, std::ptr::null()), 0);
assert_eq!(oakengine_sequence_marker_add(seq, 90, c"end".as_ptr()), 0);
assert_eq!(oakengine_sequence_marker_count(seq), 2);
// A second marker at the same time is rejected (module asserts on
// duplicate in points).
assert!(oakengine_sequence_marker_add(seq, 30, c"dup".as_ptr()) < 0);
assert_eq!(oakengine_sequence_marker_count(seq), 2);
// Removing the marker at frame 30 (undoable).
assert_eq!(oakengine_sequence_marker_remove(seq, 30), 0);
assert_eq!(oakengine_sequence_marker_count(seq), 1);
let mut time: i64 = -1;
assert_eq!(oakengine_sequence_marker_at(seq, 0, &mut time, std::ptr::null_mut(), 0, std::ptr::null_mut()), 0);
assert_eq!(time, 90, "the surviving marker is the one at 90");
// Removing from an empty time is an error.
assert!(oakengine_sequence_marker_remove(seq, 30) < 0);
assert_eq!(oakengine_sequence_marker_count(seq), 1);
// Undo restores the removed marker.
assert_eq!(oakengine_project_undo(project), 0);
assert_eq!(oakengine_sequence_marker_count(seq), 2);
drop_timeline_sequence(project, seq, footage);
}
}
/// Marker inputs: NULL sequence and out-of-range indices are errors, never
/// crashes.
#[test]
fn markers_reject_illegal_inputs() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(0);
assert_eq!(oakengine_undo_clear(), 0);
assert!(oakengine_sequence_marker_add(std::ptr::null_mut(), 10, std::ptr::null()) < 0);
assert!(oakengine_sequence_marker_remove(std::ptr::null_mut(), 10) < 0);
assert_eq!(oakengine_sequence_marker_count(std::ptr::null_mut()), 0);
assert!(oakengine_sequence_marker_remove(seq, 10) < 0, "no marker at frame 10");
let mut time: i64 = 0;
assert!(
oakengine_sequence_marker_at(seq, 3, &mut time, std::ptr::null_mut(), 0, std::ptr::null_mut()) < 0,
"index out of range"
);
drop_timeline_sequence(project, seq, footage);
}
}
// ---------------------------------------------------------------------------
// Sequence work area (oakengine_sequence_workarea_*)
// ---------------------------------------------------------------------------
/// `oakengine_sequence_set_workarea` (live) round-trips through
/// `oakengine_sequence_get_workarea` / `oakengine_sequence_workarea_is_enabled`;
/// disabling clears the enabled flag.
#[test]
fn workarea_set_get_clear_roundtrip() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(0);
assert_eq!(oakengine_sequence_workarea_is_enabled(seq), 0);
let mut in_ts: i64 = -1;
let mut out_ts: i64 = -1;
assert_eq!(oakengine_sequence_get_workarea(seq, &mut in_ts, &mut out_ts), 0);
// Default range: the reset sentinel, 0..RATIONAL_MAX in the frame
// timebase (a huge positive out point).
assert_eq!(in_ts, 0);
assert!(out_ts > 0, "default out is the reset sentinel, got {out_ts}");
// Set an enabled range and read it back.
assert_eq!(oakengine_sequence_set_workarea(seq, 1, 100, 200), 0);
assert_eq!(oakengine_sequence_workarea_is_enabled(seq), 1);
assert_eq!(oakengine_sequence_get_workarea(seq, &mut in_ts, &mut out_ts), 0);
assert_eq!((in_ts, out_ts), (100, 200));
// Disable ("clear") keeps the range but flips the flag.
assert_eq!(oakengine_sequence_set_workarea(seq, 0, 100, 200), 0);
assert_eq!(oakengine_sequence_workarea_is_enabled(seq), 0);
assert_eq!(oakengine_sequence_get_workarea(seq, &mut in_ts, &mut out_ts), 0);
assert_eq!((in_ts, out_ts), (100, 200));
drop_timeline_sequence(project, seq, footage);
}
}
/// `oakengine_sequence_set_workarea_undoable` changes enabled + range as
/// ONE undoable entry: undo restores the pre-change range (the caller
/// supplied old in/out), redo re-applies the new one.
#[test]
fn workarea_undoable_set_roundtrips() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(0);
assert_eq!(oakengine_undo_clear(), 0);
// Start from a live-set range so the undo has something to restore.
assert_eq!(oakengine_sequence_set_workarea(seq, 1, 100, 200), 0);
let rc = oakengine_sequence_set_workarea_undoable(seq, 1, 300, 400, 100, 200);
assert_eq!(rc, 0, "undoable workarea set succeeds");
let mut in_ts: i64 = 0;
let mut out_ts: i64 = 0;
assert_eq!(oakengine_sequence_get_workarea(seq, &mut in_ts, &mut out_ts), 0);
assert_eq!((in_ts, out_ts), (300, 400));
assert_eq!(oakengine_sequence_workarea_is_enabled(seq), 1);
// One undo entry: enabled + range restored together.
assert_eq!(oakengine_project_undo(project), 0);
assert_eq!(oakengine_sequence_workarea_is_enabled(seq), 1);
assert_eq!(oakengine_sequence_get_workarea(seq, &mut in_ts, &mut out_ts), 0);
assert_eq!((in_ts, out_ts), (100, 200));
// Redo re-applies.
assert_eq!(oakengine_project_redo(project), 0);
assert_eq!(oakengine_sequence_get_workarea(seq, &mut in_ts, &mut out_ts), 0);
assert_eq!((in_ts, out_ts), (300, 400));
drop_timeline_sequence(project, seq, footage);
}
}
/// Work-area inputs: NULL sequence and negative ranges are errors.
#[test]
fn workarea_rejects_illegal_inputs() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(0);
assert_eq!(oakengine_sequence_workarea_is_enabled(std::ptr::null_mut()), 0);
assert!(oakengine_sequence_get_workarea(std::ptr::null_mut(), std::ptr::null_mut(), std::ptr::null_mut()) < 0);
assert!(oakengine_sequence_set_workarea(std::ptr::null_mut(), 1, 0, 10) < 0);
assert!(oakengine_sequence_set_workarea_undoable(std::ptr::null_mut(), 1, 0, 10, 0, 0) < 0);
// Negative range values are rejected by the undoable export (never a
// crash). The live setter is a plain setter (C++ parity — it stores
// what it is given), so only the command path validates.
assert!(oakengine_sequence_set_workarea_undoable(seq, 1, 0, 10, -1, 0) < 0);
assert!(oakengine_sequence_set_workarea_undoable(seq, 1, -1, 10, 0, 0) < 0);
drop_timeline_sequence(project, seq, footage);
}
}
/// The sequence name getter used by the app's `refresh_sequence_info`
/// (two-stage buf/size) is exercised here as the assembly smoke check.
#[test]
fn assembled_sequence_has_expected_name() {
let _g = serial();
common::force_link();
unsafe {
let _storage = common::storage_off_guard();
let (project, seq, footage) = assemble_timeline_sequence(1);
let mut buf = [0 as c_char; 64];
assert!(oakengine_sequence_name(seq, buf.as_mut_ptr(), 64) > 0);
assert_eq!(read_str(buf.as_ptr()), "Timeline Test");
drop_timeline_sequence(project, seq, footage);
}
}
+1
View File
@@ -45,6 +45,7 @@ mod it_library;
mod it_plugin;
mod it_storage;
mod it_task;
mod it_timeline;
mod it_undo;
mod linkage;
mod node;
+69
View File
@@ -1577,6 +1577,75 @@ pub unsafe extern "C" fn oakengine_sequence_set_workarea(
})
}
/// `oakengine_sequence_set_workarea_undoable` — set the workarea's enabled
/// flag and in/out range as ONE undoable entry ("Set Workarea").
///
/// The old range must be supplied by the caller (the same convention as
/// `oakengine_workarea_set_range_undoable`): pass the range read before the
/// change — e.g. the drag-start range of a ruler work-area drag. The enabled
/// flag's previous value is captured by the module command itself.
#[no_mangle]
pub unsafe extern "C" fn oakengine_sequence_set_workarea_undoable(
self_: *mut OakEngineSequence,
enabled: c_int,
in_: i64,
out: i64,
old_in: i64,
old_out: i64,
) -> c_int {
guard(|| unsafe {
set_seq_error("");
let sequence = match unbox(self_) {
Ok(h) => h,
Err(_) => {
set_seq_error("invalid sequence");
return Err(Error::Invalid);
}
};
let tb = match seq_time_base(sequence) {
Ok(tb) => tb,
Err(_) => {
set_seq_error("sequence has no valid frame rate");
return Err(Error::State);
}
};
if in_ < 0 || out < 0 || old_in < 0 || old_out < 0 {
set_seq_error("invalid workarea range");
return Err(Error::Invalid);
}
let wa = seq_workarea(sequence)?;
let (new_in_num, new_in_den) = ts_to_rational(in_, tb);
let (new_out_num, new_out_den) = ts_to_rational(out, tb);
let (old_in_num, old_in_den) = ts_to_rational(old_in, tb);
let (old_out_num, old_out_den) = ts_to_rational(old_out, tb);
let enabled_cmd = tl::oaktimeline_workarea_set_enabled_command(wa, enabled);
if enabled_cmd.is_null() {
release_handle(wa);
set_seq_error("workarea enabled command failed");
return Err(Error::Failed("workarea enabled command failed".into()));
}
let range_cmd = tl::oaktimeline_workarea_set_range_command(
wa,
new_in_num as c_int,
new_in_den as c_int,
new_out_num as c_int,
new_out_den as c_int,
old_in_num as c_int,
old_in_den as c_int,
old_out_num as c_int,
old_out_den as c_int,
);
release_handle(wa);
if range_cmd.is_null() {
set_seq_error("workarea range command failed");
return Err(Error::Failed("workarea range command failed".into()));
}
// The commands hold borrowed clones of `wa` (no addref); the workarea
// lives with the sequence, so it outlives the undo entry.
push_multi_commands(&[enabled_cmd, range_cmd], "Set Workarea")
})
}
/// `oakengine_sequence_marker_count` — number of timeline markers.
#[no_mangle]
pub unsafe extern "C" fn oakengine_sequence_marker_count(self_: *const OakEngineSequence) -> c_int {