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
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ extension Bridge {
return slots + Array(repeating: 0, count: 8 - slots.count)
}

/// ColorPalette feedback: a slot, then its red, green and blue (0-255).
/// ColorPalette feedback: a slot, then its red, green and blue (0-255). Syndicate may send several slots in one
/// message, as OSC arrays, flattened to groups of four.
func colorPalette(_ arguments: [OSCArgument]) {
let numbers = arguments.compactMap(\.wholeNumber)
guard numbers.count >= 4 else { return }
palette[numbers[0]] = Array(numbers[1...3])
for start in stride(from: 0, through: numbers.count - 4, by: 4) {
palette[numbers[start]] = Array(numbers[(start + 1)...(start + 3)])
}
refreshLEDs()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,17 @@ public final class Coordinator {
/// An OSC feedback message from Syndicate. One listener fans out to every Bridge.
public func feedback(_ message: OSCMessage) {
// Syndicate's deck colors are cue palette slots 1, 3, 5 and 7 (#123).
if message.address.lowercased().hasSuffix("/colorpalette"),
let updated = syndicateDeckColors.updated(byPalette: noteBlackSlot(message.arguments.compactMap(\.wholeNumber))) {
syndicateDeckColors = updated
applyDeckColors()
// Several slots may come in one message (OSC arrays, flattened): one group of four per slot.
if message.address.lowercased().hasSuffix("/colorpalette") {
let numbers = message.arguments.compactMap(\.wholeNumber)
var colors = syndicateDeckColors
for start in stride(from: 0, to: numbers.count - 3, by: 4) {
if let updated = colors.updated(byPalette: noteBlackSlot(Array(numbers[start..<(start + 4)]))) { colors = updated }
}
if colors != syndicateDeckColors {
syndicateDeckColors = colors
applyDeckColors()
}
}
diagnostics?(.oscIn(message))
feedbackArrived()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ private struct OSCReader {
case "S": _ = try string()
case "b": _ = try take((Int(try uint32()) + 3) & ~3)
case "T", "F", "N", "I": break
// OSC 1.1 arrays carry no data of their own: Syndicate sends ColorPalette and others as "[iiii]", and the
// arguments inside are read in order, flattened.
case "[", "]": break
// Its size is unknown, so nothing after it can be read.
default: break tags
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,27 @@ struct DeckColorTests {
func ledPreview(rgb: [Int], shown: [Int]) {
#expect(DeckColors.ledPreview(rgb) == shown)
}

@Test("ColorPalette as Syndicate really sends it, an OSC array on the wire, moves deck 1's ring: slot 1 red = 48")
func paletteFromWireArray() throws {
let rig = try Self.onDeck(1)
let packet = OSCCodecTests.bytes("""
2f53796e 64696361 74652f43 6f6c6f72 50616c65 74746500
2c5b6969 69695d00
00000001 000000ff 00000000 00000000
""")
for message in try OSCPacket(decoding: packet).messages { rig.coordinator.feedback(message) }
#expect(rig.leds[40] == 48)
#expect(rig.coordinator.status.deckColors[1] == [255, 0, 0])
}

@Test("All eight slots in one ColorPalette message (flattened arrays): slot 3 red still moves deck 2's ring, 48")
func paletteAllSlotsInOneMessage() throws {
let rig = try Self.onDeck(2)
let slots: [[Int32]] = [[1, 0, 0, 255], [2, 0, 255, 0], [3, 255, 0, 0], [4, 0, 0, 255],
[5, 0, 255, 255], [6, 0, 0, 255], [7, 128, 0, 255], [8, 255, 0, 255]]
rig.coordinator.feedback(OSCMessage("/Syndicate/ColorPalette", slots.flatMap { $0 }.map { .int($0) }))
#expect(rig.leds[40] == 48)
#expect(rig.coordinator.status.deckColors[4] == [128, 0, 255])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ struct OSCCodecTests {
#expect(try OSCPacket(decoding: packet).messages == [OSCMessage("/a", [.int(7)])])
}

// Syndicate sends some feedback as OSC 1.1 arrays: the guide's "[i slot, i R, i G, i B]". Brackets carry no data;
// the arguments inside are read in order, flattened (live bug: ColorPalette arrived with no arguments).

@Test("An OSC array is flattened: ColorPalette ',[iiii]' 1, 255, 0, 0 decodes to four ints")
func decodesArray() throws {
let packet = Self.bytes("""
2f53796e 64696361 74652f43 6f6c6f72 50616c65 74746500
2c5b6969 69695d00
00000001 000000ff 00000000 00000000
""")
#expect(try OSCPacket(decoding: packet).messages == [
OSCMessage("/Syndicate/ColorPalette", [.int(1), .int(255), .int(0), .int(0)]),
])
}

@Test("Arrays of mixed arguments, one after another, flatten in order: ',[is][is]' 3, \"Drop\", 0, \"\"")
func decodesArraysInSequence() throws {
let packet = Self.bytes("""
2f610000
2c5b6973 5d5b6973 5d000000
00000003 44726f70 00000000
00000000 00000000
""")
#expect(try OSCPacket(decoding: packet).messages == [OSCMessage("/a", [.int(3), .string("Drop"), .int(0), .string("")])])
}

@Test("An unknown tag ends the arguments: the ones before it are kept")
func stopsAtUnknownTag() throws {
let packet = Self.bytes("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ struct PadsTests {
#expect(Self.padLEDs(rig)[0] == 3)
}

@Test("All eight slots in one ColorPalette message recolor the pads too: slot 3 blue lights pad 3 at 3")
func colorPaletteAllSlotsInOneMessage() throws {
let rig = try Self.startedRig()
rig.coordinator.feedback(Self.cues([3, 0, 0, 0, 0, 0, 0, 0]))
let slots: [Int32] = (1...8).flatMap { slot -> [Int32] in slot == 3 ? [3, 0, 0, 255] : [Int32(slot), 255, 255, 255] }
rig.coordinator.feedback(OSCMessage("/Syndicate/ColorPalette", slots.map { .int($0) }))
#expect(Self.padLEDs(rig)[0] == 3)
}

@Test("A dim cue color still lights: (40, 0, 0) rounds to black, so it lights red at the lowest level, 16")
func dimColorStillLights() throws {
let rig = try Self.startedRig()
Expand Down
Loading