@@ -89,20 +89,20 @@ def getNVDAVolume(self) -> VolumeTupleT:
89
89
raise RuntimeError (f"Unexpected or unknown state { self = } " )
90
90
91
91
92
- audioSessionManager : IAudioSessionManager2 | None = None
93
- activeCallback : AudioSessionNotification | None = None
92
+ _audioSessionManager : IAudioSessionManager2 | None = None
93
+ _activeCallback : AudioSessionNotification | None = None
94
94
95
95
96
96
def initialize () -> None :
97
97
if nvwave .usingWasapiWavePlayer ():
98
- global audioSessionManager
98
+ global _audioSessionManager
99
99
try :
100
- audioSessionManager = AudioUtilities .GetAudioSessionManager ()
100
+ _audioSessionManager = AudioUtilities .GetAudioSessionManager ()
101
101
except COMError :
102
102
log .exception ("Could not initialize audio session manager" )
103
103
return
104
104
state = SoundSplitState (config .conf ["audio" ]["soundSplitState" ])
105
- setSoundSplitState (state , initial = True )
105
+ _setSoundSplitState (state , initial = True )
106
106
else :
107
107
log .debug ("Cannot initialize sound split as WASAPI is disabled" )
108
108
@@ -112,27 +112,27 @@ def terminate():
112
112
if nvwave .usingWasapiWavePlayer ():
113
113
state = SoundSplitState (config .conf ["audio" ]["soundSplitState" ])
114
114
if state != SoundSplitState .OFF :
115
- setSoundSplitState (SoundSplitState .OFF )
116
- unregisterCallback ()
115
+ _setSoundSplitState (SoundSplitState .OFF )
116
+ _unregisterCallback ()
117
117
else :
118
118
log .debug ("Skipping terminating sound split as WASAPI is disabled." )
119
119
120
120
121
121
@dataclass (unsafe_hash = True )
122
- class AudioSessionNotificationWrapper (AudioSessionNotification ):
122
+ class _AudioSessionNotificationWrapper (AudioSessionNotification ):
123
123
listener : AudioSessionNotification
124
124
125
125
def on_session_created (self , new_session : AudioSession ):
126
126
pid = new_session .ProcessId
127
- with applicationExitCallbacksLock :
128
- if pid not in applicationExitCallbacks :
129
- volumeRestorer = VolumeRestorer (pid , new_session )
127
+ with _applicationExitCallbacksLock :
128
+ if pid not in _applicationExitCallbacks :
129
+ volumeRestorer = _VolumeRestorer (pid , new_session )
130
130
new_session .register_notification (volumeRestorer )
131
- applicationExitCallbacks [pid ] = volumeRestorer
131
+ _applicationExitCallbacks [pid ] = volumeRestorer
132
132
self .listener .on_session_created (new_session )
133
133
134
134
135
- def applyToAllAudioSessions (
135
+ def _applyToAllAudioSessions (
136
136
callback : AudioSessionNotification ,
137
137
applyToFuture : bool = True ,
138
138
) -> None :
@@ -141,30 +141,30 @@ def applyToAllAudioSessions(
141
141
Additionally, if applyToFuture is True, then it will register a notification with audio session manager,
142
142
which will execute the same callback for all future sessions as they are created.
143
143
That notification will be active until next invokation of this function,
144
- or until unregisterCallback () is called.
144
+ or until _unregisterCallback () is called.
145
145
"""
146
- unregisterCallback ()
147
- callback = AudioSessionNotificationWrapper (callback )
146
+ _unregisterCallback ()
147
+ callback = _AudioSessionNotificationWrapper (callback )
148
148
if applyToFuture :
149
- audioSessionManager .RegisterSessionNotification (callback )
149
+ _audioSessionManager .RegisterSessionNotification (callback )
150
150
# The following call is required to make callback to work:
151
- audioSessionManager .GetSessionEnumerator ()
152
- global activeCallback
153
- activeCallback = callback
151
+ _audioSessionManager .GetSessionEnumerator ()
152
+ global _activeCallback
153
+ _activeCallback = callback
154
154
sessions : list [AudioSession ] = AudioUtilities .GetAllSessions ()
155
155
for session in sessions :
156
156
callback .on_session_created (session )
157
157
158
158
159
- def unregisterCallback () -> None :
160
- global activeCallback
161
- if activeCallback is not None :
162
- audioSessionManager .UnregisterSessionNotification (activeCallback )
163
- activeCallback = None
159
+ def _unregisterCallback () -> None :
160
+ global _activeCallback
161
+ if _activeCallback is not None :
162
+ _audioSessionManager .UnregisterSessionNotification (_activeCallback )
163
+ _activeCallback = None
164
164
165
165
166
166
@dataclass (unsafe_hash = True )
167
- class VolumeSetter (AudioSessionNotification ):
167
+ class _VolumeSetter (AudioSessionNotification ):
168
168
leftVolume : float
169
169
rightVolume : float
170
170
leftNVDAVolume : float
@@ -187,7 +187,7 @@ def on_session_created(self, new_session: AudioSession):
187
187
channelVolume .SetChannelVolume (1 , self .rightNVDAVolume , None )
188
188
189
189
190
- def setSoundSplitState (state : SoundSplitState , initial : bool = False ) -> dict :
190
+ def _setSoundSplitState (state : SoundSplitState , initial : bool = False ) -> dict :
191
191
applyToFuture = True
192
192
if state == SoundSplitState .OFF :
193
193
if initial :
@@ -199,14 +199,14 @@ def setSoundSplitState(state: SoundSplitState, initial: bool = False) -> dict:
199
199
applyToFuture = False
200
200
leftVolume , rightVolume = state .getAppVolume ()
201
201
leftNVDAVolume , rightNVDAVolume = state .getNVDAVolume ()
202
- volumeSetter = VolumeSetter (leftVolume , rightVolume , leftNVDAVolume , rightNVDAVolume )
203
- applyToAllAudioSessions (volumeSetter , applyToFuture = applyToFuture )
202
+ volumeSetter = _VolumeSetter (leftVolume , rightVolume , leftNVDAVolume , rightNVDAVolume )
203
+ _applyToAllAudioSessions (volumeSetter , applyToFuture = applyToFuture )
204
204
return {
205
205
"foundSessionWithNot2Channels" : volumeSetter .foundSessionWithNot2Channels ,
206
206
}
207
207
208
208
209
- def toggleSoundSplitState () -> None :
209
+ def _toggleSoundSplitState () -> None :
210
210
if not nvwave .usingWasapiWavePlayer ():
211
211
message = _ (
212
212
# Translators: error message when wasapi is turned off.
@@ -224,7 +224,7 @@ def toggleSoundSplitState() -> None:
224
224
i = - 1
225
225
i = (i + 1 ) % len (allowedStates )
226
226
newState = SoundSplitState (allowedStates [i ])
227
- result = setSoundSplitState (newState )
227
+ result = _setSoundSplitState (newState )
228
228
config .conf ["audio" ]["soundSplitState" ] = newState .value
229
229
ui .message (newState .displayString )
230
230
if result ["foundSessionWithNot2Channels" ]:
@@ -238,7 +238,7 @@ def toggleSoundSplitState() -> None:
238
238
239
239
240
240
@dataclass (unsafe_hash = True )
241
- class VolumeRestorer (AudioSessionEvents ):
241
+ class _VolumeRestorer (AudioSessionEvents ):
242
242
pid : int
243
243
audioSession : AudioSession
244
244
@@ -264,9 +264,9 @@ def restoreVolume(self):
264
264
self .unregister ()
265
265
266
266
def unregister (self ):
267
- with applicationExitCallbacksLock :
267
+ with _applicationExitCallbacksLock :
268
268
try :
269
- del applicationExitCallbacks [self .pid ]
269
+ del _applicationExitCallbacks [self .pid ]
270
270
except KeyError :
271
271
pass
272
272
try :
@@ -275,5 +275,5 @@ def unregister(self):
275
275
log .exception (f"Cannot unregister audio session for process { self .pid } " )
276
276
277
277
278
- applicationExitCallbacksLock = Lock ()
279
- applicationExitCallbacks : dict [int , VolumeRestorer ] = {}
278
+ _applicationExitCallbacksLock = Lock ()
279
+ _applicationExitCallbacks : dict [int , _VolumeRestorer ] = {}
0 commit comments