Skip to content

Commit 3125016

Browse files
committed
Remove the rate argument to to_timecode.
1 parent 5b8687e commit 3125016

File tree

13 files changed

+52
-72
lines changed

13 files changed

+52
-72
lines changed

contrib/opentimelineio_contrib/adapters/ale.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,19 @@ def val_for_column(column, clip):
290290
if not clip.source_range:
291291
return ""
292292
return otio.opentime.to_timecode(
293-
clip.source_range.start_time, fps
293+
clip.source_range.start_time.rescaled_to(fps)
294294
)
295295
elif column == "Duration":
296296
if not clip.source_range:
297297
return ""
298298
return otio.opentime.to_timecode(
299-
clip.source_range.duration, fps
299+
clip.source_range.duration.rescaled_to(fps)
300300
)
301301
elif column == "End":
302302
if not clip.source_range:
303303
return ""
304304
return otio.opentime.to_timecode(
305-
clip.source_range.end_time_exclusive(), fps
305+
clip.source_range.end_time_exclusive().rescaled_to(fps)
306306
)
307307
else:
308308
return clip.metadata.get("ALE", {}).get(column)

contrib/opentimelineio_contrib/adapters/ffmpeg_burnins.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ def add_timecode(self, align, options=None):
274274
:param dict options: recommended to use TimeCodeOptions
275275
"""
276276
options = options or TimeCodeOptions()
277-
timecode = _frames_to_timecode(options['frame_offset'],
278-
self.frame_rate)
277+
timecode = _frames_to_timecode(
278+
options['frame_offset'].rescaled_to(self.frame_rate)
279+
)
279280
options = options.copy()
280281
if not options.get('fps'):
281282
options['fps'] = self.frame_rate

src/opentime/rationalTime.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,19 @@ RationalTime::from_time_string(std::string const& time_string, double rate, Erro
187187

188188
std::string
189189
RationalTime::to_timecode(
190-
double rate,
191190
IsDropFrameRate drop_frame,
192191
ErrorStatus* error_status
193192
) const {
194193

195194
*error_status = ErrorStatus();
196195

197-
double value_in_target_rate = _value;
198-
if (rate != _rate) {
199-
value_in_target_rate = this->value_rescaled_to(rate);
200-
}
201-
202-
if (value_in_target_rate < 0) {
196+
if (_value < 0) {
203197
*error_status = ErrorStatus(ErrorStatus::NEGATIVE_VALUE);
204198
return std::string();
205199
}
206200

201+
double rate = _rate;
202+
207203
if (!is_valid_timecode_rate(rate)) {
208204
*error_status = ErrorStatus(ErrorStatus::INVALID_TIMECODE_RATE);
209205
return std::string();
@@ -257,7 +253,7 @@ RationalTime::to_timecode(
257253
(std::round(rate) * 60) - dropframes);
258254

259255
// If the number of frames is more than 24 hours, roll over clock
260-
double value = std::fmod(value_in_target_rate, frames_per_24_hours);
256+
double value = std::fmod(_value, frames_per_24_hours);
261257

262258
if (rate_is_dropframe) {
263259
int ten_minute_chunks = static_cast<int>(std::floor(value/frames_per_10_minutes));

src/opentime/rationalTime.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,12 @@ class RationalTime {
8888
}
8989

9090
std::string to_timecode(
91-
double rate,
9291
IsDropFrameRate drop_frame,
9392
ErrorStatus *error_status
9493
) const;
9594

9695
std::string to_timecode(ErrorStatus *error_status) const {
97-
return to_timecode(_rate, IsDropFrameRate::InferFromRate, error_status);
96+
return to_timecode(IsDropFrameRate::InferFromRate, error_status);
9897
}
9998

10099
std::string to_time_string() const;

src/opentimelineview/track_widgets.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,21 @@ def _set_labels_timecode(self):
153153
self.source_in_label.setText(
154154
'{timeline}\n{source}'.format(
155155
timeline=otio.opentime.to_timecode(
156-
self.timeline_range.start_time,
157-
self.timeline_range.start_time.rate
156+
self.timeline_range.start_time
158157
),
159158
source=otio.opentime.to_timecode(
160-
self.item.trimmed_range.start_time,
161-
self.item.trimmed_range.start_time.rate
159+
self.item.trimmed_range.start_time
162160
)
163161
)
164162
)
165163

166164
self.source_out_label.setText(
167165
'{timeline}\n{source}'.format(
168166
timeline=otio.opentime.to_timecode(
169-
self.timeline_range.end_time_exclusive(),
170-
self.timeline_range.end_time_exclusive().rate
167+
self.timeline_range.end_time_exclusive()
171168
),
172169
source=otio.opentime.to_timecode(
173-
self.item.trimmed_range.end_time_exclusive(),
174-
self.item.trimmed_range.end_time_exclusive().rate
170+
self.item.trimmed_range.end_time_exclusive()
175171
)
176172
)
177173
)

src/py-opentimelineio/opentime-bindings/opentime_rationalTime.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,14 @@ void opentime_rationalTime_bindings(py::module m) {
8484
.def("to_frames", (int (RationalTime::*)() const) &RationalTime::to_frames)
8585
.def("to_frames", (int (RationalTime::*)(double) const) &RationalTime::to_frames, "rate"_a)
8686
.def("to_seconds", &RationalTime::to_seconds)
87-
.def("to_timecode", [](RationalTime rt, double rate, py::object drop_frame) {
87+
.def("to_timecode", [](RationalTime rt, py::object drop_frame) {
8888
return rt.to_timecode(
89-
rate,
9089
df_enum_converter(drop_frame),
9190
ErrorStatusConverter()
9291
);
93-
}, "rate"_a, "drop_frame"_a)
94-
.def("to_timecode", [](RationalTime rt, double rate) {
95-
return rt.to_timecode(
96-
rate,
97-
IsDropFrameRate::InferFromRate,
98-
ErrorStatusConverter()
99-
);
100-
}, "rate"_a)
92+
}, "drop_frame"_a)
10193
.def("to_timecode", [](RationalTime rt) {
10294
return rt.to_timecode(
103-
rt.rate(),
10495
IsDropFrameRate::InferFromRate,
10596
ErrorStatusConverter());
10697
})

src/py-opentimelineio/opentimelineio/adapters/cmx_3600.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ def parse(self, line):
556556
opentime.from_frames(
557557
int(getattr(self, prop)),
558558
self.edl_rate
559-
),
560-
self.edl_rate
559+
)
561560
)
562561
)
563562

@@ -1124,10 +1123,10 @@ def to_edl_format(self, edit_number):
11241123
'edit': edit_number,
11251124
'reel': self.reel,
11261125
'kind': self._kind,
1127-
'src_in': opentime.to_timecode(self.source_in, self._rate),
1128-
'src_out': opentime.to_timecode(self.source_out, self._rate),
1129-
'rec_in': opentime.to_timecode(self.record_in, self._rate),
1130-
'rec_out': opentime.to_timecode(self.record_out, self._rate),
1126+
'src_in': opentime.to_timecode(self.source_in.rescaled_to(self._rate)),
1127+
'src_out': opentime.to_timecode(self.source_out.rescaled_to(self._rate)),
1128+
'rec_in': opentime.to_timecode(self.record_in.rescaled_to(self._rate)),
1129+
'rec_out': opentime.to_timecode(self.record_out.rescaled_to(self._rate)),
11311130
'diss': int(
11321131
opentime.to_frames(self.dissolve_length, self._rate)
11331132
),
@@ -1182,8 +1181,7 @@ def _generate_comment_lines(
11821181
clip.name,
11831182
timing_effect.time_scalar * edl_rate,
11841183
opentime.to_timecode(
1185-
clip.trimmed_range().start_time,
1186-
edl_rate
1184+
clip.trimmed_range().start_time.rescaled_to(edl_rate)
11871185
)
11881186
)
11891187
)
@@ -1241,8 +1239,7 @@ def _generate_comment_lines(
12411239
# Output any markers on this clip
12421240
for marker in clip.markers:
12431241
timecode = opentime.to_timecode(
1244-
marker.marked_range.start_time,
1245-
edl_rate
1242+
marker.marked_range.start_time.rescaled_to(edl_rate)
12461243
)
12471244

12481245
color = marker.color

src/py-opentimelineio/opentimelineio/adapters/fcp_xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ def _build_timecode(time, fps, drop_frame=False, additional_metadata=None):
13601360

13611361
# Get the time values
13621362
tc_time = opentime.RationalTime(time.value_rescaled_to(fps), tc_fps)
1363-
tc_string = opentime.to_timecode(tc_time, tc_fps, drop_frame)
1363+
tc_string = opentime.to_timecode(tc_time.rescaled_to(tc_fps), drop_frame)
13641364

13651365
_append_new_sub_element(tc_element, "string", text=tc_string)
13661366

src/py-opentimelineio/opentimelineio/console/otiostat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _total_duration(input):
125125
def _total_duration_timecode(input):
126126
try:
127127
d = input.tracks.duration()
128-
return otio.opentime.to_timecode(d, d.rate)
128+
return otio.opentime.to_timecode(d)
129129
except AttributeError:
130130
return "n/a"
131131

src/py-opentimelineio/opentimelineio/opentime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
duration_from_start_end_time = RationalTime.duration_from_start_end_time
1414

1515

16-
def to_timecode(rt, rate=None, drop_frame=None):
16+
def to_timecode(rt, drop_frame=None):
1717
return (
1818
rt.to_timecode()
19-
if rate is None and drop_frame is None
20-
else rt.to_timecode(rate, drop_frame)
19+
if drop_frame is None
20+
else rt.to_timecode(drop_frame)
2121
)
2222

2323

0 commit comments

Comments
 (0)