24#include "opentimelineio/anyVector.h"
25#include "opentimelineio/clip.h"
26#include "opentimelineio/effect.h"
39static const AnyDictionary *
metadata_effect(SerializableObjectWithMetadata &
object)
45static const AnyDictionary *
find_parameter(
const AnyDictionary &effect,
const std::string &
id)
51 for (
const std::any &item : *parameters) {
52 const AnyDictionary *
parameter = std::any_cast<AnyDictionary>(&item);
54 if (name && *name ==
id) {
61static const std::any *
parameter(
const AnyDictionary &effect,
const std::string &
id)
67static std::optional<double>
number(
const std::any *value)
69 return value ?
to_number(*value) : std::nullopt;
73 const std::string &
id,
74 const int start_frame,
83 for (
const auto &[frame, key] : *keys) {
84 const AnyDictionary *keyframe = std::any_cast<AnyDictionary>(&key);
85 if (
const std::optional<double> value =
number(keyframe ?
find(*keyframe,
"Value") :
nullptr))
88 double2(start_frame + std::strtod(frame.c_str(),
nullptr),
convert(*value)));
100 for (
const double2 &keyframe : keyframes) {
101 values.push_back(AnyVector{keyframe.x, keyframe.y});
103 AnyDictionary animation;
104 animation[
"keyframes"] = values;
109 const std::string &
id,
110 const int start_frame,
118 return value ? std::make_optional<std::any>(
convert(*value)) : std::nullopt;
124 if (frame < keyframes[i].
x) {
125 const double2 &a = keyframes[i - 1];
130 return keyframes.
last().y;
134 const double start_frame,
135 const double end_frame,
136 const double fade_in,
137 const double fade_out)
139 const double fade_in_end = start_frame + fade_in;
140 const double fade_out_start = end_frame - fade_out;
146 for (
const double2 &keyframe : keyframes) {
147 if (keyframe.x > fade_in_end && keyframe.x < fade_out_start) {
152 if (fade_out > 0.0) {
160 const AnyDictionary &effect,
161 const std::string &
id,
162 const int start_frame,
166 effect,
id, start_frame, [&](
const double value) {
return value * factor; });
181 AnyDictionary &properties)
184 const bool *enabled =
find<bool>(effect,
"Enabled");
185 if (!name || (enabled && !*enabled)) {
190 if (strip.
data && strip.
data->transform) {
193 const int start_frame = strip.left_handle();
196 if (
number.effect == *name) {
206 if (*name ==
"Transform") {
207 const AnyVector *anchor = std::any_cast<AnyVector>(
208 parameter(effect,
"transformationAnchorPoint"));
209 if (anchor && anchor->size() == 2) {
213 ensure_dictionary(properties,
"transform")[
"origin"] = AnyVector{double(origin.x),
216 if (
const std::any *flip_x =
parameter(effect,
"transformationFlipX")) {
217 properties[
"use_flip_x"] = *flip_x;
219 if (
const std::any *flip_y =
parameter(effect,
"transformationFlipY")) {
220 properties[
"use_flip_y"] = *flip_y;
223 else if (*name ==
"Composite") {
224 const std::any *mode =
parameter(effect,
"composite mode");
225 const int64_t *mode_value = mode ? std::any_cast<int64_t>(mode) :
nullptr;
226 if (
const char *blend_type = mode_value ?
resolve_blend_type(*mode_value) :
nullptr) {
227 properties[
"blend_type"] = std::string(blend_type);
230 else if (*name ==
"Fairlight Clip Volume and Fades") {
231 const auto to_gain = [](
const double decibels) {
return std::pow(10.0, decibels / 20.0); };
237 const double fade_in =
number(
parameter(effect,
"faderIn")).value_or(0.0);
238 const double fade_out =
number(
parameter(effect,
"faderOut")).value_or(0.0);
239 if (fade_in > 0.0 || fade_out > 0.0) {
240 volume =
add_fades(volume, start_frame, strip.right_handle(&scene), fade_in, fade_out);
244 else if (*name ==
"Solid Color") {
246 if (
const std::string *hex =
color ? std::any_cast<std::string>(
color) :
nullptr) {
250 else if (*name ==
"Rich Text") {
251 if (
const std::any *text =
parameter(effect,
"rich text")) {
252 properties[
"text"] = *text;
262 const std::string &kind = generator.generator_kind();
263 if (kind ==
"Solid Color") {
266 if (kind ==
"Text" ||
StringRef(kind).startswith(
"Rich")) {
275 if (
auto *item =
dynamic_cast<Item *
>(&
object)) {
276 for (
const SerializableObject::Retainer<otio::Effect> &effect : item->effects()) {
282 if (
auto *clip =
dynamic_cast<Clip *
>(&
object)) {
283 if (
auto *generator =
dynamic_cast<GeneratorReference *
>(clip->media_reference())) {
285 for (
const std::any &item : *
list) {
286 if (
const AnyDictionary *effect = std::any_cast<AnyDictionary>(&item)) {
303 if (type && *type == 74) {
313 const std::string *name = effect ?
find<std::string>(*effect,
"Effect Name") :
nullptr;
314 if (name && *name ==
"Edge Wipe") {
324 if (!name || *name !=
"Retime and Scaling") {
343 SerializableObjectWithMetadata &
object)
345 AnyDictionary properties;
355 const bool *locked = resolve ?
find<bool>(*resolve,
"Locked") :
nullptr;
356 return locked && *locked;
360 const Span<std::pair<Strip *, SerializableObjectWithMetadata *>> strips)
363 for (
const auto &[strip,
object] : strips) {
constexpr IndexRange drop_front(int64_t n) const
Value & lookup_or_add_default(const Key &key)
ValueIterator values() const &
constexpr const T & last(const int64_t n=0) const
constexpr IndexRange index_range() const
void append(const T &value)
const T & data(const Action &owning_action) const
static constexpr int64_t not_found
float dot(VecOp< float, D >, VecOp< float, D >) RET
bool resolve_track_locked(Track &track)
static const std::any * parameter(const AnyDictionary &effect, const std::string &id)
static const AnyDictionary * find_parameter(const AnyDictionary &effect, const std::string &id)
void resolve_connect_strips(const Span< std::pair< Strip *, SerializableObjectWithMetadata * > > strips)
static std::optional< std::any > animated_number(const AnyDictionary &effect, const std::string &id, const int start_frame, const FunctionRef< double(double)> convert)
const char * resolve_blend_type(const int64_t composite_mode)
static Vector< double2 > add_fades(const Span< double2 > keyframes, const double start_frame, const double end_frame, const double fade_in, const double fade_out)
static const AnyDictionary * metadata_effect(SerializableObjectWithMetadata &object)
AnyVector hex_to_color(const std::string &hex)
static std::any keyframes_value(const Span< double2 > keyframes)
AnyDictionary & ensure_dictionary(AnyDictionary &parent, const std::string &key)
static double value_at(const Span< double2 > keyframes, const double frame)
Span< ResolveNumber > resolve_numbers()
std::optional< eSeqImageFitMethod > resolve_fit_method(Item &item)
std::optional< double > to_number(const std::any &value)
static const AnyDictionary * resolve_metadata(SerializableObjectWithMetadata &object)
AnyDictionary resolve_strip_properties(const Scene &scene, const Strip &strip, SerializableObjectWithMetadata &object)
const std::any * find(const AnyDictionary &dictionary, const std::string &key)
static void add_effect_properties(const AnyDictionary &effect, const Scene &scene, const Strip &strip, AnyDictionary &properties)
static void copy_number(AnyDictionary &properties, const StringRef rna_path, const AnyDictionary &effect, const std::string &id, const int start_frame, const double factor)
std::optional< StripType > resolve_generator_type(const GeneratorReference &generator)
bool resolve_is_adjustment_clip(Clip &clip)
static Vector< const AnyDictionary * > resolve_effects(SerializableObjectWithMetadata &object)
static Vector< double2 > parameter_keyframes(const AnyDictionary &effect, const std::string &id, const int start_frame, const FunctionRef< double(double)> convert)
std::optional< StripType > resolve_transition_type(Transition &transition)
static std::optional< double > number(const std::any *value)
T interpolate(const T &a, const T &b, const FactorT &t)
void connect(Strip *strip1, Strip *strip2)
VecBase< double, 2 > double2
VecBase< float, 2 > float2
double to_blender(ResolveUnit unit) const
float2 anchor_to_origin() const