removed unwanted bar now with waveforms, major updates
This commit is contained in:
@@ -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() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user