removed unwanted bar now with waveforms, major updates

This commit is contained in:
Mark Gregory
2026-11-06 10:46:32 +00:00
parent f947308421
commit 7b45184dff
3 changed files with 34 additions and 11 deletions
+27 -4
View File
@@ -30,9 +30,21 @@ import CoreAudio
private var loopBufferTask: Task<Void,Never>?
private var loopBuffer: AVAudioPCMBuffer?
private var preparedLoop: ClosedRange<Double>?
private var scheduledLoop: ClosedRange<Double>?
private var pendingLoopSwitch: (at: Double,range: ClosedRange<Double>)?
private(set) var loopAudioRestartCount = 0
private var rawAudioPosition: Double {
guard let file,let render = node.lastRenderTime,let current = node.playerTime(forNodeTime:render) else { return time }
return anchor+Double(current.sampleTime)/file.processingFormat.sampleRate
}
private(set) var nativeLoopActive = false
private func loopPosition(_ position: Double) -> Double {
guard nativeLoopActive,let range = preparedLoop,position >= range.upperBound else { return position }
guard nativeLoopActive else { return position }
if let pendingLoopSwitch,position >= pendingLoopSwitch.at {
let range = pendingLoopSwitch.range
return range.lowerBound+(position-pendingLoopSwitch.at).truncatingRemainder(dividingBy:range.upperBound-range.lowerBound)
}
guard let range = scheduledLoop,position >= range.upperBound else { return position }
return range.lowerBound+(position-range.upperBound).truncatingRemainder(dividingBy:range.upperBound-range.lowerBound)
}
private func prepareNativeLoop() {
@@ -54,7 +66,18 @@ import CoreAudio
guard !Task.isCancelled,let self,self.currentSongID == songID,self.loopEnabled,self.loopIn == start,self.loopOut == end else { return }
let position = self.displayTime,resume = self.playing
self.loopBuffer = buffer;self.preparedLoop = start...end
self.schedule(at:position < end ? position : start,play:resume,notifyPlayback:false)
if self.nativeLoopActive,resume {
let raw = self.rawAudioPosition
let activeRange: ClosedRange<Double>
if let pending = self.pendingLoopSwitch,raw >= pending.at { activeRange = pending.range }
else { activeRange = self.scheduledLoop ?? start...end }
let remaining = max(0,activeRange.upperBound-self.loopPosition(raw))
self.node.scheduleBuffer(buffer,at:nil,options:[.loops,.interruptsAtLoop])
self.pendingLoopSwitch = (raw+remaining,start...end)
} else {
self.loopAudioRestartCount += 1
self.schedule(at:position < end ? position : start,play:resume,notifyPlayback:false)
}
} catch { }
}
}
@@ -346,13 +369,13 @@ import CoreAudio
let start = min(file.length,max(0,AVAudioFramePosition(seconds*rate)))
anchor = Double(start)/rate; time = anchor
guard start < file.length else { playing = false; render(); return }
nativeLoopActive = false
nativeLoopActive = false;pendingLoopSwitch = nil;scheduledLoop = nil
if loopEnabled,let range = preparedLoop,range.lowerBound == loopIn,range.upperBound == loopOut,let loopBuffer,seconds < range.upperBound {
let endFrame = AVAudioFramePosition(range.upperBound*rate)
let remainder = AVAudioFrameCount(max(1,endFrame-start))
node.scheduleSegment(file,startingFrame:start,frameCount:remainder,at:nil)
node.scheduleBuffer(loopBuffer,at:nil,options:.loops)
nativeLoopActive = true
nativeLoopActive = true;scheduledLoop = range
if play { if notifyPlayback { startNodePlayback() } else { node.play() } }
playing = play;render();return
}