@@ -9,29 +9,45 @@ extension Timecode {
9
9
10
10
/// Return a new `Timecode` object converted to a new frame rate.
11
11
///
12
- /// - If `preservingValues` is `false` (default): entire timecode is converted based on the equivalent real time value .
12
+ /// - Warning: This conversion process may be lossy .
13
13
///
14
- /// - If `preservingValues` is `true`: Return a new `Timecode` instance at the new frame rate preserving literal timecode values if
15
- /// possible .
16
- /// If any value is not expressible at the new frame rate, the entire timecode will be converted .
14
+ /// - Parameters:
15
+ /// - newFrameRate: New frame rate .
16
+ /// If the new rate is identical to the current rate, the timecode will be returned unchanged .
17
17
///
18
- /// - Note: this process may be lossy.
18
+ /// - newSubFramesBase: New sub-frames base (optional).
19
+ ///
20
+ /// If not specified, the current sub-frames base will be preserved.
21
+ ///
22
+ /// - preservingValues: Preserve literal timecode component values. (Default: `false`)
23
+ ///
24
+ /// When `true`, a new `Timecode` instance at the new frame rate is returned, preserving literal timecode values
25
+ /// if possible. If any values are invalid at the new frame rate, an error is thrown.
26
+ /// If any value is not expressible at the new frame rate, the entire timecode will be converted.
27
+ /// When `false`, the timecode is converted to the new frame rate based on the equivalent real time value.
19
28
///
20
29
/// - Throws: ``ValidationError``
30
+ ///
31
+ /// - Returns: A new `Timecode` instance converted to the new frame rate and sub-frames base.
21
32
public func converted(
22
33
to newFrameRate: TimecodeFrameRate ,
34
+ base newSubFramesBase: Timecode . SubFramesBase ? = nil ,
23
35
preservingValues: Bool = false
24
36
) throws -> Timecode {
25
- // just return self if frameRate is equal
26
- guard frameRate != newFrameRate else {
37
+ let newSubFramesBase = newSubFramesBase ?? subFramesBase
38
+
39
+ // just return self if new parameters are equal to current parameters
40
+ guard frameRate != newFrameRate ||
41
+ subFramesBase != newSubFramesBase
42
+ else {
27
43
return self
28
44
}
29
45
30
46
if preservingValues,
31
47
let newTC = try ? Timecode (
32
48
. components( components) ,
33
49
at: newFrameRate,
34
- base: subFramesBase ,
50
+ base: newSubFramesBase ,
35
51
limit: upperLimit
36
52
)
37
53
{
@@ -43,7 +59,7 @@ extension Timecode {
43
59
return try Timecode (
44
60
. realTime( seconds: realTimeValue) ,
45
61
at: newFrameRate,
46
- base: subFramesBase ,
62
+ base: newSubFramesBase ,
47
63
limit: upperLimit
48
64
)
49
65
}
0 commit comments