Skip to content

Commit

Permalink
FCPXML: Refactored frame rate scaling to act directly upon fraction g…
Browse files Browse the repository at this point in the history
…et/set methods
  • Loading branch information
orchetect committed Jan 4, 2024
1 parent 5c057b0 commit ae3ff1e
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ extension FinalCutPro.FCPXML.ElementContext {
return try? element._fcpTimecode(
fromRealTime: absoluteStart,
frameRateSource: frameRateSource,
autoScale: false,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand All @@ -75,7 +74,6 @@ extension FinalCutPro.FCPXML.ElementContext {
return try? element._fcpTimecode(
fromRealTime: absoluteEnd,
frameRateSource: frameRateSource,
autoScale: true,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand Down Expand Up @@ -128,7 +126,6 @@ extension FinalCutPro.FCPXML.ElementContext {
return try? element._fcpTimecode(
fromRealTime: parentAbsoluteStart,
frameRateSource: frameRateSource,
autoScale: false,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand All @@ -152,7 +149,6 @@ extension FinalCutPro.FCPXML.ElementContext {
return try? element._fcpTimecode(
fromRealTime: parentAbsoluteEnd,
frameRateSource: frameRateSource,
autoScale: true,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand All @@ -175,7 +171,6 @@ extension FinalCutPro.FCPXML.ElementContext {
return try? element._fcpTimecode(
fromRealTime: parentDuration,
frameRateSource: frameRateSource,
autoScale: true,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ extension FCPXMLExtractedElement {
return try? element._fcpTimecode(
fromRational: duration,
frameRateSource: frameRateSource,
autoScale: true,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@ extension FinalCutPro.FCPXML.TimeMap.TimePoint {
/// New adjusted clip time. (Required)
public var time: Fraction {
get {
element._fcpGetFraction(forAttribute: Attributes.time.rawValue) ?? .zero
element._fcpGetFraction(forAttribute: Attributes.time.rawValue, scaled: true) ?? .zero
}
set {
element._fcpSet(fraction: newValue, forAttribute: Attributes.time.rawValue)
element._fcpSet(fraction: newValue, forAttribute: Attributes.time.rawValue, scaled: true)
}
}

/// Original clip time. (Required)
public var originalTime: Fraction {
get {
element._fcpGetFraction(forAttribute: Attributes.originalTime.rawValue) ?? .zero
element._fcpGetFraction(forAttribute: Attributes.originalTime.rawValue, scaled: true) ?? .zero
}
set {
element._fcpSet(fraction: newValue, forAttribute: Attributes.originalTime.rawValue)
element._fcpSet(fraction: newValue, forAttribute: Attributes.originalTime.rawValue, scaled: true)
}
}

Expand All @@ -117,20 +117,20 @@ extension FinalCutPro.FCPXML.TimeMap.TimePoint {
/// Transition in time. (Used only with smooth interpolations.)
public var transitionInTime: Fraction? {
get {
element._fcpGetFraction(forAttribute: Attributes.transitionInTime.rawValue)
element._fcpGetFraction(forAttribute: Attributes.transitionInTime.rawValue, scaled: true)
}
set {
element._fcpSet(fraction: newValue, forAttribute: Attributes.transitionInTime.rawValue)
element._fcpSet(fraction: newValue, forAttribute: Attributes.transitionInTime.rawValue, scaled: true)
}
}

/// Transition out time. (Used only with smooth interpolations.)
public var transitionOutTime: Fraction? {
get {
element._fcpGetFraction(forAttribute: Attributes.transitionOutTime.rawValue)
element._fcpGetFraction(forAttribute: Attributes.transitionOutTime.rawValue, scaled: true)
}
set {
element._fcpSet(fraction: newValue, forAttribute: Attributes.transitionOutTime.rawValue)
element._fcpSet(fraction: newValue, forAttribute: Attributes.transitionOutTime.rawValue, scaled: true)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ extension FCPXMLElementRequiredDuration {
) -> Timecode? {
try? element._fcpTimecode(
fromRational: duration,
frameRateSource: frameRateSource,
autoScale: true
frameRateSource: frameRateSource
)
}
}
Expand All @@ -50,8 +49,7 @@ extension FCPXMLElementOptionalDuration {
guard let duration = duration else { return nil }
return try? element._fcpTimecode(
fromRational: duration,
frameRateSource: frameRateSource,
autoScale: true
frameRateSource: frameRateSource
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ extension FCPXMLElementRequiredStart {
) -> Timecode? {
try? element._fcpTimecode(
fromRational: start,
frameRateSource: frameRateSource,
autoScale: true
frameRateSource: frameRateSource
)
}
}
Expand All @@ -50,8 +49,7 @@ extension FCPXMLElementOptionalStart {
guard let start = start else { return nil }
return try? element._fcpTimecode(
fromRational: start,
frameRateSource: frameRateSource,
autoScale: true
frameRateSource: frameRateSource
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ extension FCPXMLElementOptionalTCStart {
guard let tcStart = tcStart else { return nil }
return try? element._fcpTimecode(
fromRational: tcStart,
frameRateSource: frameRateSource,
autoScale: true
frameRateSource: frameRateSource
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ extension FCPXMLElementAnchorableAttributes {
guard let offset = offset else { return nil }
return try? element._fcpTimecode(
fromRational: offset,
frameRateSource: frameRateSource,
autoScale: true
frameRateSource: frameRateSource
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ extension XMLElement {
public var fcpPosterOffset: Fraction? {
get {
_fcpGetFraction(
forAttribute: FinalCutPro.FCPXML.Marker.Attributes.posterOffset.rawValue
forAttribute: FinalCutPro.FCPXML.Marker.Attributes.posterOffset.rawValue,
scaled: true
)
}
set {
_fcpSet(
fraction: newValue,
forAttribute: FinalCutPro.FCPXML.Marker.Attributes.posterOffset.rawValue
forAttribute: FinalCutPro.FCPXML.Marker.Attributes.posterOffset.rawValue,
scaled: true
)
}
}
Expand Down Expand Up @@ -237,15 +239,20 @@ extension XMLElement {
case let .toDo(completed: completed):
// note: don't allow deletion of this attribute, as the presence of `completed`
// attribute signifies that this marker is a to-do marker
set(bool: completed,
set(
bool: completed,
forAttribute: FinalCutPro.FCPXML.Marker.Attributes.completed.rawValue,
defaultValue: true, // N/A
removeIfDefault: false,
useInt: true)
useInt: true
)

case let .chapter(posterOffset: posterOffset):
_fcpSet(fraction: posterOffset,
forAttribute: FinalCutPro.FCPXML.Marker.Attributes.posterOffset.rawValue)
_fcpSet(
fraction: posterOffset,
forAttribute: FinalCutPro.FCPXML.Marker.Attributes.posterOffset.rawValue,
scaled: true
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extension XMLElement {
func _fcpTimecode(
fromRational rawString: String,
tcFormat: FinalCutPro.FCPXML.TimecodeFormat,
autoScale: Bool,
resourceID: String,
resources: XMLElement? = nil
) throws -> Timecode? {
Expand All @@ -27,7 +26,6 @@ extension XMLElement {
return try _fcpTimecode(
fromRational: fraction,
tcFormat: tcFormat,
autoScale: autoScale,
resourceID: resourceID,
resources: resources
)
Expand All @@ -37,7 +35,6 @@ extension XMLElement {
func _fcpTimecode(
fromRational fraction: Fraction,
tcFormat: FinalCutPro.FCPXML.TimecodeFormat,
autoScale: Bool,
resourceID: String,
resources: XMLElement? = nil
) throws -> Timecode? {
Expand All @@ -48,16 +45,8 @@ extension XMLElement {
)
else { return nil }

var seconds = fraction.doubleValue

if autoScale,
let scalingFactor = _fcpConformRateScalingFactor(resources: resources)
{
seconds *= scalingFactor
}

return try FinalCutPro.FCPXML._timecode(
fromRealTime: seconds,
fromRealTime: fraction.doubleValue,
frameRate: frameRate
)
}
Expand All @@ -71,7 +60,6 @@ extension XMLElement {
func _fcpTimecode(
fromRational rawString: String,
frameRateSource: FinalCutPro.FCPXML.FrameRateSource,
autoScale: Bool,
breadcrumbs: [XMLElement]? = nil,
resources: XMLElement? = nil
) throws -> Timecode? {
Expand All @@ -81,7 +69,6 @@ extension XMLElement {
return try _fcpTimecode(
fromRational: fraction,
frameRateSource: frameRateSource,
autoScale: autoScale,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand All @@ -92,14 +79,12 @@ extension XMLElement {
func _fcpTimecode(
fromRational fraction: Fraction,
frameRateSource: FinalCutPro.FCPXML.FrameRateSource,
autoScale: Bool,
breadcrumbs: [XMLElement]? = nil,
resources: XMLElement? = nil
) throws -> Timecode? {
try _fcpTimecode(
fromRealTime: fraction.doubleValue,
frameRateSource: frameRateSource,
autoScale: autoScale,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand All @@ -109,7 +94,6 @@ extension XMLElement {
func _fcpTimecode(
fromRealTime seconds: TimeInterval,
frameRateSource: FinalCutPro.FCPXML.FrameRateSource,
autoScale: Bool,
breadcrumbs: [XMLElement]? = nil,
resources: XMLElement? = nil
) throws -> Timecode? {
Expand All @@ -119,17 +103,6 @@ extension XMLElement {
resources: resources
) else { return nil }

var seconds = seconds

if autoScale,
let scalingFactor = _fcpConformRateScalingFactor(
ancestors: breadcrumbs,
resources: resources
)
{
seconds *= scalingFactor
}

return try FinalCutPro.formTimecode(realTime: seconds, at: frameRate)
}
}
Expand Down Expand Up @@ -177,7 +150,6 @@ extension XMLElement {
func _fcpTimecodeInterval(
fromRational rawString: String,
frameRateSource: FinalCutPro.FCPXML.FrameRateSource,
autoScale: Bool,
breadcrumbs: [XMLElement]? = nil,
resources: XMLElement? = nil
) throws -> TimecodeInterval? {
Expand All @@ -187,7 +159,6 @@ extension XMLElement {
return try _fcpTimecodeInterval(
fromRational: fraction,
frameRateSource: frameRateSource,
autoScale: autoScale,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand All @@ -198,14 +169,12 @@ extension XMLElement {
func _fcpTimecodeInterval(
fromRational fraction: Fraction,
frameRateSource: FinalCutPro.FCPXML.FrameRateSource,
autoScale: Bool,
breadcrumbs: [XMLElement]? = nil,
resources: XMLElement? = nil
) throws -> TimecodeInterval? {
try _fcpTimecodeInterval(
fromRealTime: fraction.doubleValue,
frameRateSource: frameRateSource,
autoScale: autoScale,
breadcrumbs: breadcrumbs,
resources: resources
)
Expand All @@ -216,7 +185,6 @@ extension XMLElement {
func _fcpTimecodeInterval(
fromRealTime seconds: TimeInterval,
frameRateSource: FinalCutPro.FCPXML.FrameRateSource,
autoScale: Bool,
breadcrumbs: [XMLElement]? = nil,
resources: XMLElement? = nil
) throws -> TimecodeInterval? {
Expand All @@ -226,17 +194,6 @@ extension XMLElement {
resources: resources
) else { return nil }

var seconds = seconds

if autoScale,
let scalingFactor = _fcpConformRateScalingFactor(
ancestors: breadcrumbs,
resources: resources
)
{
seconds *= scalingFactor
}

return try FinalCutPro.FCPXML._timecodeInterval(
fromRealTime: seconds,
frameRate: frameRate
Expand Down
Loading

0 comments on commit ae3ff1e

Please sign in to comment.