diff --git a/Sources/SwiftTimecodeCore/Documentation.docc/Documentation.md b/Sources/SwiftTimecodeCore/Documentation.docc/Documentation.md index 3a80884c..5cd16f91 100644 --- a/Sources/SwiftTimecodeCore/Documentation.docc/Documentation.md +++ b/Sources/SwiftTimecodeCore/Documentation.docc/Documentation.md @@ -42,3 +42,7 @@ Value types and related logic for representing and working with SMPTE/EBU timeco ### Additional Value Types - ``FeetAndFrames`` + +### Cross-Platform Types + +- ``PlatformInt`` diff --git a/Sources/SwiftTimecodeCore/Fraction/Fraction CMTime.swift b/Sources/SwiftTimecodeCore/Fraction/Fraction CMTime.swift index 165506fa..dcd76852 100644 --- a/Sources/SwiftTimecodeCore/Fraction/Fraction CMTime.swift +++ b/Sources/SwiftTimecodeCore/Fraction/Fraction CMTime.swift @@ -20,7 +20,7 @@ extension Fraction { return } - self.init(Int(cmTime.value), Int(cmTime.timescale)) + self.init(PlatformInt(cmTime.value), PlatformInt(cmTime.timescale)) } /// Returns the fraction as a new `CMTime` instance. diff --git a/Sources/SwiftTimecodeCore/Fraction/Fraction.swift b/Sources/SwiftTimecodeCore/Fraction/Fraction.swift index 22d5dd57..d5e738ff 100644 --- a/Sources/SwiftTimecodeCore/Fraction/Fraction.swift +++ b/Sources/SwiftTimecodeCore/Fraction/Fraction.swift @@ -10,8 +10,8 @@ import Foundation /// /// Used to convert to/from ``Timecode``, Core Media `CMTime`, or metadata encoding such as Final Cut Pro XML or AAF. public struct Fraction { - public let numerator: Int - public let denominator: Int + public let numerator: PlatformInt + public let denominator: PlatformInt private let _isReduced: Bool? @@ -40,14 +40,14 @@ public struct Fraction { // MARK: - Init /// Initialize with literal values. - public init(_ numerator: Int, _ denominator: Int) { + public init(_ numerator: PlatformInt, _ denominator: PlatformInt) { self.numerator = numerator self.denominator = denominator _isReduced = nil } /// Initialize by reducing and normalizing the fraction. - public init(reducing numerator: Int, _ denominator: Int) { + public init(reducing numerator: PlatformInt, _ denominator: PlatformInt) { let reduced = reduce(n: numerator, d: denominator) self.numerator = reduced.n self.denominator = reduced.d @@ -66,7 +66,7 @@ public struct Fraction { } /// Internal: Initialize with literal values and force the reduced flag. - init(_ numerator: Int, _ denominator: Int, isReduced: Bool?) { + init(_ numerator: PlatformInt, _ denominator: PlatformInt, isReduced: Bool?) { self.numerator = numerator self.denominator = denominator _isReduced = isReduced @@ -253,10 +253,10 @@ extension Double { // clamp exponent to avoid overflow crashes // Int.max = 9.22... x 10^18 let maxExponent = precision.clamped(to: 0 ... max(19 - integralDigitPlaces, 0)) - let pad = Int(truncating: pow(10, maxExponent) as NSNumber) + let pad = PlatformInt(truncating: pow(10, maxExponent) as NSNumber) let nFloat = absSelf * Double(pad) - let n = Int(truncating: nFloat as NSNumber) + let n = PlatformInt(truncating: nFloat as NSNumber) let d = pad return Fraction(reducing: isNegative ? -n : n, d) @@ -285,7 +285,7 @@ extension Fraction { if wholeSecsMatches.count == 3 { let negativeSign = wholeSecsMatches[1] ?? "" if let secondsString = wholeSecsMatches[2], - let seconds = Int(negativeSign + secondsString) + let seconds = PlatformInt(negativeSign + secondsString) { self.init(seconds, 1, isReduced: true) return @@ -298,9 +298,9 @@ extension Fraction { if fracMatches.count == 4 { let negativeSign = fracMatches[1] ?? "" if let numeratorString = fracMatches[2], - let numerator = Int(negativeSign + numeratorString), + let numerator = PlatformInt(negativeSign + numeratorString), let denominatorString = fracMatches[3], - let denominator = Int(denominatorString) + let denominator = PlatformInt(denominatorString) { self.init(numerator, denominator) return @@ -337,7 +337,7 @@ extension Fraction { /// Normalize a fraction. /// Fractions with two negative signs are normalized to two positive signs. /// Fractions with negative denominator are normalized to negative numerator and positive denominator. -func normalize(n: Int, d: Int) -> (n: Int, d: Int) { +func normalize(n: PlatformInt, d: PlatformInt) -> (n: PlatformInt, d: PlatformInt) { var n = n var d = d if n >= 0 && d >= 0 { return (n: n, d: d) } @@ -351,9 +351,9 @@ func normalize(n: Int, d: Int) -> (n: Int, d: Int) { /// Internal: /// Reduce a fraction to its simplest form. /// This also normalizes signs. -func reduce(n: Int, d: Int) -> (n: Int, d: Int) { - let (absN, signN) = n < 0 ? (-n, -1) : (n, 1) - let (absD, signD) = d < 0 ? (-d, -1) : (d, 1) +func reduce(n: PlatformInt, d: PlatformInt) -> (n: PlatformInt, d: PlatformInt) { + let (absN, signN): (PlatformInt, PlatformInt) = n < 0 ? (-n, -1) : (n, 1) + let (absD, signD): (PlatformInt, PlatformInt) = d < 0 ? (-d, -1) : (d, 1) var v = n var u = d @@ -376,8 +376,8 @@ func reduce(n: Int, d: Int) -> (n: Int, d: Int) { /// Internal: /// Returns greatest common divisor of two numbers. -func greatestCommonDivisor(_ n1: Int, _ n2: Int) -> Int { - var x = 0 +func greatestCommonDivisor(_ n1: PlatformInt, _ n2: PlatformInt) -> PlatformInt { + var x: PlatformInt = 0 var y = max(n1, n2) var z = min(n1, n2) @@ -392,7 +392,7 @@ func greatestCommonDivisor(_ n1: Int, _ n2: Int) -> Int { /// Internal: /// Returns least common multiple of two numbers and their respective multipliers. -func leastCommonMultiple(lhs: Int, rhs: Int) -> (denominator: Int, lhsMultiplier: Int, rhsMultiplier: Int) { +func leastCommonMultiple(lhs: PlatformInt, rhs: PlatformInt) -> (denominator: PlatformInt, lhsMultiplier: PlatformInt, rhsMultiplier: PlatformInt) { let denominator = lhs * rhs / greatestCommonDivisor(lhs, rhs) let lhsMultiplier = denominator / lhs let rhsMultiplier = denominator / rhs diff --git a/Sources/SwiftTimecodeCore/Timecode/FrameCount/FrameCount.swift b/Sources/SwiftTimecodeCore/Timecode/FrameCount/FrameCount.swift index 400e1f02..3d5bfa73 100644 --- a/Sources/SwiftTimecodeCore/Timecode/FrameCount/FrameCount.swift +++ b/Sources/SwiftTimecodeCore/Timecode/FrameCount/FrameCount.swift @@ -105,7 +105,7 @@ extension Timecode { extension Timecode.FrameCount { init( - subFrameCount: Int, + subFrameCount: PlatformInt, base: Timecode.SubFramesBase ) { let converted = Timecode.subFramesToFrames( @@ -225,7 +225,7 @@ extension Timecode.FrameCount { public func multiplying(by factor: Double) -> Self { let lhsTotalSubFrames = subFrameCount - let resultSubFrameCount = Int(Double(lhsTotalSubFrames) * factor) + let resultSubFrameCount = PlatformInt(Double(lhsTotalSubFrames) * factor) let newFrames = Timecode.subFramesToFrames( resultSubFrameCount, @@ -241,7 +241,7 @@ extension Timecode.FrameCount { public func dividing(by divisor: Double) -> Self { let lhsTotalSubFrames = subFrameCount - let resultSubFrameCount = Int(Double(lhsTotalSubFrames) / divisor) + let resultSubFrameCount = PlatformInt(Double(lhsTotalSubFrames) / divisor) let newFrames = Timecode.subFramesToFrames( resultSubFrameCount, @@ -268,7 +268,7 @@ extension Timecode.FrameCount { } extension Timecode.FrameCount { - var subFrameCount: Int { + var subFrameCount: PlatformInt { Timecode.framesToSubFrames( frames: wholeFrames, subFrames: subFrames, @@ -285,15 +285,15 @@ extension Timecode { frames: Int, subFrames: Int, base: SubFramesBase - ) -> Int { - (frames * base.rawValue) + subFrames + ) -> PlatformInt { + (PlatformInt(frames) * PlatformInt(base.rawValue)) + PlatformInt(subFrames) } /// Internal utility - static func subFramesToFrames(_ subFrames: Int, base: SubFramesBase) -> (frames: Int, subFrames: Int) { - let outSubFrames = subFrames % base.rawValue - let outFrames = (subFrames - outSubFrames) / base.rawValue + static func subFramesToFrames(_ subFrames: PlatformInt, base: SubFramesBase) -> (frames: Int, subFrames: Int) { + let outSubFrames = subFrames % PlatformInt(base.rawValue) + let outFrames = (subFrames - outSubFrames) / PlatformInt(base.rawValue) - return (frames: outFrames, subFrames: outSubFrames) + return (frames: Int(outFrames), subFrames: Int(outSubFrames)) } } diff --git a/Sources/SwiftTimecodeCore/Timecode/Math/Timecode Math Internal.swift b/Sources/SwiftTimecodeCore/Timecode/Math/Timecode Math Internal.swift index 72332677..ac9568ed 100644 --- a/Sources/SwiftTimecodeCore/Timecode/Math/Timecode Math Internal.swift +++ b/Sources/SwiftTimecodeCore/Timecode/Math/Timecode Math Internal.swift @@ -311,7 +311,7 @@ extension Timecode { if sfcNew > Double(maxSubFrameCountExpressible) { return nil } let fcNew = FrameCount( - subFrameCount: Int(sfcNew), + subFrameCount: PlatformInt(sfcNew), base: subFramesBase ) @@ -333,7 +333,7 @@ extension Timecode { base: subFramesBase ) - var sfcNew = Int(Double(fcOrigin.subFrameCount) * factor) + var sfcNew = PlatformInt(Double(fcOrigin.subFrameCount) * factor) sfcNew = sfcNew.clamped(to: 0 ... maxSubFrameCountExpressible) @@ -360,7 +360,7 @@ extension Timecode { base: subFramesBase ) - var sfcNew = Int(Double(fcOrigin.subFrameCount) * factor) + var sfcNew = PlatformInt(Double(fcOrigin.subFrameCount) * factor) let maxTotalSubFrames = frameRate.maxTotalSubFrames( in: upperLimit, @@ -401,7 +401,7 @@ extension Timecode { base: subFramesBase ) - let sfcNew = Int(Double(fcOrigin.subFrameCount) * factor) + let sfcNew = PlatformInt(Double(fcOrigin.subFrameCount) * factor) let fcNew = FrameCount( subFrameCount: sfcNew, @@ -434,7 +434,7 @@ extension Timecode { if sfcNew > Double(maxSubFrameCountExpressible) { return nil } let fcNew = FrameCount( - subFrameCount: Int(sfcNew), + subFrameCount: PlatformInt(sfcNew), base: subFramesBase ) @@ -456,7 +456,7 @@ extension Timecode { base: subFramesBase ) - var sfcNew = Int(Double(fcOrigin.subFrameCount) / divisor) + var sfcNew = PlatformInt(Double(fcOrigin.subFrameCount) / divisor) sfcNew = sfcNew.clamped(to: 0 ... maxSubFrameCountExpressible) @@ -483,7 +483,7 @@ extension Timecode { base: subFramesBase ) - var sfcNew = Int(Double(fcOrigin.subFrameCount) / divisor) + var sfcNew = PlatformInt(Double(fcOrigin.subFrameCount) / divisor) let maxTotalSubFrames = frameRate.maxTotalSubFrames( in: upperLimit, @@ -524,7 +524,7 @@ extension Timecode { base: subFramesBase ) - let sfcNew = Int(Double(fcOrigin.subFrameCount) / divisor) + let sfcNew = PlatformInt(Double(fcOrigin.subFrameCount) / divisor) let fcNew = FrameCount( subFrameCount: sfcNew, diff --git a/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Rational CMTime.swift b/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Rational CMTime.swift index 2de4bb3d..08d313ed 100644 --- a/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Rational CMTime.swift +++ b/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Rational CMTime.swift @@ -81,7 +81,7 @@ extension Timecode { /// /// - Throws: ``ValidationError`` mutating func _setTimecode(exactly: CMTime) throws { - let fraction = Fraction(Int(exactly.value), Int(exactly.timescale)) + let fraction = Fraction(PlatformInt(exactly.value), PlatformInt(exactly.timescale)) try _setTimecode(exactly: fraction) } @@ -92,7 +92,7 @@ extension Timecode { /// - Note: Many AVFoundation and Core Media objects utilize `CMTime` as a way to represent /// times and durations. mutating func _setTimecode(clamping cmTime: CMTime) { - let fraction = Fraction(Int(cmTime.value), Int(cmTime.timescale)) + let fraction = Fraction(PlatformInt(cmTime.value), PlatformInt(cmTime.timescale)) _setTimecode(clamping: fraction) } @@ -103,7 +103,7 @@ extension Timecode { /// - Note: Many AVFoundation and Core Media objects utilize `CMTime` as a way to represent /// times and durations. mutating func _setTimecode(wrapping cmTime: CMTime) { - let fraction = Fraction(Int(cmTime.value), Int(cmTime.timescale)) + let fraction = Fraction(PlatformInt(cmTime.value), PlatformInt(cmTime.timescale)) _setTimecode(wrapping: fraction) } @@ -114,7 +114,7 @@ extension Timecode { /// - Note: Many AVFoundation and Core Media objects utilize `CMTime` as a way to represent /// times and durations. mutating func _setTimecode(rawValues cmTime: CMTime) { - let fraction = Fraction(Int(cmTime.value), Int(cmTime.timescale)) + let fraction = Fraction(PlatformInt(cmTime.value), PlatformInt(cmTime.timescale)) _setTimecode(rawValues: fraction) } } diff --git a/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Rational.swift b/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Rational.swift index c6760427..3c7b299e 100644 --- a/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Rational.swift +++ b/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Rational.swift @@ -34,7 +34,7 @@ extension TimecodeSourceValue { } /// Numerical fraction containing a numerator and a denominator. - public static func rational(_ numerator: Int, _ denominator: Int) -> Self { + public static func rational(_ numerator: PlatformInt, _ denominator: PlatformInt) -> Self { .init(value: Fraction(numerator, denominator)) } } @@ -51,7 +51,7 @@ extension Timecode { public var rationalValue: Fraction { let frFrac = frameRate.frameDuration let n = frFrac.numerator * frameCount.subFrameCount - let d = frFrac.denominator * subFramesBase.rawValue + let d = frFrac.denominator * PlatformInt(subFramesBase.rawValue) return Fraction(n, d).reduced() } @@ -85,7 +85,7 @@ extension Timecode { /// fractions.) mutating func _setTimecode(clamping rational: Fraction) { let frameCount = frameCount(of: rational) - _setTimecode(clamping: .frames(frameCount)) + _setTimecode(clamping: .frames(Int(clamping: frameCount))) } /// Sets the timecode from elapsed time expressed as a rational fraction. @@ -98,7 +98,7 @@ extension Timecode { /// fractions.) mutating func _setTimecode(wrapping rational: Fraction) { let frameCount = frameCount(of: rational) - _setTimecode(wrapping: .frames(frameCount)) + _setTimecode(wrapping: .frames(Int(clamping: frameCount))) } /// Sets the timecode from elapsed time expressed as a rational fraction. @@ -111,7 +111,7 @@ extension Timecode { /// fractions.) mutating func _setTimecode(rawValues rational: Fraction) { let frameCount = frameCount(of: rational) - _setTimecode(rawValues: .frames(frameCount)) + _setTimecode(rawValues: .frames(Int(clamping: frameCount))) } // MARK: Helper Methods @@ -119,7 +119,7 @@ extension Timecode { /// Internal: /// Returns frame count of the rational fraction at current frame rate. /// Truncates subframes if present. - func frameCount(of rational: Fraction) -> Int { + func frameCount(of rational: Fraction) -> PlatformInt { let frFrac = frameRate.frameDuration let frameCount = (rational.numerator * frFrac.denominator) / (rational.denominator * frFrac.numerator) diff --git a/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Samples.swift b/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Samples.swift index 835e3bca..3fe47899 100644 --- a/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Samples.swift +++ b/Sources/SwiftTimecodeCore/Timecode/Source/Timecode Samples.swift @@ -34,11 +34,13 @@ extension SamplesPayload: _TimecodeSource { extension TimecodeSourceValue { /// Audio samples at a given sample rate. - public static func samples(_ samples: Int, sampleRate: Int) -> Self { + public static func samples(_ samples: PlatformInt, sampleRate: Int) -> Self { .init(value: SamplesPayload(samples: Double(samples), sampleRate: sampleRate)) } + // Disfavored overload avoids type ambiguity at call-site for integer literals on 32-bit platforms. /// Audio samples at a given sample rate. + @_disfavoredOverload public static func samples(_ samples: Double, sampleRate: Int) -> Self { .init(value: SamplesPayload(samples: samples, sampleRate: sampleRate)) } @@ -51,14 +53,14 @@ extension Timecode { /// Returns the current timecode converted to a duration in audio samples /// at the given sample rate, rounded to the nearest sample. /// Sample rate is expressed in Hz. (ie: 48KHz would be passed as 48000) - public func samplesValue(sampleRate: Int) -> Int { + public func samplesValue(sampleRate: Int) -> PlatformInt { let val = samplesDoubleValue(sampleRate: sampleRate).rounded() // avoid crash if Double is too big - guard val <= Double(Int.max) else { + guard val <= Double(PlatformInt.max) else { // assertionFailure("Timecode is too large to convert to audio samples. This will fail silently in a release build.") return 0 } - return Int(val) + return PlatformInt(val) } /// (Lossy) diff --git a/Sources/SwiftTimecodeCore/Timecode/Timecode Validation.swift b/Sources/SwiftTimecodeCore/Timecode/Timecode Validation.swift index a063a625..a7f3bb2b 100644 --- a/Sources/SwiftTimecodeCore/Timecode/Timecode Validation.swift +++ b/Sources/SwiftTimecodeCore/Timecode/Timecode Validation.swift @@ -197,7 +197,7 @@ extension Timecode { } /// Returns the `upperLimit` minus 1 subframe expressed as total subframes. - public var maxSubFrameCountExpressible: Int { + public var maxSubFrameCountExpressible: PlatformInt { frameRate.maxSubFrameCountExpressible( in: upperLimit, base: subFramesBase diff --git a/Sources/SwiftTimecodeCore/TimecodeFrameRate/TimecodeFrameRate Conversions.swift b/Sources/SwiftTimecodeCore/TimecodeFrameRate/TimecodeFrameRate Conversions.swift index d200579d..0c281985 100644 --- a/Sources/SwiftTimecodeCore/TimecodeFrameRate/TimecodeFrameRate Conversions.swift +++ b/Sources/SwiftTimecodeCore/TimecodeFrameRate/TimecodeFrameRate Conversions.swift @@ -122,7 +122,7 @@ extension TimecodeFrameRate { drop: Bool = false ) { self.init( - rate: Fraction(Int(cmTime.value), Int(cmTime.timescale)), + rate: Fraction(PlatformInt(cmTime.value), PlatformInt(cmTime.timescale)), drop: drop ) } @@ -141,7 +141,7 @@ extension TimecodeFrameRate { drop: Bool = false ) { self.init( - frameDuration: Fraction(Int(cmTime.value), Int(cmTime.timescale)), + frameDuration: Fraction(PlatformInt(cmTime.value), PlatformInt(cmTime.timescale)), drop: drop ) } diff --git a/Sources/SwiftTimecodeCore/TimecodeFrameRate/TimecodeFrameRate Properties.swift b/Sources/SwiftTimecodeCore/TimecodeFrameRate/TimecodeFrameRate Properties.swift index dccb0e21..5f186df3 100644 --- a/Sources/SwiftTimecodeCore/TimecodeFrameRate/TimecodeFrameRate Properties.swift +++ b/Sources/SwiftTimecodeCore/TimecodeFrameRate/TimecodeFrameRate Properties.swift @@ -303,8 +303,8 @@ extension TimecodeFrameRate { public func maxTotalSubFrames( in extent: Timecode.UpperLimit, base: Timecode.SubFramesBase - ) -> Int { - maxTotalFrames(in: extent) * base.rawValue + ) -> PlatformInt { + PlatformInt(maxTotalFrames(in: extent)) * PlatformInt(base.rawValue) } /// Returns max elapsed subframes possible before rolling over to 0. @@ -312,7 +312,7 @@ extension TimecodeFrameRate { public func maxSubFrameCountExpressible( in extent: Timecode.UpperLimit, base: Timecode.SubFramesBase - ) -> Int { + ) -> PlatformInt { maxTotalSubFrames(in: extent, base: base) - 1 } } diff --git a/Sources/SwiftTimecodeCore/Utilities/PlatformInt.swift b/Sources/SwiftTimecodeCore/Utilities/PlatformInt.swift new file mode 100644 index 00000000..cd4d5494 --- /dev/null +++ b/Sources/SwiftTimecodeCore/Utilities/PlatformInt.swift @@ -0,0 +1,51 @@ +// +// PlatformInt.swift +// swift-timecode • https://github.com/orchetect/swift-timecode +// © 2026 Steffan Andrews • Licensed under MIT License +// + +#if _pointerBitWidth(_64) || _pointerBitWidth(_128) + +/// Signed integer type that aliases to the appropriate concrete type for the target platform. +/// Resolves to `Int` on 64-bit platforms and `Int64` on 32-bit platforms (including `wasm32`, +/// `armv7k`, and `arm64_32`). +/// +/// > Tip: +/// > +/// > Consumers building for 64-bit platforms only may use `Int` at call-sites without any special +/// > accommodations. Consumers for 32-bit platforms or consumers building cross-platform modules +/// > for both 64- and 32-bit targets from one source should wrap values at call-sites with `Int64`. +/// +/// > Note: +/// > +/// > This type is used only as a retroactive solution for providing cross-platform compatibility to +/// > this library in a non-breaking way for existing 64-bit bit platform consumers while adding +/// > support for 32-bit platforms with little to no compromises. A future version of this library +/// > may remove this type alias and adopt specific bit-width integer types that are stable across +/// > all architectures. +public typealias PlatformInt = Int + +#elseif _pointerBitWidth(_32) + +/// Signed integer type that aliases to the appropriate concrete type for the target platform. +/// Resolves to `Int` on 64-bit platforms and `Int64` on 32-bit platforms (including `wasm32`, +/// `armv7k`, and `arm64_32`). +/// +/// > Tip: +/// > +/// > Consumers building for 64-bit platforms only may use `Int` at call-sites without any special +/// > accommodations. Consumers for 32-bit platforms or consumers building cross-platform modules +/// > for both 64- and 32-bit targets from one source should wrap values at call-sites with `Int64`. +/// +/// > Note: +/// > +/// > This type is used only as a retroactive solution for providing cross-platform compatibility to +/// > this library in a non-breaking way for existing 64-bit bit platform consumers while adding +/// > support for 32-bit platforms with little to no compromises. A future version of this library +/// > may remove this type alias and adopt specific bit-width integer types that are stable across +/// > all architectures. +public typealias PlatformInt = Int64 + +#else +#error("Unsupported pointer width — PlatformInt needs a mapping for this platform.") +#endif diff --git a/Sources/SwiftTimecodeCore/VideoFrameRate/VideoFrameRate Conversions.swift b/Sources/SwiftTimecodeCore/VideoFrameRate/VideoFrameRate Conversions.swift index 81b63e67..0116243b 100644 --- a/Sources/SwiftTimecodeCore/VideoFrameRate/VideoFrameRate Conversions.swift +++ b/Sources/SwiftTimecodeCore/VideoFrameRate/VideoFrameRate Conversions.swift @@ -151,7 +151,7 @@ extension VideoFrameRate { interlaced: Bool = false ) { self.init( - rate: Fraction(Int(cmTime.value), Int(cmTime.timescale)), + rate: Fraction(PlatformInt(cmTime.value), PlatformInt(cmTime.timescale)), interlaced: interlaced ) } @@ -170,7 +170,7 @@ extension VideoFrameRate { interlaced: Bool = false ) { self.init( - frameDuration: Fraction(Int(cmTime.value), Int(cmTime.timescale)), + frameDuration: Fraction(PlatformInt(cmTime.value), PlatformInt(cmTime.timescale)), interlaced: interlaced ) } diff --git a/Sources/SwiftTimecodeUI/Documentation.docc/Documentation.md b/Sources/SwiftTimecodeUI/Documentation.docc/Documentation.md index 41fbe8cf..88c40169 100644 --- a/Sources/SwiftTimecodeUI/Documentation.docc/Documentation.md +++ b/Sources/SwiftTimecodeUI/Documentation.docc/Documentation.md @@ -19,23 +19,23 @@ UI controls and tools for formatting and displaying timecode, including user-edi ### SwiftUI View Modifiers - ``SwiftUICore/View/timecodeFormat(_:)`` -- ``SwiftUICore/View/timecodeFieldHighlightStyle(_:)-(S)`` -- ``SwiftUICore/View/timecodeFieldHighlightStyle(_:)-(S?)`` +- ``SwiftUICore/View/timecodeFieldHighlightStyle(_:)-(ShapeStyle)`` +- ``SwiftUICore/View/timecodeFieldHighlightStyle(_:)-8k1sm`` - ``SwiftUICore/View/timecodeFieldInputStyle(_:)`` - ``SwiftUICore/View/timecodeFieldInputWrapping(_:)`` - ``SwiftUICore/View/timecodeFieldEscapeAction(_:)`` - ``SwiftUICore/View/timecodeFieldReturnAction(_:)`` - ``SwiftUICore/View/timecodeFieldValidationPolicy(_:)`` - ``SwiftUICore/View/timecodeFieldInputRejectionFeedback(_:)`` -- ``SwiftUICore/View/timecodeSeparatorStyle(_:)-(S)`` -- ``SwiftUICore/View/timecodeSeparatorStyle(_:)-(S?)`` -- ``SwiftUICore/View/timecodeSubFramesStyle(_:)-(S)`` -- ``SwiftUICore/View/timecodeSubFramesStyle(_:)-(S?)`` +- ``SwiftUICore/View/timecodeSeparatorStyle(_:)-(ShapeStyle)`` +- ``SwiftUICore/View/timecodeSeparatorStyle(_:)-5cwmi`` +- ``SwiftUICore/View/timecodeSubFramesStyle(_:)-(ShapeStyle)`` +- ``SwiftUICore/View/timecodeSubFramesStyle(_:)-4p9lf`` - ``SwiftUICore/View/timecodeSubFramesStyle(scale:)`` -- ``SwiftUICore/View/timecodeSubFramesStyle(_:scale:)-(S,_)`` -- ``SwiftUICore/View/timecodeSubFramesStyle(_:scale:)-(S?,_)`` -- ``SwiftUICore/View/timecodeValidationStyle(_:)-(S)`` -- ``SwiftUICore/View/timecodeValidationStyle(_:)-(S?)`` +- ``SwiftUICore/View/timecodeSubFramesStyle(_:scale:)-(ShapeStyle,_)`` +- ``SwiftUICore/View/timecodeSubFramesStyle(_:scale:)-7fidz`` +- ``SwiftUICore/View/timecodeValidationStyle(_:)-(ShapeStyle)`` +- ``SwiftUICore/View/timecodeValidationStyle(_:)-2me4o`` ### SwiftUI State diff --git a/Tests/SwiftTimecodeCoreTests/Timecode/Source/Timecode Samples Tests.swift b/Tests/SwiftTimecodeCoreTests/Timecode/Source/Timecode Samples Tests.swift index cc645c4a..1ad9a383 100644 --- a/Tests/SwiftTimecodeCoreTests/Timecode/Source/Timecode Samples Tests.swift +++ b/Tests/SwiftTimecodeCoreTests/Timecode/Source/Timecode Samples Tests.swift @@ -122,7 +122,7 @@ struct Timecode_Source_Samples_Tests { // MARK: samples as Int func validate( - using samplesIn1DayTC: Int, + using samplesIn1DayTC: PlatformInt, sRate: Int, fRate: TimecodeFrameRate ) throws { @@ -142,7 +142,7 @@ struct Timecode_Source_Samples_Tests { let sRate = 48000 var samplesIn1DayTCDouble = 0.0 - var samplesIn1DayTCInt = 0 + var samplesIn1DayTCInt: PlatformInt = 0 var roundedForDropFrame = false switch frameRate { @@ -154,7 +154,7 @@ struct Timecode_Source_Samples_Tests { .fps95_904, .fps119_88: samplesIn1DayTCDouble = samplesIn1DayTC_ShrunkFrameRates - samplesIn1DayTCInt = Int(samplesIn1DayTCDouble) + samplesIn1DayTCInt = PlatformInt(samplesIn1DayTCDouble) roundedForDropFrame = false case .fps24, @@ -168,7 +168,7 @@ struct Timecode_Source_Samples_Tests { .fps100, .fps120: samplesIn1DayTCDouble = samplesIn1DayTC_BaseFrameRates - samplesIn1DayTCInt = Int(samplesIn1DayTCDouble) + samplesIn1DayTCInt = PlatformInt(samplesIn1DayTCDouble) roundedForDropFrame = false case .fps29_97d, @@ -182,14 +182,14 @@ struct Timecode_Source_Samples_Tests { // - double this would technically be 4147195854 but Cubase shows 1 frame less samplesIn1DayTCDouble = samplesIn1DayTC_DropFrameRates - samplesIn1DayTCInt = Int(samplesIn1DayTCDouble) + samplesIn1DayTCInt = PlatformInt(samplesIn1DayTCDouble) roundedForDropFrame = true // DAWs seem to using standard rounding for DF (?) case .fps30d, .fps60d, .fps120d: samplesIn1DayTCDouble = samplesIn1DayTC_30DF - samplesIn1DayTCInt = Int(samplesIn1DayTCDouble) + samplesIn1DayTCInt = PlatformInt(samplesIn1DayTCDouble) roundedForDropFrame = false } diff --git a/Tests/SwiftTimecodeCoreTests/TimecodeFrameRate/TimecodeFrameRate Properties Tests.swift b/Tests/SwiftTimecodeCoreTests/TimecodeFrameRate/TimecodeFrameRate Properties Tests.swift index dcb90e02..2e7d17cc 100644 --- a/Tests/SwiftTimecodeCoreTests/TimecodeFrameRate/TimecodeFrameRate Properties Tests.swift +++ b/Tests/SwiftTimecodeCoreTests/TimecodeFrameRate/TimecodeFrameRate Properties Tests.swift @@ -53,14 +53,12 @@ struct TimecodeFrameRate_Properties_Tests { == 2_592_000 * 80 ) - // these integers result in overflow on armv7/i386 (32-bit arch) - #if !(arch(arm) || arch(i386)) #expect( frameRate.maxTotalSubFrames( in: .max100Days, base: .max80SubFrames ) - == 2_592_000 * 100 * 80 + == PlatformInt(2_592_000) * 100 * 80 ) #expect( @@ -68,9 +66,8 @@ struct TimecodeFrameRate_Properties_Tests { in: .max100Days, base: .max80SubFrames ) - == (2_592_000 * 100 * 80) - 1 + == (PlatformInt(2_592_000) * 100 * 80) - 1 ) - #endif #expect( frameRate.maxSubFrameCountExpressible(