You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.4 KiB

import Foundation
/// An NDI source as seen on the network.
public struct Source: Codable, Hashable, Sendable {
public var ndiName: String
public var label: String
public init(ndiName: String, label: String? = nil) {
self.ndiName = ndiName
self.label = label ?? Source.defaultLabel(for: ndiName)
}
/// NDI names look like "MACHINE (Stream)". The stream part is the friendlier label.
public static func defaultLabel(for ndiName: String) -> String {
guard let open = ndiName.firstIndex(of: "("),
let close = ndiName.lastIndex(of: ")"),
open < close
else { return ndiName }
let inner = ndiName[ndiName.index(after: open)..<close].trimmingCharacters(in: .whitespaces)
return inner.isEmpty ? ndiName : inner
}
}
public enum Role: String, Codable, CaseIterable, Sendable {
/// MacBook at the control desk: controls nodes, owns scenes.
case control
/// Mac mini on stage: follows the control, keeps its last state on its own.
case node
}
/// Which part of a stereo source feeds a mono output channel.
public enum ChannelSelection: String, Codable, CaseIterable, Sendable {
case left, right, mono
@inline(__always)
public func sample(left: Float, right: Float) -> Float {
switch self {
case .left: left
case .right: right
case .mono: 0.5 * (left + right)
}
}
}

Powered by TurnKey Linux.