Skip to content
Merged
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,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<Int>) -> 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.
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
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.
// 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])
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: 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)")
Expand Down
Loading
Loading