475 lines
11 KiB
AutoHotkey
475 lines
11 KiB
AutoHotkey
#NoEnv
|
|
#SingleInstance force
|
|
#MaxHotkeysPerInterval 99000000
|
|
#HotkeyInterval 99000000
|
|
#KeyHistory 0
|
|
#UseHook
|
|
#Persistent
|
|
ListLines Off
|
|
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
|
|
SetTitleMatchMode RegEx
|
|
StringCaseSense Off
|
|
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
|
|
|
|
OnExit("cleanup_before_exit")
|
|
SetFormat, Float, 0.3
|
|
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 . "\"
|
|
Sleep, 500
|
|
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")
|
|
add_vmr_function("GetParameterFloat")
|
|
add_vmr_function("IsParametersDirty")
|
|
|
|
; "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
|
|
}
|
|
|
|
; == MIDI ==
|
|
; ==========
|
|
#Include, MIDI\MidiStart.ahk
|
|
#Include, MIDI\Midi_In_and_GuiMonitor.ahk ; this file contains: the function to parse midi message into parts we can work with and a midi monitor.
|
|
#Include, MIDI\MidiRules.ahk ; this file contains: Rules for manipulating midi input then sending modified midi output.
|
|
#Include, MIDI\Midi_under_the_hood.ahk ; this file contains: (DO NOT EDIT THIS FILE) all the dialogs to set up midi ports and midi message handling.
|
|
|
|
midiCCin:
|
|
cc := byte1 ; The Control Channel
|
|
val := byte2 ; The value (0-127 for faders, 0 or 1 for buttons (that part is set with the software))
|
|
|
|
Switch chan
|
|
{
|
|
Case 1: ; The first fader: Work Laptop Out
|
|
Switch cc
|
|
{
|
|
Case 0:
|
|
Lvl := fader_to_fader(val)
|
|
adjustVolLvl("Strip[0]" . ".Gain", Lvl)
|
|
Return
|
|
Case 1:
|
|
Lvl := dial_to_pan(val)
|
|
adjustVolLvl("Strip[0]" . ".Pan_x", Lvl)
|
|
Case 2:
|
|
adjustToggle("Strip[0]" . ".Solo", val)
|
|
Return
|
|
Case 3:
|
|
adjustToggle("Strip[0]" . ".Mute", val)
|
|
Return
|
|
Case 4:
|
|
adjustToggle("Strip[0]" . ".B2", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Case 2: ; The second fader: Work Laptop In
|
|
Switch cc
|
|
{
|
|
Case 0:
|
|
Lvl := fader_to_fader(val)
|
|
adjustVolLvl("Bus[2]" . ".Gain", Lvl)
|
|
Return
|
|
Case 3:
|
|
adjustToggle("Bus[2]" . ".Mute", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Case 3: ; The third fader: Desktop Audio
|
|
Switch cc
|
|
{
|
|
Case 0:
|
|
Lvl := fader_to_fader(val)
|
|
adjustVolLvl("Strip[3]" . ".Gain", Lvl)
|
|
Return
|
|
Case 1:
|
|
Lvl := dial_to_pan(val)
|
|
adjustVolLvl("Strip[3]" . ".Pan_x", Lvl)
|
|
Case 2:
|
|
adjustToggle("Strip[3]" . ".Solo", val)
|
|
Return
|
|
Case 3:
|
|
adjustToggle("Strip[3]" . ".Mute", val)
|
|
Return
|
|
Case 4:
|
|
adjustToggle("Strip[3]" . ".B2", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Case 4: ; The third fader: Comms In
|
|
Switch cc
|
|
{
|
|
Case 0:
|
|
Lvl := fader_to_fader(val)
|
|
adjustVolLvl("Bus[3]" . ".Gain", Lvl)
|
|
Return
|
|
Case 3:
|
|
adjustToggle("Bus[3]" . ".Mute", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Case 5: ; The fifth fader: Comms Out
|
|
Switch cc
|
|
{
|
|
Case 0:
|
|
Lvl := fader_to_fader(val)
|
|
adjustVolLvl("Strip[4]" . ".Gain", Lvl)
|
|
Return
|
|
Case 1:
|
|
Lvl := dial_to_pan(val)
|
|
adjustVolLvl("Strip[4]" . ".Pan_x", Lvl)
|
|
Case 2:
|
|
adjustToggle("Strip[4]" . ".Solo", val)
|
|
Return
|
|
Case 3:
|
|
adjustToggle("Strip[4]" . ".Mute", val)
|
|
Return
|
|
Case 4:
|
|
adjustToggle("Strip[4]" . ".B2", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Case 6: ; The sixth fader: Speakers
|
|
Switch cc
|
|
{
|
|
Case 0:
|
|
Lvl := fader_to_fader(val)
|
|
adjustVolLvl("Bus[0]" . ".Gain", Lvl)
|
|
Return
|
|
Case 3:
|
|
adjustToggle("Bus[0]" . ".Mute", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Case 7: ; The seventh fader: Mic
|
|
Switch cc
|
|
{
|
|
Case 0:
|
|
Lvl := fader_to_fader(val)
|
|
adjustVolLvl("Bus[1]" . ".Gain", Lvl)
|
|
Return
|
|
Case 3:
|
|
adjustToggle("Bus[1]" . ".Mute", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Case 8: ; The eighth fader: Music
|
|
Switch cc
|
|
{
|
|
Case 0:
|
|
Lvl := fader_to_fader(val)
|
|
adjustVolLvl("Strip[2]" . ".Gain", Lvl)
|
|
Return
|
|
Case 1:
|
|
Lvl := dial_to_pan(val)
|
|
adjustVolLvl("Strip[2]" . ".Pan_x", Lvl)
|
|
Case 2:
|
|
adjustToggle("Strip[2]" . ".Solo", val)
|
|
Return
|
|
Case 3:
|
|
adjustToggle("Strip[2]" . ".Mute", val)
|
|
Return
|
|
Case 4:
|
|
adjustToggle("Strip[2]" . ".B1", val)
|
|
adjustToggle("Strip[2]" . ".B2", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Case 10: ; VoiceMeeter recorder controls
|
|
Switch cc
|
|
{
|
|
Case 7: ; Rewind
|
|
adjustToggle("Recorder" . ".REW", val)
|
|
Return
|
|
Case 8: ; Fast Forward
|
|
adjustToggle("Recorder" . ".FF", val)
|
|
Return
|
|
Case 9:
|
|
adjustToggle("Recorder" . ".Stop", val)
|
|
Return
|
|
Case 10:
|
|
adjustToggle("Recorder" . ".Play", val)
|
|
Return
|
|
Case 11:
|
|
adjustToggle("Recorder" . ".Record", val)
|
|
Return
|
|
Default:
|
|
Return
|
|
}
|
|
Default:
|
|
Return
|
|
}
|
|
Return
|
|
|
|
fader_to_fader(val) ; Translates MIDI fader values to the VoiceMeeter software faders
|
|
{
|
|
; The upper limit for faders in VM is 12.0
|
|
; The lower limit for the faders in VM that I would like is -40.0, how low it should go when the physical fader is all the way at the bottom
|
|
nval := Round(((val / 127) * 52) - 40)
|
|
Return nval
|
|
}
|
|
; Formula: ((value / max value) * total range) - negative part of range
|
|
dial_to_pan(val)
|
|
{
|
|
nval := Round((val / 127) - 0.5, 2)
|
|
Return nval
|
|
}
|
|
; == HOTKEYS ==
|
|
; =============
|
|
|
|
/*
|
|
Volume_Up::
|
|
If GetKeyState("ScrollLock", "T") ; Control music volume if scroll lock is on
|
|
{
|
|
cLvl := readParam("Strip[2]" . ".Gain")
|
|
if (cLvl != "")
|
|
{
|
|
cLvl += 1
|
|
adjustVolLvl("Strip[2]" . ".Gain", cLvl)
|
|
}
|
|
Return
|
|
}
|
|
|
|
b0M := Round(readParam("Bus[0]" . ".Mute"))
|
|
b1M := Round(readParam("Bus[1]" . ".Mute"))
|
|
|
|
if !(b0M)
|
|
{
|
|
cLvl := readParam("Bus[0]" . ".Gain")
|
|
if (cLvl != "")
|
|
{
|
|
cLvl += 1
|
|
adjustVolLvl("Bus[0]" . ".Gain", cLvl)
|
|
}
|
|
}
|
|
|
|
if !(b1M)
|
|
{
|
|
cLvl := readParam("Bus[1]" . ".Gain")
|
|
if (cLvl != "")
|
|
{
|
|
cLvl += 1
|
|
adjustVolLvl("Bus[1]" . ".Gain", cLvl)
|
|
}
|
|
}
|
|
return
|
|
|
|
Volume_Down::
|
|
If GetKeyState("ScrollLock", "T") ; Control music volume if scroll lock is on
|
|
{
|
|
cLvl := readParam("Strip[2]" . ".Gain")
|
|
if (cLvl != "")
|
|
{
|
|
cLvl -= 1
|
|
adjustVolLvl("Strip[2]" . ".Gain", cLvl)
|
|
}
|
|
Return
|
|
}
|
|
|
|
b0M := Round(readParam("Bus[0]" . ".Mute"))
|
|
b1M := Round(readParam("Bus[1]" . ".Mute"))
|
|
|
|
if !(b0M)
|
|
{
|
|
cLvl := readParam("Bus[0]" . ".Gain")
|
|
if (cLvl != "")
|
|
{
|
|
cLvl -= 1
|
|
adjustVolLvl("Bus[0]" . ".Gain", cLvl)
|
|
}
|
|
}
|
|
|
|
if !(b1M)
|
|
{
|
|
cLvl := readParam("Bus[1]" . ".Gain")
|
|
if (cLvl != "")
|
|
{
|
|
cLvl -= 1
|
|
adjustVolLvl("Bus[1]" . ".Gain", cLvl)
|
|
}
|
|
}
|
|
return
|
|
*/
|
|
Volume_Mute::
|
|
b0M := Round(readParam("Bus[0]" . ".Mute")) ; Speakers
|
|
b1M := Round(readParam("Bus[1]" . ".Mute")) ; Headphones
|
|
cM := b0M + b1M
|
|
|
|
if (cM = "2")
|
|
{ ; Unmute the ones that were unmuted before
|
|
adjustToggle("Bus[0]" . ".Mute", b0Ms) ; Speakers
|
|
adjustToggle("Bus[1]" . ".Mute", b1Ms) ; Headphones
|
|
} else {
|
|
if !(b0M) ; Speakers
|
|
{
|
|
b0Ms := True
|
|
} else {
|
|
b0Ms := False
|
|
}
|
|
|
|
if !(b1M) ; Headphones
|
|
{
|
|
b1Ms := True
|
|
} else {
|
|
b1Ms := False
|
|
}
|
|
; Mute
|
|
adjustToggle("Bus[0]" . ".Mute", "0") ; Speakers
|
|
adjustToggle("Bus[1]" . ".Mute", "0") ; Headphones
|
|
}
|
|
Return
|
|
|
|
/*
|
|
!m:: ; Mute: No audio out
|
|
Send {F23}
|
|
b3M := Round(readParam("Bus[3]" . ".Mute")) ; Comms IN
|
|
s4M := Round(readParam("Strip[4]" . ".Mute")) ; Comms OUT
|
|
|
|
If (s4M)
|
|
{
|
|
adjustToggle("Bus[3]" . ".Mute", "1") ; Comms IN
|
|
adjustToggle("Strip[4]" . ".Mute", "1") ; Comms OUT
|
|
return
|
|
}
|
|
|
|
If !(b3M)
|
|
{
|
|
adjustToggle("Bus[3]" . ".Mute", "0")
|
|
} else {
|
|
adjustToggle("Bus[3]" . ".Mute", "1")
|
|
}
|
|
Return
|
|
|
|
!n:: ; Deafen: No audio in or out
|
|
Send {F24}
|
|
s4M := Round(readParam("Strip[4]" . ".Mute")) ; Comms OUT
|
|
|
|
If (s4M)
|
|
{
|
|
adjustToggle("Bus[3]" . ".Mute", "1") ; Comms IN
|
|
adjustToggle("Strip[4]" . ".Mute", "1") ; Comms OUT
|
|
} else {
|
|
adjustToggle("Bus[3]" . ".Mute", "0") ; Comms IN
|
|
Sleep, 650 ; Delay so that the "deafened" sound from discord can play
|
|
adjustToggle("Strip[4]" . ".Mute", "0") ; Comms OUT
|
|
}
|
|
Return
|
|
|
|
!j:: ; Mute toggle for meetings on work laptop
|
|
Send {F24}
|
|
cM := Round(readParam("Bus[2]" . ".Mute"))
|
|
|
|
if (cM)
|
|
{
|
|
adjustToggle("Bus[2]" . ".Mute", "1") ; Work Laptop
|
|
adjustToggle("Bus[3]" . ".Mute", "0") ; Comms IN
|
|
adjustToggle("Strip[3]" . ".Mute", "0") ; Desktop
|
|
Sleep, 650 ; Delay so that the "deafened" sound from discord can play
|
|
adjustToggle("Strip[4]" . ".Mute", "0") ; Comms OUT
|
|
}
|
|
if !(cM)
|
|
{
|
|
adjustToggle("Bus[2]" . ".Mute", "0") ; Work Laptop
|
|
adjustToggle("Bus[3]" . ".Mute", "1") ; Comms IN
|
|
adjustToggle("Strip[4]" . ".Mute", "1") ; Comms OUT
|
|
adjustToggle("Strip[3]" . ".Mute", "1") ; Desktop
|
|
}
|
|
Return
|
|
*/
|
|
|
|
; == Functions ==
|
|
; ===============
|
|
readParam(loc){
|
|
Loop
|
|
{
|
|
pDirty := DLLCall(VMR_FUNCTIONS["IsParametersDirty"]) ;Check if parameters have changed.
|
|
if (pDirty==0) ;0 = no new paramters.
|
|
break
|
|
else if (pDirty<0) ;-1 = error, -2 = no server
|
|
return ""
|
|
else ;1 = New parameters -> update your display. (this only applies if YOU have a display, couldn't find any code to update VM display which can get off sometimes)
|
|
if A_Index > 200
|
|
return ""
|
|
sleep, 20
|
|
}
|
|
tParamVal := 0.0
|
|
NumPut(0.0, tParamVal, 0, "Float")
|
|
statusLvl := DllCall(VMR_FUNCTIONS["GetParameterFloat"], "AStr", loc, "Ptr", &tParamVal, "Int")
|
|
tParamVal := NumGet(tParamVal, 0, "Float")
|
|
if (statusLvl < 0)
|
|
return ""
|
|
else
|
|
return tParamVal
|
|
}
|
|
|
|
adjustVolLvl(loc, tVol) {
|
|
if (tVol > 12.0)
|
|
tVol := 12.0
|
|
else if (tVol < -60.0)
|
|
tVol := -60.0
|
|
DllCall(VMR_FUNCTIONS["SetParameterFloat"], "AStr", loc, "Float", tVol, "Int")
|
|
}
|
|
|
|
adjustToggle(loc, tM) {
|
|
if (tM = 0)
|
|
tM := 1
|
|
else
|
|
tM := 0
|
|
DllCall(VMR_FUNCTIONS["SetParameterFloat"], "AStr", loc, "Float", tM, "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
|
|
}
|