From ae3ff1ec2b5e8ba0ec5d2297cc5ddf2b738de89c Mon Sep 17 00:00:00 2001 From: Steffan Andrews Date: Wed, 3 Jan 2024 23:27:13 -0800 Subject: [PATCH] FCPXML: Refactored frame rate scaling to act directly upon fraction get/set methods --- .../Context/FCPXML ElementContext Tools.swift | 5 -- .../Extraction/FCPXMLExtractedElement.swift | 1 - .../Elements/FCPXML TimeMap TimePoint.swift | 16 ++-- .../FCPXMLElementDuration.swift | 6 +- .../FCPXMLElementStart.swift | 6 +- .../FCPXMLElementTCStart.swift | 3 +- .../FCPXMLElementAnchorableAttributes.swift | 3 +- .../Story/Annotations/FCPXML Marker.swift | 19 +++-- .../Utilities/FCPXML Time Utilities.swift | 45 +---------- .../FCPXML/XML/FCPXML Attributes.swift | 74 ++++++++++++++----- .../FCPXML Time and Frame Rate Parsing.swift | 51 ++----------- 11 files changed, 90 insertions(+), 139 deletions(-) diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Context/FCPXML ElementContext Tools.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Context/FCPXML ElementContext Tools.swift index 2400885d..b1bfe55f 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Context/FCPXML ElementContext Tools.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Context/FCPXML ElementContext Tools.swift @@ -51,7 +51,6 @@ extension FinalCutPro.FCPXML.ElementContext { return try? element._fcpTimecode( fromRealTime: absoluteStart, frameRateSource: frameRateSource, - autoScale: false, breadcrumbs: breadcrumbs, resources: resources ) @@ -75,7 +74,6 @@ extension FinalCutPro.FCPXML.ElementContext { return try? element._fcpTimecode( fromRealTime: absoluteEnd, frameRateSource: frameRateSource, - autoScale: true, breadcrumbs: breadcrumbs, resources: resources ) @@ -128,7 +126,6 @@ extension FinalCutPro.FCPXML.ElementContext { return try? element._fcpTimecode( fromRealTime: parentAbsoluteStart, frameRateSource: frameRateSource, - autoScale: false, breadcrumbs: breadcrumbs, resources: resources ) @@ -152,7 +149,6 @@ extension FinalCutPro.FCPXML.ElementContext { return try? element._fcpTimecode( fromRealTime: parentAbsoluteEnd, frameRateSource: frameRateSource, - autoScale: true, breadcrumbs: breadcrumbs, resources: resources ) @@ -175,7 +171,6 @@ extension FinalCutPro.FCPXML.ElementContext { return try? element._fcpTimecode( fromRealTime: parentDuration, frameRateSource: frameRateSource, - autoScale: true, breadcrumbs: breadcrumbs, resources: resources ) diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Extraction/FCPXMLExtractedElement.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Extraction/FCPXMLExtractedElement.swift index b0b3d4f3..38aa2895 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Extraction/FCPXMLExtractedElement.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Extraction/FCPXMLExtractedElement.swift @@ -48,7 +48,6 @@ extension FCPXMLExtractedElement { return try? element._fcpTimecode( fromRational: duration, frameRateSource: frameRateSource, - autoScale: true, breadcrumbs: breadcrumbs, resources: resources ) diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Common/Elements/FCPXML TimeMap TimePoint.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Common/Elements/FCPXML TimeMap TimePoint.swift index 5f29941d..fb9760f6 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Common/Elements/FCPXML TimeMap TimePoint.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Common/Elements/FCPXML TimeMap TimePoint.swift @@ -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) } } @@ -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) } } } diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementDuration.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementDuration.swift index 9a5b4e46..9e12163f 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementDuration.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementDuration.swift @@ -26,8 +26,7 @@ extension FCPXMLElementRequiredDuration { ) -> Timecode? { try? element._fcpTimecode( fromRational: duration, - frameRateSource: frameRateSource, - autoScale: true + frameRateSource: frameRateSource ) } } @@ -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 ) } } diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementStart.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementStart.swift index ea190b8a..e79a45b8 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementStart.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementStart.swift @@ -26,8 +26,7 @@ extension FCPXMLElementRequiredStart { ) -> Timecode? { try? element._fcpTimecode( fromRational: start, - frameRateSource: frameRateSource, - autoScale: true + frameRateSource: frameRateSource ) } } @@ -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 ) } } diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementTCStart.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementTCStart.swift index 506f89f3..5a98ec79 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementTCStart.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Single Attributes/FCPXMLElementTCStart.swift @@ -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 ) } } diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Story Elements/FCPXMLElementAnchorableAttributes.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Story Elements/FCPXMLElementAnchorableAttributes.swift index 720161d2..4179e89a 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Story Elements/FCPXMLElementAnchorableAttributes.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Protocols/Story Elements/FCPXMLElementAnchorableAttributes.swift @@ -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 ) } } diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Story/Annotations/FCPXML Marker.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Story/Annotations/FCPXML Marker.swift index 014e533a..d13641e2 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Story/Annotations/FCPXML Marker.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Model/Story/Annotations/FCPXML Marker.swift @@ -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 ) } } @@ -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 + ) } } } diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/Utilities/FCPXML Time Utilities.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/Utilities/FCPXML Time Utilities.swift index 3aeac32f..c85c614b 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/Utilities/FCPXML Time Utilities.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/Utilities/FCPXML Time Utilities.swift @@ -17,7 +17,6 @@ extension XMLElement { func _fcpTimecode( fromRational rawString: String, tcFormat: FinalCutPro.FCPXML.TimecodeFormat, - autoScale: Bool, resourceID: String, resources: XMLElement? = nil ) throws -> Timecode? { @@ -27,7 +26,6 @@ extension XMLElement { return try _fcpTimecode( fromRational: fraction, tcFormat: tcFormat, - autoScale: autoScale, resourceID: resourceID, resources: resources ) @@ -37,7 +35,6 @@ extension XMLElement { func _fcpTimecode( fromRational fraction: Fraction, tcFormat: FinalCutPro.FCPXML.TimecodeFormat, - autoScale: Bool, resourceID: String, resources: XMLElement? = nil ) throws -> Timecode? { @@ -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 ) } @@ -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? { @@ -81,7 +69,6 @@ extension XMLElement { return try _fcpTimecode( fromRational: fraction, frameRateSource: frameRateSource, - autoScale: autoScale, breadcrumbs: breadcrumbs, resources: resources ) @@ -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 ) @@ -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? { @@ -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) } } @@ -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? { @@ -187,7 +159,6 @@ extension XMLElement { return try _fcpTimecodeInterval( fromRational: fraction, frameRateSource: frameRateSource, - autoScale: autoScale, breadcrumbs: breadcrumbs, resources: resources ) @@ -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 ) @@ -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? { @@ -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 diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/XML/FCPXML Attributes.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/XML/FCPXML Attributes.swift index e1a647ee..fef6bd11 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/XML/FCPXML Attributes.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/XML/FCPXML Attributes.swift @@ -66,47 +66,54 @@ extension XMLElement { extension XMLElement { /// FCPXML: Get or set the value of the `audioStart` attribute. + /// Scales value if containing clip has a `conform-rate` child element. /// Use on `asset-clip`, `clip`, `mc-clip`, `ref-clip` or `sync-clip`. public var fcpAudioStart: Fraction? { - get { _fcpGetFraction(forAttribute: "audioStart") } - set { _fcpSet(fraction: newValue, forAttribute: "audioStart") } + get { _fcpGetFraction(forAttribute: "audioStart", scaled: true) } + set { _fcpSet(fraction: newValue, forAttribute: "audioStart", scaled: true) } } /// FCPXML: Get or set the value of the `audioDuration` attribute. + /// Scales value if containing clip has a `conform-rate` child element. /// Use on `asset-clip`, `clip`, `mc-clip`, `ref-clip` or `sync-clip`. public var fcpAudioDuration: Fraction? { - get { _fcpGetFraction(forAttribute: "audioDuration") } - set { _fcpSet(fraction: newValue, forAttribute: "audioDuration") } + get { _fcpGetFraction(forAttribute: "audioDuration", scaled: true) } + set { _fcpSet(fraction: newValue, forAttribute: "audioDuration", scaled: true) } } /// FCPXML: Get or set the value of the `duration` attribute. + /// Scales value if containing clip has a `conform-rate` child element. public var fcpDuration: Fraction? { - get { _fcpGetFraction(forAttribute: "duration") } - set { _fcpSet(fraction: newValue, forAttribute: "duration") } + get { _fcpGetFraction(forAttribute: "duration", scaled: true) } + set { _fcpSet(fraction: newValue, forAttribute: "duration", scaled: true) } } /// FCPXML: Get or set the value of the `frameDuration` attribute. + /// Scales value if containing clip has a `conform-rate` child element. public var fcpFrameDuration: Fraction? { - get { _fcpGetFraction(forAttribute: "frameDuration") } - set { _fcpSet(fraction: newValue, forAttribute: "frameDuration") } + get { _fcpGetFraction(forAttribute: "frameDuration", scaled: true) } + set { _fcpSet(fraction: newValue, forAttribute: "frameDuration", scaled: true) } } /// FCPXML: Get or set the value of the `start` attribute. + /// Scales value if containing clip has a `conform-rate` child element. public var fcpStart: Fraction? { - get { _fcpGetFraction(forAttribute: "start") } - set { _fcpSet(fraction: newValue, forAttribute: "start") } + get { _fcpGetFraction(forAttribute: "start", scaled: true) } + set { _fcpSet(fraction: newValue, forAttribute: "start", scaled: true) } } /// FCPXML: Get or set the value of the `tcStart` attribute. + /// Scales value if containing clip has a `conform-rate` child element. public var fcpTCStart: Fraction? { - get { _fcpGetFraction(forAttribute: "tcStart") } - set { _fcpSet(fraction: newValue, forAttribute: "tcStart") } + get { _fcpGetFraction(forAttribute: "tcStart", scaled: true) } + set { _fcpSet(fraction: newValue, forAttribute: "tcStart", scaled: true) } } /// FCPXML: Get or set the value of the `offset` attribute. + /// Scales value if containing clip has a `conform-rate` child element. public var fcpOffset: Fraction? { - get { _fcpGetFraction(forAttribute: "offset") } - set { _fcpSet(fraction: newValue, forAttribute: "offset") } + get { _fcpGetFraction(forAttribute: "offset", scaled: true) } + set { _fcpSet(fraction: newValue, forAttribute: "offset", scaled: true) } } /// FCPXML: Get or set the value of the `tcFormat` attribute. @@ -216,17 +223,44 @@ extension XMLElement { extension XMLElement { /// FCPXML: Get an attribute time value as a `Fraction` instance. - func _fcpGetFraction(forAttribute attributeName: String) -> Fraction? { - guard let value = stringValue(forAttributeNamed: attributeName) + func _fcpGetFraction( + forAttribute attributeName: String, + scaled: Bool + ) -> Fraction? { + guard let value = stringValue(forAttributeNamed: attributeName), + let base = Fraction(fcpxmlString: value) else { return nil } - return Fraction(fcpxmlString: value) + // scale if necessary + if scaled, + let scalingFactor = _fcpConformRateScalingFactor() + { + return Fraction(double: base.doubleValue * scalingFactor) + } else { + return base + } } /// FCPXML: Set an attribute time value from a `Fraction` instance. - func _fcpSet(fraction newValue: Fraction?, forAttribute attributeName: String) { - addAttribute(withName: attributeName, - value: newValue?.fcpxmlStringValue) + func _fcpSet( + fraction newValue: Fraction?, + forAttribute attributeName: String, + scaled: Bool + ) { + var newValue = newValue + + // scale if necessary + if scaled, + let _newValue = newValue, + let scalingFactor = _fcpConformRateScalingFactor() + { + newValue = Fraction(double: _newValue.doubleValue / scalingFactor) + } + + addAttribute( + withName: attributeName, + value: newValue?.fcpxmlStringValue + ) } } diff --git a/Sources/DAWFileKit/FinalCutPro/FCPXML/XML/FCPXML Time and Frame Rate Parsing.swift b/Sources/DAWFileKit/FinalCutPro/FCPXML/XML/FCPXML Time and Frame Rate Parsing.swift index 9dfbaf87..7a40f5c0 100644 --- a/Sources/DAWFileKit/FinalCutPro/FCPXML/XML/FCPXML Time and Frame Rate Parsing.swift +++ b/Sources/DAWFileKit/FinalCutPro/FCPXML/XML/FCPXML Time and Frame Rate Parsing.swift @@ -94,7 +94,6 @@ extension XMLElement { ) -> TimeInterval? { var accum: TimeInterval? var lastStart: TimeInterval? - var scaleFactor: Double? func add(_ value: TimeInterval?) { guard let value = value else { return } @@ -102,60 +101,29 @@ extension XMLElement { accum = base + value } - func scale(_ value: TimeInterval) -> TimeInterval { - guard let scaleFactor else { return value } - return value * scaleFactor - } - // iterate from root to current element var ancestors = Array(ancestorElements(overrideWith: ancestors, includingSelf: true)) - var consumedAncestors: [XMLElement] = [] while let ancestor = ancestors.popLast() { let elementType = ancestor.fcpElementType - defer { - // check for `conform-rate` scale factor - if let elementType = elementType, - FinalCutPro.FCPXML.ElementType.allClipCases.contains(elementType) - { - if let sf = ancestor._fcpConformRateScalingFactor( - ancestors: consumedAncestors, - sequenceFrameRate: nil, - includeSelf: true, - resources: resources - ) { - scaleFactor = sf - } else { - // reset scaling if clip does not require it - scaleFactor = nil - } - } - - // add consumed ancestor to array - consumedAncestors.insert(ancestor, at: 0) - } - if let tcStart = ancestor.fcpTCStart { assert(ancestor.fcpStart == nil) - let tcStartScaled = scale(tcStart.doubleValue) - add(tcStartScaled) - lastStart = tcStartScaled + add(tcStart.doubleValue) + lastStart = tcStart.doubleValue continue } if let offset = ancestor.fcpOffset { - let offsetScaled = scale(offset.doubleValue) - if let _lastStart = lastStart { - let diff = offsetScaled - _lastStart + let diff = offset.doubleValue - _lastStart lastStart = nil add(diff) } else { - add(offsetScaled) + add(offset.doubleValue) } } @@ -164,17 +132,15 @@ extension XMLElement { case .marker, .chapterMarker, .keyword: // markers and keywords use `start` attribute as an offset, so handle it specially if let elementStart = ancestor.fcpStart { - let elementStartScaled = scale(elementStart.doubleValue) - if let ancestorParent = ancestor.parentElement, let parentStart = ancestorParent.fcpStart { - let parentStartScaled = scale(parentStart.doubleValue) + let parentStartScaled = parentStart.doubleValue - let diffScaled = elementStartScaled - parentStartScaled + let diffScaled = elementStart.doubleValue - parentStartScaled add(diffScaled) } else { - add(elementStartScaled) + add(elementStart.doubleValue) } } case .caption: @@ -187,8 +153,7 @@ extension XMLElement { } if let start = ancestor.fcpStart { - let startScaled = scale(start.doubleValue) - lastStart = startScaled + lastStart = start.doubleValue } }