Skip to content

Commit e27a82b

Browse files
committed
Mark isValidTimecodeRate deprecated in favor of isSmpteTimecodeRate
Signed-off-by: Joshua Minor <jminor@users.noreply.github.com>
1 parent 4339891 commit e27a82b

4 files changed

Lines changed: 35 additions & 16 deletions

File tree

Sources/objc/include/opentime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ extern "C" {
6060
#endif
6161

6262

63-
63+
6464
double rational_time_value_rescaled_to(CxxRationalTime const*, double new_rate);
6565
double rational_time_value_rescaled_to_copy(CxxRationalTime, double new_rate);
6666
CxxRationalTime rational_time_rescaled_to(CxxRationalTime const* rt, double new_rate);
6767
bool rational_time_almost_equal(CxxRationalTime, CxxRationalTime, double);
6868

6969
CxxRationalTime rational_time_duration_from_start_end_time(CxxRationalTime, CxxRationalTime);
7070
bool rational_time_is_valid_timecode_rate(double);
71+
bool rational_time_is_smpte_timecode_rate(double);
7172

7273
CxxRationalTime rational_time_from_timecode(NSString* timecode, double rate, CxxErrorStruct* err);
7374
CxxRationalTime rational_time_from_timestring(NSString* timestring, double rate, CxxErrorStruct* err);

Sources/objc/opentime.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ CxxRationalTime rational_time_duration_from_start_end_time(CxxRationalTime s, Cx
4141
otioRationalTime(e)));
4242
}
4343

44+
// deprecated
4445
bool rational_time_is_valid_timecode_rate(double rate) {
4546
return otio::RationalTime::is_valid_timecode_rate(rate);
4647
}
4748

49+
bool rational_time_is_smpte_timecode_rate(double rate) {
50+
return otio::RationalTime::is_smpte_timecode_rate(rate);
51+
}
52+
4853
static inline void deal_with_error(opentime::ErrorStatus const& error_status, CxxErrorStruct* err) {
4954
if (error_status.outcome != error_status.OK) {
5055
err->statusCode = error_status.outcome;

Sources/swift/RationalTime.swift

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import OpenTimelineIO_objc
1010
public struct RationalTime: CustomStringConvertible, Equatable {
1111
public var value: Double { return cxxRationalTime.value }
1212
public var rate: Double { return cxxRationalTime.rate }
13-
13+
1414
public var description: String {
1515
return "RationalTime(\(value), \(rate))"
1616
}
17-
17+
1818
public init(value: Double = 0, rate: Double = 1) {
1919
cxxRationalTime = CxxRationalTime(value: value, rate: rate)
2020
}
21-
21+
2222
public func isInvalidTime() -> Bool {
2323
return rate <= 0
2424
}
25-
25+
2626
public func rescaled(to newRate: Double) -> RationalTime {
2727
return withUnsafePointer(to: self.cxxRationalTime) {
2828
RationalTime(rational_time_rescaled_to($0, newRate));
@@ -55,11 +55,16 @@ public struct RationalTime: CustomStringConvertible, Equatable {
5555
return RationalTime(rational_time_duration_from_start_end_time(startTime.cxxRationalTime,
5656
endTime.cxxRationalTime))
5757
}
58-
58+
59+
@available(*, deprecated, renamed: "isSmpteTimecodeRate")
5960
static public func isValidTimecodeRate(_ inRate: Double) -> Bool {
6061
return rational_time_is_valid_timecode_rate(inRate)
6162
}
62-
63+
64+
static public func isSmpteTimecodeRate(_ inRate: Double) -> Bool {
65+
return rational_time_is_smpte_timecode_rate(inRate)
66+
}
67+
6368
static public func from(frame: Double, rate inRate: Double) -> RationalTime {
6469
return RationalTime(value: floor(frame), rate: inRate)
6570
}
@@ -71,27 +76,27 @@ public struct RationalTime: CustomStringConvertible, Equatable {
7176
static public func from(seconds: Double) -> RationalTime {
7277
return RationalTime(value: seconds, rate: 1)
7378
}
74-
79+
7580
static public func from(timecode: String, rate inRate: Double) throws -> RationalTime {
7681
return try OpentimeError.returnOrThrow { RationalTime(rational_time_from_timecode(timecode, inRate, &$0)) }
7782
}
78-
83+
7984
static public func from(timestring: String, rate inRate: Double) throws -> RationalTime {
8085
return try OpentimeError.returnOrThrow { RationalTime(rational_time_from_timestring(timestring, inRate, &$0)) }
8186
}
82-
87+
8388
public func toFrames() -> Int {
8489
return Int(value)
8590
}
86-
91+
8792
public func toFrames(rate inRate: Double) -> Int {
8893
return Int(valueRescaled(to: inRate))
8994
}
90-
95+
9196
public func toSeconds() -> Double {
9297
return valueRescaled(to: 1)
9398
}
94-
99+
95100
public func toTimecode(rate inRate: Double) throws -> String {
96101
return try OpentimeError.returnOrThrow { rational_time_to_timecode(cxxRationalTime, inRate, &$0) }
97102
}
@@ -115,7 +120,7 @@ public struct RationalTime: CustomStringConvertible, Equatable {
115120
static public prefix func - (lhs: RationalTime) -> RationalTime {
116121
return RationalTime(value: -lhs.value, rate: -lhs.rate)
117122
}
118-
123+
119124
static public func + (lhs: RationalTime, rhs: RationalTime) -> RationalTime {
120125
return RationalTime(rational_time_add(lhs.cxxRationalTime, rhs.cxxRationalTime))
121126
}
@@ -151,7 +156,6 @@ public struct RationalTime: CustomStringConvertible, Equatable {
151156
internal init(_ cxxRationalTime: CxxRationalTime) {
152157
self.cxxRationalTime = cxxRationalTime
153158
}
154-
159+
155160
internal let cxxRationalTime: CxxRationalTime
156161
}
157-

Tests/OpenTimelineIOTests/testRationalTime.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ class testRationalTime: XCTestCase {
211211
try XCTAssertThrowsError(t.toTimecode())
212212
}
213213

214+
func testSmpteRates() {
215+
XCTAssertFalse(RationalTime.isSmpteTimecodeRate(29.98))
216+
XCTAssertFalse(RationalTime.isSmpteTimecodeRate(23.98))
217+
XCTAssertTrue(RationalTime.isSmpteTimecodeRate(30000.0 / 1001.0))
218+
XCTAssertTrue(RationalTime.isSmpteTimecodeRate(24000.0 / 1001.0))
219+
XCTAssertTrue(RationalTime.isSmpteTimecodeRate(30))
220+
XCTAssertTrue(RationalTime.isSmpteTimecodeRate(24))
221+
}
222+
214223
func testTimeString24() {
215224
var time_string = "00:00:00.041667"
216225
var t = RationalTime(value: 1.0, rate: 24)

0 commit comments

Comments
 (0)