Skip to content

Commit

Permalink
Fix startup recursion error when using ptt #83
Browse files Browse the repository at this point in the history
Error occurred when the microphone was already in the muted state, in which case VA would return 1 and this wasn't considered a success in micmute and therefore micmute would attempt to disabled and re-enable the controller which would execute the same code again
  • Loading branch information
SaifAqqad committed Jan 21, 2023
1 parent ef12ddd commit d1fed34
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/MicrophoneController.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,14 @@ Class MicrophoneController {
setMuteStateVA(state, mic){
; Use cached microphone id
result := VA_SetMasterMute(state, this.getMicId(mic))
return result == 0? result : VA_SetMasterMute(state, this.microphoneIds[mic]:= VA_GetDevice(mic))
if result in 0,1 ; success
return 0

; Update the cached microphone id and retry
result := VA_SetMasterMute(state, this.microphoneIds[mic]:= VA_GetDevice(mic))
if result in 0,1 ; success
return 0
return result
}

getMicId(micName){
Expand Down Expand Up @@ -149,7 +156,13 @@ Class MicrophoneController {
if (this.muteHotkey=this.unmuteHotkey){
if(this.isPushToTalk){
this.ptt_key:= (StrSplit(this.muteHotkey, [" ","#","!","^","+","&",">","<","*","~","$","UP"], " `t")).Pop()
this.setMuteState(!this.isInverted, 0)

if(this.isMicrophoneArray){
for i, mic in this.Microphone
this.setMuteStateVA(!this.isInverted, mic)
}else{
this.setMuteStateVA(!this.isInverted, this.microphone)
}

pttMethod:= ObjBindMethod(this, (this.isHybridPTT? "hybridPtt": "ptt"), !!this.isInverted)
this.muteHotkeyId:= this.unmuteHotkeyId:= HotkeyManager.register(this.muteHotkey, pttMethod, this)
Expand Down

0 comments on commit d1fed34

Please sign in to comment.