@@ -110,9 +110,9 @@ class Application {
110110 private static func installDriver ( _ completion: @escaping ( ) -> Void ) {
111111 if !Driver. isInstalled || Driver . isOutdated {
112112 Alert . confirm (
113- title: " Audio Driver Installation " ,
114- message: " eqMac needs to install an Audio Driver. \n In order to do that we will ask for your System Password. \n Please close any apps playing audio (Spotify, YouTube etc.) otherwise installation might fail. " ,
115- cancelText: " Quit eqMac "
113+ title: " Audio Driver Installation " ,
114+ message: " eqMac needs to install an Audio Driver. \n In order to do that we will ask for your System Password. \n Please close any apps playing audio (Spotify, YouTube etc.) otherwise installation might fail. " ,
115+ cancelText: " Quit eqMac "
116116 ) { install in
117117 if install {
118118 Driver . install ( started: {
@@ -201,33 +201,14 @@ class Application {
201201 }
202202
203203 static var ignoreNextVolumeEvent = false
204-
204+
205205 private static func setupDeviceEvents ( ) {
206206 AudioDeviceEvents . on ( . outputChanged) { device in
207207 if device. isHardware {
208208 Console . log ( " outputChanged: " , device, " starting PlayThrough " )
209209 startPassthrough ( )
210210 }
211211 }
212- AudioDeviceEvents . on ( . volumeChanged, onDevice: Driver . device!) {
213- if ignoreNextVolumeEvent {
214- ignoreNextVolumeEvent = false
215- return
216- }
217- if ( overrideNextVolumeEvent) {
218- overrideNextVolumeEvent = false
219- ignoreNextVolumeEvent = true
220- Driver . device!. setVirtualMasterVolume ( 1 , direction: . playback)
221- return
222- }
223- let gain = Double ( Driver . device!. virtualMasterVolume ( direction: . playback) !)
224- if ( gain <= 1 && gain != Application . store. state. effects. volume. gain) {
225- Application . dispatchAction ( VolumeAction . setGain ( gain, false ) )
226- }
227- }
228- AudioDeviceEvents . on ( . muteChanged, onDevice: Driver . device!) {
229- Application . dispatchAction ( VolumeAction . setMuted ( Driver . device!. mute) )
230- }
231212
232213 AudioDeviceEvents . onDeviceListChanged { list in
233214 Console . log ( " listChanged " , list)
@@ -252,6 +233,30 @@ class Application {
252233 selectOutput ( device: device)
253234 }
254235 }
236+
237+ setupDriverDeviceEvents ( )
238+ }
239+
240+ private static func setupDriverDeviceEvents ( ) {
241+ AudioDeviceEvents . on ( . volumeChanged, onDevice: Driver . device!) {
242+ if ignoreNextVolumeEvent {
243+ ignoreNextVolumeEvent = false
244+ return
245+ }
246+ if ( overrideNextVolumeEvent) {
247+ overrideNextVolumeEvent = false
248+ ignoreNextVolumeEvent = true
249+ Driver . device!. setVirtualMasterVolume ( 1 , direction: . playback)
250+ return
251+ }
252+ let gain = Double ( Driver . device!. virtualMasterVolume ( direction: . playback) !)
253+ if ( gain <= 1 && gain != Application . store. state. effects. volume. gain) {
254+ Application . dispatchAction ( VolumeAction . setGain ( gain, false ) )
255+ }
256+ }
257+ AudioDeviceEvents . on ( . muteChanged, onDevice: Driver . device!) {
258+ Application . dispatchAction ( VolumeAction . setMuted ( Driver . device!. mute) )
259+ }
255260 }
256261
257262 static func selectOutput ( device: AudioDevice ) {
@@ -331,10 +336,11 @@ class Application {
331336 ) {
332337 // selectOutput(device: selectedDevice)
333338 Utilities . delay ( 100 ) {
334- // need a delay, because emitter should finish it's work at first
335- try ! AudioDeviceEvents . recreateEventEmitters ( [ . isAliveChanged, . volumeChanged, . nominalSampleRateChanged] )
336- stopEngines ( )
337- createAudioPipeline ( )
339+ // need a delay, because emitter should finish it's work at first
340+ try ! AudioDeviceEvents . recreateEventEmitters ( [ . isAliveChanged, . volumeChanged, . nominalSampleRateChanged] )
341+ self . setupDriverDeviceEvents ( )
342+ stopEngines ( )
343+ createAudioPipeline ( )
338344 }
339345 }
340346
@@ -405,7 +411,7 @@ class Application {
405411 Application . dispatchAction ( VolumeAction . setGain ( newGain, false ) )
406412 }
407413 }
408-
414+
409415 private static func killEngine ( ) {
410416 engine = nil
411417 }
0 commit comments