I need help checking whether the current ahk script emits sound and, if not, do an action. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 19 Apr 2022, 09:53

Hello, i'm new to ahk scripting and i'm trying to use an ahk script as a soundboard, i'm using bass.ahk, bass.dll, and nircmd to do the following: when i press a button, say "F2," the script lowers the volume of a group of apps (dota2.exe, chrome.exe, dicord.exe, foobar2000.exe, and so on) and then holds down the "m" button, which is my voice button in the Dota 2 game, and plays a sound. and everything works fine except for the ending part, where i want the script to check if nothing is playing before reverting the volume of all apps, because if i click "F3," it plays a long sound that lasts 60 seconds, and then if i click "F2," it plays a short sound that lasts 3 seconds, and it reverts the volume of all apps before the long sound finishes playing, which ruins it for me.

So i changed my script from something like this

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

F2::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav")
Sleep 3000
;==================================================================;
Send {m Up}
Sleep 55
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

F3::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
BASS_Play("D:\Sounds\Soundboard\LongSound60sec.wav")
Sleep 60000
;==================================================================;
Send {m Up}
Sleep 55
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

F4::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
BASS_Play("D:\Sounds\Soundboard\ShortSound15sec.wav")
Sleep 15000
;==================================================================;
Send {m Up}
Sleep 55
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

Exit:
ExitApp

OnExit,
BASS_Free()
ExitApp
To this, but i'm not sure how to check if bass or the script is playing something.

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

F2::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav")
Sleep 3000
;==================================================================;
Send {m Up}
Sleep 55
gosub Doneplaying
Return

F3::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
BASS_Play("D:\Sounds\Soundboard\LongSound60sec.wav")
Sleep 60000
;==================================================================;
Send {m Up}
Sleep 55
gosub Doneplaying
Return

F4::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
BASS_Play("D:\Sounds\Soundboard\ShortSound15sec.wav")
Sleep 15000
;==================================================================;
Send {m Up}
Sleep 55
gosub Doneplaying
Return

Exit:
ExitApp

Doneplaying:
(Something here that asks if nothing is playing?)
If ErrorLevel
    Return
Else
    Run, "nircmd.exe" setappvolume "dota2.exe" 1
    Sleep 15
    Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
    Sleep 15
    Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
    Sleep 15
    Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

OnExit,
BASS_Free()
ExitApp

Descolada
Posts: 1126
Joined: 23 Dec 2021, 02:30

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by Descolada » 19 Apr 2022, 10:23

Hello,
I am not very familiar with the BASS library, but there should be a function "BASS_ChannelIsActive" which you could use to check if BASS is still playing (it should return 1 if playing).

Code: Select all

BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav")
Sleep 3000
would become

Code: Select all

hStream := BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav")
While (BASS_ChannelIsActive(hStream) == 1)
	Sleep, 100

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 19 Apr 2022, 10:45

Gives me the following
Error: Call to non existent function.
Specifically: BASS_ChannelsActive(hStream) == 1

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

F2::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav")
Sleep 3000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_ChannelIsActive(hStream) == 1)
	Return
Else
	Run, "nircmd.exe" setappvolume "dota2.exe" 1
	Sleep 15
	Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
	Sleep 15
	Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
	Sleep 15
	Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

F3::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\LongSound60sec.wav")
Sleep 60000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_ChannelIsActive(hStream) == 1)
	Return
Else
	Run, "nircmd.exe" setappvolume "dota2.exe" 1
	Sleep 15
	Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
	Sleep 15
	Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
	Sleep 15
	Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

F4::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\ShortSound15sec.wav")
Sleep 15000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_ChannelIsActive(hStream) == 1)
	Return
Else
	Run, "nircmd.exe" setappvolume "dota2.exe" 1
	Sleep 15
	Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
	Sleep 15
	Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
	Sleep 15
	Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

Exit:
BASS_Free()
ExitApp

OnExit,
BASS_Free()
ExitApp

Descolada
Posts: 1126
Joined: 23 Dec 2021, 02:30

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by Descolada » 19 Apr 2022, 10:46

Could you link the bass.ahk file you are using?

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 19 Apr 2022, 10:49

Code: Select all

; Wrapper for bass.dll (2.4.5.0)
; www.autohotkey.com/forum/topic55454.html
; for AHK 1.0.48.05
; by toralf
; Version 0.1 (2010-02-20)
; based on BASS Library	by k3ph 

; NEEDS:  bass.dll      www.un4seen

; ################################
; ##  List of public functions  ##
; ################################
; BASS_Load([DLLPath, Device, PlugIns]) ;loads BASS wrapper, must be called before any other function
; BASS_Free()                           ;frees BASS wrapper, must be called at end of script
; BASS_IsPlaying(hStream)               ;returns playback status: 0=Stopped, 1=Playing, 2=Stalled, 3=Paused
; BASS_Play([File])                     ;plays a file or restarts it when paused and no file is specified
;                                         (returns hStream on success, otherwise -1)
; BASS_Stop()                           ;stop playback of file (returns hStream="" on success, otherwise -1)
; BASS_Pause()                          ;toogles pause of playback of file (returns hStream on success, otherwise -1)
; BASS_Volume([Volume])                 ;sets or gets master volume: 0 (silent) to 1 (max)
; BASS_GetDevice(hStream)               ;returns device number, otherwise -1
; BASS_Seconds2Bytes(hStream,SecPos)    ;converts a position from seconds to bytes,
;                                         returns on Error negative value
; BASS_Bytes2Seconds(hStream,BytePos)   ;converts a position from bytes to seconds,
;                                         returns on Error negative value
; BASS_GetLen(hStream)                  ;returns playback length in bytes, returns on Error -1
; BASS_GetPos(hStream)                  ;returns playback position in bytes, returns on Error -1
; BASS_SetPos(hStream,BytePos)          ;sets playback position in bytes, returns 1, otherwise 0
; BASS_GetLevel(hStream, ByRef LeftLevel, ByRef RightLevel) ;returns level (peak amplitude) of a stream, returns on Error -1
; BASS_GetLevel(hStream)                ;returns level (peak amplitude 0-32768) of a stream, returns on Error -1 or 0 when stream is stalled
; BASS_IsSliding(hStream,Attrib)        ;returns 1 if attribute is sliding, otherwise 0, 
;                                         Attributes: 1=Freq, 2=Vol, 3=Pan, 4=EAXMix
; BASS_SetSliding(hStream,Attrib,NewValue,TimeMS)   ;set attribute from its current value to slide to new value in time period
; BASS_GetCPU()                         ;returns CPU usage of BASS
; BASS_GetVersion()                     ;returns version of BASS that is loaded
; BASS_ProgressMeter_Add([x, y, Width, Height, Color, Bgcolor, ControlID, GuiID])  ;adds a progress meter to a gui
; BASS_ProgressMeter_Update(hStream [, ControlID, GuiID])   ;updates a progress meter for a stream
; BASS_PluginLoad(File)                 ;loads a plugin of BASS
; BASS_PluginFree([hPlugin])            ;frees a plugin of BASS ("" or 0 = All Plugins)
; BASS_ErrorGetCode()                   ;Return the error message as code and description
;
; #################################
; ##  List of private functions  ##
; #################################
; BASS_InitFree([Modus, DLLPath, Device, Plugins])
; BASS_StreamFileToChannel(Modus [, File])
; BASS_ProgressMeter(GuiID, ControlID, WidthOrhStream, Height [, Color, Bgcolor, X, Y])


