Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions App/BridgeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ final class BridgeStatus {
var devices: [DeviceStatus] = []
/// Whether Syndicate's feedback is arriving (#21): the listener can be up while Syndicate is quiet or gone.
var syndicateFeedback: FeedbackState = .waiting
/// Syndicate answers with no deck info: its OSC FEEDBACK subscriptions are off (#150).
var noDeckData = false
/// LED subscriptions a loaded deck's answer lacked (#150).
var missingSubscriptions: [Subscription] = []
/// The last time Syndicate's feedback stopped, for the menu.
var lastDropout: String?
/// When feedback last dropped, as the time to show ("21:14"), stamped as it happens (#66).
Expand Down
2 changes: 2 additions & 0 deletions App/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum BridgeHost {
status.lastDropoutTime = Date.now.formatted(date: .omitted, time: .shortened)
}
status.syndicateFeedback = coordinatorStatus.feedback
status.noDeckData = coordinatorStatus.noDeckData
status.missingSubscriptions = coordinatorStatus.missingSubscriptions
status.lastDropout = coordinatorStatus.lastDropout
status.sweeping = coordinatorStatus.sweeping
status.demo = coordinatorStatus.demo
Expand Down
14 changes: 14 additions & 0 deletions App/Snapshots.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ enum Snapshots {
$0.feedback = .listening(port: 9096)
$0.syndicateFeedback = .live
}),
// Syndicate's OSC FEEDBACK subscriptions off (#150): NO DECK DATA, and help naming them.
("feedback-no-deck-data", {
$0.bridges = [ControllerStatus(deck: 1, connected: true, profile: "Denon LC6000 PRIME")]
$0.feedback = .listening(port: 9096)
$0.syndicateFeedback = .live
$0.noDeckData = true
}),
// A loaded deck answered without Cues (#150): LIVE, and help about the pad colors.
("feedback-cues-missing", {
$0.bridges = [ControllerStatus(deck: 1, connected: true, profile: "Denon LC6000 PRIME")]
$0.feedback = .listening(port: 9096)
$0.syndicateFeedback = .live
$0.missingSubscriptions = [.cues]
}),
// Syndicate stopped answering (#21): DROPPED, and the last dropout under the lights.
("feedback-dropped", {
$0.bridges = [ControllerStatus(deck: 1, connected: true, profile: "Denon LC6000 PRIME")]
Expand Down
4 changes: 2 additions & 2 deletions App/StatusPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension BridgeStatus {
case .listening(let port):
switch syndicateFeedback {
case .waiting: .waiting(port: port)
case .live: .live(port: port)
case .live: noDeckData ? .noDeckData(port: port) : .live(port: port)
case .stale: .stopped(port: port)
}
case .portInUse(let port): .portInUse(port: port)
Expand All @@ -56,7 +56,7 @@ extension BridgeStatus {
controller: first?.controller ?? .notConnected, feedback: feedback, deck: first?.deck ?? deck,
stopped: problem != nil, lastDropout: lastDropoutTime, master: self.controller?.master == true, demo: demo,
lastEvent: first?.lastEvent, others: Array(entries.dropFirst()), stopReason: stopReason,
followsLayers: first?.followsLayers ?? false
followsLayers: first?.followsLayers ?? false, missingSubscriptions: missingSubscriptions.map(\.rawValue)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public final class Coordinator {
private var lastFeedbackAt: Double?
/// When the last Resend went out, while it waits for an answer. Any feedback is the answer.
private var resendSentAt: Double?
/// The answer to the last Resend (#150): when it went out, and the addresses that arrived within its window.
private var answer: (sentAt: Double, messages: [OSCMessage])?

/// Set while the Diagnostics window is open (#26); nil otherwise, so nothing is built for it during a set.
/// The LED sweep in progress: when it started, its steps and the next one to send.
Expand Down Expand Up @@ -302,6 +304,7 @@ public final class Coordinator {
runSweep()
for bridge in bridges { bridge.tick() }
checkLiveness()
checkSubscriptions()
disconnectFailedOutputs()
}

Expand Down Expand Up @@ -408,6 +411,8 @@ public final class Coordinator {
}
}
diagnostics?(.oscIn(message))
answer?.messages.append(message)
if SubscriptionCheck.provesSubscriptions(message.address) { status.noDeckData = false }
feedbackArrived()
for bridge in bridges { bridge.handle(message) }
for index in controllers.indices { status.controllers[index].master = controllers[index].bridge.isMaster }
Expand Down Expand Up @@ -458,6 +463,15 @@ public final class Coordinator {
}
}

/// Once a Resend's answer window closes, what the answer held shows which subscriptions are on (#150).
private func checkSubscriptions() {
guard let answer, clock.now - answer.sentAt >= Double(oscSettings.feedbackAnswerMs) / 1000 else { return }
self.answer = nil
guard let check = SubscriptionCheck(answer: answer.messages) else { return }
status.noDeckData = check.noDeckData
status.missingSubscriptions = check.missing
}

/// Syndicate didn't answer: show idle for its state until it's back.
private func feedbackStopped() {
let event = "Syndicate feedback stopped"
Expand Down Expand Up @@ -665,6 +679,7 @@ public final class Coordinator {
private func requestResend() {
guard resendSentAt == nil else { return }
resendSentAt = clock.now
answer = (clock.now, [])
controllers[0].bridge.send("Feedback/Resend", .int(1))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public struct CoordinatorStatus: Equatable, Sendable {
public var feedback: FeedbackState
/// The last time feedback stopped, for the menu.
public var lastDropout: String?
/// Syndicate answered a Resend with no deck or header values: its OSC FEEDBACK subscriptions are off (#150).
public var noDeckData = false
/// LED subscriptions a loaded deck's answer lacked (#150), in `Subscription` order. Empty when none are missing.
public var missingSubscriptions: [Subscription] = []
/// An LED sweep (#26) is running.
public var sweeping = false
/// The built-in demo controller (#64) is running instead of the real one.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Which of Syndicate's OSC FEEDBACK subscriptions are on, judged from its answer to a Resend (#150).

/// A Syndicate OSC FEEDBACK subscription that the controller's LEDs need.
public enum Subscription: String, CaseIterable, Equatable, Sendable {
/// Each is named for the deck value it sends, the last part of its address.
case playing, cues, sync, loop
}

/// Syndicate answers a Resend with every subscribed value, and always ColorPalette. Values for an empty deck aren't
/// sent, so only what arrived counts: missing values are judged only on a deck that reported Loaded 1.
struct SubscriptionCheck: Equatable {
/// The answer had no deck and no header values (BPM, Metronome, MasterVolume…): subscriptions are off.
var noDeckData: Bool
/// The LED subscriptions a loaded deck lacked.
var missing: [Subscription]

/// Nil for no answer at all: silence says nothing about subscriptions.
init?(answer messages: [OSCMessage]) {
guard !messages.isEmpty else { return nil }
noDeckData = !messages.contains { Self.provesSubscriptions($0.address) }
// Each deck's values, by deck number: the last two parts of /Syndicate/Deck/<n>/<Value>.
var values: [String: Set<String>] = [:]
var loaded: Set<String> = []
for message in messages {
let parts = message.address.lowercased().split(separator: "/")
guard parts.count >= 3, parts[parts.count - 3] == "deck" else { continue }
let deck = String(parts[parts.count - 2]), value = String(parts[parts.count - 1])
values[deck, default: []].insert(value)
if value == "loaded", message.arguments.first?.wholeNumber == 1 { loaded.insert(deck) }
}
missing = Subscription.allCases.filter { subscription in
loaded.contains { !(values[$0] ?? []).contains(subscription.rawValue) }
}
}

/// A deck or header value: some deck subscriptions are on.
static func provesSubscriptions(_ address: String) -> Bool {
let path = address.lowercased()
return path.contains("/deck/") || path.contains("/header/")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ public struct HelpMessage: Equatable, Sendable {
self.init(text: "No feedback from Syndicate yet. Set OSC FEEDBACK to 127.0.0.1 : \(port).", showsGuide: true)
case .stopped:
self.init(text: "Syndicate stopped answering. Is it still running? The LEDs catch up when it's back.", showsGuide: true)
case .starting, .live, .failed:
case .starting, .live, .noDeckData, .failed:
// Every controller counts (#89): the first that needs a hand, named by its number when there are several.
let all = [state.controller] + state.others.map(\.controller)
guard let index = all.firstIndex(where: { if case .connected = $0 { false } else { true } }) else { return nil }
guard let index = all.firstIndex(where: { if case .connected = $0 { false } else { true } }) else {
guard let subscriptions = Self.subscriptions(state) else { return nil }
self = subscriptions
return
}
let name = all.count > 1 ? "Controller \(index + 1)" : nil
switch all[index] {
case .notConnected:
Expand All @@ -57,4 +61,37 @@ public struct HelpMessage: Equatable, Sendable {
}
}
}

/// Syndicate's subscriptions off, or some LED ones missing on a loaded deck (#150).
private static func subscriptions(_ state: BridgeState) -> HelpMessage? {
let place = "Syndicate › Settings › OSC FEEDBACK"
if case .noDeckData = state.feedback {
return HelpMessage(text: "Syndicate isn't sending deck info. In \(place), turn on the subscriptions: \(list(SetupGuide.subscriptions)).",
showsGuide: true)
}
let missing = state.missingSubscriptions.compactMap { value in
SetupGuide.subscriptionName(for: value).map { (led: ledName(value), name: $0) }
}
guard !missing.isEmpty else { return nil }
let leds = list(missing.map(\.led)), names = list(missing.map(\.name))
let text = missing.count == 1
? "\(leds.prefix(1).uppercased() + leds.dropFirst()) need the \(names) subscription. Turn it on in \(place)."
: "\(leds.prefix(1).uppercased() + leds.dropFirst()) need the \(names) subscriptions. Turn them on in \(place)."
return HelpMessage(text: text, showsGuide: true)
}

/// What a subscription lights on the controller.
private static func ledName(_ value: String) -> String {
switch value {
case "playing": "the Play LED"
case "cues": "hot cue pad colors"
case "sync": "the Sync LED"
default: "the loop LEDs"
}
}

/// "A, B and C".
private static func list(_ items: [String]) -> String {
items.count < 2 ? items.joined() : items.dropLast().joined(separator: ", ") + " and " + items.last!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public struct SetupGuide: Equatable, Sendable {
"BPM/Sync", "Loop",
]

/// The subscription that sends a deck value (#150), by the value's name: "cues" is "Cues". Nil for one the guide
/// doesn't list.
public static func subscriptionName(for value: String) -> String? {
switch value {
case "playing": "Playing"
case "cues": "Cues"
case "sync": "BPM/Sync"
case "loop": "Loop"
default: nil
}
}

/// Bump when the steps change in a way a returning user should see.
public static let version = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public struct BridgeState: Equatable, Sendable {
case live(port: Int)
/// Listening, but Syndicate hasn't answered since launch (#21).
case waiting(port: Int)
/// Syndicate answers, but with no deck info: its OSC FEEDBACK subscriptions are off (#150).
case noDeckData(port: Int)
/// Listening, but Syndicate stopped answering (#21).
case stopped(port: Int)
/// Another app holds the port, so no feedback arrives.
Expand Down Expand Up @@ -105,10 +107,13 @@ public struct BridgeState: Equatable, Sendable {

/// The first controller follows its own deck layers (#79).
public var followsLayers = false
/// The LED subscriptions a loaded deck's feedback lacked (#150), by deck value name: "playing", "cues"…
public var missingSubscriptions: [String] = []

public init(controller: Controller, feedback: Feedback, deck: Int, stopped: Bool = false, lastDropout: String? = nil,
master: Bool = false, demo: Bool = false, lastEvent: String? = nil, others: [ControllerEntry] = [],
stopReason: StopReason = .midi, followsLayers: Bool = false) {
stopReason: StopReason = .midi, followsLayers: Bool = false, missingSubscriptions: [String] = []) {
self.missingSubscriptions = missingSubscriptions
self.stopReason = stopReason
self.followsLayers = followsLayers
self.demo = demo
Expand Down Expand Up @@ -274,6 +279,7 @@ public struct StatusPresentation: Equatable, Sendable {
let feedback: StatusLight = switch state.feedback {
case .starting: StatusLight(label: "FEEDBACK", word: "STARTING", tone: .idle)
case .live: StatusLight(label: "FEEDBACK", word: "LIVE", tone: .live)
case .noDeckData: StatusLight(label: "FEEDBACK", word: "NO DECK DATA", tone: .attention)
case .waiting: StatusLight(label: "FEEDBACK", word: "WAITING", tone: .idle)
case .stopped: StatusLight(label: "FEEDBACK", word: "DROPPED", tone: .attention)
case .portInUse(let port): StatusLight(label: "FEEDBACK", word: "PORT \(port) IN USE", tone: .error)
Expand Down Expand Up @@ -307,7 +313,10 @@ public struct StatusPresentation: Equatable, Sendable {
else { .attention }
lastDropout = state.lastDropout.map { CaptionedValue(caption: "Last dropout", value: $0) }
// Quitting stops a working set only while feedback is live, so that's when Quit asks first (#66).
if case .live = state.feedback { quitAsks = true } else { quitAsks = false }
switch state.feedback {
case .live, .noDeckData: quitAsks = true
default: quitAsks = false
}
// In demo mode a click would be held for the real controller and jump its deck later, unasked (#90).
deckPicker = state.stopped ? .hidden
: state.demo ? .disabled(reason: "Demo controller is on, so the deck stays put.") : .enabled
Expand Down
Loading
Loading