1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-25 04:29:09 +00:00

Avoids double-setting of the OpenGL view.

This commit is contained in:
Thomas Harte 2020-02-18 22:33:16 -05:00
parent a8d082c7d2
commit 91e7400bbb

View File

@ -174,7 +174,7 @@ class MachineDocument:
// MARK: - Connections Between Machine and the Outside World // MARK: - Connections Between Machine and the Outside World
private func setupMachineOutput() { private func setupMachineOutput() {
if let machine = self.machine, let openGLView = self.openGLView { if let machine = self.machine, let openGLView = self.openGLView, machine.view != openGLView {
// Establish the output aspect ratio and audio. // Establish the output aspect ratio and audio.
let aspectRatio = self.aspectRatio() let aspectRatio = self.aspectRatio()
machine.setView(openGLView, aspectRatio: Float(aspectRatio.width / aspectRatio.height)) machine.setView(openGLView, aspectRatio: Float(aspectRatio.width / aspectRatio.height))
@ -227,13 +227,17 @@ class MachineDocument:
// //
// TODO: this needs to be threadsafe. FIX! // TODO: this needs to be threadsafe. FIX!
let maximumSamplingRate = CSAudioQueue.preferredSamplingRate() let maximumSamplingRate = CSAudioQueue.preferredSamplingRate()
let selectedSamplingRate = self.machine.idealSamplingRate(from: NSRange(location: 0, length: NSInteger(maximumSamplingRate))) let selectedSamplingRate = Float64(self.machine.idealSamplingRate(from: NSRange(location: 0, length: NSInteger(maximumSamplingRate))))
let isStereo = self.machine.isStereo() let isStereo = self.machine.isStereo()
if selectedSamplingRate > 0 { if selectedSamplingRate > 0 {
self.audioQueue = CSAudioQueue(samplingRate: Float64(selectedSamplingRate), isStereo:isStereo) // [Re]create the audio queue only if necessary.
self.audioQueue.delegate = self if self.audioQueue == nil || self.audioQueue.samplingRate != selectedSamplingRate {
self.machine.audioQueue = self.audioQueue self.machine.audioQueue = nil
self.machine.setAudioSamplingRate(selectedSamplingRate, bufferSize:audioQueue.preferredBufferSize, stereo:isStereo) self.audioQueue = CSAudioQueue(samplingRate: Float64(selectedSamplingRate), isStereo:isStereo)
self.audioQueue.delegate = self
self.machine.audioQueue = self.audioQueue
self.machine.setAudioSamplingRate(Float(selectedSamplingRate), bufferSize:audioQueue.preferredBufferSize, stereo:isStereo)
}
} }
} }