;set Include directory for plugins
#Include %A_ScriptDir%\

;include effects & handlers
#Include *i basstags.ahk
#Include *i bassfx.ahk
#Include *i bassvfx.ahk
#Include *i bassenc.ahk
#Include *i bassmix.ahk
#Include *i bassvis.ahk
#Include *i bassvst.ahk
#Include *i basswadsp.ahk
#Include *i bassvideo.ahk

;include format plugins
#Include *i basscd.ahk
#Include *i bassmidi.ahk
#Include *i bassflac.ahk
#Include *i basswma.ahk
#Include *i basswv.ahk
#Include *i bassaac.ahk
#Include *i bassape.ahk
#Include *i bassmpc.ahk
#Include *i bassac3.ahk
#Include *i bassalac.ahk
#Include *i bassspx.ahk
#Include *i basstta.ahk
#Include *i bassofr.ahk

BASS_Load(DLLPath="", Device=-1, PlugIns="ALL"){  ;loads BASS wrapper, must be called before any other function
  Return BASS_InitFree("Load", DLLPath, Device, Plugins)
}
BASS_Free(){                             ;frees BASS wrapper, must be called at end of script 
  Return BASS_InitFree("Free")
}
BASS_InitFree(Modus="", DLLPath="", Device="", Plugins=""){
  static
  DLLName = bass.dll
  If (Modus = "Load"){                             ;load dll to memory
    If (!hBassDll := DllCall("LoadLibrary", Str,DLLPath . DLLName)){
      MsgBox, 48, BASS error!, 
        (Ltrim
          Failed to start %DLLName%
          Please ensure you have %DLLName% in the correct path %DLLPath%
        )
    	Return 0
    }
    local Freq=44100,Flags=0,Win=0,Clsid=0         ;initialize output device 
    If !DllCall("BASS\BASS_Init", Int,Device, Int,Freq, Int,Flags, UInt,Win, UInt,Clsid){
      ErrorLevel := BASS_ErrorGetCode()
      MsgBox, 48, BASS error!,
        (Ltrim
          Failed to initialize BASS
          Error: %ErrorLevel%
        )
      Return 0 
    }
    ;Load plugins
    PlugIns := PlugIns = "All"
            ? "tags,fx,vfx,enc,mix,vis,vst,wadsp,video,cd,midi,flac,wma,wv,aac,ape,mpc,ac3,alac,spx,tta,ofr"
            : PlugIns
    Loop, Parse, PlugIns, `,
      If IsFunc("BASS_" A_LoopField "_Load")
        BASS_%A_LoopField%_Load(DLLPath)
  }Else If (Modus = "Free"){                       
    If !BASS_PluginFree()                          ;free all Plugins
      MsgBox, 48, BASS error!, Failed to free all plugins.`nError: %ErrorLevel%
    DllCall("BASS\BASS_Free")                      ;free all resources used by the output device
    DllCall("FreeLibrary", UInt,hBassDll)          ;free dll from memory
  }
  Return 1
}

BASS_IsPlaying(hStream){ ;returns playback status: 0=Stopped, 1=Playing, 2=Stalled, 3=Paused
;BASS_ChannelIsActive return values
; BASS_ACTIVE_STOPPED := 0 ;
; BASS_ACTIVE_PLAYING := 1 ;
; BASS_ACTIVE_STALLED := 2 ; Playback of the stream has been stalled due to a lack of sample data. The playback will automatically resume once there is sufficient data to do so.
; BASS_ACTIVE_PAUSED  := 3 ;
  Return DllCall("BASS\BASS_ChannelIsActive", UInt,hStream)
}

BASS_Play(File=""){  ;plays a file or restarts it when paused and no file is specified (returns hStream on success, otherwise -1)         
  Return BASS_StreamFileToChannel("Play",File)
}
BASS_Stop(){         ;stop playback of file (returns hStream="" on success, otherwise -1)               
  Return BASS_StreamFileToChannel("Stop")
}
BASS_Pause(){        ;toogles pause of playback of file (returns hStream on success, otherwise -1)
  Return BASS_StreamFileToChannel("Pause")
}
BASS_StreamFileToChannel(Modus,File=""){
  static
  If (File AND !FileExist(File)){     ;check if file exists when specified
    MsgBox, 48, BASS error!,
      (Ltrim
        File does not exist:
        %File%
      )
    Return -1    
  }
  If (Modus = "Play" And File){      ;play file from beginning
  	If !(hStream := DllCall("BASS\BASS_StreamCreateFile", UInt,FromMem:=0
                           , UInt,&File, UInt64,Offset:=0, UInt64,Length:=0
                           , UInt,(A_IsUnicode ? 0x80000000 : 0x40000))){
      ErrorLevel := BASS_ErrorGetCode()
      MsgBox, 48, BASS error!,
        (Ltrim
          Failed to create a stream from file:
          %File%
          Error: %ErrorLevel%
        )
      Return -1
    }
    If !DllCall("BASS\BASS_ChannelPlay", UInt,hStream, Int,Restart:=1){
      ErrorLevel := BASS_ErrorGetCode()
      MsgBox, 48, BASS error!,
        (Ltrim
          Failed to play stream from file:
          %File%
          Error: %ErrorLevel%
        )
      Return -1      
    }
  }Else If (Modus = "Play" And !File And hStream){   ;restart playback (when paused)
    If !DllCall("BASS\BASS_ChannelPlay", UInt,hStream, Int,Restart:=0){
      ErrorLevel := BASS_ErrorGetCode()
      MsgBox, 48, BASS error!,
        (Ltrim
          Failed to restart stream from file:
          %File%
          Error: %ErrorLevel%
        )
      Return -1      
    }
  }Else If (Modus = "Stop" And hStream){             ;stop playback
    If BASS_IsPlaying(hStream)
      If !DllCall("BASS\BASS_ChannelStop", UInt,hStream){
        ErrorLevel := BASS_ErrorGetCode()
        MsgBox, 48, BASS error!,
          (Ltrim
            Failed to stop stream from file:
            %File%
            Error: %ErrorLevel%
          )
        Return -1      
      }
    hStream =                                        ;clear hStream
  }Else If (Modus = "Pause" And hStream){            ;toogle pause of playback
    local IsPlaying
    IsPlaying := BASS_IsPlaying(hStream)               ;get status
    If (IsPlaying = 3)                                    ;stream is paused
      hStream := BASS_Play()                                 ;restart playback
    Else If (IsPlaying = 1){                              ;stream is playing
      If !DllCall("BASS\BASS_ChannelPause", UInt,hStream){   ;pause playback
        ErrorLevel := BASS_ErrorGetCode()
        MsgBox, 48, BASS error!,
          (Ltrim
            Failed to pause stream from file:
            %File%
            Error: %ErrorLevel%
          )
        Return -1
      }
    }
  }
  Return hStream
}

