refactor: workspace layout — crates/, app at root, legacy C++ removed

Single mechanical restructure commit:
- root Cargo.toml = oakapp bin + workspace; one cargo build produces
  oakapp, oak-cli, oak-worker, liboakengine.dylib
- app/rust/src -> src/ (app at repo root, no rust/ nesting)
- src/<mod>/rust -> crates/oak<mod>; src/oakcore-rs -> crates/oakcore;
  src/bindings/oakotio -> crates/oakotio; src/engine/rust ->
  crates/oakengine (keeps cdylib+staticlib+rlib)
- public C headers include/<mod>/ -> crates/oakengine/include/<mod>/
- OFX SDK headers vendored into crates/oakplugin/ofx/ (HostSupport gone)
- legacy deleted: old src/ C++ modules, engine/, core/, ffmpeg_bridge/,
  app/ (Qt), cli/worker C++, root CMakeLists, third_party/KDDockWidgets
  submodule, otio-install, all build-* output (~40GB)
- oakstorage kept but excluded from the workspace (skeleton w/ todos);
  gpui excluded (own workspace)
- verified: cargo build green, cargo test --workspace 1845/0
  (with the documented OCIO_RS_* env override for the homebrew OCIO)
This commit is contained in:
2026-08-10 20:24:25 +08:00
parent f8540e3892
commit 013a175707
4212 changed files with 8331 additions and 2274987 deletions
+269
View File
@@ -0,0 +1,269 @@
// 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/>.
// 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/>.
//! oakcommon C ABI imports (XML reader/writer + config), mirroring
//! `include/common/xmlutils.h` and `include/common/config.h`.
use std::ffi::{c_char, c_int};
use crate::handle::CHandle;
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_init(data: *const c_char) -> CHandle {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_init(data)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_init(data) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_free(reader: *mut CHandle) {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_free(reader)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_free(reader) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_skip_current_element(reader: CHandle) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_skip_current_element(reader)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_skip_current_element(reader) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification). The
/// real ABI advances the reader and writes a 1/0 `found` flag (the name is
/// read with [`oakcommon_xml_reader_name`]).
pub fn oakcommon_xml_reader_read_next_start_element(reader: CHandle, found: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_read_next_start_element(reader, found)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_read_next_start_element(reader, found) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_name(reader: CHandle, name: *mut c_char, buf_size: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_name(reader, name, buf_size)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_name(reader, name, buf_size) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_read_element_text(reader: CHandle, text: *mut c_char, buf_size: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_read_element_text(reader, text, buf_size)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_read_element_text(reader, text, buf_size) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_attribute_count(reader: CHandle, count: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_attribute_count(reader, count)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_attribute_count(reader, count) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_attribute_name(reader: CHandle, index: c_int, name: *mut c_char, buf_size: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_attribute_name(reader, index, name, buf_size)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_attribute_name(reader, index, name, buf_size) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_attribute_value(reader: CHandle, index: c_int, value: *mut c_char, buf_size: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_attribute_value(reader, index, value, buf_size)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_attribute_value(reader, index, value, buf_size) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_reader_has_error(reader: CHandle, has_error: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_reader_has_error(reader, has_error)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_reader_has_error(reader, has_error) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_writer_init() -> CHandle {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_writer_init()
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_writer_init() }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_writer_free(writer: *mut CHandle) {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_writer_free(writer)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_writer_free(writer) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_writer_write_start_element(writer: CHandle, name: *const c_char) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_writer_write_start_element(writer, name)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_writer_write_start_element(writer, name) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_writer_write_end_element(writer: CHandle) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_writer_write_end_element(writer)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_writer_write_end_element(writer) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_writer_write_end_document(writer: CHandle) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_writer_write_end_document(writer)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_writer_write_end_document(writer) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_writer_write_attribute(writer: CHandle, key: *const c_char, value: *const c_char) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_writer_write_attribute(writer, key, value)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_writer_write_attribute(writer, key, value) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_writer_write_characters(writer: CHandle, text: *const c_char) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_writer_write_characters(writer, text)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_writer_write_characters(writer, text) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_xml_writer_write_text_element(writer: CHandle, name: *const c_char, text: *const c_char) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_xml_writer_write_text_element(writer, name, text)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::xmlutils::oakcommon_xml_writer_write_text_element(writer, name, text) }
}
}
/// Direct call into the `oakcommon` crate (single-lib unification).
pub fn oakcommon_config_get_int(group: *const c_char, key: *const c_char, default: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakcommon_config_get_int(group, key, default)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakcommon::ffi::config::oakcommon_config_get_int(group, key, default) }
}
}
+34
View File
@@ -0,0 +1,34 @@
// 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/>.
//! C ABI imports from other oak modules. Signatures mirror the public
//! headers verbatim; they are resolved at link time against the oaknode,
//! oakundo and oakcommon DLLs.
//!
//! Timeline never reimplements C++ internals: every cross-module access
//! goes through these frozen C ABIs (see README.md "no replication").
pub mod common;
pub mod node;
pub mod undo;
/// In-crate mock implementations of the bridge surface, compiled for tests
/// (`cfg(test)` or the `test-stubs` feature); the bridge fns route to them
/// via their `#[cfg(any(test, feature = "test-stubs"))]` variants. Plain
/// Rust (no `#[no_mangle]`), so they coexist with the real
/// oaknode/oakundo/oakcommon rlibs linked in the same test binary.
#[cfg(any(test, feature = "test-stubs"))]
pub mod teststubs;
+717
View File
@@ -0,0 +1,717 @@
// 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/>.
// 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/>.
//! oaknode C ABI imports (`include/node/{block,node,sequence,track,project}.h`).
//! Timeline reads and mutates the block/track/sequence graph exclusively
//! through these frozen functions — it never reimplements node internals.
//!
//! All time quantities cross the C ABI as `int` numerator/denominator pairs
//! (the ABI is `int`; the crate's internal `Rational` is `i64`). Converting
//! between the two is the bridge's responsibility.
use std::ffi::{c_char, c_int};
use crate::handle::CHandle;
/// A timeline block (`OakNodeBlock`) — a clip or a gap. Opaque handle.
pub type OakNodeBlock = CHandle;
/// A track (`OakNodeTrack`). Opaque handle.
pub type OakNodeTrack = CHandle;
/// A sequence/timeline (`OakNodeSequence`). Opaque handle.
pub type OakNodeSequence = CHandle;
/// A generic node (`OakNodeNode`). Opaque handle.
pub type OakNodeNode = CHandle;
/// A project (`OakNodeProject`). Opaque handle.
pub type OakNodeProject = CHandle;
/// A track list (`OakNodeTrackList`). Opaque handle.
pub type OakNodeTrackList = CHandle;
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_clip_create() -> OakNodeBlock {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_clip_create()
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_clip_create() }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_gap_create() -> OakNodeBlock {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_gap_create()
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_gap_create() }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_as_node(block: OakNodeBlock) -> OakNodeNode {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_as_node(block)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_as_node(block) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_get_in(block: OakNodeBlock, numerator: *mut c_int, denominator: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_get_in(block, numerator, denominator)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_get_in(block, numerator, denominator) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_get_out(block: OakNodeBlock, numerator: *mut c_int, denominator: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_get_out(block, numerator, denominator)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_get_out(block, numerator, denominator) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_get_length(block: OakNodeBlock, numerator: *mut c_int, denominator: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_get_length(block, numerator, denominator)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_get_length(block, numerator, denominator) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_set_length_and_media_out(block: OakNodeBlock, numerator: c_int, denominator: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_set_length_and_media_out(block, numerator, denominator)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_set_length_and_media_out(block, numerator, denominator) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_set_length_and_media_in(block: OakNodeBlock, numerator: c_int, denominator: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_set_length_and_media_in(block, numerator, denominator)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_set_length_and_media_in(block, numerator, denominator) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_get_enabled(block: OakNodeBlock, enabled: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_get_enabled(block, enabled)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_get_enabled(block, enabled) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_set_enabled(block: OakNodeBlock, enabled: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_set_enabled(block, enabled)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_set_enabled(block, enabled) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_get_previous(block: OakNodeBlock, out: *mut OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_get_previous(block, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_get_previous(block, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_get_next(block: OakNodeBlock, out: *mut OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_get_next(block, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_get_next(block, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_get_track(block: OakNodeBlock, out: *mut OakNodeTrack) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_get_track(block, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_get_track(block, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_link(a: OakNodeBlock, b: OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_link(a, b)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_link(a, b) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_unlink(a: OakNodeBlock, b: OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_unlink(a, b)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_unlink(a, b) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_get_length(track: OakNodeTrack, numerator: *mut c_int, denominator: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_get_length(track, numerator, denominator)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_get_length(track, numerator, denominator) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_get_sequence(track: OakNodeTrack, out: *mut OakNodeSequence) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_get_sequence(track, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_get_sequence(track, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_prepend_block(track: OakNodeTrack, block: OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_prepend_block(track, block)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_prepend_block(track, block) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_insert_block_after(track: OakNodeTrack, block: OakNodeBlock, before: OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_insert_block_after(track, block, before)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_insert_block_after(track, block, before) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_ripple_remove_block(track: OakNodeTrack, block: OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_ripple_remove_block(track, block)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_ripple_remove_block(track, block) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_replace_block(track: OakNodeTrack, old_block: OakNodeBlock, new_block: OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_replace_block(track, old_block, new_block)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_replace_block(track, old_block, new_block) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_sequence_as_node(sequence: OakNodeSequence) -> OakNodeNode {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_sequence_as_node(sequence)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::sequence::oaknode_sequence_as_node(sequence) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_sequence_from_node(node: OakNodeNode) -> OakNodeSequence {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_sequence_from_node(node)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::sequence::oaknode_sequence_from_node(node) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_node_get_project(node: OakNodeNode, out: *mut OakNodeProject) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_node_get_project(node, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::node::oaknode_node_get_project(node, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_node_output_connection_count(node: OakNodeNode, out_count: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_node_output_connection_count(node, out_count)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::node::oaknode_node_output_connection_count(node, out_count) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_node_get_markers(node: OakNodeNode, out: *mut crate::handle::CHandle) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_node_get_markers(node, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::node::oaknode_node_get_markers(node, out as *mut std::ffi::c_void) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_node_get_work_area(node: OakNodeNode, out: *mut crate::handle::CHandle) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_node_get_work_area(node, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::node::oaknode_node_get_work_area(node, out as *mut std::ffi::c_void) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_project_add_node(project: OakNodeProject, node: OakNodeNode) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_project_add_node(project, node)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::project::oaknode_project_add_node(project, node) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_project_remove_node(project: OakNodeProject, node: OakNodeNode) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_project_remove_node(project, node)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::project::oaknode_project_remove_node(project, node) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_command_create_remove_node(node: OakNodeNode) -> crate::handle::CHandle {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_command_create_remove_node(node)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::node::oaknode_command_create_remove_node(node) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_get_kind(block: OakNodeBlock, out_kind: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_get_kind(block, out_kind)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_get_kind(block, out_kind) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_from_node(node: OakNodeNode) -> OakNodeBlock {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_from_node(node)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_from_node(node) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_block_are_linked(a: OakNodeBlock, b: OakNodeBlock, linked: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_block_are_linked(a, b, linked)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_block_are_linked(a, b, linked) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_clip_add_cache_passthrough_from(clip: OakNodeBlock, other: OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_clip_add_cache_passthrough_from(clip, other)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_clip_add_cache_passthrough_from(clip, other) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_clip_get_media_in(clip: OakNodeBlock, numerator: *mut c_int, denominator: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_clip_get_media_in(clip, numerator, denominator)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_clip_get_media_in(clip, numerator, denominator) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_clip_set_media_in(clip: OakNodeBlock, numerator: c_int, denominator: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_clip_set_media_in(clip, numerator, denominator)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::block::oaknode_clip_set_media_in(clip, numerator, denominator) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_create(kind: c_int) -> OakNodeTrack {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_create(kind)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_create(kind) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_get_locked(track: OakNodeTrack, locked: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_get_locked(track, locked)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_get_locked(track, locked) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_set_locked(track: OakNodeTrack, locked: c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_set_locked(track, locked)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_set_locked(track, locked) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_get_block_count(track: OakNodeTrack, count: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_get_block_count(track, count)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_get_block_count(track, count) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_get_block_at(track: OakNodeTrack, index: c_int, out: *mut OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_get_block_at(track, index, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_get_block_at(track, index, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_get_block_containing_time(track: OakNodeTrack, numerator: c_int, denominator: c_int, out: *mut OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_get_block_containing_time(track, numerator, denominator, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_get_block_containing_time(track, numerator, denominator, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_get_nearest_block_before_or_at(track: OakNodeTrack, numerator: c_int, denominator: c_int, out: *mut OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_get_nearest_block_before_or_at(track, numerator, denominator, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_get_nearest_block_before_or_at(track, numerator, denominator, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_track_get_nearest_block_after_or_at(track: OakNodeTrack, numerator: c_int, denominator: c_int, out: *mut OakNodeBlock) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_track_get_nearest_block_after_or_at(track, numerator, denominator, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_track_get_nearest_block_after_or_at(track, numerator, denominator, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_tracklist_get_type(list: OakNodeTrackList, kind: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_tracklist_get_type(list, kind)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_tracklist_get_type(list, kind) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_tracklist_get_track_count(list: OakNodeTrackList, count: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_tracklist_get_track_count(list, count)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_tracklist_get_track_count(list, count) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_tracklist_get_track_at(list: OakNodeTrackList, index: c_int, out: *mut OakNodeTrack) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_tracklist_get_track_at(list, index, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_tracklist_get_track_at(list, index, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_tracklist_array_append(list: OakNodeTrackList) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_tracklist_array_append(list)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_tracklist_array_append(list) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_tracklist_array_remove_last(list: OakNodeTrackList) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_tracklist_array_remove_last(list)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::track::oaknode_tracklist_array_remove_last(list) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_sequence_get_track_list(sequence: OakNodeSequence, kind: c_int, out: *mut OakNodeTrackList) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_sequence_get_track_list(sequence, kind, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::sequence::oaknode_sequence_get_track_list(sequence, kind, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_sequence_get_all_track_count(sequence: OakNodeSequence, count: *mut c_int) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_sequence_get_all_track_count(sequence, count)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::sequence::oaknode_sequence_get_all_track_count(sequence, count) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_sequence_get_all_track_at(sequence: OakNodeSequence, index: c_int, out: *mut OakNodeTrack) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_sequence_get_all_track_at(sequence, index, out)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::sequence::oaknode_sequence_get_all_track_at(sequence, index, out) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_node_connect(output_node: OakNodeNode, input_node: OakNodeNode, input_id: *const c_char) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_node_connect(output_node, input_node, input_id)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::node::oaknode_node_connect(output_node, input_node, input_id) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_node_disconnect(input_node: OakNodeNode, input_id: *const c_char) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_node_disconnect(input_node, input_id)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::node::oaknode_node_disconnect(input_node, input_id) }
}
}
/// Direct call into the `oaknode` crate (single-lib unification).
pub fn oaknode_node_copy_in_graph(node: OakNodeNode, out_command: *mut crate::handle::CHandle) -> OakNodeNode {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oaknode_node_copy_in_graph(node, out_command)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oaknode::ffi::node::oaknode_node_copy_in_graph(node, out_command) }
}
}
File diff suppressed because it is too large Load Diff
+134
View File
@@ -0,0 +1,134 @@
// 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/>.
// 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/>.
//! oakundo C ABI imports (`include/undo/undocommand.h`). Undo commands are
//! created through the C ABI vtable (`oakundo_command_init` with Rust
//! closures as `userdata`) — timeline does not subclass the C++
//! `UndoCommand`; every command struct in this crate exposes `to_command()`
//! that wraps it this way.
use std::ffi::{c_char, c_int, c_void};
use crate::handle::CHandle;
/// `OakUndoCommandVtable` — callback table backing a caller-defined undo
/// command (undocommand.h). Any callback may be NULL (a NULL redo/undo makes
/// that direction a no-op); `free_fn` runs when the command is destroyed.
/// Single-lib unification: aliases the oakundo crate's vtable POD.
pub type OakUndoCommandVtable = oakundo::undocommand::OakUndoCommandVtable;
/// Direct call into the `oakundo` crate (single-lib unification).
pub fn oakundo_command_init(vtable: *const OakUndoCommandVtable, userdata: *mut c_void) -> CHandle {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakundo_command_init(vtable, userdata)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakundo::ffi::command::oakundo_command_init(vtable, userdata) }
}
}
/// Direct call into the `oakundo` crate (single-lib unification).
pub fn oakundo_command_init_multi() -> CHandle {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakundo_command_init_multi()
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakundo::ffi::command::oakundo_command_init_multi() }
}
}
/// Direct call into the `oakundo` crate (single-lib unification).
pub fn oakundo_command_multi_add_child(multi: CHandle, child: CHandle) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakundo_command_multi_add_child(multi, child)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakundo::ffi::command::oakundo_command_multi_add_child(multi, child) }
}
}
/// Direct call into the `oakundo` crate (single-lib unification).
pub fn oakundo_command_redo_now(command: CHandle) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakundo_command_redo_now(command)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakundo::ffi::command::oakundo_command_redo_now(command) }
}
}
/// Direct call into the `oakundo` crate (single-lib unification).
pub fn oakundo_command_undo_now(command: CHandle) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakundo_command_undo_now(command)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakundo::ffi::command::oakundo_command_undo_now(command) }
}
}
/// Direct call into the `oakundo` crate (single-lib unification).
pub fn oakundo_command_free(command: *mut CHandle) {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakundo_command_free(command)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakundo::ffi::command::oakundo_command_free(command) }
}
}
/// Direct call into the `oakundo` crate (single-lib unification; the C ABI
/// name is `oakundo_undostack_push` — kept as `oakundo_stack_push` here for
/// source compatibility).
pub fn oakundo_stack_push(stack: CHandle, command: CHandle, text: *const c_char) -> c_int {
#[cfg(any(test, feature = "test-stubs"))]
{
super::teststubs::oakundo_stack_push(stack, command, text)
}
#[cfg(not(any(test, feature = "test-stubs")))]
{
unsafe { oakundo::ffi::undostack::oakundo_undostack_push(stack, command, text) }
}
}
+104
View File
@@ -0,0 +1,104 @@
// 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/>.
//! The shared `Timeline` namespace (`src/timeline/src/timelinecommon.h`):
//! movement/thumbnail/waveform modes and the `EditToInfo` struct.
//!
//! Enum discriminants are value-compatible with both `include/timeline/edit.h`
//! (`OAKTIMELINE_MOVEMENT_*`) and `include/timeline/displaymode.h`
//! (`OAK_TIMELINE_THUMBNAIL_*` / `OAK_TIMELINE_WAVEFORMS_*`); `ffi.rs` maps
//! between them mechanically.
use oakcore_rs::Rational;
/// `Timeline::MovementMode` (timelinecommon.h).
///
/// `OAKTIMELINE_MOVEMENT_NONE = 0`, `MOVE = 1`, `TRIM_IN = 2`,
/// `TRIM_OUT = 3` (include/timeline/edit.h).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MovementMode {
/// `k_none`: no movement.
None,
/// `k_move`: slide/position move.
Move,
/// `k_trim_in`: trim the in point.
TrimIn,
/// `k_trim_out`: trim the out point.
TrimOut,
}
impl MovementMode {
/// `Timeline::is_a_trim_mode`: true for `TrimIn`/`TrimOut`.
pub fn is_a_trim_mode(self) -> bool {
matches!(self, MovementMode::TrimIn | MovementMode::TrimOut)
}
/// Map to the `OAKTIMELINE_MOVEMENT_*` C enum value.
pub fn to_c_int(self) -> i32 {
match self {
MovementMode::None => 0,
MovementMode::Move => 1,
MovementMode::TrimIn => 2,
MovementMode::TrimOut => 3,
}
}
/// Map a `OAKTIMELINE_MOVEMENT_*` C enum value back; `None` when the
/// integer is out of range.
pub fn from_c_int(v: i32) -> Option<MovementMode> {
match v {
0 => Some(MovementMode::None),
1 => Some(MovementMode::Move),
2 => Some(MovementMode::TrimIn),
3 => Some(MovementMode::TrimOut),
_ => None,
}
}
}
/// `Timeline::ThumbnailMode` (timelinecommon.h). Discriminants match
/// `OAK_TIMELINE_THUMBNAIL_OFF/IN_OUT/ON` (include/timeline/displaymode.h).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ThumbnailMode {
/// `k_thumbnail_off`: no thumbnails.
Off,
/// `k_thumbnail_in_out`: thumbnail at in/out.
InOut,
/// `k_thumbnail_on`: thumbnails on.
On,
}
/// `Timeline::WaveformMode` (timelinecommon.h). Discriminants match
/// `OAK_TIMELINE_WAVEFORMS_DISABLED/ENABLED` (include/timeline/displaymode.h).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WaveformMode {
/// `k_waveforms_disabled`.
Disabled,
/// `k_waveforms_enabled`.
Enabled,
}
/// `Timeline::EditToInfo` (timelinecommon.h): where the nearest block edge
/// falls for a pointer edit. Not `Copy`/`Clone`/`Debug` — it owns
/// [`crate::handle::CHandle`]s, which are opaque refcounted handles.
pub struct EditToInfo {
/// Owning track of the nearest block.
pub track: crate::handle::CHandle,
/// Nearest edit point time.
pub nearest_time: Rational,
/// Nearest block.
pub nearest_block: crate::handle::CHandle,
}
+66
View File
@@ -0,0 +1,66 @@
// 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/>.
//! Error codes, mirroring `include/timeline/error.h` verbatim;
//! project-wide -MMCCCC scheme (module registry in include/common/error.h),
//! pass-through untranslated. Timeline is module 04 (no CANCELLED code;
//! only codec=05 and task=08 carry one).
/// ABI version stamped into every handle.
pub const OAKTIMELINE_ABI_VERSION: u32 = 1;
/// Success.
pub const OAKTIMELINE_OK: i32 = 0;
/// Null handle or invalid argument.
pub const OAKTIMELINE_E_INVALID: i32 = -40001;
/// Call not valid in the current state.
pub const OAKTIMELINE_E_STATE: i32 = -40002;
/// The underlying operation failed.
pub const OAKTIMELINE_E_FAILED: i32 = -40003;
/// Index out of range / entry not found.
pub const OAKTIMELINE_E_NOT_FOUND: i32 = -40004;
/// Allocation failed.
pub const OAKTIMELINE_E_NOMEM: i32 = -40005;
/// Crate-internal result type; the FFI layer maps it to the codes.
pub type Result<T> = std::result::Result<T, Error>;
/// Crate-internal error.
#[derive(Debug)]
pub enum Error {
/// Null handle or invalid argument.
Invalid,
/// Wrong state.
State,
/// Operation failed (context string is log-only).
Failed(String),
/// Index out of range / entry not found.
NotFound,
/// Out of memory.
NoMem,
}
impl Error {
/// Map to the public error code.
pub fn code(&self) -> i32 {
match self {
Error::Invalid => OAKTIMELINE_E_INVALID,
Error::State => OAKTIMELINE_E_STATE,
Error::Failed(_) => OAKTIMELINE_E_FAILED,
Error::NotFound => OAKTIMELINE_E_NOT_FOUND,
Error::NoMem => OAKTIMELINE_E_NOMEM,
}
}
}
File diff suppressed because it is too large Load Diff
+180
View File
@@ -0,0 +1,180 @@
// 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/>.
//! Refcounted-handle scaffolding. Same pattern as the oaknode crate
//! (`src/node/rust/src/handle.rs`); intentionally duplicated rather
//! than shared — each module DLL must run its own addref/release code
//! (the function pointers in a handle always point into the DLL that
//! created the object). Value handles (`OakTimelineMarkerList`,
//! `OakTimelineWorkArea`) share this box.
use std::ffi::c_void;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::sync::atomic::{AtomicU32, Ordering};
use crate::error::{OAKTIMELINE_E_FAILED, OAKTIMELINE_OK, Result};
/// ABI version stamped into every oaktimeline handle.
pub const OAKTIMELINE_ABI_VERSION: u32 = 1;
/// Heap box behind a handle's `ctx`.
pub struct RefBox<T: ?Sized> {
/// Atomic reference count.
pub refs: AtomicU32,
/// Boxed value.
pub value: T,
}
/// The shared ABI value-handle type (single-lib unification, see
/// `docs/zh/plans/riir/single-lib.md`): one canonical
/// `{ctx, addref, release, abi_version}` type in `oakcore-rs`, re-exported
/// here so the crate's `ffi.rs` signatures and handle scaffolding stay
/// source-compatible.
pub use oakcore_rs::handle::CHandle;
/// Generic `addref` implementation: increments the box's reference count.
///
/// # Safety
/// `ptr` must point to a `RefBox<T>`.
unsafe extern "C" fn addref_box<T: 'static>(ptr: *mut c_void) {
if ptr.is_null() {
return;
}
let rb = unsafe { &*(ptr as *const RefBox<T>) };
rb.refs.fetch_add(1, Ordering::SeqCst);
}
/// Generic `release` implementation: decrements the reference count and
/// destroys the box at zero.
///
/// # Safety
/// `ptr` must point to a `RefBox<T>`.
unsafe extern "C" fn release_box<T: 'static>(ptr: *mut c_void) {
if ptr.is_null() {
return;
}
let rb = ptr as *mut RefBox<T>;
let prev = unsafe { (*rb).refs.fetch_sub(1, Ordering::SeqCst) };
if prev == 1 {
// Last reference: reclaim the box.
drop(unsafe { Box::from_raw(rb) });
}
}
/// Owned handle with count 1; empty on allocation failure.
pub fn make_owned<T: Send + 'static>(value: T) -> CHandle {
let boxed = Box::new(RefBox {
refs: AtomicU32::new(1),
value,
});
let ptr = Box::into_raw(boxed) as *mut c_void;
CHandle {
ctx: ptr,
addref: Some(addref_box::<T>),
release: Some(release_box::<T>),
abi_version: OAKTIMELINE_ABI_VERSION,
}
}
/// Borrowed handle for an object owned elsewhere (release frees only
/// the box).
///
/// The box holds a detached copy of `*ptr`, so the underlying object is
/// never touched by the handle's release; `get` returns the copy. The
/// caller retains ownership of `ptr`.
///
/// # Safety
/// Caller guarantees `ptr` is valid for reading for the duration of the
/// call.
pub unsafe fn make_borrowed<T: Send + 'static>(ptr: *mut T) -> CHandle {
let value = unsafe { ptr.read() };
make_owned(value)
}
/// Typed view into a handle; `None` for empty handles.
///
/// # Safety
/// `T` must be the boxed type.
pub unsafe fn get<T: 'static>(h: &CHandle) -> Option<&T> {
if h.ctx.is_null() {
return None;
}
if h.addref.is_some() {
// Owned (or borrowed-via-copy) handle: `ctx` points at a `RefBox<T>`.
let rb = unsafe { &*(h.ctx as *const RefBox<T>) };
Some(&rb.value)
} else {
// Borrowed handle wrapping a raw object pointer (e.g. test-stub
// handles): `ctx` is the object itself, not a `RefBox<T>`.
Some(unsafe { &*(h.ctx as *const T) })
}
}
/// Mutable typed view into a handle; `None` for empty handles. Used by
/// undo commands to mutate the boxed value they hold a handle to.
///
/// # Safety
/// `T` must be the boxed type, and the caller must guarantee exclusive
/// access to the boxed value for the duration of the borrow (no two
/// mutable views alive at once).
pub unsafe fn get_mut<T: 'static>(h: &CHandle) -> Option<&mut T> {
if h.ctx.is_null() {
return None;
}
if h.addref.is_some() {
// Owned (or borrowed-via-copy) handle: `ctx` points at a `RefBox<T>`.
let rb = unsafe { &mut *(h.ctx as *mut RefBox<T>) };
Some(&mut rb.value)
} else {
// Borrowed handle wrapping a raw object pointer (e.g. test-stub
// handles): `ctx` is the object itself, not a `RefBox<T>`.
Some(unsafe { &mut *(h.ctx as *mut T) })
}
}
/// Panic-catching FFI wrapper for i32-returning exports.
pub fn guard<F: FnOnce() -> Result<()>>(f: F) -> i32 {
match catch_unwind(AssertUnwindSafe(f)) {
Ok(Ok(())) => OAKTIMELINE_OK,
Ok(Err(e)) => e.code(),
Err(_) => OAKTIMELINE_E_FAILED,
}
}
/// Panic-catching FFI wrapper for handle-returning exports.
pub fn guard_handle<F: FnOnce() -> Result<CHandle>>(f: F) -> CHandle {
match catch_unwind(AssertUnwindSafe(f)) {
Ok(Ok(h)) => h,
_ => CHandle::null(),
}
}
/// Panic-catching FFI wrapper for void exports.
pub fn guard_void<F: FnOnce()>(f: F) {
let _ = catch_unwind(AssertUnwindSafe(f));
}
/// Panic-catching FFI wrapper for exports returning an `i32` value that is
/// not an error code (e.g. two-stage string lengths): a successful closure
/// returns its value verbatim, errors map through `Error::code`, and a
/// panic becomes `OAKTIMELINE_E_FAILED`.
pub fn guard_i32<F: FnOnce() -> Result<i32>>(f: F) -> i32 {
match catch_unwind(AssertUnwindSafe(f)) {
Ok(Ok(v)) => v,
Ok(Err(e)) => e.code(),
Err(_) => OAKTIMELINE_E_FAILED,
}
}
+47
View File
@@ -0,0 +1,47 @@
// 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/>.
//! # oaktimeline — the timeline edit module (Rust)
//!
//! Reimplements the C++ oaktimeline module (`src/timeline/src`) behind
//! its frozen C ABI (`include/timeline/*.h`). See README.md for the
//! architectural mapping (per-header domain modules, no UndoCommand
//! inheritance → vtable commands).
//!
//! ## FFI discipline
//!
//! Identical to the oaknode crate: every export goes through
//! [`handle::guard*`], handles are opaque refcounted boxes, and all
//! cross-module access goes through the oaknode/oakundo/oakcommon C ABIs
//! (`bridge::*`).
#![deny(unsafe_op_in_unsafe_fn)]
#![warn(missing_docs)]
pub mod bridge;
pub mod common;
pub mod error;
pub mod ffi;
pub mod handle;
pub mod marker;
pub mod undocommon;
pub mod undogeneral;
pub mod undopointer;
pub mod undoripple;
pub mod undosplit;
pub mod undotrack;
pub mod util;
pub mod workarea;
+589
View File
@@ -0,0 +1,589 @@
// 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/>.
//! Timeline markers and the marker undo-command family
//! (`src/timeline/src/timelinemarker.h`): `TimelineMarker`/`TimelineMarkerList`
//! plus `MarkerAdd`/`MarkerRemove`/`MarkerChangeColor`/`MarkerChangeName`/
//! `MarkerChangeTime` commands.
//!
//! The list keeps markers sorted by time (`// CPP-PARITY:
//! src/timeline/src/timelinemarker.h` `insert_into_list`). De-Qt: no QObject,
//! no signals — change notifications are the facade's job. `set_time` does
//! not re-sort (the De-Qt marker has no parent pointer); callers restore
//! order via `TimelineMarkerList::resort`/`resort_at`.
use oakcore_rs::{Rational, TimeRange};
use crate::handle::{get, get_mut};
use crate::undocommon::{box_command, Command};
/// `TimelineMarker` — a named, colored time range on a timeline
/// (timelinemarker.h). De-Qt; `draw()` moved to the app layer.
pub struct TimelineMarker {
/// Marker time range.
time_: TimeRange,
/// Marker name (may be empty).
name_: String,
/// Marker color index.
color_: i32,
}
impl TimelineMarker {
/// Default constructor.
pub fn new() -> Self {
Self::with_time(
0,
TimeRange::new(Rational::new(0, 1), Rational::new(0, 1)),
"",
)
}
/// Construct with color, time and optional name.
pub fn with_time(color: i32, time: TimeRange, name: &str) -> Self {
Self {
time_: time,
name_: name.to_string(),
color_: color,
}
}
/// The marker's time range.
pub fn time(&self) -> &TimeRange {
&self.time_
}
/// Set the time range. De-Qt: the marker has no parent pointer, so the
/// owning list is not re-sorted here; callers use
/// `TimelineMarkerList::resort`/`resort_at` when order must be restored.
pub fn set_time(&mut self, time: TimeRange) {
self.time_ = time;
}
/// Set the time to a zero-length range at `time`.
pub fn set_time_point(&mut self, time: Rational) {
let length = self.time_.length();
self.set_time(TimeRange::new(time, time + length));
}
/// Whether another marker in the same list shares `time` as its in point.
///
/// De-Qt simplification: the marker has no parent pointer, so this always
/// returns `false`; callers that need the answer use
/// `TimelineMarkerList::get_marker_at_time` instead.
pub fn has_sibling_at_time(&self, _t: Rational) -> bool {
false
}
/// The marker's name.
pub fn name(&self) -> &str {
&self.name_
}
/// Set the marker's name.
pub fn set_name(&mut self, name: &str) {
self.name_ = name.to_string();
}
/// The marker's color index.
pub fn color(&self) -> i32 {
self.color_
}
/// Set the marker's color index.
pub fn set_color(&mut self, c: i32) {
self.color_ = c;
}
}
/// `TimelineMarkerList` — an ordered collection of markers, sorted by time
/// (timelinemarker.h).
pub struct TimelineMarkerList {
/// Markers, kept sorted by time.
markers_: Vec<TimelineMarker>,
}
impl TimelineMarkerList {
/// A new, empty list.
pub fn new() -> Self {
Self {
markers_: Vec::new(),
}
}
/// Whether the list is empty.
pub fn empty(&self) -> bool {
self.markers_.is_empty()
}
/// Number of markers.
pub fn size(&self) -> usize {
self.markers_.len()
}
/// Marker at `i`; `None` out of range.
pub fn at(&self, i: usize) -> Option<&TimelineMarker> {
self.markers_.get(i)
}
/// The last marker; `None` when empty.
pub fn back(&self) -> Option<&TimelineMarker> {
self.markers_.last()
}
/// The first marker; `None` when empty.
pub fn front(&self) -> Option<&TimelineMarker> {
self.markers_.first()
}
/// Insert a marker, keeping the list sorted by time (takes ownership).
///
/// Equal in points insert after the existing ones (`>` comparison,
/// CPP-PARITY timelinemarker.h `insert_into_list`).
pub fn add_marker(&mut self, marker: TimelineMarker) {
for i in 0..self.markers_.len() {
if self.markers_[i].time().in_() > marker.time().in_() {
self.markers_.insert(i, marker);
return;
}
}
self.markers_.push(marker);
}
/// Detach `m` from the list, returning it; `None` if not present.
pub fn remove_marker(&mut self, m: &TimelineMarker) -> Option<TimelineMarker> {
for i in 0..self.markers_.len() {
if std::ptr::eq(&self.markers_[i], m) {
return Some(self.markers_.remove(i));
}
}
None
}
/// First marker whose in point equals `t`; `None` if none.
pub fn get_marker_at_time(&self, t: Rational) -> Option<&TimelineMarker> {
self.markers_.iter().find(|m| m.time().in_() == t)
}
/// Marker closest to `t` (early-exits once the diff increases;
/// CPP-PARITY timelinemarker.h).
pub fn get_closest_marker_to_time(&self, t: Rational) -> Option<&TimelineMarker> {
let mut closest: Option<&TimelineMarker> = None;
let mut closest_diff = Rational::new(0, 1);
for m in &self.markers_ {
let this_diff = rational_abs(m.time().in_() - t);
if closest.is_some() && this_diff > closest_diff {
// Sorted by in point, so the distance is increasing from
// here on.
break;
}
if closest.is_none() || this_diff < closest_diff {
closest = Some(m);
closest_diff = this_diff;
}
}
closest
}
/// Re-sort `m` after its time changed.
pub fn resort(&mut self, m: &mut TimelineMarker) {
if let Some(index) = self.markers_.iter().position(|x| std::ptr::eq(x, &*m)) {
let marker = self.markers_.remove(index);
self.add_marker(marker);
}
}
/// Marker at `i`, mutably; `None` out of range.
fn at_mut(&mut self, i: usize) -> Option<&mut TimelineMarker> {
self.markers_.get_mut(i)
}
/// Remove the marker at `index` and re-insert it sorted; no-op when
/// `index` is out of range. Used by the time-change command after
/// mutating a marker in place.
fn resort_at(&mut self, index: usize) {
if index < self.markers_.len() {
let marker = self.markers_.remove(index);
self.add_marker(marker);
}
}
}
/// Absolute value of a rational (oakcore-rs has no `abs`).
fn rational_abs(r: Rational) -> Rational {
if r < Rational::new(0, 1) {
Rational::new(0, 1) - r
} else {
r
}
}
// ---------------------------------------------------------------------------
// Marker undo commands. Each struct exposes prepare()/redo()/undo(); the
// FFI layer wraps it through bridge::undo's vtable (to_command()).
// ---------------------------------------------------------------------------
/// `MarkerAddCommand` (timelinemarker.h).
pub struct MarkerAddCommand {
/// Target list.
marker_list: crate::handle::CHandle,
/// Marker range.
range: TimeRange,
/// Marker name.
name: String,
/// Marker color.
color: i32,
/// Whether the marker is currently in the list.
added: bool,
}
impl MarkerAddCommand {
/// Construct from range/name/color.
pub fn new(marker_list: crate::handle::CHandle, range: TimeRange, name: &str, color: i32) -> Self {
Self {
marker_list,
range,
name: name.to_string(),
color,
added: false,
}
}
/// `redo`: add the marker, sorted.
pub fn redo(&mut self) {
if self.added {
return;
}
let marker = TimelineMarker::with_time(self.color, self.range, &self.name);
// SAFETY: the boxed value is a `TimelineMarkerList` created by
// `make_owned`, and the command holds exclusive access to it.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
list.add_marker(marker);
self.added = true;
}
}
/// `undo`: remove the added marker.
///
/// Simplification: the marker is located by its in point
/// (`get_marker_at_time`); when several markers share the in point, the
/// oldest (first in the list) is removed.
pub fn undo(&mut self) {
if !self.added {
return;
}
// SAFETY: as `redo`.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(m) = list.get_marker_at_time(self.range.in_()) {
// SAFETY: `m` borrows from `list`; `remove_marker` uses it
// only for identity comparison before detaching.
let mptr = m as *const TimelineMarker;
let _ = list.remove_marker(unsafe { &*mptr });
}
self.added = false;
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> crate::handle::CHandle {
box_command(self)
}
}
impl Command for MarkerAddCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `MarkerRemoveCommand` (timelinemarker.h).
pub struct MarkerRemoveCommand {
/// Target list.
marker_list: crate::handle::CHandle,
/// Index of the marker to remove.
index: usize,
/// Marker detached on `redo`, re-inserted by `undo`.
removed: Option<TimelineMarker>,
}
impl MarkerRemoveCommand {
/// Construct from list + index of the marker to remove.
pub fn new(marker_list: crate::handle::CHandle, index: usize) -> Self {
Self {
marker_list,
index,
removed: None,
}
}
/// `redo`: remove the marker.
pub fn redo(&mut self) {
if self.removed.is_some() {
return;
}
// SAFETY: the boxed value is a `TimelineMarkerList` created by
// `make_owned`, and the command holds exclusive access to it.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(m) = list.at(self.index) {
// SAFETY: `m` borrows from `list`; `remove_marker` uses it
// only for identity comparison before detaching.
let mptr = m as *const TimelineMarker;
if let Some(removed) = list.remove_marker(unsafe { &*mptr }) {
self.removed = Some(removed);
}
}
}
}
/// `undo`: re-insert the marker, sorted.
pub fn undo(&mut self) {
// SAFETY: as `redo`.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(marker) = self.removed.take() {
list.add_marker(marker);
}
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> crate::handle::CHandle {
box_command(self)
}
}
impl Command for MarkerRemoveCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `MarkerChangeColorCommand` (timelinemarker.h).
pub struct MarkerChangeColorCommand {
/// Target list.
marker_list: crate::handle::CHandle,
/// Index of the marker to change.
index: usize,
/// Color before the change.
old_color: i32,
/// New color.
new_color: i32,
}
impl MarkerChangeColorCommand {
/// Construct from list + index + new color, capturing the current color
/// as old.
pub fn new(marker_list: crate::handle::CHandle, index: usize, new_color: i32) -> Self {
// SAFETY: the boxed value is a `TimelineMarkerList` created by
// `make_owned`; reading it here is the command's own handle.
let old_color = unsafe { get::<TimelineMarkerList>(&marker_list) }
.and_then(|l| l.at(index))
.map(|m| m.color())
.unwrap_or(0);
Self {
marker_list,
index,
old_color,
new_color,
}
}
/// `redo`: apply the new color.
pub fn redo(&mut self) {
// SAFETY: as `new`.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(m) = list.at_mut(self.index) {
m.set_color(self.new_color);
}
}
}
/// `undo`: restore the old color.
pub fn undo(&mut self) {
// SAFETY: as `new`.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(m) = list.at_mut(self.index) {
m.set_color(self.old_color);
}
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> crate::handle::CHandle {
box_command(self)
}
}
impl Command for MarkerChangeColorCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `MarkerChangeNameCommand` (timelinemarker.h).
pub struct MarkerChangeNameCommand {
/// Target list.
marker_list: crate::handle::CHandle,
/// Index of the marker to change.
index: usize,
/// Name before the change.
old_name: String,
/// New name.
new_name: String,
}
impl MarkerChangeNameCommand {
/// Construct from list + index + new name, capturing the current name as
/// old.
pub fn new(marker_list: crate::handle::CHandle, index: usize, name: &str) -> Self {
// SAFETY: the boxed value is a `TimelineMarkerList` created by
// `make_owned`; reading it here is the command's own handle.
let old_name = unsafe { get::<TimelineMarkerList>(&marker_list) }
.and_then(|l| l.at(index))
.map(|m| m.name().to_string())
.unwrap_or_default();
Self {
marker_list,
index,
old_name,
new_name: name.to_string(),
}
}
/// `redo`: apply the new name.
pub fn redo(&mut self) {
// SAFETY: as `new`.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(m) = list.at_mut(self.index) {
m.set_name(&self.new_name);
}
}
}
/// `undo`: restore the old name.
pub fn undo(&mut self) {
// SAFETY: as `new`.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(m) = list.at_mut(self.index) {
m.set_name(&self.old_name);
}
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> crate::handle::CHandle {
box_command(self)
}
}
impl Command for MarkerChangeNameCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `MarkerChangeTimeCommand` (timelinemarker.h). The old range is captured at
/// construction when not supplied.
pub struct MarkerChangeTimeCommand {
/// Target list.
marker_list: crate::handle::CHandle,
/// Index of the marker to change.
index: usize,
/// Time range before the change.
old_time: TimeRange,
/// New time range.
new_time: TimeRange,
}
impl MarkerChangeTimeCommand {
/// Construct from list + index + new time, capturing the current range as
/// old.
pub fn new(marker_list: crate::handle::CHandle, index: usize, time: TimeRange) -> Self {
// SAFETY: the boxed value is a `TimelineMarkerList` created by
// `make_owned`; reading it here is the command's own handle.
let old_time = unsafe { get::<TimelineMarkerList>(&marker_list) }
.and_then(|l| l.at(index))
.map(|m| *m.time())
.unwrap_or_else(|| TimeRange::new(Rational::new(0, 1), Rational::new(0, 1)));
Self {
marker_list,
index,
old_time,
new_time: time,
}
}
/// `redo`: apply the new time (resorts).
pub fn redo(&mut self) {
// SAFETY: as `new`.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(m) = list.at_mut(self.index) {
m.set_time(self.new_time);
}
list.resort_at(self.index);
}
}
/// `undo`: restore the old time (resorts).
pub fn undo(&mut self) {
// SAFETY: as `new`.
if let Some(list) = unsafe { get_mut::<TimelineMarkerList>(&self.marker_list) } {
if let Some(m) = list.at_mut(self.index) {
m.set_time(self.old_time);
}
list.resort_at(self.index);
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> crate::handle::CHandle {
box_command(self)
}
}
impl Command for MarkerChangeTimeCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
+234
View File
@@ -0,0 +1,234 @@
// 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/>.
//! Shared node-removal helpers and the C-command wrapper
//! (`src/timeline/src/timelineundocommon.h`). All node-graph access goes
//! through the oaknode C ABI (`bridge::node`) and undo through
//! `bridge::undo`.
//!
//! `CHandleCommandWrapper` in C++ subclasses `olive::UndoCommand` to wrap a
//! raw `OakUndoCommand`; the Rust equivalent holds a command `CHandle` and
//! forwards `redo`/`undo` to `bridge::undo::oakundo_command_redo_now/undo_now`.
use std::ffi::c_void;
use crate::bridge::undo::{oakundo_command_free, oakundo_command_init, oakundo_command_redo_now, oakundo_command_undo_now};
use crate::bridge::node::{
oaknode_block_as_node, oaknode_command_create_remove_node, oaknode_node_output_connection_count,
};
use crate::handle::CHandle;
/// `node_can_be_removed(Node)`: true when the node has no output
/// connections (timelineundocommon.h).
pub fn node_can_be_removed(node: CHandle) -> bool {
let mut count = 0;
// SAFETY: `count` is a valid out pointer.
let _ = unsafe { oaknode_node_output_connection_count(node, &mut count) };
count == 0
}
/// `node_can_be_removed(Block)`: delegates via `oaknode_block_as_node`.
pub fn block_can_be_removed(block: CHandle) -> bool {
node_can_be_removed(unsafe { oaknode_block_as_node(block) })
}
/// `create_remove_command(Node)` — `oaknode_command_create_remove_node`.
pub fn create_remove_command(node: CHandle) -> CHandle {
unsafe { oaknode_command_create_remove_node(node) }
}
/// `create_remove_command(Block)` — via `oaknode_block_as_node`.
pub fn create_block_remove_command(block: CHandle) -> CHandle {
create_remove_command(unsafe { oaknode_block_as_node(block) })
}
/// `create_and_run_remove_command(Node)` — create then `redo_now`.
pub fn create_and_run_remove_command(node: CHandle) -> CHandle {
let command = create_remove_command(node);
// SAFETY: `command` is a valid handle returned by the bridge.
let _ = unsafe { oakundo_command_redo_now(command.clone()) };
command
}
/// `create_and_run_remove_command(Block)` — via `oaknode_block_as_node`.
pub fn create_and_run_block_remove_command(block: CHandle) -> CHandle {
create_and_run_remove_command(unsafe { oaknode_block_as_node(block) })
}
/// `free_command_handle`: release and null a command handle; NULL/empty
/// no-op.
pub fn free_command_handle(command: *mut CHandle) {
// SAFETY: passed through to the bridge, which handles NULL.
unsafe { oakundo_command_free(command) };
}
/// Trait implemented by every timeline undo command. The crate's commands
/// are boxed into an oakundo vtable command via [`box_command`]; the bridge's
/// `redo_now`/`undo_now` dispatch to these callbacks.
pub trait Command {
/// Apply the change.
fn redo(&mut self);
/// Revert the change.
fn undo(&mut self);
}
/// Generic `redo` callback forwarding to [`Command::redo`].
///
/// # Safety
/// `userdata` must be the `Box<T>` produced by [`box_command`].
unsafe extern "C" fn redo_cb<T: Command>(userdata: *mut c_void) {
if userdata.is_null() {
return;
}
// SAFETY: box_command allocated a `Box<T>`; still alive because the
// command handle owns it.
(unsafe { &mut *(userdata as *mut T) }).redo();
}
/// Generic `undo` callback forwarding to [`Command::undo`].
///
/// # Safety
/// `userdata` must be the `Box<T>` produced by [`box_command`].
unsafe extern "C" fn undo_cb<T: Command>(userdata: *mut c_void) {
if userdata.is_null() {
return;
}
// SAFETY: as `redo_cb`.
(unsafe { &mut *(userdata as *mut T) }).undo();
}
/// Generic `free` callback dropping the boxed command.
///
/// # Safety
/// `userdata` must be the `Box<T>` produced by [`box_command`].
unsafe extern "C" fn free_cb<T: Command>(userdata: *mut c_void) {
if userdata.is_null() {
return;
}
// SAFETY: the handle owns this box; destroying the handle drops it.
unsafe { drop(Box::from_raw(userdata as *mut T)) };
}
/// Box a command into an oakundo vtable command handle. The handle owns the
/// boxed `T`; `redo_now`/`undo_now` dispatch to `T::redo`/`T::undo`, and
/// freeing the handle drops `T`.
pub(crate) fn box_command<T: Command + 'static>(cmd: T) -> CHandle {
let userdata = Box::into_raw(Box::new(cmd)) as *mut c_void;
let vtable = crate::bridge::undo::OakUndoCommandVtable {
redo: Some(redo_cb::<T>),
undo: Some(undo_cb::<T>),
free_fn: Some(free_cb::<T>),
};
// SAFETY: `vtable` and `userdata` remain valid for the command's lifetime
// (the bridge copies the vtable and owns `userdata`).
unsafe { oakundo_command_init(&vtable, userdata) }
}
/// `CHandleCommandWrapper` — an oakundo vtable command exposed as a
/// timeline-level command. `redo`/`undo` forward to `bridge::undo`;
/// dropping frees the handle.
pub struct CHandleCommandWrapper {
/// Wrapped command handle.
command: CHandle,
}
impl CHandleCommandWrapper {
/// Construct over an owned command handle.
pub fn new(command: CHandle) -> Self {
Self { command }
}
/// Whether the wrapped command is non-empty.
pub fn is_valid(&self) -> bool {
!self.command.is_null()
}
/// `redo`: forward to `oakundo_command_redo_now`.
pub fn redo(&mut self) {
if !self.command.is_null() {
// SAFETY: `self.command` is a valid handle while it is non-empty.
let _ = unsafe { oakundo_command_redo_now(self.command.clone()) };
}
}
/// `undo`: forward to `oakundo_command_undo_now`.
pub fn undo(&mut self) {
if !self.command.is_null() {
// SAFETY: `self.command` is a valid handle while it is non-empty.
let _ = unsafe { oakundo_command_undo_now(self.command.clone()) };
}
}
}
impl Drop for CHandleCommandWrapper {
fn drop(&mut self) {
if !self.command.is_null() {
// SAFETY: `self.command` is a valid owned handle.
unsafe { oakundo_command_free(&mut self.command) };
}
}
}
/// `MultiUndoCommand` — a command that runs several child commands in order
/// on `redo` and in reverse on `undo` (timelineundocommon.h
/// `MultiUndoCommand`). Children are boxed `Command`s; the whole group wraps
/// into a single oakundo vtable handle via [`box_command`].
pub struct MultiUndoCommand {
/// Child commands, run in order on `redo`.
commands: Vec<Box<dyn Command>>,
}
impl MultiUndoCommand {
/// A new, empty multi command.
pub fn new() -> Self {
Self {
commands: Vec::new(),
}
}
/// Append a child command; ownership transfers to the group.
pub fn add_child(&mut self, command: Box<dyn Command>) {
self.commands.push(command);
}
/// Whether the group has any children yet.
pub fn empty(&self) -> bool {
self.commands.is_empty()
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
box_command(self)
}
}
impl Command for MultiUndoCommand {
/// `redo`: run children in order.
fn redo(&mut self) {
for c in self.commands.iter_mut() {
c.redo();
}
}
/// `undo`: run children in reverse.
fn undo(&mut self) {
for c in self.commands.iter_mut().rev() {
c.undo();
}
}
}
File diff suppressed because it is too large Load Diff
+708
View File
@@ -0,0 +1,708 @@
// 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/>.
//! Pointer-edit commands (`src/timeline/src/timelineundopointer.h`): trims
//! that compensate the adjacent block (`BlockTrimCommand`), slides
//! (`TrackSlideCommand`) and destructive placement (`TrackPlaceBlockCommand`).
//!
//! Graph mutation goes through the oaknode C ABI (`bridge::node`); command
//! wrapping through `bridge::undo`.
use oakcore_rs::{Rational, TimeRange};
use crate::common::MovementMode;
use crate::bridge::node::{
oaknode_block_gap_create, oaknode_block_get_kind, oaknode_track_get_block_at,
oaknode_track_get_block_count, oaknode_track_insert_block_after, oaknode_track_prepend_block,
oaknode_track_ripple_remove_block, oaknode_tracklist_get_track_at, oaknode_tracklist_get_track_count,
};
use crate::bridge::undo::{oakundo_command_redo_now, oakundo_command_undo_now};
use crate::handle::CHandle;
use crate::undocommon::{
block_can_be_removed, box_command, create_and_run_block_remove_command, create_block_remove_command,
Command,
};
use crate::util::{
block_add_to_graph, block_length, block_next, block_previous, block_remove_from_graph,
block_set_length_and_media_in, block_set_length_and_media_out, track_length,
};
use super::undogeneral::TimelineAddTrackCommand;
use super::undoripple::TrackRippleRemoveAreaCommand;
/// C++ `oaknode_track_append_block` — not exposed by the bridge, so append is
/// synthesized as insert-after the last block (prepend on an empty track).
fn track_append_block(track: CHandle, block: CHandle) {
let mut count = 0;
// SAFETY: `count` is a valid out pointer.
let _ = unsafe { oaknode_track_get_block_count(track.clone(), &mut count) };
if count > 0 {
let mut last = CHandle::null();
// SAFETY: `last` is a valid out pointer.
let _ = unsafe { oaknode_track_get_block_at(track.clone(), count - 1, &mut last) };
// SAFETY: `track`/`last` are valid handles.
let _ = unsafe { oaknode_track_insert_block_after(track, block, last) };
} else {
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_prepend_block(track, block) };
}
}
/// C++ `oaknode_track_insert_block_before` — not exposed by the bridge, so
/// insert-before is synthesized as insert-after `next`'s predecessor (prepend
/// when `next` is the first block on the track).
fn track_insert_block_before(track: CHandle, block: CHandle, next: CHandle) {
let prev = block_previous(next.clone());
if prev.is_null() {
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_prepend_block(track, block) };
} else {
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_insert_block_after(track, block, prev) };
}
}
/// `BlockTrimCommand` — trim one block, compensating the block directly
/// adjacent so the rest of the track is unaffected (timelineundopointer.h).
///
/// By default only gaps are shortened; when the adjacent block must grow and
/// is not a gap, a gap is inserted. Set [`Self::set_trim_is_a_roll_edit`] to
/// always trim into the adjacent block instead.
pub struct BlockTrimCommand {
/// Owning track (`track_`).
track: CHandle,
/// Block to trim (`block_`).
block: CHandle,
/// New length (`new_length_`).
new_length: Rational,
/// Trim direction (`mode_`).
mode: MovementMode,
/// Whether `prepare` found the length unchanged, so `redo`/`undo` no-op
/// (`doing_nothing_`).
doing_nothing_: bool,
/// Signed difference `old_length - new_length`; positive when trimming
/// shorter (`trim_diff_`).
trim_diff_: Rational,
/// Block length before the trim (`old_length_`).
old_length_: Rational,
/// The block to compensate (`adjacent_`).
adjacent_: CHandle,
/// Whether the adjacent block is required for this trim (`needs_adjacent_`).
needs_adjacent_: bool,
/// Whether `adjacent_` was created by this command (`we_created_adjacent_`).
we_created_adjacent_: bool,
/// Whether the adjacent block is removed by this trim (`we_removed_adjacent_`).
we_removed_adjacent_: bool,
/// Graph-removal command for a removed adjacent (`deleted_adjacent_command_`).
///
/// Owns its handle like the C++ `OakUndoCommand`; `CHandle` is refcounted
/// and drops without a destructor, so releasing it is implicit — no explicit
/// `free_command_handle` is needed here.
deleted_adjacent_command_: CHandle,
/// Always trim into the adjacent block instead of creating a gap
/// (`trim_is_a_roll_edit_`).
trim_is_a_roll_edit_: bool,
/// Remove a zero-length adjacent block from the whole graph (default true)
/// rather than only from the track (`remove_block_from_graph_`).
remove_block_from_graph_: bool,
/// Whether `adjacent_` is a created gap still detached from the graph
/// (`adjacent_orphaned_`); a detached handle is owned by this command until
/// it is added to the graph.
adjacent_orphaned_: bool,
}
impl BlockTrimCommand {
/// Construct from track + block + new length + movement mode.
pub fn new(track: CHandle, block: CHandle, new_length: Rational, mode: MovementMode) -> Self {
Self {
track,
block,
new_length,
mode,
doing_nothing_: false,
trim_diff_: Rational::new(0, 1),
old_length_: Rational::new(0, 1),
adjacent_: CHandle::null(),
needs_adjacent_: false,
we_created_adjacent_: false,
we_removed_adjacent_: false,
deleted_adjacent_command_: CHandle::null(),
trim_is_a_roll_edit_: false,
remove_block_from_graph_: true,
adjacent_orphaned_: false,
}
}
/// Always trim the adjacent block instead of creating a gap
/// (`set_trim_is_a_roll_edit`).
pub fn set_trim_is_a_roll_edit(&mut self, e: bool) {
self.trim_is_a_roll_edit_ = e;
}
/// Whether an adjacent block shortened to zero length is removed from the
/// whole graph (default true) or only from the track
/// (`set_remove_zero_length_from_graph`).
pub fn set_remove_zero_length_from_graph(&mut self, e: bool) {
self.remove_block_from_graph_ = e;
}
/// `prepare`: compute the trim delta and whether an adjacent block is needed.
pub fn prepare(&mut self) {
// Store old length
self.old_length_ = block_length(self.block.clone());
// If the length isn't changing, set a flag to do nothing
if self.old_length_ == self.new_length {
self.doing_nothing_ = true;
return;
}
self.doing_nothing_ = false;
// Positive when trimming shorter, negative when trimming longer
self.trim_diff_ = self.old_length_ - self.new_length;
// Retrieve our adjacent block (or an empty handle if none)
self.adjacent_ = if self.mode == MovementMode::TrimIn {
block_previous(self.block.clone())
} else {
block_next(self.block.clone())
};
// Ignore when trimming the out with no adjacent, because the user must
// have trimmed the end of the last block in the track
self.needs_adjacent_ = self.mode == MovementMode::TrimIn || !self.adjacent_.is_null();
if self.needs_adjacent_ {
// If we're trimming shorter, we need an adjacent, so check if we have a
// viable one
let mut adjacent_kind = 0; // OAKNODE_BLOCK_OTHER
if !self.adjacent_.is_null() {
// SAFETY: `adjacent_kind` is a valid out pointer.
let _ = unsafe { oaknode_block_get_kind(self.adjacent_.clone(), &mut adjacent_kind) };
}
self.we_created_adjacent_ = self.trim_diff_ > Rational::new(0, 1)
&& (self.adjacent_.is_null() || (adjacent_kind != 2 && !self.trim_is_a_roll_edit_));
if self.we_created_adjacent_ {
// We shortened but don't have a viable adjacent to lengthen, so create
// one
// SAFETY: `oaknode_block_gap_create` returns a fresh owned handle.
self.adjacent_ = unsafe { oaknode_block_gap_create() };
block_set_length_and_media_out(self.adjacent_.clone(), self.trim_diff_);
self.adjacent_orphaned_ = true;
} else {
// Determine if we're removing the adjacent
self.we_removed_adjacent_ = (block_length(self.adjacent_.clone()) + self.trim_diff_).is_null();
}
}
}
/// `redo`: apply the trim, creating/removing the adjacent block as needed.
pub fn redo(&mut self) {
if self.doing_nothing_ {
return;
}
if self.mode == MovementMode::TrimIn {
block_set_length_and_media_in(self.block.clone(), self.new_length);
} else {
block_set_length_and_media_out(self.block.clone(), self.new_length);
}
if self.needs_adjacent_ {
if self.we_created_adjacent_ {
// Add the adjacent and insert it
block_add_to_graph(self.adjacent_.clone(), self.track.clone());
if self.mode == MovementMode::TrimIn {
track_insert_block_before(self.track.clone(), self.adjacent_.clone(), self.block.clone());
} else {
// SAFETY: `track`/`adjacent_`/`block` are valid handles.
let _ = unsafe {
oaknode_track_insert_block_after(self.track.clone(), self.adjacent_.clone(), self.block.clone())
};
}
self.adjacent_orphaned_ = false;
} else if self.we_removed_adjacent_ {
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_ripple_remove_block(self.track.clone(), self.adjacent_.clone()) };
// It no longer inputs/outputs anything, remove it
if self.remove_block_from_graph_ && block_can_be_removed(self.adjacent_.clone()) {
if self.deleted_adjacent_command_.is_null() {
self.deleted_adjacent_command_ = create_and_run_block_remove_command(self.adjacent_.clone());
} else {
// SAFETY: `deleted_adjacent_command_` is a valid command handle.
let _ = unsafe { oakundo_command_redo_now(self.deleted_adjacent_command_.clone()) };
}
}
} else {
let adjacent_length = block_length(self.adjacent_.clone()) + self.trim_diff_;
if self.mode == MovementMode::TrimIn {
block_set_length_and_media_out(self.adjacent_.clone(), adjacent_length);
} else {
block_set_length_and_media_in(self.adjacent_.clone(), adjacent_length);
}
}
}
}
/// `undo`: revert the trim and any adjacent-block changes.
pub fn undo(&mut self) {
if self.doing_nothing_ {
return;
}
// `trim_diff_` is positive when trimming shorter, negative when trimming
// longer
if self.needs_adjacent_ {
if self.we_created_adjacent_ {
// The adjacent is ours, just delete it
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_ripple_remove_block(self.track.clone(), self.adjacent_.clone()) };
block_remove_from_graph(self.adjacent_.clone(), self.track.clone());
self.adjacent_orphaned_ = true;
} else {
if self.we_removed_adjacent_ {
if !self.deleted_adjacent_command_.is_null() {
// We deleted the adjacent, restore it now
// SAFETY: `deleted_adjacent_command_` is a valid command handle.
let _ = unsafe { oakundo_command_undo_now(self.deleted_adjacent_command_.clone()) };
}
if self.mode == MovementMode::TrimIn {
track_insert_block_before(self.track.clone(), self.adjacent_.clone(), self.block.clone());
} else {
// SAFETY: valid handles.
let _ = unsafe {
oaknode_track_insert_block_after(self.track.clone(), self.adjacent_.clone(), self.block.clone())
};
}
} else {
let adjacent_length = block_length(self.adjacent_.clone()) - self.trim_diff_;
if self.mode == MovementMode::TrimIn {
block_set_length_and_media_out(self.adjacent_.clone(), adjacent_length);
} else {
block_set_length_and_media_in(self.adjacent_.clone(), adjacent_length);
}
}
}
}
if self.mode == MovementMode::TrimIn {
block_set_length_and_media_in(self.block.clone(), self.old_length_);
} else {
block_set_length_and_media_out(self.block.clone(), self.old_length_);
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
box_command(self)
}
}
impl Command for BlockTrimCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `TrackSlideCommand` — slide a set of blocks along a track by `movement`,
/// trimming or inserting the in/out adjacent blocks to compensate
/// (timelineundopointer.h).
pub struct TrackSlideCommand {
/// Owning track (`track_`).
track: CHandle,
/// Blocks to slide (`blocks_`; non-empty for a valid command).
blocks: Vec<CHandle>,
/// Signed movement (`movement_`).
movement: Rational,
/// Whether `prepare` created the in adjacent (`we_created_in_adjacent_`).
we_created_in_adjacent_: bool,
/// Whether the slide removes the in adjacent (`we_removed_in_adjacent_`).
we_removed_in_adjacent_: bool,
/// Block adjacent on the in side (`in_adjacent_`).
in_adjacent: CHandle,
/// Graph-removal command for a removed in adjacent (`in_adjacent_remove_command_`).
///
/// Owns its handle like the C++ `OakUndoCommand`; `CHandle` is refcounted
/// and drops without a destructor, so releasing it is implicit.
in_adjacent_remove_command_: CHandle,
/// Whether `in_adjacent_` is a created gap still detached from the graph
/// (`in_adjacent_orphaned_`); a detached handle is owned by this command.
in_adjacent_orphaned_: bool,
/// Whether `prepare` created the out adjacent (`we_created_out_adjacent_`).
we_created_out_adjacent_: bool,
/// Whether the slide removes the out adjacent (`we_removed_out_adjacent_`).
we_removed_out_adjacent_: bool,
/// Block adjacent on the out side (`out_adjacent_`).
out_adjacent: CHandle,
/// Graph-removal command for a removed out adjacent (`out_adjacent_remove_command_`).
out_adjacent_remove_command_: CHandle,
/// Whether `out_adjacent_` is a created gap still detached from the graph
/// (`out_adjacent_orphaned_`); a detached handle is owned by this command.
out_adjacent_orphaned_: bool,
}
impl TrackSlideCommand {
/// Construct from track + moving blocks + in/out adjacent blocks + movement.
pub fn new(
track: CHandle,
blocks: Vec<CHandle>,
in_adjacent: CHandle,
out_adjacent: CHandle,
movement: Rational,
) -> Self {
Self {
track,
blocks,
movement,
we_created_in_adjacent_: false,
we_removed_in_adjacent_: false,
in_adjacent,
in_adjacent_remove_command_: CHandle::null(),
in_adjacent_orphaned_: false,
we_created_out_adjacent_: false,
we_removed_out_adjacent_: false,
out_adjacent,
out_adjacent_remove_command_: CHandle::null(),
out_adjacent_orphaned_: false,
}
}
/// `prepare`: capture adjacent state.
pub fn prepare(&mut self) {
if self.in_adjacent.is_null() {
// SAFETY: `oaknode_block_gap_create` returns a fresh owned handle.
self.in_adjacent = unsafe { oaknode_block_gap_create() };
block_set_length_and_media_out(self.in_adjacent.clone(), self.movement);
self.in_adjacent_orphaned_ = true;
self.we_created_in_adjacent_ = true;
} else {
self.we_created_in_adjacent_ = false;
}
if self.out_adjacent.is_null() && !block_next(self.blocks[self.blocks.len() - 1].clone()).is_null() {
// SAFETY: `oaknode_block_gap_create` returns a fresh owned handle.
self.out_adjacent = unsafe { oaknode_block_gap_create() };
block_set_length_and_media_out(self.out_adjacent.clone(), Rational::new(0, 1) - self.movement);
self.out_adjacent_orphaned_ = true;
self.we_created_out_adjacent_ = true;
} else {
self.we_created_out_adjacent_ = false;
}
}
/// `redo`: apply the slide.
pub fn redo(&mut self) {
// We will always have an in adjacent if there was a valid slide
if self.we_created_in_adjacent_ {
// We created the in adjacent, so all we have to do is insert it
block_add_to_graph(self.in_adjacent.clone(), self.track.clone());
// `blocks` is non-empty when the command was constructed validly
track_insert_block_before(self.track.clone(), self.in_adjacent.clone(), self.blocks[0].clone());
self.in_adjacent_orphaned_ = false;
} else if Rational::new(0, 1) - self.movement == block_length(self.in_adjacent.clone()) {
// Movement will remove the in adjacent
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_ripple_remove_block(self.track.clone(), self.in_adjacent.clone()) };
if block_can_be_removed(self.in_adjacent.clone()) {
if self.in_adjacent_remove_command_.is_null() {
self.in_adjacent_remove_command_ = create_block_remove_command(self.in_adjacent.clone());
}
// SAFETY: `in_adjacent_remove_command_` is a valid command handle.
let _ = unsafe { oakundo_command_redo_now(self.in_adjacent_remove_command_.clone()) };
}
self.we_removed_in_adjacent_ = true;
} else {
// Simply resize the adjacent
block_set_length_and_media_out(
self.in_adjacent.clone(),
block_length(self.in_adjacent.clone()) + self.movement,
);
}
// We may not have an out adjacent if the slide was at the end of the track
if !self.out_adjacent.is_null() {
if self.we_created_out_adjacent_ {
// We created the out adjacent, so we just have to insert it
block_add_to_graph(self.out_adjacent.clone(), self.track.clone());
// SAFETY: valid handles.
let _ = unsafe {
oaknode_track_insert_block_after(
self.track.clone(),
self.out_adjacent.clone(),
self.blocks[self.blocks.len() - 1].clone(),
)
};
self.out_adjacent_orphaned_ = false;
} else if self.movement == block_length(self.out_adjacent.clone()) {
// Movement will remove the out adjacent
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_ripple_remove_block(self.track.clone(), self.out_adjacent.clone()) };
if block_can_be_removed(self.out_adjacent.clone()) {
if self.out_adjacent_remove_command_.is_null() {
self.out_adjacent_remove_command_ = create_block_remove_command(self.out_adjacent.clone());
}
// SAFETY: `out_adjacent_remove_command_` is a valid command handle.
let _ = unsafe { oakundo_command_redo_now(self.out_adjacent_remove_command_.clone()) };
}
self.we_removed_out_adjacent_ = true;
} else {
// Simply resize the adjacent
block_set_length_and_media_in(
self.out_adjacent.clone(),
block_length(self.out_adjacent.clone()) - self.movement,
);
}
}
}
/// `undo`: revert the slide.
pub fn undo(&mut self) {
if self.we_created_in_adjacent_ {
// We created this, so we can remove it now
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_ripple_remove_block(self.track.clone(), self.in_adjacent.clone()) };
block_remove_from_graph(self.in_adjacent.clone(), self.track.clone());
self.in_adjacent_orphaned_ = true;
} else if self.we_removed_in_adjacent_ {
if !self.in_adjacent_remove_command_.is_null() {
// We removed this, so we can restore it now
// SAFETY: `in_adjacent_remove_command_` is a valid command handle.
let _ = unsafe { oakundo_command_undo_now(self.in_adjacent_remove_command_.clone()) };
}
// `blocks` is non-empty when the command was constructed validly
track_insert_block_before(self.track.clone(), self.in_adjacent.clone(), self.blocks[0].clone());
} else {
// Simply resize the adjacent
block_set_length_and_media_out(
self.in_adjacent.clone(),
block_length(self.in_adjacent.clone()) - self.movement,
);
}
if !self.out_adjacent.is_null() {
if self.we_created_out_adjacent_ {
// We created this, so we can remove it now
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_ripple_remove_block(self.track.clone(), self.out_adjacent.clone()) };
block_remove_from_graph(self.out_adjacent.clone(), self.track.clone());
self.out_adjacent_orphaned_ = true;
} else if self.we_removed_out_adjacent_ {
if !self.out_adjacent_remove_command_.is_null() {
// We removed this, so we can restore it now
// SAFETY: `out_adjacent_remove_command_` is a valid command handle.
let _ = unsafe { oakundo_command_undo_now(self.out_adjacent_remove_command_.clone()) };
}
// SAFETY: valid handles.
let _ = unsafe {
oaknode_track_insert_block_after(
self.track.clone(),
self.out_adjacent.clone(),
self.blocks[self.blocks.len() - 1].clone(),
)
};
} else {
// Simply resize the adjacent
block_set_length_and_media_in(
self.out_adjacent.clone(),
block_length(self.out_adjacent.clone()) + self.movement,
);
}
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
box_command(self)
}
}
impl Command for TrackSlideCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `TrackPlaceBlockCommand` — destructively place `block` at `in`, trimming or
/// removing blocks that occupy that area and inserting a gap if the block
/// extends past the end of the sequence (timelineundopointer.h).
pub struct TrackPlaceBlockCommand {
/// Track list (`timeline_`).
timeline: CHandle,
/// Target track index (`track_index_`).
track_index: i32,
/// Placement in point (`in_`).
in_: Rational,
/// Gap inserted when the block extends past the end of the sequence (`gap_`).
gap_: CHandle,
/// Whether `gap_` is detached from the graph (`gap_orphaned_`); a detached
/// handle is owned by this command.
gap_orphaned_: bool,
/// Block to place (C++ `insert_`).
block: CHandle,
/// Track-add commands created when the track index is out of range
/// (`add_track_commands_`).
add_track_commands_: Vec<TimelineAddTrackCommand>,
/// Ripple-removal of the area the block occupies (`ripple_remove_command_`).
ripple_remove_command_: Option<TrackRippleRemoveAreaCommand>,
}
impl TrackPlaceBlockCommand {
/// Construct from track list + track index + block + in point.
pub fn new(timeline: CHandle, track_index: i32, block: CHandle, in_: Rational) -> Self {
Self {
timeline,
track_index,
in_,
gap_: CHandle::null(),
gap_orphaned_: false,
block,
add_track_commands_: Vec::new(),
ripple_remove_command_: None,
}
}
/// `redo`: place the block destructively.
pub fn redo(&mut self) {
// Determine if we need to add tracks
let mut track_count = 0;
// SAFETY: `track_count` is a valid out pointer.
let _ = unsafe { oaknode_tracklist_get_track_count(self.timeline.clone(), &mut track_count) };
if self.track_index >= track_count {
if self.add_track_commands_.is_empty() {
// First redo, create the missing tracks now
for _ in 0..(self.track_index - track_count + 1) {
self.add_track_commands_.push(TimelineAddTrackCommand::new(self.timeline.clone()));
}
}
for cmd in &mut self.add_track_commands_ {
cmd.redo();
}
}
let mut track = CHandle::null();
// SAFETY: `track` is a valid out pointer.
let _ = unsafe { oaknode_tracklist_get_track_at(self.timeline.clone(), self.track_index, &mut track) };
let in_ = self.in_;
let append = in_ >= track_length(track.clone());
// Check if the placement location is past the end of the timeline
if append {
if in_ > track_length(track.clone()) {
// If so, insert a gap here
if self.gap_.is_null() {
// SAFETY: `oaknode_block_gap_create` returns a fresh owned handle.
self.gap_ = unsafe { oaknode_block_gap_create() };
block_set_length_and_media_out(self.gap_.clone(), in_ - track_length(track.clone()));
}
block_add_to_graph(self.gap_.clone(), track.clone());
track_append_block(track.clone(), self.gap_.clone());
self.gap_orphaned_ = false;
}
track_append_block(track, self.block.clone());
} else {
// Place the block at this point
if self.ripple_remove_command_.is_none() {
let insert_length = block_length(self.block.clone());
let mut cmd = TrackRippleRemoveAreaCommand::new(track.clone(), TimeRange::new(in_, in_ + insert_length));
cmd.set_allow_splitting_gaps(true);
self.ripple_remove_command_ = Some(cmd);
}
let cmd = self.ripple_remove_command_.as_mut().unwrap();
cmd.prepare();
cmd.redo();
// Insert after the block that follows the cleared area (`blocks` is
// non-empty when the command was constructed validly)
let index = self.ripple_remove_command_.as_ref().unwrap().get_insertion_index();
// SAFETY: valid handles; `index` may be empty when the insertion is at
// the front of the track, which the ABI tolerates like C++.
let _ = unsafe { oaknode_track_insert_block_after(track, self.block.clone(), index) };
}
}
/// `undo`: remove the placed block and restore displaced blocks.
pub fn undo(&mut self) {
let mut t = CHandle::null();
// SAFETY: `t` is a valid out pointer.
let _ = unsafe { oaknode_tracklist_get_track_at(self.timeline.clone(), self.track_index, &mut t) };
// Firstly, remove our insert
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_ripple_remove_block(t.clone(), self.block.clone()) };
if self.ripple_remove_command_.is_some() {
// If we ripple-removed, just undo that
self.ripple_remove_command_.as_mut().unwrap().undo();
} else if !self.gap_.is_null() {
// SAFETY: valid handles.
let _ = unsafe { oaknode_track_ripple_remove_block(t.clone(), self.gap_.clone()) };
block_remove_from_graph(self.gap_.clone(), t.clone());
self.gap_orphaned_ = true;
}
// Remove tracks if we added them
for cmd in self.add_track_commands_.iter_mut().rev() {
cmd.undo();
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
box_command(self)
}
}
impl Command for TrackPlaceBlockCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
File diff suppressed because it is too large Load Diff
+304
View File
@@ -0,0 +1,304 @@
// 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/>.
//! Split commands (`src/timeline/src/timelineundosplit.h`). All graph
//! operations go through the oaknode C ABI.
//!
//! The C++ oracles (`timelineundosplit.cpp`) clone the split block in the
//! project graph (`oaknode_node_copy_in_graph` + `oaknode_block_from_node`),
//! run a captured node-graph reconnect command, preserve link groups
//! (`oaknode_block_are_linked`), move out-transitions across the split
//! (`oaknode_node_disconnect`/`oaknode_node_connect`), and add cache
//! passthrough (`oaknode_clip_add_cache_passthrough_from`). None of those
//! symbols are exposed by this crate's oaknode bridge, so those branches are
//! omitted here and noted at each site; the remaining length/insert/remove
//! logic mirrors the C++.
use oakcore_rs::Rational;
use crate::bridge::node::{
oaknode_block_clip_create, oaknode_track_insert_block_after, oaknode_track_ripple_remove_block,
};
use crate::handle::CHandle;
use crate::util::{
block_in, block_length, block_out, block_set_length_and_media_in,
block_set_length_and_media_out, block_track, same_block,
};
/// `BlockSplitCommand` — split one block at a point
/// (timelineundosplit.h).
pub struct BlockSplitCommand {
/// Block to split.
block: CHandle,
/// Split point.
point: Rational,
/// Second block created by the split (valid after `redo`).
new_block: CHandle,
/// Length of `block` before the split, restored on `undo`.
old_length: Rational,
}
impl BlockSplitCommand {
/// Construct from block + split point.
pub fn new(block: CHandle, point: Rational) -> Self {
Self {
block,
point,
new_block: CHandle::null(),
old_length: Rational::new(0, 1),
}
}
/// `prepare`: create the second half of the split. The C++ clone is
/// performed by `oaknode_node_copy_in_graph` + `oaknode_block_from_node`,
/// which are absent from this bridge, so a fresh clip block is created.
pub fn prepare(&mut self) {
if self.new_block.is_null() {
// SAFETY: `oaknode_block_clip_create` returns an owned handle.
self.new_block = unsafe { oaknode_block_clip_create() };
}
}
/// `redo`: shrink `block` to the first half, grow `new_block` to the
/// second half, and insert it after `block`.
pub fn redo(&mut self) {
// Create the second half if redo is invoked without a preceding
// prepare() (the C ABI command path may call redo directly).
if self.new_block.is_null() {
// SAFETY: `oaknode_block_clip_create` returns an owned handle.
self.new_block = unsafe { oaknode_block_clip_create() };
}
self.old_length = block_length(self.block.clone());
let block_in = block_in(self.block.clone());
let block_out = block_out(self.block.clone());
// The C++ asserts `point_` lies strictly inside the block; that would
// panic across the FFI boundary, so it is intentionally not replicated.
let new_length = self.point - block_in;
let new_part_length = block_out - self.point;
let track = block_track(self.block.clone());
block_set_length_and_media_out(self.block.clone(), new_length);
block_set_length_and_media_in(self.new_block.clone(), new_part_length);
// SAFETY: bridge inserts `new_block` after `block` on `track`.
let _ = unsafe {
oaknode_track_insert_block_after(track, self.new_block.clone(), self.block.clone())
};
// The C++ also re-runs a `reconnect_tree_command_` (the node-graph
// re-connection captured while cloning) and moves an out transition
// onto `new_block` via `oaknode_*` connection APIs; those symbols are
// absent from this bridge, so both are omitted here.
}
/// `undo`: restore `block`'s original length and remove the second half.
pub fn undo(&mut self) {
let track = block_track(self.block.clone());
block_set_length_and_media_out(self.block.clone(), self.old_length);
// SAFETY: bridge ripple-removes `new_block` from `track`.
let _ = unsafe { oaknode_track_ripple_remove_block(track, self.new_block.clone()) };
// The C++ first moves a previously-moved out transition back onto
// `block` and runs `reconnect_tree_command_`'s undo; both need oaknode
// symbols absent from this bridge, so they are omitted here.
}
/// The second block created by the split; only valid after `redo`.
pub fn new_block(&self) -> CHandle {
self.new_block.clone()
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
crate::undocommon::box_command(self)
}
}
impl crate::undocommon::Command for BlockSplitCommand {
fn redo(&mut self) {
self.redo();
}
fn undo(&mut self) {
self.undo();
}
}
/// `BlockSplitPreservingLinksCommand` — split a set of blocks at per-block
/// times, preserving link groups (timelineundosplit.h).
pub struct BlockSplitPreservingLinksCommand {
/// Blocks to split.
blocks: Vec<CHandle>,
/// Split times.
times: Vec<Rational>,
/// Child split commands, executed in order on `redo`.
commands: Vec<BlockSplitCommand>,
/// `splits[time_index][block_index]`: second half created for that
/// block/time, or an empty handle when the block was not split there.
splits: Vec<Vec<CHandle>>,
}
impl BlockSplitPreservingLinksCommand {
/// Construct from blocks + times (one per block).
pub fn new(blocks: Vec<CHandle>, times: Vec<Rational>) -> Self {
Self {
blocks,
times,
commands: Vec::new(),
splits: Vec::new(),
}
}
/// `prepare`: build the child split commands.
pub fn prepare(&mut self) {
let n_times = self.times.len();
let n_blocks = self.blocks.len();
self.splits = vec![vec![CHandle::null(); n_blocks]; n_times];
for i in 0..n_times {
let time = self.times[i];
// The C++ asserts the times are strictly ordered; that would
// panic across the FFI boundary, so it is not replicated.
for j in 0..n_blocks {
let b_in = block_in(self.blocks[j].clone());
let b_out = block_out(self.blocks[j].clone());
if b_in < time && b_out > time {
let mut split = BlockSplitCommand::new(self.blocks[j].clone(), time);
split.prepare();
split.redo();
self.splits[i][j] = split.new_block();
self.commands.push(split);
}
}
}
// The C++ then relinks every pair of originally-linked blocks by
// creating link commands between their split halves
// (`oaknode_block_are_linked`); that symbol is absent from this
// bridge, so link preservation is omitted.
}
/// `redo`: redo every child command in order.
pub fn redo(&mut self) {
for c in self.commands.iter_mut() {
c.redo();
}
}
/// `undo`: undo every child command in reverse.
pub fn undo(&mut self) {
for c in self.commands.iter_mut().rev() {
c.undo();
}
}
/// The block produced by splitting `original` at `time_index`;
/// `None` when not applicable (timelineundosplit.h `get_split`).
pub fn get_split(&self, original: CHandle, time_index: usize) -> Option<CHandle> {
if time_index < self.times.len() {
for (i, b) in self.blocks.iter().enumerate() {
if same_block(b.clone(), original.clone()) {
return self.splits.get(time_index).and_then(|row| row.get(i)).cloned();
}
}
}
None
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
crate::undocommon::box_command(self)
}
}
impl crate::undocommon::Command for BlockSplitPreservingLinksCommand {
fn redo(&mut self) {
self.redo();
}
fn undo(&mut self) {
self.undo();
}
}
/// `TrackSplitAtTimeCommand` — split every block on a track at a point
/// (timelineundosplit.h).
pub struct TrackSplitAtTimeCommand {
/// Owning track.
track: CHandle,
/// Split point.
point: Rational,
/// Inner per-block split command, built by `prepare`.
command: Option<BlockSplitCommand>,
}
impl TrackSplitAtTimeCommand {
/// Construct from track + point.
pub fn new(track: CHandle, point: Rational) -> Self {
Self {
track,
point,
command: None,
}
}
/// `prepare`: build the per-block split command. The C++ finds the block
/// via `oaknode_track_get_block_containing_time`, which is not exposed by
/// this crate's oaknode bridge (and there is no block-enumeration helper
/// to search for it), so the inner command cannot be built here and
/// redo/undo remain no-ops until that lookup API exists.
pub fn prepare(&mut self) {
let _ = (self.track.clone(), self.point);
}
/// `redo`: forward to the inner command.
pub fn redo(&mut self) {
if let Some(c) = self.command.as_mut() {
c.redo();
}
}
/// `undo`: forward to the inner command.
pub fn undo(&mut self) {
if let Some(c) = self.command.as_mut() {
c.undo();
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
crate::undocommon::box_command(self)
}
}
impl crate::undocommon::Command for TrackSplitAtTimeCommand {
fn redo(&mut self) {
self.redo();
}
fn undo(&mut self) {
self.undo();
}
}
+225
View File
@@ -0,0 +1,225 @@
// 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/>.
//! Track-level block commands (`src/timeline/src/timelineundotrack.h`).
//! All graph operations go through the oaknode C ABI (`bridge::node`).
use crate::bridge::node::{
oaknode_block_get_previous, oaknode_track_insert_block_after, oaknode_track_prepend_block,
oaknode_track_replace_block, oaknode_track_ripple_remove_block,
};
use crate::handle::CHandle;
use crate::undocommon::{box_command, Command};
/// `TrackRippleRemoveBlockCommand` — ripple-remove a block from a track
/// (timelineundotrack.h).
pub struct TrackRippleRemoveBlockCommand {
/// Owning track.
track: CHandle,
/// Block to remove.
block: CHandle,
/// Predecessor of the removed block, captured at `redo` time so `undo`
/// can restore the block at its original position.
before: CHandle,
}
impl TrackRippleRemoveBlockCommand {
/// Construct from track + block.
pub fn new(track: CHandle, block: CHandle) -> Self {
Self {
track,
block,
before: CHandle::null(),
}
}
/// `redo`: capture the predecessor, then `oaknode_track_ripple_remove_block`.
pub fn redo(&mut self) {
unsafe {
oaknode_block_get_previous(self.block.clone(), &mut self.before);
oaknode_track_ripple_remove_block(self.track.clone(), self.block.clone());
}
}
/// `undo`: re-insert via `oaknode_track_insert_block_after`.
pub fn undo(&mut self) {
unsafe {
oaknode_track_insert_block_after(self.track.clone(), self.block.clone(), self.before.clone());
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
box_command(self)
}
}
impl Command for TrackRippleRemoveBlockCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `TrackPrependBlockCommand` — prepend a block to a track
/// (timelineundotrack.h).
pub struct TrackPrependBlockCommand {
/// Owning track.
track: CHandle,
/// Block to prepend.
block: CHandle,
}
impl TrackPrependBlockCommand {
/// Construct from track + block.
pub fn new(track: CHandle, block: CHandle) -> Self {
Self { track, block }
}
/// `redo`: `oaknode_track_prepend_block`.
pub fn redo(&mut self) {
unsafe {
oaknode_track_prepend_block(self.track.clone(), self.block.clone());
}
}
/// `undo`: `oaknode_track_ripple_remove_block`.
pub fn undo(&mut self) {
unsafe {
oaknode_track_ripple_remove_block(self.track.clone(), self.block.clone());
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
box_command(self)
}
}
impl Command for TrackPrependBlockCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `TrackInsertBlockAfterCommand` — insert a block after a predecessor
/// (timelineundotrack.h).
pub struct TrackInsertBlockAfterCommand {
/// Owning track.
track: CHandle,
/// Block to insert.
block: CHandle,
/// Predecessor block.
before: CHandle,
}
impl TrackInsertBlockAfterCommand {
/// Construct from track + block + predecessor.
pub fn new(track: CHandle, block: CHandle, before: CHandle) -> Self {
Self { track, block, before }
}
/// `redo`: `oaknode_track_insert_block_after`.
pub fn redo(&mut self) {
unsafe {
oaknode_track_insert_block_after(self.track.clone(), self.block.clone(), self.before.clone());
}
}
/// `undo`: `oaknode_track_ripple_remove_block`.
pub fn undo(&mut self) {
unsafe {
oaknode_track_ripple_remove_block(self.track.clone(), self.block.clone());
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
box_command(self)
}
}
impl Command for TrackInsertBlockAfterCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `TrackReplaceBlockCommand` — replace block `old` with block `replace`
/// (equal lengths required) (timelineundotrack.h).
pub struct TrackReplaceBlockCommand {
/// Owning track.
track: CHandle,
/// Block to replace.
old: CHandle,
/// Replacement block.
replace: CHandle,
}
impl TrackReplaceBlockCommand {
/// Construct from track + old + replace.
pub fn new(track: CHandle, old: CHandle, replace: CHandle) -> Self {
Self { track, old, replace }
}
/// `redo`: `oaknode_track_replace_block(track, old, replace)`.
pub fn redo(&mut self) {
unsafe {
oaknode_track_replace_block(self.track.clone(), self.old.clone(), self.replace.clone());
}
}
/// `undo`: `oaknode_track_replace_block(track, replace, old)`.
pub fn undo(&mut self) {
unsafe {
oaknode_track_replace_block(self.track.clone(), self.replace.clone(), self.old.clone());
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> CHandle {
box_command(self)
}
}
impl Command for TrackReplaceBlockCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
+211
View File
@@ -0,0 +1,211 @@
// 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/>.
//! Inline helpers from `src/timeline/src/timelineutil.h`: Rational ↔
//! num/den pairs, value-handle identity, and block/track/project queries.
//!
//! All graph access goes through the oaknode C ABI (`bridge::node`). The
//! C++ `oaknode_c_api::to_native` internals are NOT replicated — handles
//! are opaque here; identity (`same_*`) is decided by `ctx` equality, not
//! by `to_native` (borrowed accessors box a fresh handle per call).
use std::cmp::Ordering;
use oakcore_rs::Rational;
use crate::bridge::node::{
oaknode_block_as_node, oaknode_block_get_in, oaknode_block_get_length, oaknode_block_get_next,
oaknode_block_get_out, oaknode_block_get_previous, oaknode_block_get_track,
oaknode_block_set_length_and_media_in, oaknode_block_set_length_and_media_out,
oaknode_node_get_project, oaknode_project_add_node, oaknode_project_remove_node,
oaknode_sequence_as_node, oaknode_track_get_length, oaknode_track_get_sequence,
};
use crate::handle::CHandle;
/// Split a `Rational` into numerator/denominator pairs for the C ABI
/// (timelineutil.h `rat_nd`).
pub fn rat_nd(r: Rational, n: &mut i32, d: &mut i32) {
*n = r.numerator() as i32;
*d = r.denominator() as i32;
}
/// Identity of two handles by `ctx` pointer equality.
fn same_handle(a: CHandle, b: CHandle) -> bool {
a.ctx == b.ctx
}
/// `same_block`: two block handles wrap the same object.
pub fn same_block(a: CHandle, b: CHandle) -> bool {
same_handle(a, b)
}
/// `same_track`: two track handles wrap the same object.
pub fn same_track(a: CHandle, b: CHandle) -> bool {
same_handle(a, b)
}
/// `same_node`: two node handles wrap the same object.
pub fn same_node(a: CHandle, b: CHandle) -> bool {
same_handle(a, b)
}
/// Total order over handles by `ctx`, so maps work across freshly boxed
/// handles of the same origin.
fn handle_less(a: CHandle, b: CHandle) -> Ordering {
a.ctx.cmp(&b.ctx)
}
/// `BlockHandleLess`: total order over block handles by wrapped native
/// pointer (identity), so maps work across freshly-boxed borrowed handles.
pub fn block_handle_less(a: CHandle, b: CHandle) -> std::cmp::Ordering {
handle_less(a, b)
}
/// `TrackHandleLess`: total order over track handles by wrapped native
/// pointer.
pub fn track_handle_less(a: CHandle, b: CHandle) -> std::cmp::Ordering {
handle_less(a, b)
}
/// `free_detached_handle`: re-take ownership of a detached object's handle
/// then release, destroying it (timelineutil.h).
///
/// In this crate's model a detached block/track handle is an owned handle
/// (it owns its box), so releasing it destroys the object. NULL/empty no-op.
pub fn free_detached_handle(h: *mut CHandle) {
if h.is_null() {
return;
}
// SAFETY: caller passes a valid handle pointer.
let handle = unsafe { &mut *h };
if handle.ctx.is_null() {
return;
}
if let Some(release) = handle.release {
// SAFETY: `release` is the boxed type's release callback.
unsafe { release(handle.ctx) };
}
handle.ctx = std::ptr::null_mut();
handle.addref = None;
handle.release = None;
handle.abi_version = 0;
}
/// Read a block time field as a `Rational`.
fn block_pair(b: CHandle, f: fn(CHandle, *mut i32, *mut i32) -> i32) -> Rational {
let mut n = 0;
let mut d = 0;
// SAFETY: `n`/`d` are valid out pointers.
let _ = unsafe { f(b, &mut n, &mut d) };
Rational::new(n as i64, d as i64)
}
/// `block_in`: in point as a `Rational`.
pub fn block_in(b: CHandle) -> Rational {
block_pair(b, oaknode_block_get_in)
}
/// `block_out`: out point as a `Rational`.
pub fn block_out(b: CHandle) -> Rational {
block_pair(b, oaknode_block_get_out)
}
/// `block_length`: block length as a `Rational`.
pub fn block_length(b: CHandle) -> Rational {
block_pair(b, oaknode_block_get_length)
}
/// `block_set_length_and_media_out`.
pub fn block_set_length_and_media_out(b: CHandle, len: Rational) {
let (mut n, mut d) = (0, 0);
rat_nd(len, &mut n, &mut d);
// SAFETY: `n`/`d` are valid ints.
let _ = unsafe { oaknode_block_set_length_and_media_out(b, n, d) };
}
/// `block_set_length_and_media_in`.
pub fn block_set_length_and_media_in(b: CHandle, len: Rational) {
let (mut n, mut d) = (0, 0);
rat_nd(len, &mut n, &mut d);
// SAFETY: `n`/`d` are valid ints.
let _ = unsafe { oaknode_block_set_length_and_media_in(b, n, d) };
}
/// `track_length`: track length as a `Rational`.
pub fn track_length(t: CHandle) -> Rational {
let mut n = 0;
let mut d = 0;
// SAFETY: `n`/`d` are valid out pointers.
let _ = unsafe { oaknode_track_get_length(t, &mut n, &mut d) };
Rational::new(n as i64, d as i64)
}
/// `block_previous`: the block before `b` on its track.
pub fn block_previous(b: CHandle) -> CHandle {
let mut out = CHandle::null();
// SAFETY: `out` is a valid out pointer.
let _ = unsafe { oaknode_block_get_previous(b, &mut out) };
out
}
/// `block_next`: the block after `b` on its track.
pub fn block_next(b: CHandle) -> CHandle {
let mut out = CHandle::null();
// SAFETY: `out` is a valid out pointer.
let _ = unsafe { oaknode_block_get_next(b, &mut out) };
out
}
/// `block_track`: the track owning `b`.
pub fn block_track(b: CHandle) -> CHandle {
let mut out = CHandle::null();
// SAFETY: `out` is a valid out pointer.
let _ = unsafe { oaknode_block_get_track(b, &mut out) };
out
}
/// `track_project`: the project graph owning the track's sequence, via
/// `oaknode_track_get_sequence` + `oaknode_sequence_as_node` +
/// `oaknode_node_get_project`.
pub fn track_project(track: CHandle) -> CHandle {
let mut sequence = CHandle::null();
if unsafe { oaknode_track_get_sequence(track, &mut sequence) } != 0 || sequence.is_null() {
return CHandle::null();
}
let mut project = CHandle::null();
// SAFETY: `project` is a valid out pointer; the sequence node view is valid.
let _ = unsafe { oaknode_node_get_project(oaknode_sequence_as_node(sequence), &mut project) };
project
}
/// `block_add_to_graph`: attach `b` to the project graph owning `track`.
pub fn block_add_to_graph(b: CHandle, track: CHandle) {
let project = track_project(track);
if !project.is_null() {
// SAFETY: `project` is a valid handle.
let _ = unsafe { oaknode_project_add_node(project, oaknode_block_as_node(b)) };
}
}
/// `block_remove_from_graph`: detach `b` from the project graph owning
/// `track`.
pub fn block_remove_from_graph(b: CHandle, track: CHandle) {
let project = track_project(track);
if !project.is_null() {
// SAFETY: `project` is a valid handle.
let _ = unsafe { oaknode_project_remove_node(project, oaknode_block_as_node(b)) };
}
}
+206
View File
@@ -0,0 +1,206 @@
// 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/>.
//! Timeline work area (`src/timeline/src/timelineworkarea.h` +
//! `timelineundoworkarea.h`): the in/out range, its enabled flag, and the
//! `WorkareaSetEnabledCommand`/`WorkareaSetRangeCommand` undo commands.
//!
//! De-Qt: no QObject, no signals — change notifications are the facade's
//! job.
use oakcore_rs::{Rational, TimeRange};
/// The reset sentinel `k_reset_in` (timelineworkarea.h): 0/1. Exposed as a
/// function because `Rational::new` is not yet `const` in oakcore-rs.
pub fn reset_in() -> Rational {
Rational::new(0, 1)
}
/// The reset sentinel `k_reset_out` (timelineworkarea.h): RATIONAL_MAX,
/// i.e. 2147483647/1.
pub fn reset_out() -> Rational {
Rational::new(2147483647, 1)
}
/// `TimelineWorkArea` — the in/out range on a timeline (timelineworkarea.h).
pub struct TimelineWorkArea {
/// Whether the work area is enabled.
workarea_enabled_: bool,
/// The in/out range.
workarea_range_: TimeRange,
}
impl TimelineWorkArea {
/// A new, disabled work area at `k_reset_in`..`k_reset_out`.
pub fn new() -> Self {
Self {
workarea_enabled_: false,
workarea_range_: TimeRange::new(reset_in(), reset_out()),
}
}
/// Whether the work area is enabled.
pub fn enabled(&self) -> bool {
self.workarea_enabled_
}
/// Set enabled.
pub fn set_enabled(&mut self, e: bool) {
self.workarea_enabled_ = e;
}
/// The in point.
pub fn in_(&self) -> Rational {
self.workarea_range_.in_()
}
/// The out point.
pub fn out(&self) -> Rational {
self.workarea_range_.out()
}
/// The range length.
pub fn length(&self) -> Rational {
self.workarea_range_.length()
}
/// The full range.
pub fn range(&self) -> &TimeRange {
&self.workarea_range_
}
/// Set the range.
pub fn set_range(&mut self, range: TimeRange) {
self.workarea_range_ = range;
}
}
/// `WorkareaSetEnabledCommand` (timelineundoworkarea.h).
pub struct WorkareaSetEnabledCommand {
/// Target work area handle.
points: crate::handle::CHandle,
/// New enabled flag.
new_enabled: bool,
/// Enabled flag captured at construction, restored by `undo`.
old_enabled: bool,
}
impl WorkareaSetEnabledCommand {
/// Construct from work area + new enabled value (captures old at ctor).
pub fn new(points: crate::handle::CHandle, enabled: bool) -> Self {
let old_enabled = unsafe { crate::handle::get::<TimelineWorkArea>(&points) }
.map(|wa| wa.enabled())
.unwrap_or(false);
Self {
points,
new_enabled: enabled,
old_enabled,
}
}
/// `redo`: set enabled.
pub fn redo(&mut self) {
if let Some(wa) = unsafe { crate::handle::get_mut::<TimelineWorkArea>(&self.points) } {
wa.set_enabled(self.new_enabled);
}
}
/// `undo`: restore old enabled.
pub fn undo(&mut self) {
if let Some(wa) = unsafe { crate::handle::get_mut::<TimelineWorkArea>(&self.points) } {
wa.set_enabled(self.old_enabled);
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> crate::handle::CHandle {
crate::undocommon::box_command(self)
}
}
impl crate::undocommon::Command for WorkareaSetEnabledCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}
/// `WorkareaSetRangeCommand` (timelineundoworkarea.h). The old range is
/// captured at construction when not supplied.
pub struct WorkareaSetRangeCommand {
/// Target work area handle.
workarea: crate::handle::CHandle,
/// New range.
new_range: TimeRange,
/// Range captured at construction, restored by `undo`.
old_range: TimeRange,
}
impl WorkareaSetRangeCommand {
/// Construct from work area + new range (captures current as old).
pub fn new(workarea: crate::handle::CHandle, range: TimeRange) -> Self {
let old_range = unsafe { crate::handle::get::<TimelineWorkArea>(&workarea) }
.map(|wa| *wa.range())
.unwrap_or(range);
Self::new_with_old(workarea, range, old_range)
}
/// Construct from work area + new range + explicitly supplied old
/// range (used by the FFI layer, which may have a previously captured
/// range; `new` delegates here with the current range).
pub fn new_with_old(workarea: crate::handle::CHandle, range: TimeRange, old_range: TimeRange) -> Self {
Self {
workarea,
new_range: range,
old_range,
}
}
/// `redo`: set the range.
pub fn redo(&mut self) {
if let Some(wa) = unsafe { crate::handle::get_mut::<TimelineWorkArea>(&self.workarea) } {
wa.set_range(self.new_range);
}
}
/// `undo`: restore the old range.
pub fn undo(&mut self) {
if let Some(wa) = unsafe { crate::handle::get_mut::<TimelineWorkArea>(&self.workarea) } {
wa.set_range(self.old_range);
}
}
/// Wrap as an oakundo vtable command handle.
pub fn to_command(self) -> crate::handle::CHandle {
crate::undocommon::box_command(self)
}
}
impl crate::undocommon::Command for WorkareaSetRangeCommand {
/// `Command::redo` — the inherent method takes precedence.
fn redo(&mut self) {
self.redo();
}
/// `Command::undo` — the inherent method takes precedence.
fn undo(&mut self) {
self.undo();
}
}