broken changes
This commit is contained in:
@@ -113,15 +113,18 @@ struct DJAudioDevice: Identifiable, Equatable {
|
||||
var uid: String
|
||||
var name: String
|
||||
var outputChannels = 2
|
||||
static func channelCount(_ id: AudioDeviceID) -> Int {
|
||||
var address = AudioObjectPropertyAddress(mSelector:kAudioDevicePropertyStreamConfiguration,mScope:kAudioDevicePropertyScopeOutput,mElement:kAudioObjectPropertyElementMain)
|
||||
var inputChannels = 0
|
||||
var stereoPairs: [Int] { Array(stride(from:0,to:max(0,outputChannels-1),by:2)) }
|
||||
static func channelCount(_ id: AudioDeviceID,scope: AudioObjectPropertyScope = kAudioDevicePropertyScopeOutput) -> Int {
|
||||
var address = AudioObjectPropertyAddress(mSelector:kAudioDevicePropertyStreamConfiguration,mScope:scope,mElement:kAudioObjectPropertyElementMain)
|
||||
var size: UInt32 = 0
|
||||
guard AudioObjectGetPropertyDataSize(id,&address,0,nil,&size) == noErr,size >= MemoryLayout<AudioBufferList>.size else { return 0 }
|
||||
let memory = UnsafeMutableRawPointer.allocate(byteCount:Int(size),alignment:MemoryLayout<AudioBufferList>.alignment);defer { memory.deallocate() }
|
||||
guard AudioObjectGetPropertyData(id,&address,0,nil,&size,memory) == noErr else { return 0 }
|
||||
return UnsafeMutableAudioBufferListPointer(memory.assumingMemoryBound(to:AudioBufferList.self)).reduce(0) { $0+Int($1.mNumberChannels) }
|
||||
}
|
||||
static func outputs() -> [Self] {
|
||||
static func outputs() -> [Self] { allDevices().filter { $0.outputChannels > 0 } }
|
||||
static func allDevices() -> [Self] {
|
||||
var address = AudioObjectPropertyAddress(mSelector:kAudioHardwarePropertyDevices,mScope:kAudioObjectPropertyScopeGlobal,mElement:kAudioObjectPropertyElementMain)
|
||||
var size: UInt32 = 0
|
||||
guard AudioObjectGetPropertyDataSize(AudioObjectID(kAudioObjectSystemObject),&address,0,nil,&size) == noErr else { return [] }
|
||||
@@ -129,15 +132,15 @@ struct DJAudioDevice: Identifiable, Equatable {
|
||||
let result = ids.withUnsafeMutableBytes { AudioObjectGetPropertyData(AudioObjectID(kAudioObjectSystemObject),&address,0,nil,&size,$0.baseAddress!) }
|
||||
guard result == noErr else { return [] }
|
||||
return ids.compactMap { id in
|
||||
let channels = channelCount(id)
|
||||
guard channels > 0 else { return nil }
|
||||
let channels = channelCount(id),inputs = channelCount(id,scope:kAudioDevicePropertyScopeInput)
|
||||
guard channels > 0 || inputs > 0 else { return nil }
|
||||
func string(_ selector: AudioObjectPropertySelector) -> String? {
|
||||
var property = AudioObjectPropertyAddress(mSelector:selector,mScope:kAudioObjectPropertyScopeGlobal,mElement:kAudioObjectPropertyElementMain)
|
||||
var text: Unmanaged<CFString>?;var bytes = UInt32(MemoryLayout<CFString?>.size)
|
||||
guard AudioObjectGetPropertyData(id,&property,0,nil,&bytes,&text) == noErr else { return nil }
|
||||
return text?.takeRetainedValue() as String?
|
||||
}
|
||||
return .init(id:id,uid:string(kAudioDevicePropertyDeviceUID) ?? String(id),name:string(kAudioObjectPropertyName) ?? "Audio output",outputChannels:channels)
|
||||
return .init(id:id,uid:string(kAudioDevicePropertyDeviceUID) ?? String(id),name:string(kAudioObjectPropertyName) ?? "Audio output",outputChannels:channels,inputChannels:inputs)
|
||||
}
|
||||
}
|
||||
static func defaultOutput() -> AudioDeviceID? {
|
||||
@@ -165,6 +168,7 @@ struct DJAudioDevice: Identifiable, Equatable {
|
||||
@Published var cueLevel: Double = 0.6 { didSet { preview.volume = cueLevel } }
|
||||
@Published private(set) var previewDeck: String?
|
||||
@Published var devices = [DJAudioDevice]()
|
||||
@Published private(set) var detectedDevices = [DJAudioDevice]()
|
||||
@Published var masterUID = ""
|
||||
@Published var cueUID = ""
|
||||
@Published private(set) var routing = DJAudioRouting()
|
||||
@@ -180,6 +184,7 @@ struct DJAudioDevice: Identifiable, Equatable {
|
||||
@Published var importProgress: ImportProgress?
|
||||
@Published private(set) var importing = false
|
||||
private var importTask: Task<Void,Never>?
|
||||
private var queuedFileLoads = [(urls:[URL],deck:String,override:Bool,song:Int64?)]()
|
||||
init(storageURL: URL? = nil) {
|
||||
root = storageURL ?? FileManager.default.urls(for:.applicationSupportDirectory,in:.userDomainMask)[0].appendingPathComponent("KJamsClone/DJ")
|
||||
preview.autoFade = false;preview.volume = cueLevel;refreshDevices();applyMix()
|
||||
@@ -231,10 +236,17 @@ struct DJAudioDevice: Identifiable, Equatable {
|
||||
self.perform { try self.refresh() }
|
||||
if let failure = result.failure { self.error = failure }
|
||||
else if let loadInto,let song = self.songs.first(where:{loadedIDs.contains($0.id)}) { self.load(song,into:loadInto,overridePlaying:overridePlaying && self.channel(loadInto).song?.id == replacedSong) }
|
||||
self.continueFileLoads()
|
||||
}
|
||||
}
|
||||
}
|
||||
func cancelImport() { importTask?.cancel() }
|
||||
func cancelImport() { queuedFileLoads = [];importTask?.cancel() }
|
||||
func continueFileLoads() {
|
||||
guard !importing,pendingReplacement == nil,!queuedFileLoads.isEmpty else { return }
|
||||
let next = queuedFileLoads.removeFirst()
|
||||
requestFileLoad(next.urls,into:next.deck,override:next.override && channel(next.deck).song?.id == next.song)
|
||||
}
|
||||
func cancelReplacement() { pendingReplacement = nil;continueFileLoads() }
|
||||
deinit { importTask?.cancel() }
|
||||
|
||||
func perform(_ action: () throws -> Void) { do { try action() } catch { self.error = error.localizedDescription } }
|
||||
@@ -257,7 +269,12 @@ struct DJAudioDevice: Identifiable, Equatable {
|
||||
status = "\(song.title) ready on \(letter) · set or tap BPM for tempo sync and beat loops"
|
||||
}
|
||||
}
|
||||
func refreshDevices() { devices = DJAudioDevice.outputs();midi.refreshSources() }
|
||||
func refreshDevices() {
|
||||
let all = DJAudioDevice.allDevices(),outputs = all.filter{$0.outputChannels > 0}
|
||||
if detectedDevices != all { detectedDevices = all }
|
||||
if devices != outputs { devices = outputs }
|
||||
midi.refreshSources()
|
||||
}
|
||||
private func device(_ uid: String) throws -> AudioDeviceID {
|
||||
if uid.isEmpty,let id = DJAudioDevice.defaultOutput() { return id }
|
||||
guard let output = devices.first(where:{$0.uid == uid}) else { throw LibraryError.message("Selected audio output is disconnected. Refresh and choose an available output.") }
|
||||
@@ -713,7 +730,7 @@ struct DJConsole: View {
|
||||
}.background(DJStyle.background).foregroundStyle(.white)
|
||||
.preferredColorScheme(.dark)
|
||||
.alert("Replace playing track?",isPresented:Binding(get:{system.pendingReplacement != nil},set:{if !$0 { system.pendingReplacement = nil }}),presenting:system.pendingReplacement) { request in
|
||||
Button("Cancel",role:.cancel) { system.pendingReplacement = nil }
|
||||
Button("Cancel",role:.cancel) { system.cancelReplacement() }
|
||||
Button("Replace & Load",role:.destructive) { system.confirmReplacement(request) }
|
||||
} message: { request in Text("Deck \(request.deck) is playing. Replacing it with \(request.title) stops the current track. Continue?") }
|
||||
.sheet(isPresented:$system.cueEditing) { DJCueEditor(system:system) }
|
||||
@@ -1084,8 +1101,8 @@ struct DJContinuousConsole: View {
|
||||
DJConsoleWing(deck:system.a,player:system.a.player,system:system)
|
||||
Divider()
|
||||
VStack(spacing:1) {
|
||||
DJCentreWaveform(deck:system.a,player:system.a.player,letter:"A",color:DJStyle.a,settings:system.settings)
|
||||
DJCentreWaveform(deck:system.b,player:system.b.player,letter:"B",color:DJStyle.b,settings:system.settings)
|
||||
DJCentreWaveform(deck:system.a,player:system.a.player,letter:"A",color:DJStyle.a,settings:system.settings).contentShape(Rectangle()).onDrop(of:[UTType.fileURL.identifier,"public.text"],isTargeted:nil) { system.acceptDrop($0,into:"A") }
|
||||
DJCentreWaveform(deck:system.b,player:system.b.player,letter:"B",color:DJStyle.b,settings:system.settings).contentShape(Rectangle()).onDrop(of:[UTType.fileURL.identifier,"public.text"],isTargeted:nil) { system.acceptDrop($0,into:"B") }
|
||||
}.frame(maxWidth:.infinity).background(.black)
|
||||
Divider()
|
||||
DJConsoleWing(deck:system.b,player:system.b.player,system:system)
|
||||
@@ -1130,7 +1147,7 @@ private struct DJTrackHeader: View {
|
||||
}
|
||||
if deck.letter == "B" { artwork }
|
||||
}.padding(10).frame(maxWidth:.infinity)
|
||||
.onDrop(of:[UTType.fileURL.identifier,"public.text"],isTargeted:nil) { system.acceptDrop($0,into:deck.letter) }
|
||||
.contentShape(Rectangle()).onDrop(of:[UTType.fileURL.identifier,"public.text"],isTargeted:nil) { system.acceptDrop($0,into:deck.letter) }
|
||||
}
|
||||
private var artwork: some View {
|
||||
ZStack {
|
||||
@@ -1162,7 +1179,7 @@ private struct DJConsoleWing: View {
|
||||
if deck.letter == "A" { face.tonePanel }
|
||||
if deck.letter == "B" { face.tempoStrip }
|
||||
}.padding(.horizontal,9).frame(width:322).opacity(system.settings.dimInactiveDeck && !player.playing ? 0.55 : 1)
|
||||
.onDrop(of:[UTType.fileURL.identifier,"public.text"],isTargeted:nil) { system.acceptDrop($0,into:deck.letter) }
|
||||
.contentShape(Rectangle()).onDrop(of:[UTType.fileURL.identifier,"public.text"],isTargeted:nil) { system.acceptDrop($0,into:deck.letter) }
|
||||
}
|
||||
}
|
||||
private struct DJConsoleTransport: View {
|
||||
@@ -1238,18 +1255,23 @@ struct DJPreferencesPane: View {
|
||||
@ObservedObject var system: DJSystem
|
||||
let category: String
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment:.leading,spacing:26) {
|
||||
switch category {
|
||||
case "General": general
|
||||
case "Devices": devices
|
||||
case "Sound": sound
|
||||
case "Library": library
|
||||
case "Appearance": appearance
|
||||
case "MIDI": midi
|
||||
default: advanced
|
||||
Group {
|
||||
if category == "Devices" {
|
||||
DJAudioDevicesPane(system:system).padding(26)
|
||||
} else {
|
||||
ScrollView {
|
||||
VStack(alignment:.leading,spacing:26) {
|
||||
switch category {
|
||||
case "General": general
|
||||
case "Sound": sound
|
||||
case "Library": library
|
||||
case "Appearance": appearance
|
||||
case "MIDI": midi
|
||||
default: advanced
|
||||
}
|
||||
}.padding(26).frame(maxWidth:.infinity,alignment:.leading)
|
||||
}
|
||||
}.padding(26).frame(maxWidth:.infinity,alignment:.leading)
|
||||
}
|
||||
}.alert("DJ settings",isPresented:Binding(get:{system.error != nil},set:{if !$0 { system.error = nil }})) { Button("OK") { system.error = nil } } message: { Text(system.error ?? "") }
|
||||
}
|
||||
private var general: some View {
|
||||
@@ -1270,7 +1292,6 @@ struct DJPreferencesPane: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
private var devices: some View { DJAudioDevicesPane(system:system) }
|
||||
private var sound: some View {
|
||||
VStack(alignment:.leading,spacing:26) {
|
||||
PreferencesSection("Mixer") {
|
||||
@@ -1382,12 +1403,15 @@ struct DJReplacement: Identifiable {
|
||||
func requestFileLoad(_ urls: [URL],into letter: String,override: Bool = false) {
|
||||
guard !urls.isEmpty else { return }
|
||||
if channel(letter).player.playing,!override { pendingReplacement = .init(deck:letter,song:nil,urls:urls);return }
|
||||
guard !importing else { status = "Wait for the current DJ import to finish.";return }
|
||||
if importing {
|
||||
queuedFileLoads.append((urls,letter,override,channel(letter).song?.id))
|
||||
status = "Queued file drop for deck \(letter) · waiting for the current import";return
|
||||
}
|
||||
importFiles(urls,loadInto:letter,overridePlaying:override)
|
||||
}
|
||||
func confirmReplacement(_ captured: DJReplacement? = nil) {
|
||||
guard let request = captured ?? pendingReplacement else { return };pendingReplacement = nil
|
||||
if let song = request.song { load(song,into:request.deck,overridePlaying:true) }
|
||||
if let song = request.song { load(song,into:request.deck,overridePlaying:true);continueFileLoads() }
|
||||
else { requestFileLoad(request.urls,into:request.deck,override:true) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user