BASS_Volume(Volume=""){ ;sets or gets master volume: 0 (silent) to 1 (max)  
	If Volume is float
    Return DllCall("BASS\BASS_SetVolume", Float,Volume)
  Else
	  Return DllCall("BASS\BASS_GetVolume", Float)
}
BASS_GetDevice(hStream){  ;returns device number, otherwise -1
	Return DllCall("BASS\BASS_ChannelGetDevice", UInt,hStream)
}

BASS_Seconds2Bytes(hStream,SecPos){  ;converts a position from seconds to bytes, returns on Error negative value
	Return DllCall("BASS\BASS_ChannelSeconds2Bytes", UInt,hStream, Double,SecPos, UInt64)
}
BASS_Bytes2Seconds(hStream,BytePos){ ;converts a position from bytes to seconds, returns on Error negative value
	Return DllCall("BASS\BASS_ChannelBytes2Seconds", UInt,hStream, UInt64,BytePos, Double)
}
BASS_GetLen(hStream){        ;returns playback length in bytes, returns on Error -1
	Return DllCall("BASS\BASS_ChannelGetLength", UInt,hStream, UInt,BASS_POS_BYTE := 0, UInt64)
}             
BASS_GetPos(hStream){      ;returns playback position in bytes, returns on Error -1
	Return DllCall("BASS\BASS_ChannelGetPosition", UInt,hStream, UInt,BASS_POS_BYTE := 0, UInt64)
}
BASS_SetPos(hStream,BytePos){   ;sets playback position in bytes, returns 1, otherwise 0
	Return DllCall("BASS\BASS_ChannelSetPosition", UInt,hStream, UInt64,Bytepos, UInt,BASS_POS_BYTE := 0)
}

BASS_GetLevel(WidthOrhStream, Byref LeftLevel,Byref RightLevel){ ;returns level (peak amplitude 0-32768) of a stream, returns on Error -1 or 0 when stream is stalled
	If ((LevelDWord := DllCall("BASS\BASS_ChannelGetLevel", UInt,hStream)) = -1)
    ErrorLevel := BASS_ErrorGetCode()
  If (LevelDWord > 0) {                       ;the level of the ...
    LeftLevel := LevelDWord & 0xffff            ;left channel is returned in the low word (low 16-bits)
    RightLevel := (LevelDWord>>16) & 0xffff     ;right channel is returned in the high word (high 16-bits)
  }Else{
    LeftLevel = 0
    RightLevel = 0
  }
  ;Return LevelDWord
  Return LeftLevel
}

BASS_IsSliding(hStream,Attrib){ ;returns 1 if attribute is sliding, otherwise 0, Attributes: 1=Freq, 2=Vol, 3=Pan, 4=EAXMix
;   BASS_ATTRIB_FREQ                := 1 ; 100 (min) to 100000 (max), 0 = original rate 
;   BASS_ATTRIB_VOL                 := 2 ; 0 (silent) to 1 (full).
;   BASS_ATTRIB_PAN                 := 3 ; -1 (full left) to +1 (full right), 0 = centre
;   BASS_ATTRIB_EAXMIX              := 4 ; 0 (full dry) to 1 (full wet), -1 = automatically calculate the mix based on the distance (the default).
  If Attrib is not number
  {
    If InStr(Attrib,"Freq")
      Attrib = 1
    Else If InStr(Attrib,"Vol")
      Attrib = 2
    Else If InStr(Attrib,"Pan")
      Attrib = 3
    Else If InStr(Attrib,"EAX")
      Attrib = 4
  }
  If Attrib not between 1 and 4
    Return 0
	Return DllCall("BASS\BASS_ChannelIsSliding", UInt,hStream, UInt,Attrib)
}
BASS_SetSliding(hStream,Attrib,NewValue,TimeMS){ ;set attribute from its current value to slide to new value in time period
;   BASS_ATTRIB_FREQ                := 1 ; 100 (min) to 100000 (max), 0 = original rate 
;   BASS_ATTRIB_VOL                 := 2 ; 0 (silent) to 1 (full).
;   BASS_ATTRIB_PAN                 := 3 ; -1 (full left) to +1 (full right), 0 = centre
;   BASS_ATTRIB_EAXMIX              := 4 ; 0 (full dry) to 1 (full wet), -1 = automatically calculate the mix based on the distance (the default).
  If Attrib is not number
  {
    If InStr(Attrib,"Freq")
      Attrib = 1
    Else If InStr(Attrib,"Vol")
      Attrib = 2
    Else If InStr(Attrib,"Pan")
      Attrib = 3
    Else If InStr(Attrib,"EAX")
      Attrib = 4
  }
  If Attrib not between 1 and 4
    Return 0
  If NewValue is not float
    Return 0
  If TimeMS is not number
    Return 0
	Return DllCall("BASS\BASS_ChannelSlideAttribute", UInt,hStream, UInt,Attrib, Float,NewValue, UInt,TimeMS)
}

BASS_GetCPU(){      ;returns CPU usage of BASS
	Return DllCall("BASS\BASS_GetCPU", Float)
}
BASS_GetVersion(){  ;returns version of BASS that is loaded
	Return DllCall("BASS\BASS_GetVersion")
}

