Skip to content

Commit e590144

Browse files
authored
Merge pull request #10 from orchetect/dev
Performance improvements; 100fps stringValue bugfix; added FrameRate.CompatibleGroup
2 parents 429b634 + f49c58c commit e590144

File tree

52 files changed

+631
-295
lines changed

Some content is hidden

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

52 files changed

+631
-295
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# Custom
2+
[Dd]ev/
3+
14
# Xcode
2-
/dev/
35

46
# macOS
57
.DS_Store

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ let package = Package(
1818
dependencies: [
1919

2020
// utility/support code:
21-
.package(url: "https://github.com/orchetect/OTCore", from: "1.0.0"),
21+
.package(url: "https://github.com/orchetect/OTCore", from: "1.1.0"),
2222

2323
// console progress module for dev tests:
24-
.package(url: "https://github.com/orchetect/SegmentedProgress", from: "1.0.0")
24+
.package(url: "https://github.com/orchetect/SegmentedProgress", from: "1.0.1")
2525

2626
],
2727

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat"
1818
alt="License: MIT" /></a>
1919
</p>
20-
A robust multiplatform Swift library for working with SMPTE timecode supporting 20 industry frame rates, and including methods to convert to/from timecode strings and perform calculations.
20+
A robust multi-platform Swift library for working with SMPTE timecode supporting 20 industry frame rates, and including methods to convert to/from timecode strings and perform calculations.
2121

2222
## Supported Frame Rates
2323

@@ -50,7 +50,7 @@ A robust multiplatform Swift library for working with SMPTE timecode supporting
5050

5151
To add TimecodeKit to your Xcode project:
5252

53-
1. Select File → Swift Packages → Add Package Depedancy
53+
1. Select File → Swift Packages → Add Package Dependency
5454
2. Add package using `https://github.com/orchetect/TimecodeKit` as the URL.
5555

5656
## Documentation

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

0 commit comments

Comments
 (0)