Skip to content

Instantly share code, notes, and snippets.

@pprince
Created December 21, 2015 02:06
Show Gist options
  • Save pprince/f42c8c9d06e54f8adbb6 to your computer and use it in GitHub Desktop.
Save pprince/f42c8c9d06e54f8adbb6 to your computer and use it in GitHub Desktop.
/*
PTT_for_Voicemeeter.ahk - AHKscript Push-to-Talk for VoicemeeterBanana
======================================================================
Author: "Paul Prince" <[email protected]>
License: Modified BSD License; see ./LICENSE.txt
Inspired by:
------------
- WindowPadX
https://github.com/hoppfrosch/WindowPadX
*/
; Display warnings about poor practices and possible errors
; This should probably only be used during development/debugging...
; TODO: Remove before production release.
#Warn All
; Don't lookup references to undefined variables in the environment
#NoEnv
; If we detect another copy of this script is already running,
; automatically replace the older instance, much like a 'Reload'
#SingleInstance force
#UseHook
global VERSION := "0.0.1"
global VMR_FUNCTIONS := {}
global VMR_DLL_DRIVE := "C:"
global VMR_DLL_DIRPATH := "Program Files (x86)\VB\Voicemeeter"
global VMR_DLL_FILENAME_32 := "VoicemeeterRemote.dll"
global VMR_DLL_FILENAME_64 := "VoicemeeterRemote64.dll"
global VMR_DLL_FULL_PATH := VMR_DLL_DRIVE . "\" . VMR_DLL_DIRPATH . "\"
if (A_Is64bitOS) {
VMR_DLL_FULL_PATH .= VMR_DLL_FILENAME_64
} else {
VMR_DLL_FULL_PATH .= VMR_DLL_FILENAME_32
}
; == START OF EXECUTION ==
; ========================
; Load the VoicemeeterRemote DLL:
; This returns a module handle
global VMR_MODULE := DllCall("LoadLibrary", "Str", VMR_DLL_FULL_PATH, "Ptr")
if (ErrorLevel || VMR_MODULE == 0)
die("Attempt to load VoiceMeeter Remote DLL failed.")
; Populate VMR_FUNCTIONS
add_vmr_function("Login")
add_vmr_function("Logout")
add_vmr_function("RunVoicemeeter")
add_vmr_function("SetParameterFloat")
; "Login" to Voicemeeter, by calling the function in the DLL named 'VBVMR_Login()'...
login_result := DllCall(VMR_FUNCTIONS["Login"], "Int")
if (ErrorLevel || login_result < 0)
die("VoiceMeeter Remote login failed.")
; If the login returns 1, that apparently means that Voicemeeter isn't running,
; so we start it; pass 1 to run Voicemeeter, or 2 for Voicemeeter Banana:
if (login_result == 1) {
DllCall(VMR_FUNCTIONS["RunVoicemeeter"], "Int", 2, "Int")
if (ErrorLevel)
die("Attempt to run VoiceMeeter failed.")
Sleep 2000
}
ptt_off()
; == HOTKEYS ==
; =============
F22::
ptt_on()
KeyWait, F22
ptt_off()
return
#IfWinActive ahk_exe BlackOps3.exe
/::
Send {/ down}
ptt_on()
KeyWait, /
Send {/ up}
ptt_off()
return
; == Functions ==
; ===============
ptt_on() {
DllCall(VMR_FUNCTIONS["SetParameterFloat"], "AStr", "Strip[0].B1", "Float", 1.0, "Int")
DllCall(VMR_FUNCTIONS["SetParameterFloat"], "AStr", "Strip[0].B2", "Float", 1.0, "Int")
}
ptt_off() {
DllCall(VMR_FUNCTIONS["SetParameterFloat"], "AStr", "Strip[0].B1", "Float", 0.0, "Int")
DllCall(VMR_FUNCTIONS["SetParameterFloat"], "AStr", "Strip[0].B2", "Float", 0.0, "Int")
}
add_vmr_function(func_name) {
VMR_FUNCTIONS[func_name] := DllCall("GetProcAddress", "Ptr", VMR_MODULE, "AStr", "VBVMR_" . func_name, "Ptr")
if (ErrorLevel || VMR_FUNCTIONS[func_name] == 0)
die("Failed to register VMR function " . func_name . ".")
}
cleanup_before_exit(exit_reason, exit_code) {
DllCall(VMR_FUNCTIONS["Logout"], "Int")
; OnExit functions must return 0 to allow the app to exit.
return 0
}
die(die_string:="UNSPECIFIED FATAL ERROR.", exit_status:=254) {
MsgBox 16, FATAL ERROR, %die_string%
ExitApp exit_status
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment