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
20 changes: 14 additions & 6 deletions tools/lc6000-display/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ In short:
- `0D`: chunks of a 21-bit offset plus the data as an MSB-first 7-bit bitstream
- `0E`: slot `01`, then the PNG's 32-bit byte-sum as 8 nibbles
3. **Commit:** wait for the `01 10 0F 00 01 00` acks, then send `7E 00 06 01` and `10`.
4. **Show:** `0A 01 00 01 0D`, which displays image index 01.
4. **Show:** `0A 01 00 <slot> 0D`, which displays the image in that slot.

The display shows uploads **rotated 180°**, so images are sent pre-rotated. Uploads move about 3.1 KB/s, so they're
for what changes rarely, not real-time readouts.
`0C`'s three bytes are only the 21-bit size. The slot is `0E`'s first byte and `0A`'s image index: djay keeps its
logo in slot 01 and loads cover art into slot 02 (#165).

The display shows uploads **rotated 180°**, so images are sent pre-rotated.

**Upload speed depends on the send API, not the unit.**
- `MIDISendSysex` paces SysEx at MIDI 1.0 speed (31,250 baud, about 3.1 KB/s), so a 30 KB image takes about 10 s.
- djay hands about 74 KB of cover art to CoreMIDI in about 40 ms, and the unit acks it all within about 1.1 s:
roughly 60–70 KB/s, as UMP or packet-list sends at USB speed.

For real-time readouts, djay also sends two channel messages to WD on ch1 (#165):
- **Pitch bend:** the platter marker. It's the virtual record's angle at 33⅓ rpm, wrapping once per turn, sent at
Expand All @@ -30,8 +37,8 @@ For real-time readouts, djay also sends two channel messages to WD on ch1 (#165)

| File | What it does |
|---|---|
| `jogbuild.py` | PNG in, upload out. `png` re-encodes a 198×198 PNG for the unit (rotated 180°, in the layout the unit has accepted). `plan` writes a `jogseq` plan. `selftest` runs round trips with no device. |
| `jogseq.swift` | Sends a plan to the unit once, listening on both ports. `dry` checks a plan and prints it. |
| `jogbuild.py` | PNG in, upload out. `png` re-encodes a 198×198 PNG for the unit (rotated 180°, in the layout the unit has accepted). `plan` writes a `jogseq` plan, into slot 1 or the slot given. `selftest` runs round trips with no device. |
| `jogseq.swift` | Sends a plan to the unit once, listening on both ports. `send` paces SysEx through `MIDISendSysex`; `burst` sends it as UMP packets at USB speed, as djay does, and checks the acks after. `dry` checks a plan and prints it. `selftest` checks the UMP packing. |
| `sysex_decode.py` | Reads a MIDI Monitor capture (`.mmon`, text export or `.syx`), groups the SysEx, and rebuilds image uploads as PNG files (`--dump DIR`). |
| `mmon_list.py` | Lists every message in a `.mmon`, with timing and "To"/"From" endpoints. |
| `images/deck-ring.png` | Our app icon at 198×198, as a source image, not rotated. |
Expand All @@ -45,7 +52,8 @@ python3 -I jogbuild.py selftest
python3 -I jogbuild.py plan images/deck-ring.png /tmp/deck-ring.plan
swiftc -O -swift-version 5 jogseq.swift -o /tmp/jogseq
/tmp/jogseq dry /tmp/deck-ring.plan # checks and prints; sends nothing
/tmp/jogseq send /tmp/deck-ring.plan # sends once: see the rules below
/tmp/jogseq send /tmp/deck-ring.plan # sends once, SysEx paced at MIDI 1.0 speed: see the rules below
/tmp/jogseq burst /tmp/deck-ring.plan # the same at USB speed (not yet tried on hardware)
```

A plan is one message per line: `<delay ms> WD|CTL <hex bytes>`, or `<delay ms> ACKS <count> <timeout ms>`, which
Expand Down
28 changes: 18 additions & 10 deletions tools/lc6000-display/jogbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"""Builds the LC6000 jog-display upload (#121, #165): a 198x198 PNG in, a jogseq plan out.

python3 -I jogbuild.py png <in.png> <out.png> re-encode for the unit: rotated 180°, the PNG layout it accepts
python3 -I jogbuild.py plan <in.png> <out.plan> the full host + upload + commit + show plan for jogseq
python3 -I jogbuild.py plan <in.png> <out.plan> [slot] the host + upload + commit + show plan for jogseq (slot 1)
python3 -I jogbuild.py selftest encoder round trips, no device

The recipe, as verified on hardware (see #121's recipe comment):
CTL F0 00 02 0B 7F 10 60 00 04 04 01 01 00 F7, then F0 00 20 7F 01 F7 host hello (without it: ack 06)
(0C's three bytes are only the 21-bit size; the slot is 0E's first byte and 0A's image index.)
WD 90 01 00, 0A 01 00 06 0D, 0C <size>, 0D <offset + 7-bit data>…, 0E <slot + byte-sum>
WD wait for the 01 10 0F 00 01 00 acks (06 = refused), then 7E 00 06 01, 10 (commit; unit answers 01 10 10)
WD 0A … 01 00 01 0D show image index 01
WD 0A … 01 00 <slot> 0D show the uploaded slot (djay: 01 logo, 02 cover art)
Frame: F0 00 02 0B <target 7F> 10 <cmd> <len, 14-bit> <payload> F7.
"""
import struct
Expand All @@ -26,7 +27,11 @@
]
HOST_GOODBYE = [0xF0, 0x00, 0x20, 0x7F, 0x02, 0xF7]
SHOW_BLANK = [0x01, 0x00, 0x06, 0x0D] # 0A before an upload: image index 06
SHOW_INDEX_1 = [0x01, 0x00, 0x01, 0x0D] # 0A after the commit: image index 01, the upload


def show(slot):
"""0A after the commit: show image index `slot`, the upload's slot (djay: 01 for its logo, 02 for cover art)."""
return [0x01, 0x00, slot, 0x0D]


def frame(cmd, payload):
Expand Down Expand Up @@ -147,19 +152,19 @@ def hexs(msg):
return ' '.join(f'{b:02X}' for b in msg)


def plan(png):
"""A jogseq plan: hello, upload, wait for the acks, commit, show index 01."""
msgs = upload(png)
def plan(png, slot=1):
"""A jogseq plan: hello, upload into `slot`, wait for the acks, commit, show that slot."""
msgs = upload(png, slot)
body, commit = msgs[:-1], msgs[-1]
lines = ["# LC6000 jog upload (#121): host hello, upload, acks, commit, show index 01"]
lines = [f"# LC6000 jog upload (#121): host hello, upload to slot {slot}, acks, commit, show index {slot}"]
lines += [f"0 CTL {hexs(m)}" for m in HOST_HELLO]
lines.append("0 WD 90 01 00")
lines += [f"{8 if i == 1 else 0} WD {hexs(m)}" for i, m in enumerate(body)]
# Each upload message but one is acked: the count seen on hardware.
lines.append(f"0 ACKS {len(body) - 1} 20000")
lines.append(f"0 WD {hexs([0xF0, 0x7E, 0x00, 0x06, 0x01, 0xF7])}")
lines.append(f"10 WD {hexs(commit)}")
lines.append(f"500 WD {hexs(frame(0x0A, SHOW_INDEX_1))}")
lines.append(f"500 WD {hexs(frame(0x0A, show(slot)))}")
return '\n'.join(lines) + '\n'


Expand All @@ -177,18 +182,21 @@ def selftest():
assert sysex_decode.lc6000_images(messages) == [png], "upload rebuilds to the same PNG"
assert commit_0e(bytes([1, 2, 3])) == [1, 0, 0, 0, 0, 0, 0, 0, 6], "byte-sum as nibbles"
assert commit_0e(bytes([0xFF] * 0x3AEE))[1:] == [(0x3AEE * 0xFF >> s) & 0xF for s in range(28, -4, -4)]
slot2 = plan(png, slot=2)
assert "7F 10 0E 00 09 02 " in slot2, "0E names the slot"
assert slot2.rstrip().endswith("7F 10 0A 00 04 01 00 02 0D F7"), "the show index is the slot"
print("selftest ok:", len(png), "byte PNG,", len(messages), "messages")


if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'selftest':
selftest()
elif len(sys.argv) == 4 and sys.argv[1] in ('png', 'plan'):
elif len(sys.argv) in (4, 5) and sys.argv[1] in ('png', 'plan'):
source = open(sys.argv[2], 'rb').read()
if sys.argv[1] == 'png':
open(sys.argv[3], 'wb').write(for_unit(source))
else:
open(sys.argv[3], 'w').write(plan(for_unit(source)))
open(sys.argv[3], 'w').write(plan(for_unit(source), slot=int(sys.argv[4]) if len(sys.argv) == 5 else 1))
else:
print(__doc__)
sys.exit(2)
51 changes: 50 additions & 1 deletion tools/lc6000-display/jogseq.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,43 @@ func name(_ e: MIDIEndpointRef) -> String {
MIDIObjectGetStringProperty(e, kMIDIPropertyDisplayName, &s)
return (s?.takeRetainedValue() as String?) ?? "?"
}
/// One SysEx message (F0 … F7) as UMP SysEx7 packets of two words each: the bytes between F0 and F7, six at a time.
func sysex7Packets(_ message: [UInt8]) -> [[UInt32]] {
let body = Array(message.dropFirst().dropLast())
let pieces = stride(from: 0, to: max(body.count, 1), by: 6).map { Array(body[$0..<min($0 + 6, body.count)]) }
return pieces.enumerated().map { index, piece in
let status: UInt32 = pieces.count == 1 ? 0 : index == 0 ? 1 : index == pieces.count - 1 ? 3 : 2
let b = piece.map(UInt32.init) + Array(repeating: 0, count: 6 - piece.count)
return [0x3000_0000 | status << 20 | UInt32(piece.count) << 16 | b[0] << 8 | b[1],
b[2] << 24 | b[3] << 16 | b[4] << 8 | b[5]]
}
}

func hex(_ b: [UInt8], _ n: Int = 12) -> String {
b.prefix(n).map { String(format: "%02X", $0) }.joined(separator: " ") + (b.count > n ? " … (\(b.count) B)" : "")
}

enum Step { case send(port: String, bytes: [UInt8]); case acks(count: Int, timeoutMs: Int) }
let args = CommandLine.arguments
guard args.count == 3, ["dry", "send"].contains(args[1]) else { print("usage: dry|send <plan>"); exit(2) }
if args.count == 2 && args[1] == "selftest" {
// UMP SysEx7 (MIDI 2.0 spec, type 3): up to 6 bytes a packet; status 0 complete, 1 start, 2 continue, 3 end.
func hex(_ packets: [[UInt32]]) -> String { packets.map { $0.map { String(format: "%08X", $0) }.joined(separator: " ") }.joined(separator: " | ") }
let identity = sysex7Packets([0xF0, 0x7E, 0x00, 0x06, 0x01, 0xF7])
let thirteen = sysex7Packets([0xF0] + Array(1...13).map(UInt8.init) + [0xF7])
let checks = [
(hex(identity), "30047E00 06010000"),
(hex(thirteen), "30160102 03040506 | 30260708 090A0B0C | 30310D00 00000000"),
(hex(sysex7Packets([0xF0, 1, 2, 3, 4, 5, 6, 0xF7])), "30060102 03040506"),
(hex(sysex7Packets([0xF0, 0xF7])), "30000000 00000000"),
]
for (got, want) in checks where got != want { print("FAIL: \(got) != \(want)"); exit(1) }
print("selftest ok")
exit(0)
}
guard args.count == 3, ["dry", "send", "burst"].contains(args[1]) else { print("usage: dry|send|burst <plan> | selftest"); exit(2) }
// send: SysEx through MIDISendSysex, which paces it at MIDI 1.0 speed (31250 baud, about 3.1 KB/s).
// burst: SysEx as UMP packets through MIDISendEventList, at USB speed, as djay sends it (#165); acks are checked after.
let burst = args[1] == "burst"
var plan: [(delay: Int, step: Step)] = []
for (n, raw) in try String(contentsOfFile: args[2], encoding: .utf8).split(separator: "\n").enumerated() {
let line = raw.trimmingCharacters(in: .whitespaces)
Expand Down Expand Up @@ -147,6 +177,7 @@ func send(_ bytes: [UInt8], to d: MIDIEndpointRef) -> Bool {
_ = MIDIEventListAdd(&list, MemoryLayout<MIDIEventList>.size, packet, 0, 1, [word])
return MIDISendEventList(outPort, d, &list) == noErr
}
if burst { return sendBurst(bytes, to: d) }
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bytes.count)
buffer.initialize(from: bytes, count: bytes.count)
defer { buffer.deallocate() }
Expand All @@ -163,6 +194,24 @@ func send(_ bytes: [UInt8], to d: MIDIEndpointRef) -> Bool {
return done.flag && req.pointee.bytesToSend == 0
}

/// Sends a SysEx message as UMP SysEx7 packets without waiting: 512 packets (1024 words, about 4.3 KB of event
/// list) per MIDIEventList, well inside its 64 KB buffer.
func sendBurst(_ bytes: [UInt8], to d: MIDIEndpointRef) -> Bool {
let capacity = 65536
let raw = UnsafeMutableRawPointer.allocate(byteCount: capacity, alignment: 8)
defer { raw.deallocate() }
let list = raw.bindMemory(to: MIDIEventList.self, capacity: 1)
let packets = sysex7Packets(bytes)
for start in stride(from: 0, to: packets.count, by: 512) {
var packet = MIDIEventListInit(list, ._1_0)
for words in packets[start..<min(start + 512, packets.count)] {
packet = MIDIEventListAdd(list, capacity, packet, 0, words.count, words)
}
guard MIDISendEventList(outPort, d, list) == noErr else { return false }
}
return true
}

print("\(since()) listening on WD and CTL")
var acked = 0
for (i, s) in plan.enumerated() {
Expand Down
Loading