Skip to content

Commit

Permalink
Fix error when using multiple VMR instances #27
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed Jan 26, 2025
1 parent b96e9c0 commit d396312
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ahkpm.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.0",
"version": "2.0.1",
"description": "AutoHotkey wrapper class for Voicemeeter's Remote API",
"repository": "https://github.com/SaifAqqad/VMR.ahk",
"website": "https://saifaqqad.github.io/VMR.ahk",
Expand Down
30 changes: 21 additions & 9 deletions dist/VMR.ahk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* VMR.ahk - A wrapper for Voicemeeter's Remote API
* - Version 2.0.0
* - Build timestamp 2024-03-09 19:51:57 UTC
* - Version 2.0.1
* - Build timestamp 2025-01-26 18:41:33 UTC
* - Repository: {@link https://github.com/SaifAqqad/VMR.ahk GitHub}
* - Documentation: {@link https://saifaqqad.github.io/VMR.ahk VMR Docs}
*/
Expand Down Expand Up @@ -257,7 +257,7 @@ class VBVMR {
SetParameters: 0,
SetParametersW: 0
}
static DLL := "", DLL_PATH := ""
static DLL := "", DLL_PATH := "", LOGGED_IN := false
/**
* Initializes the VBVMR class by loading the Voicemeeter Remote DLL and getting the addresses of all needed functions.
* If the DLL is already loaded, it returns immediately.
Expand Down Expand Up @@ -303,12 +303,15 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static Login() {
local result
local result := 0
if (VBVMR.LOGGED_IN)
return result
try result := DllCall(VBVMR.FUNC.Login)
catch Error as err
throw VMRError(err, VBVMR.Login.Name)
if (result < 0)
throw VMRError(result, VBVMR.Login.Name)
VBVMR.LOGGED_IN := true
return result
}
/**
Expand All @@ -319,12 +322,15 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static Logout() {
local result
local result := 0
if (!VBVMR.LOGGED_IN)
return result
try result := DllCall(VBVMR.FUNC.Logout)
catch Error as err
throw VMRError(err, VBVMR.Logout.Name)
if (result < 0)
throw VMRError(result, VBVMR.Logout.Name)
VBVMR.LOGGED_IN := false
return result
}
/**
Expand Down Expand Up @@ -536,7 +542,9 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static IsParametersDirty() {
local result
local result := 0
if (!VBVMR.LOGGED_IN)
return result
try result := DllCall(VBVMR.FUNC.IsParametersDirty)
catch Error as err
throw VMRError(err, VBVMR.IsParametersDirty.Name)
Expand Down Expand Up @@ -600,7 +608,9 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static MacroButton_IsDirty() {
local result
local result := 0
if (!VBVMR.LOGGED_IN)
return result
try result := DllCall(VBVMR.FUNC.MacroButton_IsDirty)
catch Error as err
throw VMRError(err, VBVMR.MacroButton_IsDirty.Name)
Expand All @@ -617,8 +627,10 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static GetMidiMessage() {
local result, data := Buffer(1024),
local result := "", data := Buffer(1024),
messages := []
if (!VBVMR.LOGGED_IN)
return result
try result := DllCall(VBVMR.FUNC.GetMidiMessage, "Ptr", data, "Int", 1024)
catch Error as err
throw VMRError(err, VBVMR.GetMidiMessage.Name)
Expand Down Expand Up @@ -1751,7 +1763,7 @@ class VMR {
Login(p_launchVoicemeeter := true) {
local loginStatus := VBVMR.Login()
; Check if we should launch the Voicemeeter UI
if (loginStatus != 0 && p_launchVoicemeeter) {
if (loginStatus == 1 && p_launchVoicemeeter) {
local vmPID := this.RunVoicemeeter()
WinWait("ahk_class VBCABLE0Voicemeeter0MainWindow0 ahk_pid" vmPID)
Sleep(2000)
Expand Down
29 changes: 23 additions & 6 deletions src/VBVMR.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class VBVMR {
SetParameters: 0,
SetParametersW: 0
}
static DLL := "", DLL_PATH := ""
static DLL := "", DLL_PATH := "", LOGGED_IN := false

/**
* Initializes the VBVMR class by loading the Voicemeeter Remote DLL and getting the addresses of all needed functions.
Expand Down Expand Up @@ -86,7 +86,10 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static Login() {
local result
local result := 0

if (VBVMR.LOGGED_IN)
return result

try result := DllCall(VBVMR.FUNC.Login)
catch Error as err
Expand All @@ -95,6 +98,7 @@ class VBVMR {
if (result < 0)
throw VMRError(result, VBVMR.Login.Name)

VBVMR.LOGGED_IN := true
return result
}

Expand All @@ -106,7 +110,10 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static Logout() {
local result
local result := 0

if (!VBVMR.LOGGED_IN)
return result

try result := DllCall(VBVMR.FUNC.Logout)
catch Error as err
Expand All @@ -115,6 +122,7 @@ class VBVMR {
if (result < 0)
throw VMRError(result, VBVMR.Logout.Name)

VBVMR.LOGGED_IN := false
return result
}

Expand Down Expand Up @@ -372,7 +380,10 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static IsParametersDirty() {
local result
local result := 0

if (!VBVMR.LOGGED_IN)
return result

try result := DllCall(VBVMR.FUNC.IsParametersDirty)
catch Error as err
Expand Down Expand Up @@ -448,7 +459,10 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static MacroButton_IsDirty() {
local result
local result := 0

if (!VBVMR.LOGGED_IN)
return result

try result := DllCall(VBVMR.FUNC.MacroButton_IsDirty)
catch Error as err
Expand All @@ -469,9 +483,12 @@ class VBVMR {
* @throws {VMRError} - If an internal error occurs.
*/
static GetMidiMessage() {
local result, data := Buffer(1024),
local result := "", data := Buffer(1024),
messages := []

if (!VBVMR.LOGGED_IN)
return result

try result := DllCall(VBVMR.FUNC.GetMidiMessage, "Ptr", data, "Int", 1024)
catch Error as err
throw VMRError(err, VBVMR.GetMidiMessage.Name)
Expand Down
2 changes: 1 addition & 1 deletion src/VMR.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class VMR {
local loginStatus := VBVMR.Login()

; Check if we should launch the Voicemeeter UI
if (loginStatus != 0 && p_launchVoicemeeter) {
if (loginStatus == 1 && p_launchVoicemeeter) {
local vmPID := this.RunVoicemeeter()
WinWait("ahk_class VBCABLE0Voicemeeter0MainWindow0 ahk_pid" vmPID)
Sleep(2000)
Expand Down

0 comments on commit d396312

Please sign in to comment.