Skip to content

Instantly share code, notes, and snippets.

@LaserKaspar
Forked from pprince/PTT_for_Voicemeeter.ahk
Last active April 28, 2021 20:11
Show Gist options
  • Save LaserKaspar/f17c8d5047e0bec1277b68034456e9f8 to your computer and use it in GitHub Desktop.
Save LaserKaspar/f17c8d5047e0bec1277b68034456e9f8 to your computer and use it in GitHub Desktop.
/*
ChangeVoicemeeterProfile.ahk - AHKscript Changing Presets for VoicemeeterBanana
======================================================================
Based On:
---------
PTT_for_Voicemeeter.ahk
https://gist.github.com/pprince/f42c8c9d06e54f8adbb6
*/
/*
Voicemeeter API Docs
https://forum.vb-audio.com/viewtopic.php?f=8&t=346
*/
; 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("SetParameterStringW")
; "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
}
; == HOTKEYS ==
; =============
^F1::
load_settings(A_ScriptDir . "\monitor.xml")
return
^F2::
load_settings(A_ScriptDir . "\micorbluetooth.xml")
return
^F3::
load_settings(A_ScriptDir . "\laptop.xml")
return
; == Functions ==
; ===============
load_settings(settingsPath) {
WhichButton := DllCall(VMR_FUNCTIONS["SetParameterStringW"], "AStr", "Command.Load", "WStr", settingsPath, "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