diff --git a/cpp_api/opentime.h b/cpp_api/opentime.h index 614e7ce7a4..dadc7dd3f9 100644 --- a/cpp_api/opentime.h +++ b/cpp_api/opentime.h @@ -69,6 +69,10 @@ class RationalTime value(0), rate(1) {} + RationalTime(const RationalTime& in): + value(in.value), + rate(in.rate) + {} // data rt_value_t value; diff --git a/cpp_api/test_wrap.c b/cpp_api/test_wrap.c new file mode 100644 index 0000000000..60f4a48fd5 --- /dev/null +++ b/cpp_api/test_wrap.c @@ -0,0 +1,21 @@ +#include +#include "wrap.h" + +int main(int argc, char**argv){ + printf("Hello\n"); + + RationalTime* t1 = OTIO_RationalTime_new(1,24); + RationalTime* t2 = OTIO_RationalTime_new(10,24); + RationalTime* t3 = OTIO_RationalTime_add(t1, t2); + RationalTime* t4 = OTIO_RationalTime_rescaled_to(t3, 30); + + printf("t3 = %g @ %g\n", OTIO_RationalTime_get_value(t3), OTIO_RationalTime_get_rate(t3)); + printf("t4 = %g @ %g\n", OTIO_RationalTime_get_value(t4), OTIO_RationalTime_get_rate(t4)); + + OTIO_RationalTime_delete(t1); + OTIO_RationalTime_delete(t2); + OTIO_RationalTime_delete(t3); + OTIO_RationalTime_delete(t4); + + return 0; +} diff --git a/cpp_api/test_wrap.sh b/cpp_api/test_wrap.sh new file mode 100755 index 0000000000..69c77fde76 --- /dev/null +++ b/cpp_api/test_wrap.sh @@ -0,0 +1 @@ +c++ -std=c++11 test_wrap.c wrap.cpp opentime.cpp && ./a.out diff --git a/cpp_api/wrap.cpp b/cpp_api/wrap.cpp new file mode 100644 index 0000000000..e88df63f0c --- /dev/null +++ b/cpp_api/wrap.cpp @@ -0,0 +1,33 @@ + +#include "wrap.h" + +#include "opentime.h" + +RationalTime* OTIO_RationalTime_new(double value, double rate) { + return (RationalTime*)new opentime::RationalTime(value, rate); +} + +void OTIO_RationalTime_delete(RationalTime* t) { + delete (opentime::RationalTime*)t; +} + +RationalTime* OTIO_RationalTime_add(RationalTime* a, RationalTime* b) { + opentime::RationalTime* result = new opentime::RationalTime(*(opentime::RationalTime*)a); + *result += *(opentime::RationalTime*)b; + return (RationalTime*)result; +} + +RationalTime* OTIO_RationalTime_rescaled_to(RationalTime* t, double rate) { + opentime::RationalTime* result = new opentime::RationalTime( + ((opentime::RationalTime*)t)->rescaled_to(rate) + ); + return (RationalTime*)result; +} + +double OTIO_RationalTime_get_value(RationalTime* t) { + return ((opentime::RationalTime*)t)->value; +} + +double OTIO_RationalTime_get_rate(RationalTime* t) { + return ((opentime::RationalTime*)t)->rate; +} diff --git a/cpp_api/wrap.h b/cpp_api/wrap.h new file mode 100644 index 0000000000..e5b510a0d3 --- /dev/null +++ b/cpp_api/wrap.h @@ -0,0 +1,12 @@ + +extern "C" +{ +typedef void* RationalTime; + +RationalTime* OTIO_RationalTime_new(double value, double rate); +void OTIO_RationalTime_delete(RationalTime* t); +RationalTime* OTIO_RationalTime_add(RationalTime* a, RationalTime* b); +RationalTime* OTIO_RationalTime_rescaled_to(RationalTime* t, double rate); +double OTIO_RationalTime_get_value(RationalTime* t); +double OTIO_RationalTime_get_rate(RationalTime* t); +}