Skip to content

Commit 8b27f30

Browse files
committed
Removed redundant imports, added @inlinable where possible, formatting
1 parent 93a4fd9 commit 8b27f30

File tree

49 files changed

+463
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+463
-286
lines changed

Sources/TimecodeKit/Components/Component.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright © 2020 Steffan Andrews. All rights reserved.
77
//
88

9-
import Foundation
10-
119
extension Timecode {
1210

1311
/// Enum naming an individual timecode component

Sources/TimecodeKit/Components/Components.swift

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright © 2018 Steffan Andrews. All rights reserved.
77
//
88

9-
import Foundation
10-
119
/// Convenience typealias for cleaner code.
1210
public typealias TCC = Timecode.Components
1311

@@ -41,12 +39,12 @@ extension Timecode {
4139

4240
// MARK: init
4341

44-
public init(d: Int = 0,
45-
h: Int = 0,
46-
m: Int = 0,
47-
s: Int = 0,
48-
f: Int = 0,
49-
sf: Int = 0)
42+
@inlinable public init(d: Int = 0,
43+
h: Int = 0,
44+
m: Int = 0,
45+
s: Int = 0,
46+
f: Int = 0,
47+
sf: Int = 0)
5048
{
5149

5250
self.d = d
@@ -64,7 +62,7 @@ extension Timecode {
6462

6563
extension Timecode.Components: Equatable {
6664

67-
public static func ==(lhs: Self, rhs: Self) -> Bool {
65+
@inlinable public static func ==(lhs: Self, rhs: Self) -> Bool {
6866

6967
lhs.d == rhs.d &&
7068
lhs.h == rhs.h &&
@@ -80,9 +78,9 @@ extension Timecode.Components: Equatable {
8078
extension Timecode.Components {
8179

8280
/// Returns an instance of `Timecode(exactly:)`.
83-
public func toTimecode(at frameRate: Timecode.FrameRate,
84-
limit: Timecode.UpperLimit = ._24hours,
85-
subFramesDivisor: Int? = nil) -> Timecode?
81+
@inlinable public func toTimecode(at frameRate: Timecode.FrameRate,
82+
limit: Timecode.UpperLimit = ._24hours,
83+
subFramesDivisor: Int? = nil) -> Timecode?
8684
{
8785

8886
if let sfd = subFramesDivisor {
@@ -102,9 +100,9 @@ extension Timecode.Components {
102100
}
103101

104102
/// Returns an instance of `Timecode(rawValues:)`.
105-
public func toTimecode(rawValuesAt frameRate: Timecode.FrameRate,
106-
limit: Timecode.UpperLimit = ._24hours,
107-
subFramesDivisor: Int? = nil) -> Timecode
103+
@inlinable public func toTimecode(rawValuesAt frameRate: Timecode.FrameRate,
104+
limit: Timecode.UpperLimit = ._24hours,
105+
subFramesDivisor: Int? = nil) -> Timecode
108106
{
109107

110108
if let sfd = subFramesDivisor {

Sources/TimecodeKit/Data Interchange/Timecode Components.swift

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,38 @@
66
// Copyright © 2020 Steffan Andrews. All rights reserved.
77
//
88

9-
import Foundation
10-
119
extension Timecode {
1210

1311
/// Timecode components.
1412
/// When setting, invalid values will cause the setter to fail silently. (Validation is based on the frame rate and `upperLimit` property.)
15-
public var components: Components {
13+
@inlinable public var components: Components {
14+
1615
get {
17-
return Components(d: days,
18-
h: hours,
19-
m: minutes,
20-
s: seconds,
21-
f: frames,
22-
sf: subFrames)
16+
Components(d: days,
17+
h: hours,
18+
m: minutes,
19+
s: seconds,
20+
f: frames,
21+
sf: subFrames)
2322
}
2423
set {
2524
_ = setTimecode(exactly: newValue)
2625
}
26+
2727
}
2828

2929
/** Set timecode from tuple values.
3030
Returns true/false depending on whether the string values are valid or not.
3131
Values which are out-of-bounds will return false. (Validation is based on the frame rate and `upperLimit` property.)
3232
*/
3333
@discardableResult
34-
public mutating func setTimecode(exactly values: Components) -> Bool {
34+
@inlinable public mutating func setTimecode(exactly values: Components) -> Bool {
3535

36-
guard values.invalidComponents(at: frameRate,
37-
limit: upperLimit,
38-
subFramesDivisor: subFramesDivisor).count == 0
36+
guard values
37+
.invalidComponents(at: frameRate,
38+
limit: upperLimit,
39+
subFramesDivisor: subFramesDivisor)
40+
.count == 0
3941
else { return false }
4042

4143
days = values.d
@@ -46,12 +48,14 @@ extension Timecode {
4648
subFrames = values.sf
4749

4850
return true
51+
4952
}
5053

5154
/** Set timecode from tuple values.
5255
(Validation is based on the frame rate and `upperLimit` property.)
5356
*/
54-
public mutating func setTimecode(clamping values: Components) {
57+
@inlinable public mutating func setTimecode(clamping values: Components) {
58+
5559
days = values.d
5660
hours = values.h
5761
minutes = values.m
@@ -60,27 +64,33 @@ extension Timecode {
6064
subFrames = values.sf
6165

6266
clampComponents()
67+
6368
}
6469

6570
/** Set timecode from tuple values.
6671
Timecode will wrap if out-of-bounds. Will handle negative values and wrap accordingly. (Wrapping is based on the frame rate and `upperLimit` property.)
6772
*/
68-
public mutating func setTimecode(wrapping values: Components) {
73+
@inlinable public mutating func setTimecode(wrapping values: Components) {
74+
6975
// guaranteed to work so we can ignore the value returned
7076

71-
_ = setTimecode(exactly: __add(wrapping: values, to: Components(f: 0)))
77+
_ = setTimecode(exactly: __add(wrapping: values,
78+
to: Components(f: 0)))
79+
7280
}
7381

7482
/** Set timecode from tuple values.
7583
Timecode values will not be validated or rejected if they overflow.
7684
*/
77-
public mutating func setTimecode(rawValues values: Components) {
85+
@inlinable public mutating func setTimecode(rawValues values: Components) {
86+
7887
days = values.d
7988
hours = values.h
8089
minutes = values.m
8190
seconds = values.s
8291
frames = values.f
8392
subFrames = values.sf
93+
8494
}
8595

8696
}

Sources/TimecodeKit/Data Interchange/Timecode Real Time.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright © 2018 Steffan Andrews. All rights reserved.
77
//
88

9-
import Foundation
10-
119
extension Timecode {
1210

1311
/// (Lossy) Returns the current timecode converted to a duration in real-time milliseconds (wall-clock time), based on the frame rate. Value is returned as a Double so a high level of precision can be maintained.
@@ -67,20 +65,20 @@ extension TimeValue {
6765
/// Convenience method to create an `Timecode` struct using the default `(_ exactly:)` initializer.
6866
public func toTimecode(at frameRate: Timecode.FrameRate,
6967
limit: Timecode.UpperLimit = ._24hours,
70-
subFramesDivisor: Int? = nil) -> Timecode?
71-
{
68+
subFramesDivisor: Int? = nil) -> Timecode? {
69+
7270
if let sfd = subFramesDivisor {
7371

7472
return Timecode(self,
75-
at: frameRate,
76-
limit: limit,
77-
subFramesDivisor: sfd)
73+
at: frameRate,
74+
limit: limit,
75+
subFramesDivisor: sfd)
7876

7977
} else {
8078

8179
return Timecode(self,
82-
at: frameRate,
83-
limit: limit)
80+
at: frameRate,
81+
limit: limit)
8482

8583
}
8684

Sources/TimecodeKit/Data Interchange/Timecode Samples.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
// Copyright © 2020 Steffan Andrews. All rights reserved.
77
//
88

9-
import Foundation
10-
119
extension Timecode {
1210

1311
/// (Lossy)
1412
/// Returns the current timecode converted to a duration in real-time audio samples at the given sample rate, rounded to the nearest sample.
1513
/// Sample rate must be expressed as an Integer in Hz (ie: 48KHz would be passed as 48000)
16-
public func samplesValue(atSampleRate: Int) -> Double {
14+
@inlinable public func samplesValue(atSampleRate: Int) -> Double {
1715

1816
// prepare coefficients
1917

2018
var fRate = frameRate.frameRateForElapsedFramesCalculation
2119

22-
if frameRate.isDrop
23-
&& frameRate != ._30_drop
24-
&& frameRate != ._60_drop
25-
&& frameRate != ._120_drop {
20+
if frameRate.isDrop,
21+
frameRate != ._30_drop,
22+
frameRate != ._60_drop,
23+
frameRate != ._120_drop {
24+
2625
// all dropframe rates require this except 30 DF and its multiples
2726
fRate = Double(frameRate.maxFrames) / 1.001
27+
2828
}
2929

3030
var offset = 1.0
@@ -35,7 +35,9 @@ extension Timecode {
3535
._47_952,
3636
._59_94,
3737
._119_88:
38-
offset = 1.001 // not sure why this works, but it makes for an accurate calculation
38+
39+
// not sure why this works, but it makes for an accurate calculation
40+
offset = 1.001
3941

4042
case ._24,
4143
._25,
@@ -48,11 +50,13 @@ extension Timecode {
4850
._100,
4951
._119_88_drop,
5052
._120:
53+
5154
break
5255

5356
case ._30_drop,
5457
._60_drop,
5558
._120_drop:
59+
5660
offset = 0.999
5761

5862
}
@@ -76,8 +80,8 @@ extension Timecode {
7680
/// Returns false if it underflows or overflows valid timecode range.
7781
/// Sample rate must be expressed as an Integer of Hz (ie: 48KHz would be passed as 48000)
7882
@discardableResult
79-
public mutating func setTimecode(fromSamplesValue: Double,
80-
atSampleRate: Int) -> Bool {
83+
@inlinable public mutating func setTimecode(fromSamplesValue: Double,
84+
atSampleRate: Int) -> Bool {
8185

8286
// prepare coefficients
8387

Sources/TimecodeKit/Data Interchange/Timecode String.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,35 @@
66
// Copyright © 2020 Steffan Andrews. All rights reserved.
77
//
88

9-
import Foundation
10-
119
#if os(macOS)
12-
import Cocoa
10+
import AppKit
1311
#elseif os(iOS) || os(tvOS) || os(watchOS)
1412
import UIKit
13+
#else
14+
import Foundation
1515
#endif
1616

1717
extension Timecode {
1818

1919
// MARK: stringValue
2020

21-
/** Timecode string representation.
22-
23-
Valid formats for 24-hour:
24-
25-
```
26-
"00:00:00:00" "00:00:00;00"
27-
"0:00:00:00" "0:00:00;00"
28-
"00000000"
29-
```
30-
31-
Valid formats for 100-day: All of the above, as well as:
32-
33-
```
34-
"0 00:00:00:00" "0 00:00:00;00"
35-
"0:00:00:00:00" "0:00:00:00;00"
36-
```
37-
38-
When setting, an improperly formatted timecode string or one with invalid values will cause the setter to fail silently. (Validation is based on the frame rate and `upperLimit` property.)
39-
*/
40-
public var stringValue: String {
21+
/// Timecode string representation.
22+
///
23+
/// Valid formats for 24-hour:
24+
///
25+
/// "00:00:00:00" "00:00:00;00"
26+
/// "0:00:00:00" "0:00:00;00"
27+
/// "00000000"
28+
///
29+
/// Valid formats for 100-day: All of the above, as well as:
30+
///
31+
/// "0 00:00:00:00" "0 00:00:00;00"
32+
/// "0:00:00:00:00" "0:00:00:00;00"
33+
///
34+
/// When setting, an improperly formatted timecode string or one with invalid values will cause the setter to fail silently.
35+
///
36+
/// (Validation is based on the frame rate and `upperLimit` property.)
37+
@inlinable public var stringValue: String {
4138

4239
get {
4340

@@ -105,6 +102,9 @@ extension Timecode {
105102
#elseif os(iOS) || os(tvOS) || os(watchOS)
106103
let invalidColor = invalidAttributes
107104
?? [.foregroundColor : UIColor.red]
105+
#else
106+
let invalidColor = invalidAttributes
107+
?? []
108108
#endif
109109

110110
let invalids = invalidComponents

0 commit comments

Comments
 (0)