Skip to content

Commit 231cb70

Browse files
committed
Transitions: Add enabled flag
Signed-off-by: Natchar Ratanasirigulchai <natchar.r@outlook.com>
1 parent 7adfb27 commit 231cb70

8 files changed

Lines changed: 45 additions & 11 deletions

File tree

docs/tutorials/otio-serialized-schema-only-fields.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ parameters:
289289
### Transition.1
290290

291291
parameters:
292+
- *enabled*
292293
- *in_offset*
293294
- *metadata*
294295
- *name*

docs/tutorials/otio-serialized-schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ dissolve or wipe.
665665
```
666666

667667
parameters:
668+
- *enabled*: If true, a Transition contributes to compositions. For example, when a transition is ``enabled=false`` the transition is ignored and the adjacent clips are cut together with no transition.
668669
- *in_offset*: Amount of the previous clip this transition overlaps, exclusive.
669670
- *metadata*:
670671
- *name*:

src/opentimelineio/transition.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Transition::Transition(
1111
std::string const& transition_type,
1212
RationalTime in_offset,
1313
RationalTime out_offset,
14-
AnyDictionary const& metadata)
14+
AnyDictionary const& metadata,
15+
bool enabled)
1516
: Parent(name, metadata)
1617
, _transition_type(transition_type)
1718
, _in_offset(in_offset)
1819
, _out_offset(out_offset)
20+
, _enabled(enabled)
1921
{}
2022

2123
Transition::~Transition()
@@ -33,6 +35,7 @@ Transition::read_from(Reader& reader)
3335
return reader.read("in_offset", &_in_offset)
3436
&& reader.read("out_offset", &_out_offset)
3537
&& reader.read("transition_type", &_transition_type)
38+
&& reader.read_if_present("enabled", &_enabled)
3639
&& Parent::read_from(reader);
3740
}
3841

@@ -43,6 +46,7 @@ Transition::write_to(Writer& writer) const
4346
writer.write("in_offset", _in_offset);
4447
writer.write("out_offset", _out_offset);
4548
writer.write("transition_type", _transition_type);
49+
writer.write("enabled", _enabled);
4650
}
4751

4852
RationalTime

src/opentimelineio/transition.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class OTIO_API_TYPE Transition : public Composable
4141
std::string const& transition_type = std::string(),
4242
RationalTime in_offset = RationalTime(),
4343
RationalTime out_offset = RationalTime(),
44-
AnyDictionary const& metadata = AnyDictionary());
44+
AnyDictionary const& metadata = AnyDictionary(),
45+
bool enabled = true);
4546

4647
bool overlapping() const override;
4748

@@ -72,6 +73,12 @@ class OTIO_API_TYPE Transition : public Composable
7273
_out_offset = out_offset;
7374
}
7475

76+
/// @brief Return whether the transition is enabled.
77+
bool enabled() const { return _enabled; }
78+
79+
/// @brief Set whether the transition is enabled.
80+
void set_enabled(bool enabled) { _enabled = enabled; }
81+
7582
RationalTime duration(ErrorStatus* error_status = nullptr) const override;
7683

7784
/// @brief Return the range in the parent's time.
@@ -91,6 +98,7 @@ class OTIO_API_TYPE Transition : public Composable
9198
private:
9299
std::string _transition_type;
93100
RationalTime _in_offset, _out_offset;
101+
bool _enabled;
94102
};
95103

96104
}} // namespace opentimelineio::OPENTIMELINEIO_VERSION_NS

src/py-opentimelineio/opentimelineio-bindings/otio_serializableObjects.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,19 +721,22 @@ An object that can be composed within a :class:`~Composition` (such as :class:`~
721721
std::string const& transition_type,
722722
RationalTime in_offset,
723723
RationalTime out_offset,
724-
py::object metadata) {
724+
py::object metadata,
725+
py::bool_ enabled) {
725726
return new Transition(
726727
name,
727728
transition_type,
728729
in_offset,
729730
out_offset,
730-
py_to_any_dictionary(metadata));
731+
py_to_any_dictionary(metadata),
732+
enabled);
731733
}),
732734
py::arg_v("name"_a = std::string()),
733735
"transition_type"_a = std::string(),
734736
"in_offset"_a = RationalTime(),
735737
"out_offset"_a = RationalTime(),
736-
py::arg_v("metadata"_a = py::none()))
738+
py::arg_v("metadata"_a = py::none()),
739+
"enabled"_a = true)
737740
.def_property(
738741
"transition_type",
739742
&Transition::transition_type,
@@ -749,6 +752,11 @@ An object that can be composed within a :class:`~Composition` (such as :class:`~
749752
&Transition::out_offset,
750753
&Transition::set_out_offset,
751754
"Amount of the next clip this transition overlaps, exclusive.")
755+
.def_property(
756+
"enabled",
757+
&Transition::enabled,
758+
&Transition::set_enabled,
759+
"If true, a Transition contributes to compositions. For example, when a transition is ``enabled=false`` the transition is ignored and the adjacent clips are cut together with no transition.")
752760
.def(
753761
"duration",
754762
[](Transition* t) { return t->duration(ErrorStatusHandler()); })

src/py-opentimelineio/opentimelineio/schema/transition.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
@add_method(_otio.Transition)
99
def __str__(self):
10-
return 'Transition("{}", "{}", {}, {}, {})'.format(
10+
return 'Transition("{}", "{}", {}, {}, {}, {})'.format(
1111
self.name,
1212
self.transition_type,
1313
self.in_offset,
1414
self.out_offset,
15-
self.metadata
15+
self.metadata,
16+
self.enabled
1617
)
1718

1819

@@ -24,12 +25,14 @@ def __repr__(self):
2425
'transition_type={}, '
2526
'in_offset={}, '
2627
'out_offset={}, '
27-
'metadata={}'
28+
'metadata={}, '
29+
'enabled={}'
2830
')'.format(
2931
repr(self.name),
3032
repr(self.transition_type),
3133
repr(self.in_offset),
3234
repr(self.out_offset),
3335
repr(self.metadata),
36+
repr(self.enabled)
3437
)
3538
)

tests/baselines/empty_transition.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"OTIO_SCHEMA": "Transition.1",
3+
"enabled": true,
34
"metadata": {},
45
"name": "",
56
"transition_type": "",

tests/test_transition.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ def test_constructor(self):
1616
transition_type="SMPTE.Dissolve",
1717
metadata={
1818
"foo": "bar"
19-
}
19+
},
20+
enabled=False
2021
)
2122
self.assertEqual(trx.transition_type, "SMPTE.Dissolve")
2223
self.assertEqual(trx.name, "AtoB")
2324
self.assertEqual(trx.metadata, {"foo": "bar"})
25+
self.assertEqual(trx.enabled, False)
2426

2527
def test_serialize(self):
2628
trx = otio.schema.Transition(
2729
name="AtoB",
2830
transition_type="SMPTE.Dissolve",
2931
metadata={
3032
"foo": "bar"
31-
}
33+
},
34+
enabled=False
3235
)
3336
encoded = otio.adapters.otio_json.write_to_string(trx)
3437
decoded = otio.adapters.otio_json.read_from_string(encoded)
@@ -47,13 +50,15 @@ def test_stringify(self):
4750
'"{}", '
4851
'{}, '
4952
"{}, "
53+
"{}, "
5054
"{}"
5155
")".format(
5256
str(trx.name),
5357
str(trx.transition_type),
5458
str(trx.in_offset),
5559
str(trx.out_offset),
5660
str(trx.metadata),
61+
str(trx.enabled)
5762
)
5863
)
5964

@@ -64,13 +69,15 @@ def test_stringify(self):
6469
"transition_type={}, "
6570
"in_offset={}, "
6671
"out_offset={}, "
67-
"metadata={}"
72+
"metadata={}, "
73+
"enabled={}"
6874
")".format(
6975
repr(trx.name),
7076
repr(trx.transition_type),
7177
repr(trx.in_offset),
7278
repr(trx.out_offset),
7379
repr(trx.metadata),
80+
repr(trx.enabled)
7481
)
7582
)
7683

@@ -85,6 +92,7 @@ def test_setters(self):
8592
self.assertEqual(trx.transition_type, "SMPTE.Dissolve")
8693
trx.transition_type = "EdgeWipe"
8794
self.assertEqual(trx.transition_type, "EdgeWipe")
95+
self.assertTrue(trx.enabled)
8896

8997
def test_parent_range(self):
9098
timeline = otio.schema.Timeline(

0 commit comments

Comments
 (0)