removed unwanted bar now with waveforms, major updates

This commit is contained in:
Mark Gregory
2026-11-06 13:51:45 +00:00
parent 2dc3c96ef3
commit 50e7fb358a
6 changed files with 184 additions and 30 deletions
+38
View File
@@ -188,3 +188,41 @@ extension WaveformBatch {
progress(state);return state
}
}
/// Serial batches of background analysis, independent of import completion.
@MainActor final class PostImportWaveformQueue {
private var pending = [Int64:Song]()
private var locations = [MediaLocation]()
private var cache: URL?
private var task: Task<Void,Never>?
private var token = UUID()
private var update: ((WaveformJobProgress) -> Void)?
private var completed: (([Song]) -> Void)?
private var latest: WaveformJobProgress?
var isRunning: Bool { task != nil }
func enqueue(_ songs: [Song],locations: [MediaLocation],cache: URL,update: @escaping (WaveformJobProgress) -> Void,completed: @escaping ([Song]) -> Void) {
for song in songs { pending[song.id] = song }
self.locations = locations;self.cache = cache;self.update = update;self.completed = completed
if task == nil { startNext() }
}
private func startNext() {
guard !pending.isEmpty,let cache else { return }
let songs = pending.values.sorted{$0.id < $1.id},locations = self.locations,id = UUID()
pending.removeAll();token = id;latest = .init(total:songs.count);update?(latest!)
task = Task.detached(priority:.utility) { [weak self] in
let result = await WaveformBatch.runConcurrent(songs:songs,locations:locations,cache:cache) { value in
Task { @MainActor [weak self] in guard let self,self.token == id,self.task != nil else { return };self.latest = value;self.update?(value) }
}
await MainActor.run { [weak self] in
guard let self,self.token == id else { return }
self.task = nil;self.latest = result;self.update?(result);self.completed?(songs)
self.startNext()
}
}
}
func cancel() {
token = UUID();pending.removeAll();task?.cancel();task = nil
if var value = latest { value.finished = true;value.cancelled = true;value.current = "Background waveform job cancelled";latest = value;update?(value) }
}
deinit { task?.cancel() }
}