Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Sep 17, 2020
0 parents commit 7f60f01
Show file tree
Hide file tree
Showing 55 changed files with 6,065 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Xcode

# macOS
.DS_Store

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

## SPM support in Xcode
.swiftpm

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
Packages/
Package.pins
Package.resolved
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control

Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Steffan Andrews - https://github.com/orchetect

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 38 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(

name: "SwiftTimecode",

products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "SwiftTimecode",
targets: ["SwiftTimecode"])
],

dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],

targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "SwiftTimecode",
dependencies: []),
.testTarget(
name: "SwiftTimecode-Unit-Tests",
dependencies: ["SwiftTimecode"]),

.testTarget(
name: "SwiftTimecode-Dev-Tests",
dependencies: ["SwiftTimecode"]
)
]

)
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SwiftTimecode

<p>
<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/Swift%205.3-compatible-orange.svg?style=flat" alt="Swift 5.3 compatible" /></a>
<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/SPM-compatible-orange.svg?style=flat" alt="Swift Package Manager (SPM) compatible" /></a>
<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/platform-macOS%20|%20iOS%20|%20tvOS%20|%20watchOS-green.svg?style=flat" alt="Platform - macOS | iOS | tvOS | watchOS" /></a>
<a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/Linux-not%20tested-black.svg?style=flat" alt="Linux - not tested" /></a>
<a href="https://raw.githubusercontent.com/uraimo/Bitter/master/LICENSE"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License: MIT" /></a>
</p>

A robust library for working with SMPTE timecode supporting 20 industry frame rates, and including methods to convert to/from timecode strings and perform calculations.

## Supported Frame Rates

| NTSC | PAL | HD / Film | Other |
| --------- | ---- | --------- | ------ |
| 29.97 | 25 | 23.976 | 30 |
| 29.97 DF | 50 | 24 | 30 DF |
| 59.94 | 100 | 24.98 | 60 |
| 59.94 DF | | 47.952 | 60 DF |
| 119.88 | | 48 | 120 |
| 119.88 DF | | | 120 DF |

## Core Features

- Convert timecode to string, or a timecode string to values
- Convert timecode to real wall-clock time, and vice-versa
- Convert timecode to # of samples at any audio sample-rate, and vice-versa
- Granular timecode validation
- A Formatter object that can format timecode and also provide an NSAttributedString showing invalid timecode components in an alternate color (such as red)
- Support for Days as a timecode component (which Cubase supports as part of its timecode format)
- Support for sub-frames
- Common math operations between timecodes: add, subtract, multiply, divide
- Exhaustive unit tests ensuring accuracy

## Development Status

### Incomplete Features (Still in Development)

- [ ] Complete sub-frame support

- [ ] Test subFrameDivisor effect when set to -1, 0, 1, or 1000000
- [ ] Needs to be added to String getters/setters
- Add 100-120 fps 3-digit frames display support

- [ ] Add method to convert to another framerate by producing a new `OTTimecode` object. But make it clear that it's a LOSSY process. Suggested API:

```swift
func convert(to: FrameRate, limit: UpperLimit) -> OTTimecode
```

### Maintenance

- [ ] Add code examples to README.md or wiki.

### Future Features Planned

- None at this time.

## Known Issues

- The Dev Tests are not meant to be run as routine unit tests, but are designed as a test harness to be used only when altering critical parts of the library to ensure stability of internal calculations.
- Unit Tests won't build/run for watchOS Simulator because XCTest does not work on watchOS
- Workaround: Don't run unit tests for a watchOS target. Using macOS or iOS as a unit test target should be sufficient enough. If anyone runs into issues with the library on watchOS, feel free to contribute a solution or fix anything that requires fixing.
25 changes: 25 additions & 0 deletions Sources/SwiftTimecode/Components/Component.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Component.swift
// SwiftTimecode
//
// Created by Steffan Andrews on 2020-06-15.
// Copyright © 2020 Steffan Andrews. All rights reserved.
//

import Foundation

extension OTTimecode {

/// Enum naming an individual timecode component
public enum Component {

case days
case hours
case minutes
case seconds
case frames
case subFrames

}

}
121 changes: 121 additions & 0 deletions Sources/SwiftTimecode/Components/Components.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// Components.swift
// SwiftTimecode
//
// Created by Steffan Andrews on 2018-07-20.
// Copyright © 2018 Steffan Andrews. All rights reserved.
//

import Foundation

/// Convenience typealias for cleaner code.
public typealias TCC = OTTimecode.Components

extension OTTimecode {

/// Primitive struct that can contain timecode values, agnostic of frame rate.
/// Raw values are stored and are not internally limited or clamped.
/// The global typealias TCC() is also available for convenience.
public struct Components {

// MARK: Contents

/// Days
public var d: Int

/// Hours
public var h: Int

/// Minutes
public var m: Int

/// Seconds
public var s: Int

/// Frames
public var f: Int

/// Subframe component (expressed as unit interval 0.0...1.0)
public var sf: Int

// MARK: init

public init(d: Int = 0,
h: Int = 0,
m: Int = 0,
s: Int = 0,
f: Int = 0,
sf: Int = 0)
{
self.d = d
self.h = h
self.m = m
self.s = s
self.f = f
self.sf = sf
}

}

}

extension OTTimecode.Components: Equatable {

public static func ==(lhs: Self, rhs: Self) -> Bool {
return lhs.d == rhs.d &&
lhs.h == rhs.h &&
lhs.m == rhs.m &&
lhs.s == rhs.s &&
lhs.f == rhs.f &&
lhs.sf == rhs.sf
}

}

extension OTTimecode.Components {

/// Returns an instance of `OTTimecode(exactly:)`.
public func toTimecode(at frameRate: OTTimecode.FrameRate,
limit: OTTimecode.UpperLimit = ._24hours,
subFramesDivisor: Int? = nil) -> OTTimecode?
{

if let sfd = subFramesDivisor {

return OTTimecode(self,
at: frameRate,
limit: limit,
subFramesDivisor: sfd)

} else {

return OTTimecode(self,
at: frameRate,
limit: limit)

}
}

/// Returns an instance of `OTTimecode(rawValues:)`.
public func toTimecode(rawValuesAt frameRate: OTTimecode.FrameRate,
limit: OTTimecode.UpperLimit = ._24hours,
subFramesDivisor: Int? = nil) -> OTTimecode?
{

if let sfd = subFramesDivisor {

return OTTimecode(rawValues: self,
at: frameRate,
limit: limit,
subFramesDivisor: sfd)

} else {

return OTTimecode(rawValues: self,
at: frameRate,
limit: limit)

}
}

}
Loading

0 comments on commit 7f60f01

Please sign in to comment.