first commit

This commit is contained in:
onyx-and-iris 2024-06-25 04:34:28 +01:00
commit 7805b14ff1
8 changed files with 1561 additions and 0 deletions

54
.gitignore vendored Normal file
View File

@ -0,0 +1,54 @@
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
.vscode/

1093
include/VoicemeeterRemote.h Normal file

File diff suppressed because it is too large Load Diff

9
include/cdll.h Normal file
View File

@ -0,0 +1,9 @@
#include <windows.h>
#include "VoicemeeterRemote.h"
#ifndef __CDLL_H__
#define __CDLL_H__
long initialize_dll_interfaces(T_VBVMR_INTERFACE *iVMR);
#endif /*__CDLL_H__*/

22
include/vmr.h Normal file
View File

@ -0,0 +1,22 @@
#include <stdbool.h>
#include "voicemeeterRemote.h"
#ifndef __VMR_H__
#define __VMR_H__
long login(T_VBVMR_INTERFACE *iVMR);
long logout(T_VBVMR_INTERFACE *iVMR);
long run_voicemeeter(T_VBVMR_INTERFACE *iVMR);
long type(T_VBVMR_INTERFACE *iVMR, long *type);
long version(T_VBVMR_INTERFACE *iVMR, long *version);
bool pdirty(T_VBVMR_INTERFACE *iVMR);
long set_parameters(T_VBVMR_INTERFACE *iVMR, char *command);
bool mdirty(T_VBVMR_INTERFACE *iVMR);
long macrobutton_getstatus(T_VBVMR_INTERFACE *iVMR, long n, float *val, long mode);
long macrobutton_setstatus(T_VBVMR_INTERFACE *iVMR, long n, float val, long mode);
void clear_dirty(T_VBVMR_INTERFACE *iVMR);
#endif

33
makefile Normal file
View File

