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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/py-opentimelineio/bindings-common/casters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "nonstd/optional.hpp"

using nonstd::optional;
using nonstd::nullopt_t;

namespace pybind11 { namespace detail {
template<typename T> struct type_caster<optional<T>>
: public optional_caster<optional<T>> {};

template<> struct type_caster<nullopt_t>
: public void_caster<nullopt_t> {};
}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "opentime/rationalTime.h"
#include "opentimelineio/stringUtils.h"
#include "opentimelineio/optional.h"
#include "py-opentimelineio/bindings-common/casters.h"

namespace py = pybind11;
using namespace pybind11::literals;
Expand All @@ -28,11 +30,10 @@ struct ErrorStatusConverter {
ErrorStatus error_status;
};


IsDropFrameRate df_enum_converter(py::object& df) {
if (df.is(py::none())) {
IsDropFrameRate df_enum_converter(optional<bool>& df) {
if (!df.has_value()) {
return IsDropFrameRate::InferFromRate;
} else if (py::cast<bool>(py::bool_(df))) {
} else if (df.value()) {
return IsDropFrameRate::ForceYes;
} else {
return IsDropFrameRate::ForceNo;
Expand Down Expand Up @@ -107,7 +108,7 @@ For example, the duration of a clip from frame 10 to frame 15 is 6 frames. Resul
.def("to_frames", (int (RationalTime::*)() const) &RationalTime::to_frames, "Returns the frame number based on the current rate.")
.def("to_frames", (int (RationalTime::*)(double) const) &RationalTime::to_frames, "rate"_a, "Returns the frame number based on the given rate.")
.def("to_seconds", &RationalTime::to_seconds)
.def("to_timecode", [](RationalTime rt, double rate, py::object drop_frame) {
.def("to_timecode", [](RationalTime rt, double rate, optional<bool> drop_frame) {
return rt.to_timecode(
rate,
df_enum_converter(drop_frame),
Expand Down
9 changes: 1 addition & 8 deletions src/py-opentimelineio/opentimelineio-bindings/otio_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <string>
#include "py-opentimelineio/bindings-common/casters.h"
#include "opentimelineio/any.h"
#include "opentimelineio/optional.h"
#include "opentimelineio/stringUtils.h"
#include "opentimelineio/serializableObject.h"
#include "opentimelineio/vectorIndexing.h"
Expand All @@ -17,13 +17,6 @@ using namespace opentimelineio::OPENTIMELINEIO_VERSION;

void install_external_keepalive_monitor(SerializableObject* so, bool apply_now);

namespace pybind11 { namespace detail {
template<typename T> struct type_caster<optional<T>>
: public optional_caster<optional<T>> {};

template<> struct type_caster<nullopt_t>
: public void_caster<nullopt_t> {};
}}

template <typename T>
struct managing_ptr {
Expand Down