Swiftpack.co - Dev1an/Swift-Atem as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Dev1an.
Dev1an/Swift-Atem 2.0.0-alpha.2
Blackmagic Design Atem network protocol implementation in swift 5.1 using NIO 2
⭐️ 55
🕓 2 years ago
.package(url: "https://github.com/Dev1an/Swift-Atem.git", from: "2.0.0-alpha.2")

Swift 5.1 Platforms: macOS & Linux

Atem network protocol implementation

Implementation of BlackMagicDesign's ATEM communication protocol in Swift. It is written on top of Apple's networking library NIO and implements both sides of the protocol: the control panel and the switcher side. This means that you can not only use it to control atem switchers but also to connect to your control panels without the need for a switcher. Opening a whole new world of applications for the Atem control panels. An example can be found at Atem-Simulator

Starting from version 1.0.0 this package uses Swift 5 and NIO2.

Tested platforms

  • macOS 10.14.6 on a MacBook Pro retina 15" late 2013
  • macOS 10.15.3 on a MacBook Pro retina 15" late 2013
  • Raspbian GNU/Linux 9 stretch on a Raspberry Pi model 3 B
  • Raspbian GNU/Linux 10 Buster on a Raspberry Pi 4 model B Rev 1.2

Installation

When starting a new project: create a Swift package via SPM

# Shell
> swift package init # --type empty|library|executable|system-module

Then 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 resolve

Finally import the Atem module in your code

import Atem

You 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
      )
    )
  }
}

GitHub

link
Stars: 55
Last commit: 25 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

V2 | Alpha 2
2 years ago

Version 2 is a breaking change that solves some bugs and many new features. This is a prerelease so some parts of the API can still change before the official release.

Bug fixes

  • use relative byte offset in ProductInfo decoding (2b9c5c505c1c0301dd8fb1b03a298d00603778d0)
  • fix faulty circular counter loop (47ab113df81c034841a0338ffe6297046938fab4)
  • fix mac host resolve errors (41918b73148c86220d75ee8cc4120207db2c65a9)
  • better duplicate packet resolution (039d761070030fe585d25a46ca9ae55cfa441635)
  • handle packets in correct order (bd73571c83849efff6b898adf08230cd7732af40)
  • match session IDs (e23b581b5fbad571d458bf1429bc1feca10f675c)
  • removed memory leak (57d675344c2f7eacadefb612ed498cfb1cbab265)
  • reuse the same NIO EventLoopGroup (727fbadd068d9e43642a4f4da4f8689299d83899)

New features

New in Alpha 2

  • Switch back to swift-tools-version:5.5 now that Swift 5.5 is officially released (4a97aa17a62eb430b8bc15a22e679751c2c6a8da)
  • Update Swift-NIO to fix compatibility issue in Xcode 13 (fd8d070f0477b28727ad16b159f04b4f35cfb7c9)

New in Alpha 1

  • Add DocC documentation pages (dc9b45e165a11c1e7000f1a2a926ec49d528b85e)
  • Static Strings for message titles (5d9f39e276bcde2468fe31626cfaad0337b13434)
  • Continuous integration for macOS and Ubuntu using GH actions (ed5588da9e905e330bb41a0eb6210b7be665f40c)
  • Added context references to message handlers (4beb49d28ec01e6e6137f493fd4d190747578c5a)
  • Added onError an onDisconnect handlers (a0b1bdf288d240340a4c2090b71928b8e46f93c2)
  • Use max amount of processor-cores (68203184b89cb13e867adfcd620a69e657ff4666)
  • Temporal disconnection detection (1608b356d7371cbde7993ed7c1a8b92a8ab48281)
  • Public controller IP address (794c9c4384c0a887864677c4d8477b8644682dd6)
  • Bonjour discovery (cf29aaf51b58658a08921b9b3cbb04844421bc0c)
  • Media (de)compression functions (671946cc758a2591d7e14d13236bca6c1698dac5)
  • Media coding functions (fa866ac8fa455918a932b55089fbca239fd271f7)
  • a Media manager for the Controller side (1f9014210e79f0728e4bc0425001f73e82e4b336)
  • Added support for big endian systems (ab0aa1906242187c159d53d09013d5ca208d2c71)
  • Added new message definitions for:
    • “_MeC”, “_mpl”, “_MvC” messages (38cbcb6e76b0573ec1aca85d28a7b76605394c05)
    • Data transfers (2fe41e1fefb11000c982a670116c2f9cba6ee8fb)
    • Timecodes (f8e9ebc86c6db876530ab395236950b00dba97f6)
    • ChangeKeyDVE (24757eea1b64a21ed30bd97adc46c1f3c55aa081)
  • Added examples
    • PreviewSwitcher (73b0c3e10dc92820a0f2e58cad59597cef3f1f6b)
    • MediaConverter (671946cc758a2591d7e14d13236bca6c1698dac5)
    • TitleGenerator (0db68982d5331a174916909cc055353b35bbe792)
    • SourceLabeler (7b864964284cf5d91537af2b6db56ce7c01ef99f)
    • Simulator
      • Receive small data transfers (3a34e8740a7e23c395f23702a0c34cc8ecc751f2)
  • More semantic naming
    • Do, Did, Config semantics (162ee2dac1c628a2a4372b2b8a9bf85adfa43153)
    • use BMD terminology for ME blocks (b81fc341bd76a5e810a214df2ccaffbb18b619be)
    • remove duplicate message definition (f6746ef79284f1f377c80ff1289b614ba89539fe)
    • remove AtemSize enum (60ef20920eb1d25fd9c771ba5886081837b60fdd)
  • Added tests
    • previously disabled tests (da06ce7a1ae6476749badb06d5877c14f0c053a9)
    • data transfer message tests (2fe41e1fefb11000c982a670116c2f9cba6ee8fb)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics