diff --git a/App/BridgeModel.swift b/App/BridgeModel.swift index e79c055..f6df934 100644 --- a/App/BridgeModel.swift +++ b/App/BridgeModel.swift @@ -207,6 +207,7 @@ final class BridgeModel { if new.followSyndicateDeckColors != old.followSyndicateDeckColors || new.customDeckColors != old.customDeckColors { producer.setDeckColors(followSyndicate: new.followSyndicateDeckColors, custom: new.customDeckColors) } + if new.ringColors != old.ringColors { producer.setRingColors(new.ringColors) } if new.feedbackPort != old.feedbackPort || new.feedbackListen != old.feedbackListen { listen(new) } } @@ -297,6 +298,7 @@ final class BridgeModel { } // The saved deck colors (#123), queued behind the Coordinator's start. pipe.producer.setDeckColors(followSyndicate: settings.followSyndicateDeckColors, custom: settings.customDeckColors) + pipe.producer.setRingColors(settings.ringColors) } diff --git a/App/SettingsView.swift b/App/SettingsView.swift index 41a1366..a8a605d 100644 --- a/App/SettingsView.swift +++ b/App/SettingsView.swift @@ -289,6 +289,17 @@ struct SettingsView: View { ? "Cue palette slots 1, 3, 5 and 7 in Syndicate's CUE COLORS, as they change" : "Your own colors, for the app's badges and the LC6000's ring") } + row("Ring colors") { + // Vivid keeps a color's hue on the LC6000's 64 colors; Exact rounds each channel (#151). + Picker("Ring colors", selection: settings.ringColors) { + Text("Vivid").tag(RingColors.vivid) + Text("Exact").tag(RingColors.exact) + } + .pickerStyle(.segmented).labelsHidden().fixedSize() + hint(settings.wrappedValue.ringColors == .vivid + ? "Strong colors on the ring and a held pad, keeping each hue" + : "Each channel rounded, as the pads' cue colors are; softer colors look paler") + } ForEach(1...4, id: \.self) { deck in row("Deck \(deck)") { HStack(spacing: Theme.Space.m) { @@ -300,7 +311,7 @@ struct SettingsView: View { // What the LC6000's ring will show: rgb222, so a subtle color may come out plainer. let shown = settings.wrappedValue.followSyndicateDeckColors ? deckColors[deck] : settings.wrappedValue.customDeckColors[deck] RoundedRectangle(cornerRadius: Theme.corner) - .fill(Color(RGB(deckColor: DeckColors.ledPreview(shown ?? [0, 0, 0])))) + .fill(Color(RGB(deckColor: DeckColors.ledPreview(shown ?? [0, 0, 0], mode: settings.wrappedValue.ringColors)))) .frame(width: 26, height: 26) .accessibilityLabel("Deck \(deck) on the LC6000") hint("On the LC6000") diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge+Pads.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge+Pads.swift index 2a46cb2..a98db88 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge+Pads.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge+Pads.swift @@ -85,7 +85,8 @@ extension Bridge { guard slot != 0 else { return Self.off } let color = palette[slot] ?? [255, 255, 255] // A held hot cue shows the brightest version of its color, so you can see which one is sounding. - return Self.velocity(held.contains(.pad(index)) ? Self.brightest(color) : color) + // Held, it's vivid too (#151), so the sounding cue stands out in its hue, not whiter. + return held.contains(.pad(index)) ? ringVelocity(Self.brightest(color)) : Self.velocity(color) } case .loop: return cues.map { $0 == 0 ? Self.off : Self.velocity(leds.loopPadColor) } case .roll: return Array(repeating: Self.velocity(leds.rollPadColor), count: cues.count) @@ -99,6 +100,17 @@ extension Bridge { return rgb.map { $0 * 255 / top } } + /// A vivid velocity (#151) for an [r, g, b] color: the ring, and a held pad. + static func vividVelocity(_ rgb: [Int]) -> UInt8 { + guard rgb.count == 3 else { return off } + return ControllerBridgeCore.vividVelocity(rgb[0], rgb[1], rgb[2]) + } + + /// The ring's and a held pad's velocity, by the Settings mapping (#151). + func ringVelocity(_ rgb: [Int]) -> UInt8 { + ringColors == .vivid ? Self.vividVelocity(rgb) : Self.velocity(rgb) + } + /// A pad or ring velocity for an [r, g, b] color. static func velocity(_ rgb: [Int]) -> UInt8 { // A user mapping can hold any list here until the mapping check (#24) refuses it. diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge+Timing.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge+Timing.swift index 92d046a..10d475c 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge+Timing.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge+Timing.swift @@ -35,7 +35,13 @@ extension Bridge { if let pulse = lastPulseTime, let beat = lastClockTime, clock.now - beat <= Self.clockTimeout { lit = lit && clock.now - pulse < Double(mapping.leds.pulseMs) / 1000 } - led(mapping.leds.ring, lit ? Self.velocity(ringColor) : Self.off) + led(mapping.leds.ring, lit ? ringVelocity(ringColor) : Self.off) + } + + /// Vivid or exact (#151): the ring and pads repaint. + func setRingColors(_ mode: RingColors) { + ringColors = mode + refreshLEDs() } /// New deck colors (#123): the ring repaints in its deck's. diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge.swift index 2233057..50b1907 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Bridge.swift @@ -80,6 +80,8 @@ final class Bridge { var keyLockOn = false /// The deck colors the ring shows (#122); a setting can replace the defaults (#123). var deckColors = DeckColors.defaults + /// Vivid or exact ring and held-pad colors (#151). + var ringColors = RingColors.vivid /// The address of a Reverse latched on with Shift + Censor (#114), so release-all turns it off on that deck. var latchedReverse: String? /// Lines for the log, taken by the Coordinator after each event (#114). diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Coordinator.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Coordinator.swift index cadd6c0..9ea5c70 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Coordinator.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Coordinator.swift @@ -24,9 +24,13 @@ public final class Coordinator { var deckColors: DeckColors { followSyndicateDeckColors ? syndicateDeckColors : customDeckColors } /// A Bridge for a controller, with the deck colors in use. + /// Settings' ring color mapping (#151). + private var ringColors = RingColors.vivid + private func makeBridge(_ mapping: Mapping) -> Bridge { let bridge = Bridge(mapping: mapping, osc: osc, clock: clock) bridge.deckColors = deckColors + bridge.ringColors = ringColors return bridge } @@ -654,6 +658,13 @@ public final class Coordinator { disconnectFailedOutputs() } + /// Settings (#151): vivid or exact ring colors, repainted at once. + public func setRingColors(_ mode: RingColors) { + ringColors = mode + for bridge in bridges { bridge.setRingColors(mode) } + disconnectFailedOutputs() + } + /// Settings (#19): the LEDs switch, for every controller. public func setLEDs(enabled: Bool) { ledsEnabled = enabled diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/DeckColors.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/DeckColors.swift index c483e10..c9c700b 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/DeckColors.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/DeckColors.swift @@ -2,6 +2,12 @@ /// /// One source of truth: the Presentation tests pin `DeckBadge`'s fills to `defaults`. A value, so a user setting can /// replace the defaults later (#123): the Bridge reads its colors from its own `deckColors`. +/// How the ring (and a held pad) turns a color into the LC6000's 64 (#151): vivid keeps the hue; exact rounds each +/// channel, as the pad cue colors do. +public enum RingColors: String, Equatable, Sendable, Codable, CaseIterable { + case vivid, exact +} + public struct DeckColors: Equatable, Sendable, Codable { /// [r, g, b] for decks 1-4. public var rgb: [Int: [Int]] @@ -25,21 +31,20 @@ public struct DeckColors: Equatable, Sendable, Codable { public subscript(deck: Int) -> [Int]? { rgb[deck] } /// The color as the LC6000 shows it, for Settings' preview swatch: the ring's rgb222 velocity, read back as RGB. - public static func ledPreview(_ rgb: [Int]) -> [Int] { + public static func ledPreview(_ rgb: [Int], mode: RingColors = .exact) -> [Int] { guard rgb.count == 3 else { return [0, 0, 0] } - let velocity = Int(rgbToVelocity(rgb[0], rgb[1], rgb[2])) + let velocity = Int(mode == .vivid ? vividVelocity(rgb[0], rgb[1], rgb[2]) : rgbToVelocity(rgb[0], rgb[1], rgb[2])) return [velocity >> 4 & 3, velocity >> 2 & 3, velocity & 3].map { $0 * 85 } } /// Whether the color is black, the one color the LC6000's ring can't show. public static func isBlack(_ rgb: some Collection) -> Bool { rgb.allSatisfy { $0 == 0 } } - public static let defaults = DeckColors(rgb: [ - 1: [0x6C, 0x72, 0x77], - 2: [0xEC, 0xCF, 0x65], - 3: [0xC5, 0x75, 0x4E], - 4: [0x62, 0x92, 0x9E], - ]) + /// Before Syndicate's palette arrives: its factory deck colors, cue palette slots 1, 3, 5 and 7 of the same + /// factory table the pads use (red, yellow, cyan, purple). + public static let defaults = DeckColors(rgb: Dictionary(uniqueKeysWithValues: (1...4).map { + ($0, Bridge.defaultPalette[2 * $0 - 1] ?? [0, 0, 0]) + })) /// After a ColorPalette message ([slot, r, g, b]): the deck whose slot it is (slot 2N−1 is deck N) takes the color. /// Nil when the message isn't a deck's slot, so nothing needs repainting. diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Engine.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Engine.swift index 38cf00a..7e183e8 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Engine.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Engine.swift @@ -44,6 +44,7 @@ public struct Engine { coordinator.setDevices(input: input, output: output, controller: controller) case .setLEDs(let enabled): coordinator.setLEDs(enabled: enabled) case .setDeckColors(let follow, let custom): coordinator.setDeckColors(followSyndicate: follow, custom: custom) + case .setRingColors(let mode): coordinator.setRingColors(mode) case .resync: coordinator.resync() case .setControllers(let entries): coordinator.setControllers(entries) case .setProfiles(let profiles): coordinator.setProfiles(profiles) @@ -84,7 +85,7 @@ public struct Engine { setDiagnostics(active, open: open) case .ledSweep(let delay): active.startLEDSweep(delay: delay) case .stopLEDSweep: active.stopLEDSweep() - case .setDeck, .setDevices, .setLEDs, .setDeckColors, .setControllers, .setProfiles, .resync: + case .setDeck, .setDevices, .setLEDs, .setDeckColors, .setRingColors, .setControllers, .setProfiles, .resync: if demo == nil { apply(event) } else { waiting.append(event) } case .demo(let on): if on, demo == nil, let makeDemo { diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/EventPipe.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/EventPipe.swift index 2adfae3..058f55f 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/EventPipe.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/EventPipe.swift @@ -21,6 +21,7 @@ public enum PipeEvent: Equatable, Sendable { case setDevices(input: MIDIEndpoint?, output: MIDIEndpoint?, controller: Int) case setLEDs(enabled: Bool) case setDeckColors(followSyndicate: Bool, custom: DeckColors) + case setRingColors(RingColors) /// The OSC destination opened late (#84): ask Syndicate to resend its state, since what was sent before was dropped. case resync case setControllers([ControllerSettings]) @@ -63,6 +64,7 @@ public struct EventPipe: Sendable { continuation.yield(.setDevices(input: input, output: output, controller: controller)) } public func setLEDs(enabled: Bool) { continuation.yield(.setLEDs(enabled: enabled)) } + public func setRingColors(_ mode: RingColors) { continuation.yield(.setRingColors(mode)) } public func setDeckColors(followSyndicate: Bool, custom: DeckColors) { continuation.yield(.setDeckColors(followSyndicate: followSyndicate, custom: custom)) } diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/MIDIValues.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/MIDIValues.swift index d842b3d..0357a44 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/MIDIValues.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/MIDIValues.swift @@ -32,3 +32,18 @@ func tempoSlider(from value14: Int, invert: Bool, deadZone: Double) -> Double { if abs(t) < deadZone { t = 0 } return min(1, max(-1, t)) } + +/// A vivid LC6000 color velocity that keeps the hue (#151), for the platter ring and a held pad. rgb222 rounding on +/// its own lands a color's weaker channels on level 1-2, which adds white and washes the color out on the unit. So: +/// take out the white (the smallest channel), scale the strongest channel to level 3, drop any channel under 30 % of +/// it, then quantize. A near-gray (saturation under 20 %) has no hue to keep and uses the exact mapping. +func vividVelocity(_ red: Int, _ green: Int, _ blue: Int) -> UInt8 { + let rgb = [red, green, blue].map { max(0, min(255, $0)) } + let top = rgb.max() ?? 0, bottom = rgb.min() ?? 0 + guard top > 0, Double(top - bottom) / Double(top) >= 0.2 else { return rgbToVelocity(red, green, blue) } + let levels = rgb.map { channel -> Int in + let share = Double(channel - bottom) / Double(top - bottom) + return share < 0.3 ? 0 : Int((share * 3).rounded()) + } + return UInt8(levels[0] << 4 | levels[1] << 2 | levels[2]) +} diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Settings.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Settings.swift index dcd5e02..b12c057 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Settings.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgeCore/Settings.swift @@ -16,12 +16,14 @@ public struct BridgeSettings: Codable, Equatable, Sendable { public var followSyndicateDeckColors = true /// The deck colors used while following is off (#123). public var customDeckColors = DeckColors.defaults + /// The ring's color mapping (#151). Vivid by default. + public var ringColors = RingColors.vivid /// Light or dark (#127). Syndicate's own LIGHT MODE can't be read over OSC, so the DJ picks it to match. public var appearance = Appearance.matchMacOS enum CodingKeys: String, CodingKey { case controllers, syndicateHost, syndicatePort, feedbackPort, feedbackListen, ledsEnabled - case followSyndicateDeckColors, customDeckColors, appearance + case followSyndicateDeckColors, customDeckColors, appearance, ringColors } /// Settings saved before #123 have no deck colors: they load with the defaults. @@ -36,6 +38,7 @@ public struct BridgeSettings: Codable, Equatable, Sendable { followSyndicateDeckColors = try c.decodeIfPresent(Bool.self, forKey: .followSyndicateDeckColors) ?? true customDeckColors = try c.decodeIfPresent(DeckColors.self, forKey: .customDeckColors) ?? .defaults appearance = try c.decodeIfPresent(Appearance.self, forKey: .appearance) ?? .matchMacOS + ringColors = try c.decodeIfPresent(RingColors.self, forKey: .ringColors) ?? .vivid } public init( @@ -80,6 +83,7 @@ extension BridgeSettings { out.followSyndicateDeckColors = pick(\.followSyndicateDeckColors) out.customDeckColors = pick(\.customDeckColors) out.appearance = pick(\.appearance) + out.ringColors = pick(\.ringColors) // Controllers: the draft's list (an add or remove is the DJ's edit), each field rebased where both had it. out.controllers = draft.controllers.indices.map { index in let edited = draft.controllers[index] diff --git a/Packages/ControllerBridgeKit/Sources/ControllerBridgePresentation/DeckBadge.swift b/Packages/ControllerBridgeKit/Sources/ControllerBridgePresentation/DeckBadge.swift index 42d36ed..2fad7d8 100644 --- a/Packages/ControllerBridgeKit/Sources/ControllerBridgePresentation/DeckBadge.swift +++ b/Packages/ControllerBridgeKit/Sources/ControllerBridgePresentation/DeckBadge.swift @@ -18,12 +18,12 @@ public struct DeckBadge: Equatable, Sendable { self.init(fill: fill, digit: Self.legibleDigit(on: fill)) } - /// Sampled from Syndicate's deck headers. + /// Syndicate's factory deck colors (cue palette slots 1, 3, 5 and 7), pinned to Core's DeckColors.defaults. static let fills: [Int: RGB] = [ - 1: RGB(hex: 0x6C7277), - 2: RGB(hex: 0xECCF65), - 3: RGB(hex: 0xC5754E), - 4: RGB(hex: 0x62929E), + 1: RGB(hex: 0xFF0000), + 2: RGB(hex: 0xFFFF00), + 3: RGB(hex: 0x00FFFF), + 4: RGB(hex: 0x8000FF), ] /// A deck outside 1-4. Badge colors are deck colors, not theme surfaces, so they don't change with the theme diff --git a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/DeckColorTests.swift b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/DeckColorTests.swift index 0985574..9e9f7be 100644 --- a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/DeckColorTests.swift +++ b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/DeckColorTests.swift @@ -127,4 +127,46 @@ struct DeckColorTests { #expect(rig.leds[40] == 48) #expect(rig.coordinator.status.deckColors[4] == [128, 0, 255]) } + + // #151: the ring is vivid. Take out the white (the smallest channel), scale the strongest to level 3, drop a channel + // under 30 % of it, quantize. A near-gray (saturation under 20 %) keeps the exact mapping. + static let vividCases: [([Int32], UInt8)] = [ + ([255, 0, 0], 48), // red, unchanged + ([128, 0, 255], 35), // purple: 50 % ≥ 30 %, so (2, 0, 3) + ([0, 200, 180], 15), // teal-ish: (0, 3, 3) + ([255, 180, 180], 48), // pastel: the white comes out, (3, 0, 0) + ([0x6C, 0x72, 0x77], 21), // near-gray: exact, (1, 1, 1) + ([255, 140, 0], 56), // orange stays orange, never red: (3, 2, 0) + ([0xC5, 0x75, 0x4E], 52), // a muted orange: green is 33 % ≥ 30 %, so (3, 1, 0), not red + ] + + @Test("Vivid ring colors from Syndicate's palette (slot 1, deck 1)", arguments: vividCases) + func vividRing(rgb: [Int32], velocity: UInt8) throws { + let rig = try Self.onDeck(1) + Self.palette(rig, slot: 1, rgb[0], rgb[1], rgb[2]) + #expect(rig.leds[40] == velocity) + } + + @Test("Switching ring colors to Exact repaints at once: deck 2 at #ECCF65 goes from vivid 56 to exact 57, and back") + func ringColorsSwitch() throws { + let rig = try Self.onDeck(2) + Self.palette(rig, slot: 3, 0xEC, 0xCF, 0x65) + #expect(rig.leds[40] == 56) + rig.coordinator.setRingColors(.exact) + #expect(rig.leds[40] == 57) + rig.coordinator.setRingColors(.vivid) + #expect(rig.leds[40] == 56) + } + + @Test("The LC6000 preview follows the ring mode: Syndicate's yellow is (255, 170, 85) exact, (255, 170, 0) vivid") + func previewFollowsMode() { + #expect(DeckColors.ledPreview([236, 207, 101], mode: .exact) == [255, 170, 85]) + #expect(DeckColors.ledPreview([236, 207, 101], mode: .vivid) == [255, 170, 0]) + #expect(DeckColors.ledPreview([255, 180, 180], mode: .vivid) == [255, 0, 0]) + } + + @Test("The default deck colors are Syndicate's factory cue palette slots 1, 3, 5 and 7: red, yellow, cyan, purple") + func defaultsAreFactorySlots() { + #expect(DeckColors.defaults == DeckColors(rgb: [1: [255, 0, 0], 2: [255, 255, 0], 3: [0, 255, 255], 4: [128, 0, 255]])) + } } diff --git a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/DemoTests.swift b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/DemoTests.swift index 539beaf..c6c047d 100644 --- a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/DemoTests.swift +++ b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/DemoTests.swift @@ -47,7 +47,7 @@ struct DemoTests { #expect(rig.session.status.feedback == .live) #expect(rig.session.status.controllers.map(\.connected) == [true]) // Play dim (stopped), Cue lit (loaded and stopped), pads 1-2 in cue colors red 48 and orange 56, ring 11. - #expect([rig.led[1], rig.led[2], rig.led[32], rig.led[33], rig.led[34], rig.led[40]] == [1, 127, 48, 56, 0, 21]) + #expect([rig.led[1], rig.led[2], rig.led[32], rig.led[33], rig.led[34], rig.led[40]] == [1, 127, 48, 56, 0, 48]) } @Test("The first seconds of the script: Play, a pitch fader move from center, a jog nudge, as literal OSC") diff --git a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/LayersTests.swift b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/LayersTests.swift index 0ac6c98..824449a 100644 --- a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/LayersTests.swift +++ b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/LayersTests.swift @@ -327,19 +327,19 @@ struct LayersTests { } // #122: the ring shows the deck the layer drives, so a layer change visibly changes it. Deck 2's badge #ECCF65 is - // rgb222 3,2,1 = 57. + // yellow (255, 255, 0), 3,3,0 = 60. - @Test("Normal mode: switching to layer 2 with deck 2 loaded repaints the ring on ch1 in deck 2's color, 57") + @Test("Normal mode: switching to layer 2 with deck 2 loaded repaints the ring on ch1 in deck 2's color, 60") func normalModeRingInDeckColor() throws { let rig = try Self.layered() rig.coordinator.feedback(OSCMessage("/Syndicate/Deck/2/Loaded", [.int(1)])) let output = try #require(rig.midi.outputs[Rig.lc6000Out.id]) output.sent.removeAll() Self.note(rig, channel: 2, 51, 127) - #expect(output.sent.last { if case .noteOn(0, 40, _) = $0 { true } else { false } } == .noteOn(channel: 0, note: 40, velocity: 57)) + #expect(output.sent.last { if case .noteOn(0, 40, _) = $0 { true } else { false } } == .noteOn(channel: 0, note: 40, velocity: 60)) } - @Test("Multi-channel mode: with layer 2 in front, deck 2's ring goes out on ch2 in deck 2's color, 57") + @Test("Multi-channel mode: with layer 2 in front, deck 2's ring goes out on ch2 in deck 2's color, 60") func multiChannelRingInDeckColor() throws { let rig = try Self.layered() let output = try #require(rig.midi.outputs[Rig.lc6000Out.id]) @@ -347,7 +347,7 @@ struct LayersTests { Self.note(rig, channel: 2, 1, 127) // Play on ch2: controls on ch2 output.sent.removeAll() rig.coordinator.feedback(OSCMessage("/Syndicate/Deck/2/Loaded", [.int(1)])) - #expect(output.sent.contains(.noteOn(channel: 1, note: 40, velocity: 57))) + #expect(output.sent.contains(.noteOn(channel: 1, note: 40, velocity: 60))) } @Test("A profile swap on layer 3 stays on layer 3: ch1 Play goes to deck 3, and only layer 3 paints the LEDs (#115)") diff --git a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/LivenessTests.swift b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/LivenessTests.swift index 8800efd..641a9f0 100644 --- a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/LivenessTests.swift +++ b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/LivenessTests.swift @@ -65,7 +65,7 @@ struct LivenessTests { rig.coordinator.midi(.noteOn(channel: 0, note: 22, velocity: 127), source: Rig.lc6000.id) // Key Lock on // Play, Sync, Master, Loop In, pad 1 (red, 48), ring (11) and Key Lock are lit. #expect([rig.leds[1], rig.leds[20], rig.leds[21], rig.leds[8], rig.leds[32], rig.leds[40], rig.leds[22]] - == [127, 127, 127, 127, 48, 21, 127]) + == [127, 127, 127, 127, 48, 48, 127]) Self.tick(rig, at: 10.5) Self.tick(rig, at: 12.4) diff --git a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/PadsTests.swift b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/PadsTests.swift index 4350ff9..226fa9d 100644 --- a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/PadsTests.swift +++ b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/PadsTests.swift @@ -227,21 +227,21 @@ struct PadsTests { } } - @Test("The platter ring (note 40) lights in deck 1's badge color (#6C7277) while a track is loaded: 0b00_01_01_01 = 21") + @Test("The platter ring (note 40) lights in deck 1's default color, Syndicate's factory red, while a track is loaded: 48") func ringFollowsLoaded() throws { let rig = try Self.startedRig() #expect(rig.leds[40] == 0) rig.coordinator.feedback(OSCMessage("/Syndicate/Deck/1/Loaded", [.int(1)])) - #expect(rig.leds[40] == 21) + #expect(rig.leds[40] == 48) rig.coordinator.feedback(OSCMessage("/Syndicate/Deck/1/Loaded", [.int(0)])) #expect(rig.leds[40] == 0) } - // #122: the ring shows the deck's badge color, worked by hand through rgb222 (round(c / 255 * 3) per channel): - // deck 2 #ECCF65 → 3,2,1 = 57; deck 3 #C5754E → 2,1,1 = 37; deck 4 #62929E → 1,2,2 = 26. - @Test("On decks 2, 3 and 4 the ring lights in that deck's badge color", arguments: [(2, UInt8(57)), (3, 37), (4, 26)]) + // #122: the defaults are Syndicate's factory deck colors, cue palette slots 3, 5 and 7: yellow (255, 255, 0) = + // 3,3,0 = 60; cyan (0, 255, 255) = 0,3,3 = 15; purple (128, 0, 255) = 2,0,3 = 35. + @Test("On decks 2, 3 and 4 the ring lights in that deck's default color", arguments: [(2, UInt8(60)), (3, 15), (4, 35)]) func ringInDeckColor(deck: Int, velocity: UInt8) throws { let rig = try Self.startedRig() rig.coordinator.setDeck(deck, controller: 0) @@ -262,7 +262,7 @@ struct PadsTests { let rig = try Rig(override: #"{ "leds": { "ring_color": [255, 0, 0] } }"#) rig.coordinator.start() rig.coordinator.feedback(OSCMessage("/Syndicate/Deck/1/Loaded", [.int(1)])) - #expect(rig.leds[40] == 21) + #expect(rig.leds[40] == 48) } @Test("Cues and Loaded feedback for another deck leave this controller's pads and ring alone") diff --git a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/SettingsTests.swift b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/SettingsTests.swift index 17c1142..610238c 100644 --- a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/SettingsTests.swift +++ b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/SettingsTests.swift @@ -279,6 +279,26 @@ struct SettingsTests { #expect(after.syndicatePort == 9191) } + // #151: the ring's color mapping. + + @Test("Ring colors default to Vivid; old settings load as Vivid; Exact round-trips and survives a rebase") + func ringColorsSetting() { + #expect(Self.defaults.ringColors == .vivid) + let store = MemoryStore() + store.values[BridgeSettings.storageKey] = Data(#""" + {"controllers":[{"deck":1}],"syndicateHost":"127.0.0.1","syndicatePort":9090,"feedbackPort":9096, + "feedbackListen":"thisMac","ledsEnabled":true} + """#.utf8) + #expect(BridgeSettings.load(from: store, defaults: Self.defaults).ringColors == .vivid) + var exact = Self.defaults + exact.ringColors = .exact + try? exact.save(to: store) + #expect(BridgeSettings.load(from: store, defaults: Self.defaults).ringColors == .exact) + var saved = Self.defaults + saved.controllers[0].deck = 2 + #expect(BridgeSettings.rebased(draft: exact, base: Self.defaults, onto: saved).ringColors == .exact) + } + @Test("A field the DJ also edited in Settings keeps the DJ's value") func editedFieldWins() { let base = Self.defaults diff --git a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/TimingTests.swift b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/TimingTests.swift index 417a7f8..dbfc6c9 100644 --- a/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/TimingTests.swift +++ b/Packages/ControllerBridgeKit/Tests/ControllerBridgeCoreTests/TimingTests.swift @@ -109,6 +109,16 @@ struct TimingTests { #expect([rig.leds[32], rig.leds[33]] == [2, 48]) } + @Test("A held pad is vivid (#151); unheld it keeps the exact cue color: pastel (255, 180, 180) is 58 unheld, 48 held") + func heldPadIsVivid() throws { + let rig = try Self.startedRig() + rig.coordinator.feedback(Self.palette(4, 255, 180, 180)) + rig.coordinator.feedback(Self.cues([4, 0, 0, 0, 0, 0, 0, 0])) + #expect(rig.leds[32] == 58) // exact: 3, 2, 2 + rig.coordinator.midi(.noteOn(channel: 0, note: 32, velocity: 127), source: Rig.lc6000.id) + #expect(rig.leds[32] == 48) // vivid: the white comes out, 3, 0, 0 + } + /// A started controller whose mapping sets `leds.beat_pulse`, with a track loaded so the ring is lit. final class PulseRig { let midi = Rig.FakeMIDISystem(sources: [Rig.lc6000], destinations: [Rig.lc6000Out]) @@ -141,20 +151,20 @@ struct TimingTests { } } - // The ring shows deck 1's badge color (#6C7277), 0b00_01_01_01 = 21 (#122). Pulses last pulse_ms, 100 ms by default. + // The ring shows deck 1's default color, Syndicate's factory red (255, 0, 0): 0b00_11_00_00 = 48 (#122). Pulses last pulse_ms, 100 ms by default. @Test("With beat pulse on, the ring is solid until a clock arrives, then lit for 100 ms after each beat") func ringPulsesOnBeat() throws { let rig = try PulseRig(beatPulse: "beat") - #expect(rig.ring(at: 9.0) == 21) + #expect(rig.ring(at: 9.0) == 48) rig.clockBeat(2, at: 10.0) - #expect(rig.ring(at: 10.0) == 21) - #expect(rig.ring(at: 10.09) == 21) + #expect(rig.ring(at: 10.0) == 48) + #expect(rig.ring(at: 10.09) == 48) #expect(rig.ring(at: 10.11) == 0) rig.clockBeat(3, at: 10.5) - #expect(rig.ring(at: 10.5) == 21) + #expect(rig.ring(at: 10.5) == 48) #expect(rig.ring(at: 10.61) == 0) } @@ -162,7 +172,7 @@ struct TimingTests { func ringPulsesOnDownbeat() throws { let rig = try PulseRig(beatPulse: "downbeat") rig.clockBeat(1, at: 20.0) - #expect(rig.ring(at: 20.05) == 21) + #expect(rig.ring(at: 20.05) == 48) #expect(rig.ring(at: 20.2) == 0) rig.clockBeat(2, at: 20.5) @@ -171,7 +181,7 @@ struct TimingTests { #expect(rig.ring(at: 21.55) == 0) rig.clockBeat(1, at: 22.0) - #expect(rig.ring(at: 22.05) == 21) + #expect(rig.ring(at: 22.05) == 48) } @Test("When the master clock stops for more than 2 s, the ring goes back to solid") @@ -180,7 +190,7 @@ struct TimingTests { rig.clockBeat(1, at: 30.0) #expect(rig.ring(at: 30.5) == 0) #expect(rig.ring(at: 31.9) == 0) - #expect(rig.ring(at: 32.1) == 21) + #expect(rig.ring(at: 32.1) == 48) } @Test("A downbeat pulse at a slow tempo stays pulsing: beats 2-4 count as the clock arriving") @@ -199,9 +209,9 @@ struct TimingTests { func pulseOffKeepsRingSolid() throws { let rig = try PulseRig(beatPulse: "off") rig.clockBeat(1, at: 50.0) - #expect(rig.ring(at: 50.5) == 21) + #expect(rig.ring(at: 50.5) == 48) rig.clockBeat(2, at: 51.0) - #expect(rig.ring(at: 51.5) == 21) + #expect(rig.ring(at: 51.5) == 48) } @Test("With no track loaded the ring stays off, even on a pulsed beat") diff --git a/Packages/ControllerBridgeKit/Tests/ControllerBridgePresentationTests/DeckBadgeTests.swift b/Packages/ControllerBridgeKit/Tests/ControllerBridgePresentationTests/DeckBadgeTests.swift index 80e5810..0ee0cbb 100644 --- a/Packages/ControllerBridgeKit/Tests/ControllerBridgePresentationTests/DeckBadgeTests.swift +++ b/Packages/ControllerBridgeKit/Tests/ControllerBridgePresentationTests/DeckBadgeTests.swift @@ -5,18 +5,14 @@ import Testing /// the ratios in the comments are worked from the WCAG formula. @Suite("Deck badge") struct DeckBadgeTests { - @Test("Deck 1 is gray with a white digit (4.9:1; near-black would be 3.8:1)") - func deckOne() { - #expect(DeckBadge(deck: 1) == DeckBadge(fill: RGB(hex: 0x6C7277), digit: RGB(hex: 0xFFFFFF))) - } - - @Test("Decks 2, 3 and 4 are yellow, orange-red and steel blue, each with a near-black digit", arguments: [ - (2, 0xECCF65), // near-black 12.0:1, white 1.5:1 - (3, 0xC5754E), // near-black 5.3:1, white 3.5:1 - (4, 0x62929E), // near-black 5.4:1, white 3.4:1 - ] as [(Int, UInt32)]) - func colorDecks(deck: Int, fill: UInt32) { - #expect(DeckBadge(deck: deck) == DeckBadge(fill: RGB(hex: fill), digit: RGB(hex: 0x141415))) + @Test("The deck badges are Syndicate's factory deck colors: red, yellow and cyan with a dark digit, purple with white", arguments: [ + (1, 0xFF0000, 0x141415), // dark 5.3:1, white 4.0:1 + (2, 0xFFFF00, 0x141415), + (3, 0x00FFFF, 0x141415), + (4, 0x8000FF, 0xFFFFFF), // white 6.3:1 + ] as [(Int, UInt32, UInt32)]) + func factoryDecks(deck: Int, fill: UInt32, digit: UInt32) { + #expect(DeckBadge(deck: deck) == DeckBadge(fill: RGB(hex: fill), digit: RGB(hex: digit))) } @Test("A deck outside 1–4 gets a neutral raised-gray badge with a white digit (10.1:1)", arguments: [0, 5, -1])