Skip to content

Commit 79ab3c8

Browse files
authored
Merge pull request #20 from orchetect/dev
Dev branch merge
2 parents 826bc0c + 73ac0d4 commit 79ab3c8

File tree

10 files changed

+303
-57
lines changed

10 files changed

+303
-57
lines changed

Sources/TimecodeKit/Components/Components.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,45 +78,55 @@ extension Timecode.Components: Equatable {
7878
extension Timecode.Components {
7979

8080
/// Returns an instance of `Timecode(exactly:)`.
81-
@inlinable public func toTimecode(at frameRate: Timecode.FrameRate,
82-
limit: Timecode.UpperLimit = ._24hours,
83-
subFramesDivisor: Int? = nil) -> Timecode?
81+
@inlinable public func toTimecode(
82+
at frameRate: Timecode.FrameRate,
83+
limit: Timecode.UpperLimit = ._24hours,
84+
subFramesDivisor: Int? = nil,
85+
displaySubFrames: Bool = false
86+
) -> Timecode?
8487
{
8588

8689
if let sfd = subFramesDivisor {
8790

8891
return Timecode(self,
8992
at: frameRate,
9093
limit: limit,
91-
subFramesDivisor: sfd)
94+
subFramesDivisor: sfd,
95+
displaySubFrames: displaySubFrames)
9296

9397
} else {
9498

9599
return Timecode(self,
96100
at: frameRate,
97-
limit: limit)
101+
limit: limit,
102+
displaySubFrames: displaySubFrames)
98103

99104
}
100105
}
101106

102107
/// Returns an instance of `Timecode(rawValues:)`.
103-
@inlinable public func toTimecode(rawValuesAt frameRate: Timecode.FrameRate,
104-
limit: Timecode.UpperLimit = ._24hours,
105-
subFramesDivisor: Int? = nil) -> Timecode
108+
@inlinable public func toTimecode(
109+
rawValuesAt frameRate: Timecode.FrameRate,
110+
limit: Timecode.UpperLimit = ._24hours,
111+
subFramesDivisor: Int? = nil,
112+
displaySubFrames: Bool = false
113+
) -> Timecode
106114
{
107115

108116
if let sfd = subFramesDivisor {
109117

110118
return Timecode(rawValues: self,
111119
at: frameRate,
112120
limit: limit,
113-
subFramesDivisor: sfd)
121+
subFramesDivisor: sfd,
122+
displaySubFrames: displaySubFrames)
114123

115124
} else {
116125

117126
return Timecode(rawValues: self,
118127
at: frameRate,
119-
limit: limit)
128+
limit: limit,
129+
displaySubFrames: displaySubFrames)
120130