@ -0,0 +1,33 @@
program = vmrcli
CC = gcc
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := bin
EXE := $(BIN_DIR)/$(program).exe
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
CPPFLAGS := -Iinclude -MMD -MP
CFLAGS = -O -Wall -W -pedantic -ansi -std=c99
LDFLAGS := -Llib
LDLIBS := -lm
.PHONY: all clean
all: $(EXE)
$(EXE): $(OBJ) | $(BIN_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(BIN_DIR) $(OBJ_DIR):
mkdir -p $@
clean:
@$(RM) -rv $(EXE) $(OBJ_DIR)
-include $(OBJ:.o=.d)

172
src/cdll.c Normal file
View File

@ -0,0 +1,172 @@
#include <stdbool.h>
#include <stdio.h>
#include "cdll.h"
/*******************************************************************************/
/** GET VOICEMEETER DIRECTORY **/
/*******************************************************************************/
static char uninstDirKey[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
#define INSTALLER_UNINST_KEY "VB:Voicemeeter {17359A74-1236-5467}"
void remove_name_in_path(char *szPath)
{
char *p = szPath;
while (*p++)
;
while (p > szPath && *p != '\\')
p--;
if (*p == '\\')
*p = '\0';
}
#ifndef KEY_WOW64_32KEY
#define KEY_WOW64_32KEY 0x0200
#endif
bool __cdecl registry_get_voicemeeter_folder(char *szDir)
{
char szKey[256];
char sss[1024];
DWORD nnsize = 1024;
HKEY hkResult;
LONG rep;
DWORD pptype = REG_SZ;
sss[0] = 0;
// build Voicemeeter uninstallation key
strcpy(szKey, uninstDirKey);
strcat(szKey, "\\");
strcat(szKey, INSTALLER_UNINST_KEY);
// open key
rep = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &hkResult);
if (rep != ERROR_SUCCESS)
{
// if not present we consider running in 64bit mode and force to read 32bit registry
rep = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ | KEY_WOW64_32KEY, &hkResult);
}
if (rep != ERROR_SUCCESS)
return false;
// read uninstall path from registry
rep = RegQueryValueEx(hkResult, "UninstallString", 0, &pptype, (unsigned char *)sss, &nnsize);
RegCloseKey(hkResult);
if (pptype != REG_SZ)
return false;
if (rep != ERROR_SUCCESS)
return false;
// remove name to get the path only
remove_name_in_path(sss);
if (nnsize > 512)
nnsize = 512;
strncpy(szDir, sss, nnsize);
return true;
}
/*******************************************************************************/
/** GET DLL INTERFACE **/
/*******************************************************************************/
static HMODULE G_H_Module = NULL;
long initialize_dll_interfaces(T_VBVMR_INTERFACE *iVMR)
{
char szDllName[1024];
memset(iVMR, 0, sizeof(T_VBVMR_INTERFACE));
// get folder where is installed Voicemeeter
if (!registry_get_voicemeeter_folder(szDllName))
{
// voicemeeter not installed
return -100;
}
// use right dll according O/S type
if (sizeof(void *) == 8)
strcat(szDllName, "\\VoicemeeterRemote64.dll");
else
strcat(szDllName, "\\VoicemeeterRemote.dll");
// Load Dll
G_H_Module = LoadLibrary(szDllName);
if (G_H_Module == NULL)
return -101;
// Get function pointers
iVMR->VBVMR_Login = (T_VBVMR_Login)GetProcAddress(G_H_Module, "VBVMR_Login");
iVMR->VBVMR_Logout = (T_VBVMR_Logout)GetProcAddress(G_H_Module, "VBVMR_Logout");
iVMR->VBVMR_RunVoicemeeter = (T_VBVMR_RunVoicemeeter)GetProcAddress(G_H_Module, "VBVMR_RunVoicemeeter");
iVMR->VBVMR_GetVoicemeeterType = (T_VBVMR_GetVoicemeeterType)GetProcAddress(G_H_Module, "VBVMR_GetVoicemeeterType");
iVMR->VBVMR_GetVoicemeeterVersion = (T_VBVMR_GetVoicemeeterVersion)GetProcAddress(G_H_Module, "VBVMR_GetVoicemeeterVersion");
iVMR->VBVMR_IsParametersDirty = (T_VBVMR_IsParametersDirty)GetProcAddress(G_H_Module, "VBVMR_IsParametersDirty");
iVMR->VBVMR_GetParameterFloat = (T_VBVMR_GetParameterFloat)GetProcAddress(G_H_Module, "VBVMR_GetParameterFloat");
iVMR->VBVMR_GetParameterStringA = (T_VBVMR_GetParameterStringA)GetProcAddress(G_H_Module, "VBVMR_GetParameterStringA");
iVMR->VBVMR_GetParameterStringW = (T_VBVMR_GetParameterStringW)GetProcAddress(G_H_Module, "VBVMR_GetParameterStringW");
iVMR->VBVMR_GetLevel = (T_VBVMR_GetLevel)GetProcAddress(G_H_Module, "VBVMR_GetLevel");
iVMR->VBVMR_GetMidiMessage = (T_VBVMR_GetMidiMessage)GetProcAddress(G_H_Module, "VBVMR_GetMidiMessage");
iVMR->VBVMR_SetParameterFloat = (T_VBVMR_SetParameterFloat)GetProcAddress(G_H_Module, "VBVMR_SetParameterFloat");
iVMR->VBVMR_SetParameters = (T_VBVMR_SetParameters)GetProcAddress(G_H_Module, "VBVMR_SetParameters");
iVMR->VBVMR_SetParametersW = (T_VBVMR_SetParametersW)GetProcAddress(G_H_Module, "VBVMR_SetParametersW");
iVMR->VBVMR_SetParameterStringA = (T_VBVMR_SetParameterStringA)GetProcAddress(G_H_Module, "VBVMR_SetParameterStringA");
iVMR->VBVMR_SetParameterStringW = (T_VBVMR_SetParameterStringW)GetProcAddress(G_H_Module, "VBVMR_SetParameterStringW");
iVMR->VBVMR_Output_GetDeviceNumber = (T_VBVMR_Output_GetDeviceNumber)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceNumber");
iVMR->VBVMR_Output_GetDeviceDescA = (T_VBVMR_Output_GetDeviceDescA)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceDescA");
iVMR->VBVMR_Output_GetDeviceDescW = (T_VBVMR_Output_GetDeviceDescW)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceDescW");
iVMR->VBVMR_Input_GetDeviceNumber = (T_VBVMR_Input_GetDeviceNumber)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceNumber");
iVMR->VBVMR_Input_GetDeviceDescA = (T_VBVMR_Input_GetDeviceDescA)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceDescA");
iVMR->VBVMR_Input_GetDeviceDescW = (T_VBVMR_Input_GetDeviceDescW)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceDescW");
// check pointers are valid
if (iVMR->VBVMR_Login == NULL)
return -1;
if (iVMR->VBVMR_Logout == NULL)
return -2;
if (iVMR->VBVMR_RunVoicemeeter == NULL)
return -2;
if (iVMR->VBVMR_GetVoicemeeterType == NULL)
return -3;
if (iVMR->VBVMR_GetVoicemeeterVersion == NULL)
return -4;
if (iVMR->VBVMR_IsParametersDirty == NULL)
return -5;
if (iVMR->VBVMR_GetParameterFloat == NULL)
return -6;
if (iVMR->VBVMR_GetParameterStringA == NULL)
return -7;
if (iVMR->VBVMR_GetParameterStringW == NULL)
return -8;
if (iVMR->VBVMR_GetLevel == NULL)
return -9;
if (iVMR->VBVMR_SetParameterFloat == NULL)
return -10;
if (iVMR->VBVMR_SetParameters == NULL)
return -11;
if (iVMR->VBVMR_SetParametersW == NULL)
return -12;
if (iVMR->VBVMR_SetParameterStringA == NULL)
return -13;
if (iVMR->VBVMR_SetParameterStringW == NULL)
return -14;
if (iVMR->VBVMR_GetMidiMessage == NULL)
return -15;
if (iVMR->VBVMR_Output_GetDeviceNumber == NULL)
return -30;
if (iVMR->VBVMR_Output_GetDeviceDescA == NULL)
return -31;
if (iVMR->VBVMR_Output_GetDeviceDescW == NULL)
return -32;
if (iVMR->VBVMR_Input_GetDeviceNumber == NULL)
return -33;
if (iVMR->VBVMR_Input_GetDeviceDescA == NULL)
return -34;
if (iVMR->VBVMR_Input_GetDeviceDescW == NULL)
return -35;
return 0;
}

