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.
35 lines
1.6 KiB
35 lines
1.6 KiB
/// Parses `--audio-route "<kind>:<source>=<device>:<channel>"` launch arguments (scripted tests until scenes exist).
|
|
///
|
|
/// `kind` is `ndi` (NDI source name) or `input` (input device name, substring match).
|
|
/// `device` is an output device name (substring match), `channel` is 1-based.
|
|
/// Example: `--audio-route "ndi:ZOWIEBOX (PGM)=MOTU:2"`
|
|
public enum AudioRouteArgument {
|
|
public enum Kind: String, Sendable { case ndi, input }
|
|
|
|
public struct Parsed: Equatable, Sendable {
|
|
public var kind: Kind
|
|
public var source: String
|
|
public var device: String
|
|
public var channel: Int // 1-based
|
|
}
|
|
|
|
public static func parse(_ arguments: [String]) -> [Parsed] {
|
|
zip(arguments, arguments.dropFirst()).compactMap { flag, value in
|
|
guard flag == "--audio-route",
|
|
let colon = value.firstIndex(of: ":"),
|
|
let kind = Kind(rawValue: String(value[..<colon])),
|
|
let equals = value.lastIndex(of: "="),
|
|
equals > colon
|
|
else { return nil }
|
|
let source = String(value[value.index(after: colon)..<equals])
|
|
let target = value[value.index(after: equals)...]
|
|
guard let lastColon = target.lastIndex(of: ":"),
|
|
let channel = Int(target[target.index(after: lastColon)...]), channel >= 1
|
|
else { return nil }
|
|
let device = String(target[..<lastColon])
|
|
guard !source.isEmpty, !device.isEmpty else { return nil }
|
|
return Parsed(kind: kind, source: source, device: device, channel: channel)
|
|
}
|
|
}
|
|
}
|