Giter Club home page Giter Club logo

pipeline-neo's Introduction

Pipeline Neo

license platform

A Swift framework for working with Final Cut Pro's FCPXML.

Core Features

  • Access an FCPXML document's resources, events, clips, and projects through simple object properties.
  • Create and modify resources, events, clips, and projects with included properties and methods.
  • Easily manipulate timing values.
  • Output FCPXML files with proper text formatting.
  • Validate FCPXML documents with the DTD.
  • Works with FCPXML v1.6 through v1.8 files

Important

Pipeline Neo is not in active development.

Table of contents

Background

Pipeline was originally developed by Reuel Kim and it is no longer maintained. Pipeline Neo was created as a spin-off project to fix and update the library when necessary.

Pipeline Neo extends the XMLDocument and XMLElement classes in the Foundation framework. It adds properties and methods that simplify the creation and management of FCPXML document structure.

Pipeline Neo also includes supplemental classes and a CMTime extension to help in the processing of FCPXML data. For example, you can easily convert a timing value that looks like 59983924/30000s in the XML to 00:33:19,464 for display in an app.

Documentation

The latest framework documentation is viewable at reuelk.github.io/pipeline and is also included in the project's docs folder as HTML files.

Usage

To use this package in a SwiftPM project, you need to set it up as a package dependency:

// swift-tools-version:5.6
import PackageDescription

let package = Package(
  name: "MyPackage",
  dependencies: [
    .package(
      url: "https://github.com/TheAcharya/pipeline-neo",
      .upToNextMajor(from: "0.1.0") // or `.upToNextMinor
    )
  ],
  targets: [
    .target(
      name: "MyTarget",
      dependencies: [
        .product(name: "pipeline-neo", package: "pipeline-neo")
      ]
    )
  ]
)

Examples

Open an FCPXML File

Subsequent examples use the fcpxmlDoc object declared here.

// Change the path below to your FCPXML file's path
let fileURL = URL(fileURLWithPath: "/Users/[username]/Documents/sample.fcpxml")  // Create a new URL object that points to the FCPXML file's path.

do {
	try fileURL.checkResourceIsReachable()
} catch {
	print("The file cannot be found at the given path.")
	return
}

let fcpxmlDoc: XMLDocument  // Declare the fcpxmlDoc constant as an XMLDocument object

do {
	fcpxmlDoc = try XMLDocument(contentsOfFCPXML: fileURL)  // Load the FCPXML file using the fileURL object
} catch {
	print("Error loading FCPXML file.")
	return
}

List the Names of All Events

let eventNames = fcpxmlDoc.fcpxEventNames  // Get the event names in the FCPXML document
dump(eventNames)  // Neatly display all of the event names

Create and Add a New Event

let newEvent = XMLElement().fcpxEvent(name: "My New Event")  // Create a new empty event
fcpxmlDoc.add(event: newEvent)  // Add the new event to the FCPXML document
dump(fcpxmlDoc.fcpxEventNames) // Neatly display all of the event names

Get Clips That Match a Resource ID and Delete Them

let firstEvent = fcpxmlDoc.fcpxEvents[0]  // Get the first event in the FCPXML document
let matchingClips = try! firstEvent.eventClips(forResourceID: "r1")  // Get any clips that match resource ID "r1".

// The eventClips(forResourceID:) method throws an error if the XMLElement that calls it is not an event. Since we know that firstEvent is an event, it is safe to use "try!" to override the error handling.

try! firstEvent.removeFromEvent(items: matchingClips)  // Remove the clips that reference resource "r1".

guard let resource = fcpxmlDoc.resource(matchingID: "r1") else {  // Get the "r1" resource
	return
}
fcpxmlDoc.remove(resourceAtIndex: resource.index)  // Remove the "r1" resource from the FCPXML document

Display the Duration of a Clip

let firstEvent = fcpxmlDoc.fcpxEvents[0]  // Get the first event in the FCPXML document

guard let eventClips = firstEvent.eventClips else {  // Get the event clips while guarding against a potential nil value
	return
}

if eventClips.count > 0 {  // Make sure there's at least one clip in the event
	let firstClip = eventClips[0]  // Get the first clip in the event
	let duration = firstClip.fcpxDuration  // Get the duration of the clip
	let timeDisplay = duration?.timeAsCounter().counterString  // Convert the duration, which is a CMTime value, to a String formatted as HH:MM:SS,MMM
	print(timeDisplay) 
}

Save the FCPXML File

do {
	// Change the path below to your new FCPXML file's path
	try fcpxmlDoc.fcpxmlString.write(toFile: "/Users/[username]/Documents/sample-output.fcpxml", atomically: false, encoding: String.Encoding.utf8)
	print("Wrote FCPXML file.")
} catch {
	print("Error writing to file.")
}

Understanding FCPXML

Further information on FCPXML can be found here.

Credits

Original Work by Reuel Kim (0.5 ... 0.6)

Icon Design by Bor Jen Goh

License

Licensed under the MIT license. See LICENSE for details.

Reporting Bugs

For bug reports, feature requests and other suggestions you can create a new issue to discuss.

pipeline-neo's People

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.