dev1an/swift-atem
Implementation of BlackMagicDesign's ATEM communication protocol in Swift. It is written on top of Apple's networking library [NIO](https://github.com/apple/swift-nio) and implements both sides of the protocol: the control panel and the switcher side. This means that you can not
Installation
When starting a new project: create a Swift package via SPM
# Shell
> swift package init # --type empty|library|executable|system-moduleThen add this library to the package description's dependencies
.package(url: "https://github.com/Dev1an/Swift-Atem", from: "1.0.0")And resolve this new dependency
# Shell
> swift package resolveFinally import the Atem module in your code
import AtemYou are now ready to create atem controllers and switchers 😎 !
Usage
After looking at the following examples, study the API reference for more details.
Controller
This example shows how to create a controller that connects to a swicther at ip address 10.1.0.67 and print a message whenever the preview bus changes.
try Controller(ipAddress: "10.1.0.67") { connection in
connection.when{ (change: PreviewBusChanged) in
print(change) // prints: 'Preview bus changed to input(x)'
}
}Sending messages
To send a message to the switcher use the send(...) method like this:
controller.send(message: ChangeTransitionPosition(to: 5000))Switcher
The following example shows how to emulate the basic functionality of an atem switcher. It will forward incoming messages containing transition and preview & program bus changes to all connected controllers.
This snippet is also included in a seperate SPM target "Simulator" (./Sources/Simulator) and can be run by simply executing swift run Simulator in the terminal.
let switcher = Switcher { controllers in
controllers.when { (change: ChangePreviewBus, _) in
controllers.send(
PreviewBusChanged(
to: change.previewBus,
mixEffect: change.mixEffect
)
)
}
controllers.when{ (change: ChangeProgramBus, _) in
controllers.send(
ProgramBusChanged(
to: change.programBus,
mixEffect: change.mixEffect
)
)
}
controllers.when { (change: ChangeTransitionPosition, _) in
controllers.send(
TransitionPositionChanged(
to: change.position,
remainingFrames: 250 - UInt8(change.position/40),
mixEffect: change.mixEffect
)
)
}
controllers.when { (change: ChangeAuxiliaryOutput, _) in
controllers.send(
AuxiliaryOutputChanged(
source: change.source,
output: change.output
)
)
}
}Package Metadata
Repository: dev1an/swift-atem
Default branch: master
README: README.md