121131
}
122132
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,27 @@ extension Timecode {
6161
extension TimeInterval {
6262

6363
/// Convenience method to create an `Timecode` struct using the default `(_ exactly:)` initializer.
64-
public func toTimecode(at frameRate: Timecode.FrameRate,
65-
limit: Timecode.UpperLimit = ._24hours,
66-
subFramesDivisor: Int? = nil) -> Timecode? {
64+
@inlinable public func toTimecode(
65+
at frameRate: Timecode.FrameRate,
66+
limit: Timecode.UpperLimit = ._24hours,
67+
subFramesDivisor: Int? = nil,
68+
displaySubFrames: Bool = false
69+
) -> Timecode? {
6770

6871
if let sfd = subFramesDivisor {
6972

7073
return Timecode(realTimeValue: self,
7174
at: frameRate,
7275
limit: limit,
73-
subFramesDivisor: sfd)
76+
subFramesDivisor: sfd,
77+
displaySubFrames: displaySubFrames)
7478

7579
} else {
7680

7781
return Timecode(realTimeValue: self,
7882
at: frameRate,
79-
limit: limit)
83+
limit: limit,
84+
displaySubFrames: displaySubFrames)
8085

8186
}
8287

Sources/TimecodeKit/FrameRate/FrameRate Properties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ extension Timecode.FrameRate {
266266

267267
}
268268

269-
/// Internal use. Used in marker MIDI file export.
269+
/// Internal use. Used in SMF export.
270270
@inlinable internal var frameRateForRealTimeCalculation: Double {
271271

272272
switch self {

Sources/TimecodeKit/Math/Timecode Math Public.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extension Timecode {
1313
/// Add a duration to the current timecode.
1414
/// Returns false if resulting value is not within valid timecode range.
1515
/// Input values can be as large as desired and will be calculated recursively. ie: (0,0,0,1000) or (0,0,500,0)
16+
@discardableResult
1617
@inlinable public mutating func add(_ exactly: Components) -> Bool {
1718

1819
guard let newTC = __add(exactly: exactly,
@@ -97,6 +98,7 @@ extension Timecode {
9798
/// Subtract a duration from the current timecode.
9899
/// Returns false if resulting value is not within valid timecode range.
99100
/// Input values can be as large as desired and will be calculated recursively. ie: (0,0,0,1000) or (0,0,500,0)
101+
@discardableResult
100102
@inlinable public mutating func subtract(_ exactly: Components) -> Bool {
101103

102104
guard let newTC = __subtract(exactly: exactly,
@@ -180,6 +182,7 @@ extension Timecode {
180182

181183
/// Multiply the current timecode by an amount.
182184
/// Returns false if resulting value is > the `upperLimit` property.
185+
@discardableResult
183186
public mutating func multiply(_ exactly: Double) -> Bool {
184187

185188
guard let newTC = __multiply(exactly: exactly,
@@ -256,6 +259,7 @@ extension Timecode {
256259

257260
/// Divide the current timecode by a duration.
258261
/// Returns false if resulting value is > the `upperLimit` property.
262+
@discardableResult
259263
public mutating func divide(_ exactly: Double) -> Bool {
260264

261265
guard let newTC = __divide(exactly: exactly, into: components) else { return false }

Sources/TimecodeKit/Timecode String Extensions.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,55 @@ extension String {
1212

1313
/// Returns an instance of `Timecode(exactly:)`.
1414
/// If the string is not a valid timecode string, it returns nil.
15-
@inlinable public func toTimecode(at frameRate: Timecode.FrameRate,
16-
limit: Timecode.UpperLimit = ._24hours,
17-
subFramesDivisor: Int? = nil) -> Timecode? {
15+
@inlinable public func toTimecode(
16+
at frameRate: Timecode.FrameRate,
17+
limit: Timecode.UpperLimit = ._24hours,
18+
subFramesDivisor: Int? = nil,
19+
displaySubFrames: Bool = false
20+
) -> Timecode? {
1821

1922
if let sfd = subFramesDivisor {
2023

2124
return Timecode(self,
2225
at: frameRate,
2326
limit: limit,
24-
subFramesDivisor: sfd)
27+
subFramesDivisor: sfd,
28+
displaySubFrames: displaySubFrames)
2529

2630
} else {
2731

2832
return Timecode(self,
2933
at: frameRate,
30-
limit: limit)
34+
limit: limit,
35+
displaySubFrames: displaySubFrames)
3136

3237
}
3338

3439
}
3540

3641
/// Returns an instance of `Timecode(rawValues:)`.
3742
/// If the string is not a valid timecode string, it returns nil.
38-
@inlinable public func toTimecode(rawValuesAt frameRate: Timecode.FrameRate,
39-
limit: Timecode.UpperLimit = ._24hours,
40-
subFramesDivisor: Int? = nil) -> Timecode? {
43+
@inlinable public func toTimecode(
44+
rawValuesAt frameRate: Timecode.FrameRate,
45+
limit: Timecode.UpperLimit = ._24hours,
46+
subFramesDivisor: Int? = nil,
47+
displaySubFrames: Bool = false
48+
) -> Timecode? {
4149

4250
if let sfd = subFramesDivisor {
4351

4452
return Timecode(rawValues: self,
4553
at: frameRate,
4654
limit: limit,
47-
subFramesDivisor: sfd)
55+
subFramesDivisor: sfd,
56+
displaySubFrames: displaySubFrames)
4857

4958
} else {
5059

5160
return Timecode(rawValues: self,
5261
at: frameRate,
53-
limit: limit)
62+
limit: limit,
63+
displaySubFrames: displaySubFrames)
5464

5565
}
5666

Sources/TimecodeKit/Timecode init.swift

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ extension Timecode {
1515
/// Instance with default timecode (00:00:00:00) at a given frame rate.
1616
@inlinable public init(at frameRate: FrameRate,
1717
limit: UpperLimit = ._24hours,
18-
subFramesDivisor: Int = 80) {
18+
subFramesDivisor: Int = 80,
19+
displaySubFrames: Bool = false) {
1920

2021
self.frameRate = frameRate
2122
self.upperLimit = limit
2223
self.subFramesDivisor = subFramesDivisor
24+
self.displaySubFrames = displaySubFrames
2325

2426
}
2527

@@ -34,11 +36,13 @@ extension Timecode {
3436
@inlinable public init?(_ exactly: Components,
3537
at frameRate: FrameRate,
3638
limit: UpperLimit = ._24hours,
37-
subFramesDivisor: Int = 80) {
39+
subFramesDivisor: Int = 80,
40+
displaySubFrames: Bool = false) {
3841

3942
self.frameRate = frameRate
4043
self.upperLimit = limit
4144
self.subFramesDivisor = subFramesDivisor
45+
self.displaySubFrames = displaySubFrames
4246

4347
if !setTimecode(exactly: exactly) { return nil }
4448

@@ -52,11 +56,13 @@ extension Timecode {
5256
@inlinable public init(clamping: Components,
5357
at frameRate: FrameRate,
5458
limit: UpperLimit = ._24hours,
55-
subFramesDivisor: Int = 80) {
59+
subFramesDivisor: Int = 80,
60+
displaySubFrames: Bool = false) {
5661

5762
self.frameRate = frameRate
5863
self.upperLimit = limit
5964
self.subFramesDivisor = subFramesDivisor
65+
self.displaySubFrames = displaySubFrames
6066

6167
setTimecode(clamping: clamping)
6268

@@ -70,11 +76,13 @@ extension Timecode {
7076
@inlinable public init(wrapping: Components,
7177
at frameRate: FrameRate,
7278
limit: UpperLimit = ._24hours,
73-
subFramesDivisor: Int = 80) {
79+
subFramesDivisor: Int = 80,
80+
displaySubFrames: Bool = false) {
7481

7582
self.frameRate = frameRate
7683
self.upperLimit = limit
7784
self.subFramesDivisor = subFramesDivisor
85+
self.displaySubFrames = displaySubFrames
7886

7987
setTimecode(wrapping: wrapping)
8088

@@ -87,11 +95,13 @@ extension Timecode {
8795
@inlinable public init(rawValues: Components,
8896
at frameRate: FrameRate,
8997
limit: UpperLimit = ._24hours,
90-
subFramesDivisor: Int = 80) {
98+
subFramesDivisor: Int = 80,
99+
displaySubFrames: Bool = false) {
91100

92101
self.frameRate = frameRate
93102
self.upperLimit = limit
94103
self.subFramesDivisor = subFramesDivisor
104+
self.displaySubFrames = displaySubFrames
95105

96106
setTimecode(rawValues: rawValues)
97107

@@ -108,11 +118,13 @@ extension Timecode {
108118
@inlinable public init?(_ exactly: String,
109119
at frameRate: FrameRate,
110120
limit: UpperLimit = ._24hours,
111-
subFramesDivisor: Int = 80) {
121+
subFramesDivisor: Int = 80,
122+
displaySubFrames: Bool = false) {
112123

113124
self.frameRate = frameRate
114125
self.upperLimit = limit
115126
self.subFramesDivisor = subFramesDivisor
127+
self.displaySubFrames = displaySubFrames
116128

117129
if !setTimecode(exactly: exactly) { return nil }
118130

@@ -125,11 +137,13 @@ extension Timecode {
125137
@inlinable public init?(clamping: String,
126138
at frameRate: FrameRate,
127139
limit: UpperLimit = ._24hours,
128-
subFramesDivisor: Int = 80) {
140+
subFramesDivisor: Int = 80,
141+
displaySubFrames: Bool = false) {
129142

130143
self.frameRate = frameRate
131144
self.upperLimit = limit
132145
self.subFramesDivisor = subFramesDivisor
146+
self.displaySubFrames = displaySubFrames
133147

134148
if !setTimecode(clamping: clamping) { return nil }
135149

@@ -143,11 +157,13 @@ extension Timecode {
143157
@inlinable public init?(wrapping: String,
144158
at frameRate: FrameRate,
145159
limit: UpperLimit = ._24hours,
146-
subFramesDivisor: Int = 80) {
160+
subFramesDivisor: Int = 80,
161+
displaySubFrames: Bool = false) {
147162

148163
self.frameRate = frameRate
149164
self.upperLimit = limit
150165
self.subFramesDivisor = subFramesDivisor
166+
self.displaySubFrames = displaySubFrames
151167

152168
if !setTimecode(wrapping: wrapping) { return nil }
153169

@@ -160,11 +176,13 @@ extension Timecode {
160176
@inlinable public init?(rawValues: String,
161177
at frameRate: FrameRate,
162178
limit: UpperLimit = ._24hours,
163-
subFramesDivisor: Int = 80) {
179+
subFramesDivisor: Int = 80,
180+
displaySubFrames: Bool = false) {
164181

165182
self.frameRate = frameRate
166183
self.upperLimit = limit
167184
self.subFramesDivisor = subFramesDivisor
185+
self.displaySubFrames = displaySubFrames
168186

169187
if !setTimecode(rawValues: rawValues) { return nil }
170188

@@ -178,11 +196,13 @@ extension Timecode {
178196
@inlinable public init?(realTimeValue: TimeInterval,
179197
at frameRate: FrameRate,
180198
limit: UpperLimit = ._24hours,
181-
subFramesDivisor: Int = 80) {
199+
subFramesDivisor: Int = 80,
200+
displaySubFrames: Bool = false) {
182201

183202
self.frameRate = frameRate
184203
self.upperLimit = limit
185204
self.subFramesDivisor = subFramesDivisor
205+
self.displaySubFrames = displaySubFrames
186206

187207
if !self.setTimecode(fromRealTimeValue: realTimeValue) { return nil }
188208

@@ -195,11 +215,13 @@ extension Timecode {
195215
sampleRate: Int,
196216
at frameRate: FrameRate,
197217
limit: UpperLimit = ._24hours,
198-
subFramesDivisor: Int = 80) {
218+
subFramesDivisor: Int = 80,
219+
displaySubFrames: Bool = false) {
199220

200221
self.frameRate = frameRate
201222
self.upperLimit = limit
202223
self.subFramesDivisor = subFramesDivisor
224+
self.displaySubFrames = displaySubFrames
203225

204226
if !self.setTimecode(fromSamplesValue: samples,
205227
atSampleRate: sampleRate) { return nil }

0 commit comments

Comments
 (0)