; BASS_ProgressMeter
; based on idea by zed gecko  (StreamGUI, which comes with bass lib)
; adds a progress meter to a gui
BASS_ProgressMeter_Add(x = "", y = "", Width=300, Height=100, Color="green", Bgcolor="gray", ControlID="", GuiID=1){
  Return BASS_ProgressMeter(GuiID, ControlID, Width, Height//2, Color, Bgcolor, X, Y)
}
; updates a progress meter for a stream
BASS_ProgressMeter_Update(hStream, ControlID="", GuiID=1){
  Return BASS_ProgressMeter(GuiID, ControlID, hStream, "???????????")
}
BASS_ProgressMeter(GuiID, ControlID, WidthOrhStream, Height, Color="", Bgcolor="", X="", Y=""){
  global 
  local  SegmentSpace,SegmentSize,TransferVar,PrevSegment,NOS,LeftLevel,RightLevel
  If (Height = "???????????"){
    SetControlDelay, -1
    Loop, % NOS := NumberOfProgressMeterSegments%ControlID% {
      PrevSegment := A_Index - 1
      GuiControlGet, TransferVar, %GuiID%:, ProgressMeterL%ControlID%%A_Index%
      GuiControl,%GuiID%:, ProgressMeterL%ControlID%%PrevSegment%, %TransferVar%
      GuiControlGet, TransferVar, %GuiID%:, ProgressMeterR%ControlID%%A_Index%
      GuiControl,%GuiID%:, ProgressMeterR%ControlID%%PrevSegment%, %TransferVar%
    }
    BASS_GetLevel(WidthOrhStream, LeftLevel, RightLevel)
    GuiControl,%GuiID%:, ProgressMeterL%ControlID%%NOS%, %LeftLevel%
    GuiControl,%GuiID%:, ProgressMeterR%ControlID%%NOS%, % 32768 - RightLevel 
  }Else{
    SegmentSpace = 2                    ;visible size of one segment in pixel
    SegmentSize := SegmentSpace + 1
    NumberOfProgressMeterSegments%ControlID% := (WidthOrhStream // SegmentSize) - 1
    Gui, %GuiID%:Add, Progress, Range0-32768 vProgressMeterL%ControlID%0 w%SegmentSize% h%Height% %X% %Y% c%Color% Background%Bgcolor% Vertical,
    Gui, %GuiID%:Add, Progress, Range0-32768 vProgressMeterR%ControlID%0 w%SegmentSize% h%Height% y+0 c%Bgcolor% Background%Color% Vertical, 32769
    Loop, % NumberOfProgressMeterSegments%ControlID%{
      Gui, %GuiID%:Add, Progress, Range0-32768 vProgressMeterL%ControlID%%A_Index% w%SegmentSize% h%Height% xp+%SegmentSpace% yp-%Height% c%Color% Background%Bgcolor% Vertical,
      Gui, %GuiID%:Add, Progress, Range0-32768 vProgressMeterR%ControlID%%A_Index% w%SegmentSize% h%Height% y+0 c%Bgcolor% Background%Color% Vertical, 32769 
    }
  }
  Return 1
}

BASS_PluginLoad(File){   ;loads a plugin of BASS
;With any combination of these flags
;   BASS_UNICODE = 0x80000000 ;file is unicode
  Flags = 0
  If !hPlugin := DllCall("BASS\BASS_PluginLoad", UInt,&File, UInt,Flags)
    ErrorLevel := BASS_ErrorGetCode()
  Return hPlugin
}
BASS_PluginFree(hPlugin=0){  ;frees a plugin of BASS (0 = All Plugins)
	If !(Ret := DllCall("BASS\BASS_PluginFree", UInt,hPlugin))
    ErrorLevel := BASS_ErrorGetCode()
  Return Ret 
}

BASS_ErrorGetCode(){ ;Return the error message as code and description 
  static ErrorCodes :=
    (LTrim
      ";error codes returned by BASS_ErrorGetCode
      0  BASS_OK             all is OK
      1  BASS_ERROR_MEM      memory error
      2  BASS_ERROR_FILEOPEN can't open the file
      3  BASS_ERROR_DRIVER   can't find a free sound driver
      4  BASS_ERROR_BUFLOST  the sample buffer was lost
      5  BASS_ERROR_HANDLE   invalid handle
      6  BASS_ERROR_FORMAT   unsupported sample format
      7  BASS_ERROR_POSITION invalid position
      8  BASS_ERROR_INIT     BASS_Init has not been successfully called
      9  BASS_ERROR_START    BASS_Start has not been successfully called
      14 BASS_ERROR_ALREADY  already initialized/paused/whatever
      18 BASS_ERROR_NOCHAN   can't get a free channel
      19 BASS_ERROR_ILLTYPE  an illegal type was specified
      20 BASS_ERROR_ILLPARAM an illegal parameter was specified
      21 BASS_ERROR_NO3D     no 3D support
      22 BASS_ERROR_NOEAX    no EAX support
      23 BASS_ERROR_DEVICE   illegal device number
      24 BASS_ERROR_NOPLAY   not playing
      25 BASS_ERROR_FREQ     illegal sample rate
      27 BASS_ERROR_NOTFILE  the stream is not a file stream
      29 BASS_ERROR_NOHW     no hardware voices available
      31 BASS_ERROR_EMPTY    the MOD music has no sequence data
      32 BASS_ERROR_NONET    no internet connection could be opened
      33 BASS_ERROR_CREATE   couldn't create the file
      34 BASS_ERROR_NOFX     effects are not enabled
      37 BASS_ERROR_NOTAVAIL requested data is not available
      38 BASS_ERROR_DECODE   the channel is a decoding channel
      39 BASS_ERROR_DX       a sufficient DirectX version is not installed
      40 BASS_ERROR_TIMEOUT  connection timedout
      41 BASS_ERROR_FILEFORM unsupported file format
      42 BASS_ERROR_SPEAKER  unavailable speaker
      43 BASS_ERROR_VERSION  invalid BASS version (used by add-ons)
      44 BASS_ERROR_CODEC    codec is not available/supported
      45 BASS_ERROR_ENDED    the channel/file has ended
      -1 BASS_ERROR_UNKNOWN  some other mystery problem"
    )  
  Error := DllCall("BASS\BASS_ErrorGetCode", Int)
  Needle := "m`n)^" Error " +\w*\s*(?P<Value>.*)$"
  RegExMatch(ErrorCodes, Needle, Return)
  Return Error " = " ReturnValue
}

Descolada
Posts: 1126
Joined: 23 Dec 2021, 02:30

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by Descolada » 19 Apr 2022, 11:44

It seems your version has the function "BASS_IsPlaying"

Code: Select all

hStream := BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav")
While (BASS_IsPlaying(hStream) == 1)
	Sleep, 100

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 19 Apr 2022, 11:54

@Descolada This doesn't give me any errors, but it also doesn't work. pressing "F3" to play a long sound and then "F2" to play a short sound resets the volume of all apps before the long sound has finished playing.

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

F2::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav")
Sleep 3000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

F3::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\LongSound60sec.wav")
Sleep 60000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

F4::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\ShortSound15sec.wav")
Sleep 15000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Return

Exit:
BASS_Free()
ExitApp

OnExit,
BASS_Free()
ExitApp
[Mod edit: [code][/code] tags added.]

Descolada
Posts: 1126
Joined: 23 Dec 2021, 02:30

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.  Topic is solved

Post by Descolada » 19 Apr 2022, 12:49

I'm sorry, it seems I totally misunderstood the problem you were having. If I understand you correctly now, it seems that you want to keep all the apps quiet while your script is playing any sound, and then restore the volumes. First your hotkey quiets the apps, then starts playing the sound, finally it restores the volumes. But if you press another hotkey while a sound is already playing, the second hotkey will launch in another thread and interrupt the first one, it will play its sound and restores the volumes. Now the code returns to the first hotkey which still is playing, but the volume got set to normal in the meanwhile by the second hotkey.

This can easily be fixed by creating a new global variable to keep track of any playing sounds and only restore app volumes when all the sounds have stopped playing. In my example I am using a variable "InstancesPlaying", which I will increase before playing the sound and decrease after finishing playing, thus other hotkeys can "know" if anything else is playing and will avoid restoring the sounds.

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

InstancesPlaying := 0

F2::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
if (hStream := BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav"))
	InstancesPlaying++
Sleep 3000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
InstancesPlaying--
if !InstancesPlaying {
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

F3::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
if (hStream := BASS_Play("D:\Sounds\Soundboard\LongSound60sec.wav"))
	InstancesPlaying++
Sleep 60000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
InstancesPlaying--
if !InstancesPlaying {
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

F4::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
if (hStream := BASS_Play("D:\Sounds\Soundboard\ShortSound15sec.wav"))
	InstancesPlaying++
Sleep 15000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
InstancesPlaying--
if !InstancesPlaying {
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

Exit:
BASS_Free()
ExitApp

OnExit,
BASS_Free()
ExitApp
I also noticed that your script is using a lot of code over and over again. I recommend creating functions for recurring code to keep it less error-prone and make the code compacter. Since I do not have your apps nor the sound files, this is untested:

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

myAppsQuietVolumes := {"dota2.exe":0.1
	,"C:\Program Files\Google\Chrome\Application\chrome.exe":0.1
	,"Discord.exe":0.1
	,"foobar2000.exe":0.0} ; here you can add additional apps with the corresponding "quiet" volume

myAppsNormalVolumes := {"dota2.exe":1
	,"C:\Program Files\Google\Chrome\Application\chrome.exe":1
	,"Discord.exe":0.3
	,"foobar2000.exe":1} ; here you can add additional apps with the corresponding "normal" volume

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

SetAppVolume(app, volume, wait:=15) { ; sets an app volume and sleeps for "wait" amount of time (by default 15ms)
	Run, "nircmd.exe" setappvolume "%app%" %volume%
	Sleep %wait%
}

QuietAppsPlaySound(soundFile, appsQuiet, appsNormal) { ; takes the sound file name and an object containing your apps with the corresponding volumes
	static InstancesPlaying ; keep track of multiple sound playing and only restore "normal" when anything else isn't playing. A static variable is remembered between different calls of only this function, so if you play something using another function this will not work.
	if !InstancesPlaying ; if the variable doesn't exist, set it to 0
		InstancesPlaying := 0
	for app, volume in appsQuiet ; quiet the volumes
		SetAppVolume(app, volume)
	Send {m Down}
	Sleep 55
	;==================================================================;
	if (hStream := BASS_Play(soundFile)) ; if the sound play was successful, increase our counter
		InstancesPlaying++
	While (BASS_IsPlaying(hStream) == 1) ; wait until the sound has finished playing
		Sleep 100
	InstancesPlaying-- ; decrease our counter
	;==================================================================;
	Send {m Up}
	Sleep 55
	if !InstancesPlaying { ; restore the volumes if nothing else is playing
		for app, volume in appsNormal
			SetAppVolume(app, volume)
	}
	Return
}

F2::
	QuietAppsPlaySound("D:\Sounds\Soundboard\SuperShortSound3sec.wav", myAppsQuietVolumes, myAppsNormalVolumes)
	return

F3::
	QuietAppsPlaySound("D:\Sounds\Soundboard\LongSound60sec.wav", myAppsQuietVolumes, myAppsNormalVolumes)
	return

F4::
	QuietAppsPlaySound("D:\Sounds\Soundboard\ShortSound15sec.wav", myAppsQuietVolumes, myAppsNormalVolumes)
	return

Exit:
BASS_Free()
ExitApp

OnExit,
BASS_Free()
ExitApp

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 19 Apr 2022, 12:51

EDIT: I'm currently reading your response above me.
This also does not work :(

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

F2::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav")
Sleep 3000
;==================================================================;
Send {m Up}
Sleep 55
If (BASS_IsPlaying(hStream) == 1)
{
	Return
}
Else
{
    Run, "nircmd.exe" setappvolume "dota2.exe" 1
    Sleep 15
    Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
    Sleep 15
    Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
    Sleep 15
    Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

F3::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\LongSound60sec.wav")
Sleep 60000
;==================================================================;
Send {m Up}
Sleep 55
If (BASS_IsPlaying(hStream) == 1)
{
	Return
}
Else
{
    Run, "nircmd.exe" setappvolume "dota2.exe" 1
    Sleep 15
    Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
    Sleep 15
    Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
    Sleep 15
    Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

F4::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
hStream := BASS_Play("D:\Sounds\Soundboard\ShortSound15sec.wav")
Sleep 15000
;==================================================================;
Send {m Up}
Sleep 55
If (BASS_IsPlaying(hStream) == 1)
{
	Return
}
Else
{
    Run, "nircmd.exe" setappvolume "dota2.exe" 1
    Sleep 15
    Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
    Sleep 15
    Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
    Sleep 15
    Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

Exit:
BASS_Free()
ExitApp

OnExit,
BASS_Free()
ExitApp
And i believe it has something to do with this section.

Code: Select all

If (BASS_IsPlaying(hStream) == 1)
It appears to me that it's only checking to see if that specific file is playing, which is why it reverts all volumes back to normal without waiting for the file with the long sound to end.

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 19 Apr 2022, 13:06

Descolada wrote:
19 Apr 2022, 12:49
I'm sorry, it seems I totally misunderstood the problem you were having. If I understand you correctly now, it seems that you want to keep all the apps quiet while your script is playing any sound, and then restore the volumes. First your hotkey quiets the apps, then starts playing the sound, finally it restores the volumes. But if you press another hotkey while a sound is already playing, the second hotkey will launch in another thread and interrupt the first one, it will play its sound and restores the volumes. Now the code returns to the first hotkey which still is playing, but the volume got set to normal in the meanwhile by the second hotkey.

This can easily be fixed by creating a new global variable to keep track of any playing sounds and only restore app volumes when all the sounds have stopped playing. In my example I am using a variable "InstancesPlaying", which I will increase before playing the sound and decrease after finishing playing, thus other hotkeys can "know" if anything else is playing and will avoid restoring the sounds.

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

InstancesPlaying := 0

F2::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
if (hStream := BASS_Play("D:\Sounds\Soundboard\SuperShortSound3sec.wav"))
	InstancesPlaying++
Sleep 3000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
InstancesPlaying--
if !InstancesPlaying {
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

F3::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
if (hStream := BASS_Play("D:\Sounds\Soundboard\LongSound60sec.wav"))
	InstancesPlaying++
Sleep 60000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
InstancesPlaying--
if !InstancesPlaying {
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

F4::
Run, "nircmd.exe" setappvolume "dota2.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.1
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 0.0
Sleep 15
Send {m Down}
Sleep 55
;==================================================================;
if (hStream := BASS_Play("D:\Sounds\Soundboard\ShortSound15sec.wav"))
	InstancesPlaying++
Sleep 15000
;==================================================================;
Send {m Up}
Sleep 55
While (BASS_IsPlaying(hStream) == 1)
	Sleep 100
InstancesPlaying--
if !InstancesPlaying {
Run, "nircmd.exe" setappvolume "dota2.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep 15
Run, "nircmd.exe" setappvolume "Discord.exe" 0.3
Sleep 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
}
Return

Exit:
BASS_Free()
ExitApp

OnExit,
BASS_Free()
ExitApp
I also noticed that your script is using a lot of code over and over again. I recommend creating functions for recurring code to keep it less error-prone and make the code compacter. Since I do not have your apps nor the sound files, this is untested:

Code: Select all

#NoEnv
#SingleInstance force
SendMode Input
#include bass.ahk

myAppsQuietVolumes := {"dota2.exe":0.1
	,"C:\Program Files\Google\Chrome\Application\chrome.exe":0.1
	,"Discord.exe":0.1
	,"foobar2000.exe":0.0} ; here you can add additional apps with the corresponding "quiet" volume

myAppsNormalVolumes := {"dota2.exe":1
	,"C:\Program Files\Google\Chrome\Application\chrome.exe":1
	,"Discord.exe":0.3
	,"foobar2000.exe":1} ; here you can add additional apps with the corresponding "normal" volume

Menu, Tray, NoStandard
Menu, Tray, Add, Exit

BASS_Load()

SetAppVolume(app, volume, wait:=15) { ; sets an app volume and sleeps for "wait" amount of time (by default 15ms)
	Run, "nircmd.exe" setappvolume "%app%" %volume%
	Sleep %wait%
}

QuietAppsPlaySound(soundFile, appsQuiet, appsNormal) { ; takes the sound file name and an object containing your apps with the corresponding volumes
	static InstancesPlaying ; keep track of multiple sound playing and only restore "normal" when anything else isn't playing. A static variable is remembered between different calls of only this function, so if you play something using another function this will not work.
	if !InstancesPlaying ; if the variable doesn't exist, set it to 0
		InstancesPlaying := 0
	for app, volume in appsQuiet ; quiet the volumes
		SetAppVolume(app, volume)
	Send {m Down}
	Sleep 55
	;==================================================================;
	if (hStream := BASS_Play(soundFile)) ; if the sound play was successful, increase our counter
		InstancesPlaying++
	While (BASS_IsPlaying(hStream) == 1) ; wait until the sound has finished playing
		Sleep 100
	InstancesPlaying-- ; decrease our counter
	;==================================================================;
	Send {m Up}
	Sleep 55
	if !InstancesPlaying { ; restore the volumes if nothing else is playing
		for app, volume in appsNormal
			SetAppVolume(app, volume)
	}
	Return
}

F2::
	QuietAppsPlaySound("D:\Sounds\Soundboard\SuperShortSound3sec.wav", myAppsQuietVolumes, myAppsNormalVolumes)
	return

F3::
	QuietAppsPlaySound("D:\Sounds\Soundboard\LongSound60sec.wav", myAppsQuietVolumes, myAppsNormalVolumes)
	return

F4::
	QuietAppsPlaySound("D:\Sounds\Soundboard\ShortSound15sec.wav", myAppsQuietVolumes, myAppsNormalVolumes)
	return

Exit:
BASS_Free()
ExitApp

OnExit,
BASS_Free()
ExitApp
@Descolada Wow, thank you so much, man! This works perfectly! :superhappy:

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 01 Dec 2022, 11:56

@Descolada I know it's been a while, but I have some questions about your code that I'd like you to answer if that's okay.

I took a portion of your code and attempted to use it to make another code I have more compact.

what I wanted to do create a button that only raises the volume of my apps without playing any sound

Code: Select all

^!F9::
Send, {m Up}
Sleep, 15
Send, {k Up}
Sleep, 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "Discord.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "csgo.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "hl.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "hl2.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "iw3mp.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "left4dead2.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "reactivedrop.exe" 1
Sleep, 15
WinClose, %Script1% ahk_class AutoHotkey
WinClose, %Script2% ahk_class AutoHotkey
WinClose, %Script3% ahk_class AutoHotkey
WinClose, %Script4% ahk_class AutoHotkey
WinClose, %Script5% ahk_class AutoHotkey
Return
To this

Code: Select all

myAppsNormalVolumes := {"C:\Program Files\Google\Chrome\Application\chrome.exe": 1, "Discord.exe": 1, "csgo.exe": 1, "foobar2000.exe": 1, "hl.exe": 1, "hl2.exe": 1, "iw3mp.exe": 1, "left4dead2.exe": 1, "reactivedrop.exe": 1}
SetAppVolume(app, volume, wait:=5) {
	Run, "nircmd.exe" setappvolume "%app%" %volume%
	Sleep, %wait%
}
QuietApps(appsNormal) {
	Send, {m Up}
	Send, {k Up}
	for app, volume in appsNormal
		SetAppVolume(app, volume)
}
;------------------------------------------------------------------;
^!F9::
QuietApps(appsNormal)
WinClose, %Script1% ahk_class AutoHotkey
WinClose, %Script2% ahk_class AutoHotkey
WinClose, %Script3% ahk_class AutoHotkey
WinClose, %Script4% ahk_class AutoHotkey
WinClose, %Script5% ahk_class AutoHotkey
Return
But it doesn't increase the volume of the apps; what am I doing wrong?


One more question
You've used

Code: Select all

QuietAppsPlaySound(soundFile, appsQuiet, appsNormal)
..
	for app, volume in appsQuiet
		SetAppVolume(app, volume)
..
	for app, volume in appsNormal
		SetAppVolume(app, volume)


Why cant you do

Code: Select all

QuietAppsPlaySound(soundFile, myAppsQuietVolumes , myAppsNormalVolumes)
..
	for app, volume in myAppsQuietVolumes
		SetAppVolume(app, volume)
..
	for app, volume in myAppsNormalVolumes
		SetAppVolume(app, volume)

Descolada
Posts: 1126
Joined: 23 Dec 2021, 02:30

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by Descolada » 02 Dec 2022, 02:51

LG Zana wrote:
01 Dec 2022, 11:56
@Descolada I know it's been a while, but I have some questions about your code that I'd like you to answer if that's okay.

I took a portion of your code and attempted to use it to make another code I have more compact.

what I wanted to do create a button that only raises the volume of my apps without playing any sound

Code: Select all

^!F9::
Send, {m Up}
Sleep, 15
Send, {k Up}
Sleep, 15
Run, "nircmd.exe" setappvolume "C:\Program Files\Google\Chrome\Application\chrome.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "Discord.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "csgo.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "foobar2000.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "hl.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "hl2.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "iw3mp.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "left4dead2.exe" 1
Sleep, 15
Run, "nircmd.exe" setappvolume "reactivedrop.exe" 1
Sleep, 15
WinClose, %Script1% ahk_class AutoHotkey
WinClose, %Script2% ahk_class AutoHotkey
WinClose, %Script3% ahk_class AutoHotkey
WinClose, %Script4% ahk_class AutoHotkey
WinClose, %Script5% ahk_class AutoHotkey
Return
To this

Code: Select all

myAppsNormalVolumes := {"C:\Program Files\Google\Chrome\Application\chrome.exe": 1, "Discord.exe": 1, "csgo.exe": 1, "foobar2000.exe": 1, "hl.exe": 1, "hl2.exe": 1, "iw3mp.exe": 1, "left4dead2.exe": 1, "reactivedrop.exe": 1}
SetAppVolume(app, volume, wait:=5) {
	Run, "nircmd.exe" setappvolume "%app%" %volume%
	Sleep, %wait%
}
QuietApps(appsNormal) {
	Send, {m Up}
	Send, {k Up}
	for app, volume in appsNormal
		SetAppVolume(app, volume)
}
;------------------------------------------------------------------;
^!F9::
QuietApps(appsNormal)
WinClose, %Script1% ahk_class AutoHotkey
WinClose, %Script2% ahk_class AutoHotkey
WinClose, %Script3% ahk_class AutoHotkey
WinClose, %Script4% ahk_class AutoHotkey
WinClose, %Script5% ahk_class AutoHotkey
Return
But it doesn't increase the volume of the apps; what am I doing wrong?
The function QuietApps takes one argument: an object containing the exe name with the corresponding desired volume value. Inside QuietApps function that variable is called appsNormal, but outside the function it can be named anything: in my example it was named myAppsNormalVolumes. This means that inside your hotkey you should be calling QuietApps(myAppsNormalVolumes) instead of QuietApps(appsNormal)
One more question
You've used

Code: Select all

QuietAppsPlaySound(soundFile, appsQuiet, appsNormal)
..
	for app, volume in appsQuiet
		SetAppVolume(app, volume)
..
	for app, volume in appsNormal
		SetAppVolume(app, volume)


Why cant you do

Code: Select all

QuietAppsPlaySound(soundFile, myAppsQuietVolumes , myAppsNormalVolumes)
..
	for app, volume in myAppsQuietVolumes
		SetAppVolume(app, volume)
..
	for app, volume in myAppsNormalVolumes
		SetAppVolume(app, volume)
You can do that, but it would cause conflicting variable names. You could for example have multiple types of apps you want to quiet separately, and my way would allow to do that. Something like this:

Code: Select all

browsersQuiet := {"chrome.exe":0, "edge.exe":0}
browsersNormal := {"chrome.exe":1, "edge.exe":1}
gamesQuiet := {"csgo.exe": 0, "left4dead2.exe":0}
gamesNormal:= {"csgo.exe": 1, "left4dead2.exe":1}

QuietAppsPlaySound("soundfile.wav", browsersQuiet, browsersNormal) ; Only quiets and then sets volume back for browsers
QuietAppsPlaySound("soundfile2.wav", gamesQuiet, gamesNormal) ; Only for games

QuietAppsPlaySound(soundFile, appsQuiet, appsNormal)
..
	for app, volume in appsQuiet
		SetAppVolume(app, volume)
..
	for app, volume in appsNormal
		SetAppVolume(app, volume)

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 02 Dec 2022, 07:09

@Descolada Thank you for clarifying, I now understand it better, and using QuietApps(myAppsNormalVolumes) inside the hotkey did the trick, many thanks!

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 09 Nov 2023, 21:13

Hi Descolada, thanks a lot for the script. I'm still using it to this day. i did mess with it a bit, and it's still working nicely, but i have this one problem. i don't know how to fix it. if i keep spamming a hotkey too many times in a short time, like 'Alt + Numpad1' to play the same sound too many times, it gets out of control, and the script becomes unresponsive until it finishes playing the many sounds i spammed. So i can't end it with Numpad0. i want Numpad0 to become absolute or have authority over the other hotkeys. So, even if the script becomes unresponsive, it still listens to that hotkey. is that possible?

Also, a question: it seems this bass library here is newer, i think?
viewtopic.php?p=162253#p162253
If so, can i use it instead, and how? It doesnt have the functions 'BASS_Play' or 'BASS_IsPlaying'. or should i keep using what i have?

Soundboard.ahk

Code: Select all

;#Requires AutoHotkey >=1.1.36 <1.2
#HotkeyInterval 99000000
#KeyHistory 0
#MaxHotkeysPerInterval 99000000
#MaxThreadsPerHotkey 255
#NoEnv
#Persistent
#SingleInstance force
DetectHiddenWindows, On
ListLines, Off
SendMode, Input
SetBatchLines, 10ms
SetKeyDelay, 0, 50
SetWinDelay, 0
;******************************************************************
;                          Include external scripts
;******************************************************************
#Include bass.ahk
;******************************************************************
;                          Menu setup
;******************************************************************
Menu, Tray, Icon, D:\Soundboard.ico, , 1
Menu, Tray, NoStandard
Menu, Tray, Add, Exit
;******************************************************************
;                          Definitions
;******************************************************************
; List of processes to add to the group
ProcessesToAdd =
(
Discord.exe
explorer.exe
chrome.exe
foobar2000.exe
notepad++.exe
notepad.exe
powershell.exe
steam.exe
)
; Loop to add processes to the group
Loop, Parse, ProcessesToAdd, `n
{
    ProcessName := A_LoopField
    GroupAdd, MusicSafetyDota, ahk_exe %ProcessName%
}
;********************************
global BUTTON_F9_IS_PRESSED := "false"
global BUTTON_PAUSE := "F9"
global BUTTON_VOICE := "m"
global DOTA_ANY_IS_PLAYING := "0"
global DOTA_JOJO_IS_PLAYING := "0"
global DOTA_MUSIC := "D:\Soundboard.ahk"
global DOTA_REMINDERS_WATCHDOG := "D:\Dota2Reminders.ahk"
global SOUNDBOARD_DOTA_ANY := "SoundboardDotaAny"
global SOUNDBOARD_DOTA_JOJO := "SoundboardDotaJojo"
global SOUNDBOARD_FOLDER_PATH := "D:\Soundboard_Sounds"
global VOLUMES_NORMAL := "VolumesNormalDota"
global VOLUMES_QUIET := "VolumesQuietDota"
;********************************
VolumesQuietDota := {}
VolumesQuietDota["chrome.exe"] := 0.1
VolumesQuietDota["Discord.exe"] := 0.1
VolumesQuietDota["dota2.exe"] := 0.1
VolumesQuietDota["foobar2000.exe"] := 0.0
;********************************
VolumesNormalDota := {}
VolumesNormalDota["chrome.exe"] := 1
VolumesNormalDota["Discord.exe"] := 0.6
VolumesNormalDota["dota2.exe"] := 1
VolumesNormalDota["foobar2000.exe"] := 1
;******************************************************************
;                          Function to set the volume for an application
;******************************************************************
SetAppVolume(app, volume, wait:=5) {
    Run, "nircmd.exe" setappvolume "%app%" %volume%
    Sleep, %wait%
}
;******************************************************************
;                          Function to play a sound on the Dota Any soundboard
;******************************************************************
SoundboardDotaAny(soundFile, appsQuiet, appsNormal) {
    if (!DOTA_ANY_IS_PLAYING && !DOTA_JOJO_IS_PLAYING) {
        if (ProcessExist("dota2.exe") && ProcessExist("Dota 2 Reminders.exe")) {
            IfWinNotExist, %DOTA_REMINDERS_WATCHDOG% ahk_class AutoHotkey
            {
                Run, %DOTA_REMINDERS_WATCHDOG%
            }
            if (ProcessExist("powershell.exe"))
            {
                Run, "SoundVolumeView.exe" /Mute "powershell.exe"
            }
        }
        for app, volume in appsQuiet {
            SetAppVolume(app, volume)
        }
        Send, {%BUTTON_VOICE% Down}
        Sleep, 5
    }
    if (hStream := BASS_Play(soundFile)) {
        DOTA_ANY_IS_PLAYING++
        While (BASS_IsPlaying(hStream) == 1) ; wait until the sound is playing
        {
            Sleep, 15
        }
        DOTA_ANY_IS_PLAYING-- ; decrease our counter
    }
    if (!DOTA_ANY_IS_PLAYING && !DOTA_JOJO_IS_PLAYING) {
        Send, {%BUTTON_VOICE% Up}
        Sleep, 5
        for app, volume in appsNormal {
            SetAppVolume(app, volume)
        }
        IfWinExist, %DOTA_REMINDERS_WATCHDOG% ahk_class AutoHotkey
        {
            WinClose, %DOTA_REMINDERS_WATCHDOG% ahk_class AutoHotkey
        }
    }
}
;******************************************************************
;                          Function to play a sound on the Dota Jojo soundboard
;******************************************************************
SoundboardDotaJojo(soundFile, appsQuiet, appsNormal) {
    startTime := A_TickCount ; store the start time
    if (!DOTA_ANY_IS_PLAYING && !DOTA_JOJO_IS_PLAYING) {
        if (ProcessExist("dota2.exe") && ProcessExist("Dota 2 Reminders.exe")) {
            IfWinNotExist, %DOTA_REMINDERS_WATCHDOG% ahk_class AutoHotkey
            {
                Run, "%DOTA_REMINDERS_WATCHDOG%"
            }
            if (ProcessExist("powershell.exe"))
            {
                Run, "SoundVolumeView.exe" /Mute "powershell.exe"
            }
        }
        for app, volume in appsQuiet {
            SetAppVolume(app, volume)
        }
        Send, {%BUTTON_VOICE% Down}
        Sleep, 5
    }
    if (hStream := BASS_Play(soundFile)) {
        DOTA_JOJO_IS_PLAYING++
        While (BASS_IsPlaying(hStream) == 1) ; wait until the sound is playing
        {
            elapsedTime := (A_TickCount - startTime)
            if (elapsedTime >= 250 && !BUTTON_F9_IS_PRESSED) ; Check if 250 milliseconds have passed and F9 not pressed yet
            {
                Send, {%BUTTON_PAUSE%} ; Press F9 after 250 milliseconds
                BUTTON_F9_IS_PRESSED := true ; Mark F9 as pressed
            }
            Sleep, 15
        }
        DOTA_JOJO_IS_PLAYING-- ; decrease our counter
    }
    Send, {%BUTTON_PAUSE%}
    if (!DOTA_ANY_IS_PLAYING && !DOTA_JOJO_IS_PLAYING) {
        Send, {%BUTTON_VOICE% Up}
        Sleep, 5
        for app, volume in appsNormal {
            SetAppVolume(app, volume)
        }
        IfWinExist, %DOTA_REMINDERS_WATCHDOG% ahk_class AutoHotkey
        {
            WinClose, %DOTA_REMINDERS_WATCHDOG% ahk_class AutoHotkey
        }
    }
}
;******************************************************************
;                          Function to reset volume levels for Dota
;******************************************************************
VOLUMES_RESET() {
    ; List of applications and their corresponding volume settings
    apps := ["chrome.exe", "Discord.exe", "dota2.exe", "foobar2000.exe"]
    volumes := [1, 0.6, 1, 1]

    ; Loop through each application and adjust its volume
    for index, app in apps {
        volume := volumes[index]
        Run, % "nircmd.exe setappvolume """ app """ " volume
        ; Wait for a short moment to ensure the command completes
        Sleep, 5
    }
}
;******************************************************************
;                          Function to check if a process with the given name exists
;******************************************************************
ProcessExist(name) {
    Process, Exist, %name%
    return ErrorLevel
}
;******************************************************************
;                          BASS initialization
;******************************************************************
BASS_Load()
;******************************************************************
; Only activate the following hotkeys when no windows in the 'MusicSafetyDota' group are active.
; This means the hotkeys will work only when none of the specified processes are in focus.
;******************************************************************
;#If !WinActive("ahk_group MusicSafetyDota")
;#IfWinNotActive, ahk_group MusicSafetyDota
;******************************************************************
;                          Remap Right Win and Left Win keys to VK_E8
;******************************************************************
~RWin::vkE8
~LWin::vkE8
;******************************************************************
;                          N U M P A D 0
;******************************************************************
*^!Numpad0::
    IfWinExist, %DOTA_REMINDERS_WATCHDOG% ahk_class AutoHotkey
    {
        WinClose, %DOTA_REMINDERS_WATCHDOG% ahk_class AutoHotkey
    }
    VOLUMES_RESET()
    Send, {%BUTTON_VOICE% Up}
    Run, "%DOTA_MUSIC%" ; or Reload
Return
;******************************************************************
;                          N U M P A D 1
;******************************************************************
!Numpad1::%SOUNDBOARD_DOTA_ANY%(SOUNDBOARD_FOLDER_PATH . "haha.wav", %VOLUMES_QUIET%, %VOLUMES_NORMAL%)
Attachments
haha.7z
(145.28 KiB) Downloaded 33 times

LG Zana
Posts: 33
Joined: 06 Dec 2021, 17:50

Re: I need help checking whether the current ahk script emits sound and, if not, do an action.

Post by LG Zana » 11 Nov 2023, 01:43

I fixed it by adding '#MaxThreads 255'. :D

Post Reply

Return to “Ask for Help (v1)”