broken changes

This commit is contained in:
Mark Gregory
2026-11-05 16:43:08 +00:00
parent 1b5e48dfa1
commit 13a6a9e1c8
6 changed files with 173 additions and 26 deletions
+47 -10
View File
@@ -430,6 +430,8 @@ struct DJMIDIMapping: Codable, Identifiable, Equatable {
var activeXML: DJXMLProfile? { profiles[String(sourceID)]?.hasPrefix("XML:") == true ? xmlAssignments[String(sourceID)] : nil }
private var mixtrack = MixtrackGoProtocol()
private var outputPort = MIDIPortRef(0),outputDestination = MIDIEndpointRef(0)
private var initializationTask: Task<Void,Never>?
private var lastFeedback = [UInt8]()
@Published var learning: String?
@Published var learnMode = "Absolute"
@Published var status = "Choose a MIDI source; learn each control. No assumed factory mapping."
@@ -483,6 +485,7 @@ struct DJMIDIMapping: Codable, Identifiable, Equatable {
}
}
private func disconnect() {
initializationTask?.cancel();initializationTask = nil;lastFeedback = []
if connected != 0 { MIDIPortDisconnectSource(port,connected) };connected = 0;sourceID = 0;decoder = .init();learning = nil;outputDestination = 0;pickupValues = [:];pickedUp = []
}
func select(_ id: Int32) {
@@ -494,8 +497,7 @@ struct DJMIDIMapping: Codable, Identifiable, Equatable {
if autoDetect,profiles[String(id)] == nil {
if let profile = DJXMLProfile.match(source.name,in:xmlCatalog) { applyXML(profile) }
else if DJXMLProfile.normalized(source.name) == "numark mixtrack go" { installMixtrackGo() }
}
if let profile = activeXML,profile.adapter == "Mixtrack Go" { applyXML(profile) }
} else if let profile = activeXML,profile.adapter == "Mixtrack Go" { applyXML(profile) }
}
else { status = "Could not connect MIDI source (\(result))" }
}
@@ -541,11 +543,11 @@ struct DJMIDIMapping: Codable, Identifiable, Equatable {
let preset = MixtrackGoProtocol.mappings(source:sourceID)
let ids = Set(preset.map(\.id));mappings.removeAll{ids.contains($0.id)};mappings += preset
profiles[String(sourceID)] = "Mixtrack Go";defaults.set(profiles,forKey:"DJ.MIDIProfiles.v1");mixtrack = .init();save()
sendBytes([0xF0,0x7E,0x7F,0x06,0x01,0xF7])
initializeMixtrack()
status = "Mixtrack Go preset loaded · 14-bit tempo, relative jog, hot-cue/loop pad modes. Hardware testing required."
onAction?("Controller feedback",0,false)
}
func useCustomProfile() { profiles[String(sourceID)] = "Custom";defaults.set(profiles,forKey:"DJ.MIDIProfiles.v1");status = "Custom MIDI learn active" }
func useCustomProfile() { initializationTask?.cancel();lastFeedback = [];profiles[String(sourceID)] = "Custom";defaults.set(profiles,forKey:"DJ.MIDIProfiles.v1");status = "Custom MIDI learn active" }
func mergeXML(_ imported: [DJXMLProfile]) {
let ids = Set(imported.map(\.id));xmlCatalog.removeAll { ids.contains($0.id) };xmlCatalog += imported
xmlCatalog.sort { $0.name.localizedStandardCompare($1.name) == .orderedAscending }
@@ -565,22 +567,56 @@ struct DJMIDIMapping: Codable, Identifiable, Equatable {
if profile.adapter == "Mixtrack Go" {
mixtrack = .init();let preset = MixtrackGoProtocol.mappings(source:sourceID)
let ids = Set(preset.map(\.id));mappings.removeAll { ids.contains($0.id) };mappings += preset;save()
sendBytes([0xF0,0x7E,0x7F,0x06,0x01,0xF7]);onAction?("Controller feedback",0,false)
initializeMixtrack()
}
onAction?("Controller feedback",0,false)
status = "\(profile.name) · \(profile.bindings.count) supported controls · review compatibility report"
}
private func initializeMixtrack() {
initializationTask?.cancel();lastFeedback = []
sendBytes([0xF0,0x7E,0x7F,0x06,0x01,0xF7])
sendBytes([0xF0,0x00,0x20,0x7F,0x03,0x01,0xF7])
let source = sourceID,destination = outputDestination
// The controller can clear LEDs as its startup demo stops. Refresh after that transition.
initializationTask = Task { [weak self] in
do { try await Task.sleep(nanoseconds:2_000_000_000) } catch { return }
guard let self,self.sourceID == source,self.outputDestination == destination,self.mixtrackEnabled else { return }
self.onAction?("Controller feedback",0,false);self.sendBytes(self.lastFeedback)
}
}
private func selectFeedbackOutput(_ name: String) {
outputDestination = 0
for i in 0..<MIDIGetNumberOfDestinations() {
let endpoint = MIDIGetDestination(i);var result: Unmanaged<CFString>?
MIDIObjectGetStringProperty(endpoint,kMIDIPropertyDisplayName,&result)
let candidate = (result?.takeRetainedValue() as String? ?? "").lowercased()
if candidate == name.lowercased() || (candidate.contains("mixtrack") && candidate.contains("go")) { outputDestination = endpoint;break }
if candidate == name.lowercased() { outputDestination = endpoint;break }
}
}
func updateFeedback(aPlaying: Bool,bPlaying: Bool,sync: Bool,aLoaded: Bool,bLoaded: Bool,cue: String?,aCues: [Bool] = [],bCues: [Bool] = [],aLoop: Bool = false,bLoop: Bool = false) {
guard mixtrackEnabled else { return }
sendBytes(mixtrack.feedback(aPlaying:aPlaying,bPlaying:bPlaying,sync:sync,aLoaded:aLoaded,bLoaded:bLoaded,cue:cue,aCues:aCues,bCues:bCues,aLoop:aLoop,bLoop:bLoop))
if !mixtrackEnabled {
guard let outputs = activeXML?.outputs else { return }
for output in outputs {
let parts = output.action.split(separator:" ",maxSplits:1).map(String.init)
guard parts.count == 2 else { continue }
let isA = parts[0] == "A",loaded = isA ? aLoaded : bLoaded,cues = isA ? aCues : bCues
let active: Bool
switch parts[1] {
case "Play": active = isA ? aPlaying : bPlaying
case "Cue button": active = loaded
case "Sync": active = sync
case "Headphones": active = cue == parts[0]
case "Loop": active = isA ? aLoop : bLoop
default:
let index = (Int(parts[1].split(separator:" ").last ?? "0") ?? 0)-1
active = cues.indices.contains(index) && cues[index]
}
sendBytes(output.packet(active:active))
}
return
}
lastFeedback = mixtrack.feedback(aPlaying:aPlaying,bPlaying:bPlaying,sync:sync,aLoaded:aLoaded,bLoaded:bLoaded,cue:cue,aCues:aCues,bCues:bCues,aLoop:aLoop,bLoop:bLoop)
sendBytes(lastFeedback)
}
private func sendBytes(_ bytes: [UInt8]) {
guard outputDestination != 0,outputPort != 0,!bytes.isEmpty,bytes.count <= 256 else { return }
@@ -593,7 +629,7 @@ struct DJMIDIMapping: Codable, Identifiable, Equatable {
}
func remove(_ id: String) { mappings.removeAll{$0.id == id};save() }
private func save() { if let data = try? JSONEncoder().encode(mappings) { defaults.set(data,forKey:"DJ.MIDIMappings.v1") } }
deinit { if port != 0 { MIDIPortDispose(port) };if outputPort != 0 { MIDIPortDispose(outputPort) };if client != 0 { MIDIClientDispose(client) } }
deinit { initializationTask?.cancel();if port != 0 { MIDIPortDispose(port) };if outputPort != 0 { MIDIPortDispose(outputPort) };if client != 0 { MIDIClientDispose(client) } }
}
private enum DJStyle {
@@ -1027,7 +1063,7 @@ struct DJContinuousConsole: View {
HStack(spacing:12) {
DJConsoleTransport(deck:system.a,player:system.a.player,system:system)
VStack(spacing:0) {
DJHardwareFader(value:$system.crossfader,label:"DJ crossfader").frame(height:36)
DJHardwareFader(value:$system.crossfader,label:"DJ crossfader").frame(height:36).disabled(system.routing.mode == "External")
HStack { Text("A").foregroundStyle(DJStyle.a);Spacer();Button("Centre") { system.crossfader = 0.5 }.buttonStyle(.plain);Spacer();Text("B").foregroundStyle(DJStyle.b) }.font(.system(size:9))
}.frame(width:195)
DJConsoleTransport(deck:system.b,player:system.b.player,system:system)
@@ -1457,6 +1493,7 @@ struct MixtrackGoProtocol {
let status = UInt8(0x90+i),pad = UInt8(0x94+i),loaded = i == 0 ? aLoaded : bLoaded,playing = i == 0 ? aPlaying : bPlaying
bytes += [status,0x00,playing ? 127 : (loaded ? 1 : 0),status,0x01,loaded ? 1 : 0,status,0x02,sync ? 127 : 0]
bytes += [UInt8(0x80+i),0x1B,cue == (i == 0 ? "A" : "B") ? 127 : 1]
bytes += [status,0x04,playing ? 127 : 1,status,0x05,loaded ? 127 : 1,status,0x03,sync ? 127 : 1,0x9F,UInt8(0x02+i),loaded ? 127 : 1]
for index in 0..<4 {
let cues = i == 0 ? aCues : bCues,loop = i == 0 ? aLoop : bLoop
let on = modes[i] == 0 ? (cues.indices.contains(index) && cues[index]) : modes[i] == 1 && loop