Skip to content

Commit

Permalink
Refactored RolesExtractor to be consistent with manifest file role …
Browse files Browse the repository at this point in the history
…name formatting (#69)
  • Loading branch information
orchetect committed Dec 15, 2023
1 parent c078f86 commit 4f79d0b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
27 changes: 16 additions & 11 deletions Sources/MarkersExtractor/Extractors/FCPXMLMarkerExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,8 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
}
}

// collapse subroles that are redundant
markerRoles.collapseSubroles()

// remove any roles with empty strings
markerRoles.removeEmptyStrings()

// FCP often writes built-in roles as lowercase strings
// (ie: "dialogue" or "dialogue.dialogue-1")
// so we will explicitly title-case these if encountered, so as to match
// FCP's title-cased display of these roles (ie: "Dialogue")
markerRoles.titleCaseBuiltInRoles()
// process markers
markerRoles.process()

return markerRoles
}
Expand All @@ -338,3 +329,17 @@ class FCPXMLMarkerExtractor: NSObject, ProgressReporting {
enableSubframes ? [.showSubFrames] : .default()
}
}

extension FCPXMLMarkerExtractor {
static func processExtractedRole<Role: FCPXMLRole>(role: Role) -> Role {
role
// collapse subroles that are redundant
.collapsingSubRole()

// FCP often writes built-in roles as lowercase strings
// (ie: "dialogue" or "dialogue.dialogue-1")
// so we will explicitly title-case these if encountered, so as to match
// FCP's title-cased display of these roles (ie: "Dialogue")
.titleCasedDefaultRole(derivedOnly: true)
}
}
23 changes: 13 additions & 10 deletions Sources/MarkersExtractor/Import/Marker/MarkerRoles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,27 @@ extension MarkerRoles {
}
}

/// FCP often writes built-in roles as lowercase strings
/// (ie: "dialogue" or "dialogue.dialogue-1").
/// This will title-cased these roles (ie: "Dialogue") to match FCP's display.
public mutating func titleCaseBuiltInRoles() {
/// Process markers, performing post-extraction formatting.
public mutating func process() {
removeEmptyStrings()
if var audioRoles = audio {
for index in audioRoles.indices {
if audioRoles[index].isMainRoleBuiltIn == true {
audioRoles[index] = audioRoles[index].titleCased(derivedOnly: true)
}
audioRoles[index] = FCPXMLMarkerExtractor
.processExtractedRole(role: audioRoles[index])
}
audio = audioRoles
}

if video?.isMainRoleBuiltIn == true {
video = video?.titleCased(derivedOnly: true)
if let videoRole = video {
video = FCPXMLMarkerExtractor
.processExtractedRole(role: videoRole)
}

// don't title-case caption roles.
if let captionRole = caption {
caption = FCPXMLMarkerExtractor
.processExtractedRole(role: captionRole)
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion Sources/MarkersExtractor/RolesExtractor/RolesExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
// Licensed under MIT License
//

import Foundation
import DAWFileKit
import Foundation
import OTCore

/// Returns all the roles used in a FCPXML document that are relevant to the main project
/// timeline.
///
/// Results will be formatted in the same manner as ``MarkersExtractor`` formats
/// roles for output manifest files.
///
/// Results will be sorted by type (video, audio, caption), then by name.
public final class RolesExtractor {
public var fcpxml: FCPXMLFile
Expand All @@ -22,6 +25,9 @@ public final class RolesExtractor {
/// Returns all the roles used in the FCPXML document that are relevant to the main project
/// timeline.
///
/// Results will be formatted in the same manner as ``MarkersExtractor`` formats
/// roles for output manifest files.
///
/// Results will be sorted by type (video, audio, caption), then by name.
///
/// - Returns: A flat array of roles.
Expand All @@ -38,6 +44,9 @@ public final class RolesExtractor {

let sorted = projectsRoles
.flatMap { $0 }
.map {
FCPXMLMarkerExtractor.processExtractedRole(role: $0)
}

return sorted
}
Expand Down

0 comments on commit 4f79d0b

Please sign in to comment.