81
src/vmr.c Normal file
View File

@ -0,0 +1,81 @@
#include <windows.h>
#include <stdio.h>
#include "vmr.h"
enum kind
{
BASIC = 1,
BANANA,
POTATO,
POTATOX64 = 6
} kind;
long login(T_VBVMR_INTERFACE *iVMR)
{
int rep;
rep = iVMR->VBVMR_Login();
if (rep == 1)
{
rep = run_voicemeeter(iVMR);
puts("Launching Voicemeeter GUI");
Sleep(1200);
}
return rep;
}
long logout(T_VBVMR_INTERFACE *iVMR)
{
Sleep(20); /* give time for last command */
return iVMR->VBVMR_Logout();
}
long run_voicemeeter(T_VBVMR_INTERFACE *iVMR)
{
int kind = POTATO;
if (sizeof(void *) == 8)
kind = POTATOX64;
return iVMR->VBVMR_RunVoicemeeter((long)kind);
}
long type(T_VBVMR_INTERFACE *iVMR, long *type)
{
return iVMR->VBVMR_GetVoicemeeterType(type);
}
long version(T_VBVMR_INTERFACE *iVMR, long *version)
{
return iVMR->VBVMR_GetVoicemeeterType(version);
}
bool pdirty(T_VBVMR_INTERFACE *iVMR)
{
return iVMR->VBVMR_IsParametersDirty() == 1;
}
long set_parameters(T_VBVMR_INTERFACE *iVMR, char *command)
{
return iVMR->VBVMR_SetParameters(command);
}
bool mdirty(T_VBVMR_INTERFACE *iVMR)
{
return iVMR->VBVMR_MacroButton_IsDirty() == 1;
}
long macrobutton_getstatus(T_VBVMR_INTERFACE *iVMR, long n, float *val, long mode)
{
return iVMR->VBVMR_MacroButton_GetStatus(n, val, mode);
}
long macrobutton_setstatus(T_VBVMR_INTERFACE *iVMR, long n, float val, long mode)
{
return iVMR->VBVMR_MacroButton_SetStatus(n, val, mode);
}
void clear_dirty(T_VBVMR_INTERFACE *iVMR)
{
Sleep(30);
while (pdirty(iVMR))
Sleep(1);
}

97
src/vmrcli.c Normal file
View File

@ -0,0 +1,97 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include "cdll.h"
#include "vmr.h"
#define MAX_LINE 1024
int init_voicemeeter(T_VBVMR_INTERFACE *vmr);
void interactive(T_VBVMR_INTERFACE *vmr);
int main(int argc, char *argv[])
{
bool iflag = false;
int c;
while ((c = getopt(argc, argv, "i")) != -1)
{
switch (c)
{
case 'i':
iflag = true;
break;
default:
abort();
}
}
static T_VBVMR_INTERFACE iVMR;
T_VBVMR_INTERFACE *vmr = &iVMR;
int rep = init_voicemeeter(vmr);
if (rep)
{
exit(EXIT_FAILURE);
}
if (iflag)
{
puts("Interactive mode enabled. Enter 'Q' to exit.");
interactive(vmr);
}
else
{
for (int i = optind; i < argc; i++)
{
set_parameters(vmr, argv[i]);
}
}
rep = logout(vmr);
if (!rep)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
int init_voicemeeter(T_VBVMR_INTERFACE *vmr)
{
int rep = initialize_dll_interfaces(vmr);
if (rep < 0)
{
if (rep == -100)
{
fputs("Voicemeeter is not installed", stderr);
}
else
{
fprintf(stderr, "Error loading Voicemeeter dll with code %d\n", rep);
}
return rep;
}
rep = login(vmr);
if (rep != 0)
{
fputs("Error logging into Voicemeeter", stderr);
return rep;
}
clear_dirty(vmr);
return 0;
}
void interactive(T_VBVMR_INTERFACE *vmr)
{
char input[MAX_LINE];
while (fgets(input, MAX_LINE, stdin) != NULL)
{
if (strncmp(input, "Q", 1) == 0 || strncmp(input, "q", 1) == 0)
break;
set_parameters(vmr, input);
}
}