Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support swift 5.9 with minimum 5.5 compatibility. #61

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Testing otio swift/c++ interop.
Signed-off-by: furby™ <devs@wabi.foundation>
  • Loading branch information
furby-tm committed Oct 28, 2024
commit f23bb27e0bae76e16bf20b9cbcf8970b5413ede1
34 changes: 19 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -9,9 +9,11 @@ import PackageDescription
let package = Package(
name: "OpenTimelineIO",
platforms: [
.macOS(.v10_13),
.iOS(.v12),
.visionOS(.v1)
.macOS(.v14),
.visionOS(.v1),
.iOS(.v17),
.tvOS(.v17),
.watchOS(.v10),
],
products: [
.library(name: "Imath", targets: ["ImathConfig", "Imath"]),
@@ -53,22 +55,24 @@ let package = Package(
exclude: ["deps", "opentime", "opentimelineview", "py-opentimelineio", "opentimelineio/CORE_VERSION_MAP.last.cpp"],
publicHeadersPath: "."),

.target(name: "OpenTimelineIO_objc",
// .target(name: "OpenTimelineIO_objc",
// dependencies: ["OpenTimelineIO_CXX"],
// path: "Sources",
// exclude: ["swift", "shims", "interop", "ImathConfig"],
// sources: ["objc"],
// publicHeadersPath: "objc/include",
// cxxSettings: [
// .headerSearchPath("../OpenTimelineIO/src/deps/Imath/src/Imath"),
// .headerSearchPath("objc/include")]),

.target(name: "OpenTimelineIO_cpp",
dependencies: ["OpenTimelineIO_CXX"],
path: "Sources",
exclude: ["swift", "shims", "interop", "ImathConfig"],
sources: ["objc"],
publicHeadersPath: "objc/include",
cxxSettings: [
.headerSearchPath("../OpenTimelineIO/src/deps/Imath/src/Imath"),
.headerSearchPath("objc/include")]),
path: "Sources/cpp"),

// public swift/c++ target
.target(name: "OpenTimelineIO",
dependencies: ["OpenTime_CXX", "OpenTimelineIO_CXX"],
path: "Sources",
exclude: ["swift", "shims", "objc", "ImathConfig"],
sources: ["interop"],
dependencies: ["OpenTimelineIO_cpp"],
path: "Sources/interop",
swiftSettings: [
.interoperabilityMode(.Cxx)]),

59 changes: 59 additions & 0 deletions Sources/cpp/include/opentimelineio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// opentimelineio.h
//
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project

#include <opentimelineio/clip.h>
#include <opentimelineio/composable.h>
#include <opentimelineio/composition.h>
#include <opentimelineio/effect.h>
#include <opentimelineio/externalReference.h>
#include <opentimelineio/freezeFrame.h>
#include <opentimelineio/gap.h>
#include <opentimelineio/generatorReference.h>
#include <opentimelineio/item.h>
#include <opentimelineio/linearTimeWarp.h>
#include <opentimelineio/marker.h>
#include <opentimelineio/mediaReference.h>
#include <opentimelineio/missingReference.h>
#include <opentimelineio/serializableCollection.h>
#include <opentimelineio/serializableObject.h>
#include <opentimelineio/serializableObjectWithMetadata.h>
#include <opentimelineio/stack.h>
#include <opentimelineio/timeEffect.h>
#include <opentimelineio/timeline.h>
#include <opentimelineio/track.h>
#include <opentimelineio/transition.h>
#include <opentimelineio/stack.h>
#include <opentimelineio/stringUtils.h>
#include <opentimelineio/unknownSchema.h>
#include <opentimelineio/stringUtils.h>
#include <opentimelineio/trackAlgorithm.h>
#include <opentimelineio/stackAlgorithm.h>

namespace otio {
using namespace opentimelineio::OPENTIMELINEIO_VERSION;

Clip* otio_new_clip();
Composable* otio_new_composable();
Composition* otio_new_composition();
Effect* otio_new_effect();
ExternalReference* otio_new_external_reference();
FreezeFrame* otio_new_freeze_frame();
Gap* otio_new_gap();
GeneratorReference* otio_new_generator_reference();
Item* otio_new_item();
LinearTimeWarp* otio_new_linear_time_warp();
Marker* otio_new_marker();
MediaReference* otio_new_media_reference();
MissingReference* otio_new_missing_reference();
SerializableCollection* otio_new_serializable_collection();
SerializableObject* otio_new_serializable_object();
SerializableObjectWithMetadata* otio_new_serializable_object_with_metadata();
Stack* otio_new_stack();
TimeEffect* otio_new_time_effect();
Timeline* otio_new_timeline();
Track* otio_new_track();
Transition* otio_new_transition();
}
111 changes: 111 additions & 0 deletions Sources/cpp/opentimelineio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// opentimelineio.m
// otio_macos
//
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project

#include <opentimelineio.h>

namespace otio {

// MARK: - otio_new_XXX() methods

Clip* otio_new_clip() {
return new Clip;
/*
Clip* c = new Clip;
AnyDictionary d, d2;
d["abc"] = 123;
d["xyz"] = 456;

d2["r1"] = RationalTime(1,2);
d2["r2"] = RationalTime(100,200);
d2["plugh"] = 37;

d["nested"] = d2;
c->metadata() = d;
return c;*/
}

Composable* otio_new_composable() {
return new Composable;
}

Composition* otio_new_composition() {
return new Composition;
}

Effect* otio_new_effect() {
return new Effect;
}

ExternalReference* otio_new_external_reference() {
return new ExternalReference;
}

FreezeFrame* otio_new_freeze_frame() {
return new FreezeFrame;
}

Gap* otio_new_gap() {
return new Gap;
}

GeneratorReference* otio_new_generator_reference() {
return new GeneratorReference;
}

Item* otio_new_item() {
return new Item;
}

LinearTimeWarp* otio_new_linear_time_warp() {
return new LinearTimeWarp;
}

Marker* otio_new_marker() {
return new Marker;
}

MediaReference* otio_new_media_reference() {
return new MediaReference;
}

MissingReference* otio_new_missing_reference() {
return new MissingReference;
}

SerializableCollection* otio_new_serializable_collection() {
return new SerializableCollection;
}

SerializableObject* otio_new_serializable_object() {
return new SerializableObject;
}

SerializableObjectWithMetadata* otio_new_serializable_object_with_metadata() {
return new SerializableObjectWithMetadata;
}

Stack* otio_new_stack() {
return new Stack;
}

TimeEffect* otio_new_time_effect() {
return new TimeEffect;
}

Timeline* otio_new_timeline() {
return new Timeline;
}

Track* otio_new_track() {
return new Track;
}

Transition* otio_new_transition() {
return new Transition;
}

} // namespace otio
3 changes: 2 additions & 1 deletion Sources/interop/Export.swift
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project

@_exported import CxxStdlib
@_exported import Imath
@_exported import rapidjson
@_exported import OpenTime_CXX
@_exported import OpenTimelineIO_CXX

@_exported import OpenTimelineIO_cpp
29 changes: 21 additions & 8 deletions Tests/OpenTimelineIOInteropTests/testInterop.swift
Original file line number Diff line number Diff line change
@@ -9,9 +9,6 @@ import Testing

import Foundation

public typealias ot = opentime.v1_0
public typealias otio = opentimelineio.v1_0

// dumb tests, remove these.
@Suite("Swift/C++ Interop")
struct InteropTests {
@@ -21,12 +18,28 @@ struct InteropTests {
(5, 24),
])
func testInterop(value: Double, rate: Double) {
let start_time = ot.RationalTime(value, rate)
let duration = ot.RationalTime(value / 2, rate)

let tr1 = ot.TimeRange(start_time, duration)
let tr2 = ot.TimeRange(start_time, duration)
let start_time = opentime.v1_0.RationalTime(value, rate)
let duration = opentime.v1_0.RationalTime(value / 2, rate)

let tr1 = opentime.v1_0.TimeRange(start_time, duration)
let tr2 = opentime.v1_0.TimeRange(start_time, duration)

#expect(tr1 == tr2)
}

@Test("Item creation and name property", arguments: [
"hello item",
"example item",
"otio item",
])
func testTrack(name: String)
{
let item = otio.otio_new_item()

#expect(item != nil)

item?.set_name(std.string(name))

#expect(item?.name() == std.string(name))
}
}