diff --git a/index.js b/index.js index 21b91bb..195cc06 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const { dirname, join } = require("path"); const Registry = require("winreg"); const koffi = require("koffi"); -const { VoicemeeterDefaultConfig, VoicemeeterType, InterfaceType, MacroButtonState, MacroButtonTrigger, MacroButtonColor } = require("./voicemeeterEnums"); +const { VoicemeeterDefaultConfig, VoicemeeterType, RunVoicemeeterType, InterfaceType, LevelType, DeviceType, MacroButtonState, MacroButtonTrigger, MacroButtonColor } = require("./voicemeeterEnums"); const getDLLPath = () => { const regKey = new Registry({ @@ -80,8 +80,8 @@ const voicemeeter = { this.isInitialised = true; }, - runVoicemeeter(voicemeeterType) { - if (libvoicemeeter.VBVMR_RunVoicemeeter(voicemeeterType) !== 0) + runVoicemeeter(runVoicemeeterType) { + if (libvoicemeeter.VBVMR_RunVoicemeeter(runVoicemeeterType) !== 0) throw "Running failed"; }, @@ -90,20 +90,63 @@ const voicemeeter = { }, /** - * @deprecated + * @deprecated Use getRawParameterFloat */ getParameter(parameterName) { + return getRawParameterFloat(parameterName); + }, + + getRawParameterFloat(parameter) { if (!this.isConnected) throw "Not connected"; const value = [0]; - if (libvoicemeeter.VBVMR_GetParameterFloat(parameterName, value) !== 0) + if (libvoicemeeter.VBVMR_GetParameterFloat(parameter, value) !== 0) throw "Running failed"; return value[0]; }, + getRawParameterString(parameter) { + + if (!this.isConnected) + throw "Not connected"; + + const value = Buffer.alloc(512); + if (libvoicemeeter.VBVMR_GetParameterStringA(parameter, value) !== 0) + throw "Running failed"; + + return value.toString().replace(/\x00+$/, ""); + }, + + setRawParameterFloat(parameter, value) { + + if (!this.isConnected) + throw "Not connected"; + + if (libvoicemeeter.VBVMR_SetParameterFloat(parameter, value) !== 0) + throw "Running failed"; + }, + + setRawParameterString(parameter, value) { + + if (!this.isConnected) + throw "Not connected"; + + if (libvoicemeeter.VBVMR_SetParameterStringA(parameter, value) !== 0) + throw "Running failed"; + }, + + setRawParameters(parameters) { + + if (!this.isConnected) + throw "Not connected"; + + if (libvoicemeeter.VBVMR_SetParameters(parameters) !== 0) + throw "Running failed"; + }, + login() { if (!this.isInitialised) @@ -184,53 +227,53 @@ const voicemeeter = { }, showVoicemeeter() { - this._sendRawParameterScript("Command.Show=1;"); + this.setRawParameters("Command.Show=1;"); }, shutdownVoicemeeter() { - this._sendRawParameterScript("Command.Shutdown=1;"); + this.setRawParameters("Command.Shutdown=1;"); }, restartVoicemeeterAudioEngine() { - this._sendRawParameterScript("Command.Restart=1;"); + this.setRawParameters("Command.Restart=1;"); }, ejectVoicemeeterCassette() { - this._sendRawParameterScript("Command.Eject=1;"); + this.setRawParameters("Command.Eject=1;"); }, resetVoicemeeterConfiguration() { - this._sendRawParameterScript("Command.Reset=1;"); + this.setRawParameters("Command.Reset=1;"); }, saveVoicemeeterConfiguration(filename) { - this._sendRawParameterScript("Command.Save=" + filename + ";"); + this.setRawParameters("Command.Save=" + filename + ";"); }, loadVoicemeeterConfiguration(filename) { - this._sendRawParameterScript("Command.Load=" + filename + ";"); + this.setRawParameters("Command.Load=" + filename + ";"); }, lockVoicemeeterGui(lock) { - this._sendRawParameterScript("Command.Lock=" + (lock ? 1 : 0) + ";"); + this.setRawParameters("Command.Lock=" + (lock ? 1 : 0) + ";"); }, setMacroButtonState(button, state) { if (!Object.values(MacroButtonState).includes(state)) throw "Invalid state"; - this._sendRawParameterScript("Command.Button[" + button + "].State=" + state + ";"); + this.setRawParameters("Command.Button[" + button + "].State=" + state + ";"); }, setMacroButtonStateOnly(button, state) { if (!Object.values(MacroButtonState).includes(state)) throw "Invalid state"; - this._sendRawParameterScript("Command.Button[" + button + "].StateOnly=" + state + ";"); + this.setRawParameters("Command.Button[" + button + "].StateOnly=" + state + ";"); }, setMacroButtonTrigger(button, trigger) { if (!Object.values(MacroButtonTrigger).includes(trigger)) throw "Invalid trigger"; - this._sendRawParameterScript("Command.Button[" + button + "].Trigger=" + trigger + ";"); + this.setRawParameters("Command.Button[" + button + "].Trigger=" + trigger + ";"); }, /** @@ -239,11 +282,11 @@ const voicemeeter = { setMacroButtonColor(button, color) { if (!Object.values(MacroButtonColor).includes(color)) throw "Invalid color"; - this._sendRawParameterScript("Command.Button[" + button + "].Color=" + color + ";"); + this.setRawParameters("Command.Button[" + button + "].Color=" + color + ";"); }, showVbanChatDialog() { - this._sendRawParameterScript("Command.DialogShow.VBANCHAT=1;"); + this.setRawParameters("Command.DialogShow.VBANCHAT=1;"); }, getLevel(type, channel) { @@ -252,7 +295,6 @@ const voicemeeter = { throw "Not connected"; const value = [0]; - if (libvoicemeeter.VBVMR_GetLevel(type, channel, value) !== 0) throw "Running failed"; @@ -272,8 +314,6 @@ const voicemeeter = { return VoicemeeterType.voicemeeterBanana; case 3: return VoicemeeterType.voicemeeterPotato; - case 6: - return VoicemeeterType.voicemeeterPotato64; default: return VoicemeeterType.unknown; } @@ -311,11 +351,7 @@ const voicemeeter = { const parameter = `${interfaceType}[${id}].${name}`; - const value = [0]; - if (libvoicemeeter.VBVMR_GetParameterFloat(parameter, value) !== 0) - throw "Running failed"; - - return value[0]; + return this.getRawParameterFloat(parameter); }, _getParameterString(type, name, id) { @@ -336,11 +372,7 @@ const voicemeeter = { const parameter = `${interfaceType}[${id}].${name}`; - const value = Buffer.alloc(512); - if (libvoicemeeter.VBVMR_GetParameterStringA(parameter, value) !== 0) - throw "Running failed"; - - return value.toString().replace(/\x00+$/, ""); + return this.getRawParameterString(parameter); }, _setParameterFloat(type, name, id, value) { @@ -361,8 +393,7 @@ const voicemeeter = { const parameter = `${interfaceType}[${id}].${name}`; - if (libvoicemeeter.VBVMR_SetParameterFloat(parameter, value) !== 0) - throw "Running failed"; + this.setRawParameterFloat(parameter, value); }, _setParameterString(type, name, id, value) { @@ -383,8 +414,7 @@ const voicemeeter = { const parameter = `${interfaceType}[${id}].${name}`; - if (libvoicemeeter.VBVMR_SetParameterStringA(parameter, value) !== 0) - throw "Running failed"; + this.setRawParameterString(parameter, value); }, _setParameters(parameters) { @@ -412,12 +442,14 @@ const voicemeeter = { }).join(""); - this._sendRawParameterScript(script); + this.setRawParameters(script); }, + /** + * @deprecated Use setRawParameters + */ _sendRawParameterScript(script) { - if (libvoicemeeter.VBVMR_SetParameters(script) !== 0) - throw "Running failed"; + this.setRawParameters(script); } } @@ -454,7 +486,10 @@ stripParametersNames.forEach((name) => { module.exports = voicemeeter; module.exports.VoicemeeterType = VoicemeeterType; +module.exports.RunVoicemeeterType = RunVoicemeeterType; module.exports.InterfaceType = InterfaceType; +module.exports.LevelType = LevelType; +module.exports.DeviceType = DeviceType; module.exports.MacroButtonState = MacroButtonState; module.exports.MacroButtonTrigger = MacroButtonTrigger; module.exports.MacroButtonColor = MacroButtonColor; diff --git a/package.json b/package.json index 6ad8e67..6482114 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "voicemeeter-remote", - "version": "0.4.0", + "version": "0.5.0", "description": "A Node.js voicemeeter remote wrapper", "main": "index.js", "author": "Mickael MAYEUR", diff --git a/voicemeeterEnums.js b/voicemeeterEnums.js index 060341c..417bbca 100644 --- a/voicemeeterEnums.js +++ b/voicemeeterEnums.js @@ -102,56 +102,6 @@ const VoicemeeterDefaultConfig = { // key is VoicemeeterType id: 7, isVirtual: true }], - }, - 6: { - strips: [{ - id: 0, - name: "Hardware input 1" - }, { - id: 1, - name: "Hardware input 2" - }, { - id: 2, - name: "Hardware input 3" - }, { - id: 3, - name: "Hardware input 4" - }, { - id: 4, - name: "Hardware input 5" - }, { - id: 5, - name: "Voicemeeter VAIO", - isVirtual: true - }, { - id: 6, - name: "Voicemeeter AUX", - isVirtual: true - }, { - id: 7, - name: "Voicemeeter VAIO 3", - isVirtual: true - }], - buses: [{ - id: 0, - }, { - id: 1, - }, { - id: 2, - }, { - id: 3, - }, { - id: 4, - }, { - id: 5, - isVirtual: true - }, { - id: 6, - isVirtual: true - }, { - id: 7, - isVirtual: true - }], } } @@ -159,8 +109,26 @@ const VoicemeeterType = { unknown: 0, voicemeeter: 1, voicemeeterBanana: 2, - voicemeeterPotato: 3, - voicemeeterPotato64: 6 + voicemeeterPotato: 3 +} + +const RunVoicemeeterType = { + VoicemeeterStandard: 1, + VoicemeeterBanana: 2, + VoicemeeterPotato: 3, + VoicemeeterStandardx64: 4, + VoicemeeterBananax64: 5, + VoicemeeterPotatox64: 6, + VBDeviceCheck: 10, + VoicemeeterMacroButtons: 11, + VMStreamerView: 12, + VoicemeeterBUSMatrix8: 13, + VoicemeeterBUSGEQ15: 14, + VBAN2MIDI: 15, + VBCABLE_ControlPanel: 20, + VBVMAUX_ControlPanel: 21, + VBVMVAIO3_ControlPanel: 22, + VBVoicemeeterVAIO_ControlPanel: 23 } const InterfaceType = { @@ -204,4 +172,4 @@ const MacroButtonColor = { red: 8 } -module.exports = { VoicemeeterDefaultConfig, VoicemeeterType, InterfaceType, LevelType, DeviceType, MacroButtonState, MacroButtonTrigger, MacroButtonColor }; +module.exports = { VoicemeeterDefaultConfig, VoicemeeterType, RunVoicemeeterType, InterfaceType, LevelType, DeviceType, MacroButtonState, MacroButtonTrigger, MacroButtonColor };