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
2 changes: 2 additions & 0 deletions App/BridgeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down Expand Up @@ -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)

}

Expand Down
13 changes: 12 additions & 1 deletion App/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -25,9 +31,9 @@ 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 }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,40 @@ 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's yellow goes from vivid 56 to exact 57, and back")
func ringColorsSwitch() throws {
let rig = try Self.onDeck(2)
#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])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,27 +327,27 @@ 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.
// rgb222 3,2,1 = 57 exact, 3,2,0 = 56 vivid (#151).

@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, 56")
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: 56))
}

@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, 56")
func multiChannelRingInDeckColor() throws {
let rig = try Self.layered()
let output = try #require(rig.midi.outputs[Rig.lc6000Out.id])
Self.note(rig, channel: 1, 51, 0); Self.note(rig, channel: 2, 51, 127)
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: 56)))
}

@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)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ struct PadsTests {
#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, vivid since #151 (white out, strongest to 3, under 30 % dropped): deck 2 #ECCF65 → 3,2,0 = 56;
// deck 3 #C5754E → 3,1,0 = 52 (green is 33 % of red, so it stays orange); deck 4 #62929E → 0,2,3 = 11.
@Test("On decks 2, 3 and 4 the ring lights in that deck's badge color, vivid", arguments: [(2, UInt8(56)), (3, 52), (4, 11)])
func ringInDeckColor(deck: Int, velocity: UInt8) throws {
let rig = try Self.startedRig()
rig.coordinator.setDeck(deck, controller: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading