voicemeeter-connector
Version:
A Connector to use the Voicemeeter API
226 lines (225 loc) • 9.39 kB
TypeScript
import { AudioCallbackFunction, Device, VoiceMeeterTypes } from "../types/voicemeeter-types";
import { AudioCallbackModes, BusProperties, StripProperties } from "./constants";
export default class Voicemeeter {
/**
* Initializes the voice meeter dll connection.
* This call is neccessary to use the api. It returns a promise with a VoiceMeeter instance
*/
static init: () => Promise<Voicemeeter>;
private isInitialised;
private isConnected;
private outputDevices;
private inputDevices;
private version;
private type;
private eventPool;
private stringParameters;
private timerInterval;
private audioCallbackStates;
private awaitAudioCallbackEvents;
/**
* Starts a connection to VoiceMeeter
*/
connect: () => {
success: boolean;
message: string;
code: number;
} | never;
/**
* Getter $outputDevices
* @return {Device[] }
*/
get $outputDevices(): Device[];
/**
* Getter $inputDevices
* @return {Device[] }
*/
get $inputDevices(): Device[];
/**
* Getter $version
* @return {string }
*/
get $version(): string;
/**
* Getter $type
* @return {VoiceMeeterTypes}
*/
get $type(): VoiceMeeterTypes;
/**
* Terminates the connection to VoiceMeeter
*/
disconnect: () => void;
/**
* Updates all input and ouput devices
*/
updateDeviceList: () => void;
/**
* Returns wheter a parameter has been changed
*/
isParametersDirty: () => any;
/**
* Gets a bus parameter.
* @param {number} index Index of the bus
* @param {BusProperties} property Property which should be get
*/
getBusParameter: (index: number, property: BusProperties) => string | number;
/**
* Gets a strip parameter
* @param {number} index Index of the strip
* @param {StripProperties} property Property which should be get
*/
getStripParameter: (index: number, property: StripProperties) => string | number;
/**
* Sets a parameter of a strip.
* @param {number} index Strip number
* @param {StripProperties} property Propertyname which should be changed
* @param {any} value Property value
*/
setStripParameter: (index: number, property: StripProperties, value: any) => Promise<any>;
/**
* Sets a parameter of a bus.
* @param {number} index Bus number
* @param {StripProperties} property Propertyname which should be changed
* @param {any} value Property value
*/
setBusParameter: (index: number, property: BusProperties, value: any) => Promise<any>;
/**
* @param {()=>any} fn Function which should be called if something changes
*/
attachChangeEvent: (fn: () => any) => void;
/**
* @param parameterName Name of the parameter that should be get
* @returns {any} Parameter value
*/
getOption: (parameterName: string) => string | number;
/**
* Sets an option.
* @param {string} option Option to set
*/
setOption: (option: string) => Promise<unknown>;
/**
* Checks if any macro button has unsaved changes
*/
isMacroButtonDirty: () => any;
/**
* Gets the status of a specific macro button
* @param {number} buttonIndex - The index of the macro button
* @param {number} [bitmode=0] - Bit mode parameter (optional, defaults to MacroButtonModes.DEFAULT)
* @returns {number} The current status value of the macro button
* @throws {Error} Throws an error if failed to get the button status
*/
getMacroButtonStatus: (buttonIndex: number, bitmode?: number) => number;
/**
* Sets the status of a specific macro button
* @param {number} buttonIndex - The index of the macro button
* @param {number} value - The status value to set
* @param {number} [bitmode=0] - Bit mode parameter (optional, defaults to MacroButtonModes.DEFAULT)
* @throws {Error} Throws an error if failed to set the button status
*/
setMacroButtonStatus: (buttonIndex: number, value: number, bitmode?: number) => void;
/**
* The amount of input channels per voicemeeter version
*/
static inputChannelCountMap: Record<Exclude<VoiceMeeterTypes, undefined>, number>;
/**
* The amount of output channels per voicemeeter version
*/
static outputChannelCountMap: Record<Exclude<VoiceMeeterTypes, undefined>, number>;
/**
* Registers an audio callback function to process/change real time audio stream data from Voicemeeter.
* @description For more detailed info about the audio callback system, see the Voicemeeter Remote API pdf and VoicemeeterRemote.h on https://github.com/vburel2018/Voicemeeter-SDK
* @param {AudioCallbackModes} mode - The audio callback type. See {@link AudioCallbackModes}
* @param {string} clientName - Name of the application registering the callback (max 64 ASCII chars)
* @param {AudioCallbackFunction} callback - Function called for each audio stream event.
* The first argument is an Error if one occurs, otherwise null. The second argument provides the decoded audio event.
* @param {Object} [config] - Optional configuration object.
* @param {Buffer} [config.lpUser] - Optional user context pointer passed to the callback.
* @param {boolean} [config.restartOnChangedStream=true] - If true, automatically restarts the callback when the audio stream changes. Defaults to true
* @throws {Error} Throws an error if the callback is already registered, or if registration fails.
*/
registerAudioCallback: (mode: AudioCallbackModes, clientName: string, callback: AudioCallbackFunction, config?: {
lpUser?: Buffer;
restartOnChangedStream?: boolean;
}) => void;
/**
* Starts the audio stream to the audio callback.
* @returns {Promise<void>} Resolves when started, rejects with Error if failed.
*/
startAudioCallback: () => Promise<void>;
/**
* Stops the audio stream to the audio callback.
* @returns {Promise<void>} Resolves when stopped, rejects with Error if failed.
*/
stopAudioCallback: () => Promise<void>;
/**
* Unregisters the audio callback.
* @description Internally voicemeeter automatically calls stopAudioCallback(), so it's not strictly necessary to stop and then unregister.
* @param {AudioCallbackModes} mode - The audio callback type. See {@link AudioCallbackModes}
* @returns {Promise<void>} Resolves when unregistered, rejects with Error if failed.
*/
unregisterAudioCallback: (mode: AudioCallbackModes) => Promise<void>;
/**
* Unregisters all registered audio callbacks.
* @returns {Promise<void[]>} Resolves when all callbacks are unregistered.
*/
unregisterAllAudioCallbacks: () => Promise<void[]>;
/**
* Resolves all pending promises for a given audio callback event type.
* @param {"start"|"stop"} type - The event type to resolve ('start' or 'stop').
*/
private resolveAudioCallbackEvent;
/**
* Converts raw callback data to an AudioCallbackInfo object.
* @param {unknown} lpData - Raw data pointer from Voicemeeter.
* @returns {AudioCallbackInfo} Decoded audio callback info.
*/
private convertToAudioCallbackInfo;
/**
* Converts raw callback data to an AudioCallbackBuffer object.
* @param {unknown} lpData - Raw data pointer from Voicemeeter.
* @returns {AudioCallbackBuffer} Decoded audio buffer data.
*/
private convertToAudioCallbackBuffer;
/**
* Converts an unknown error value to an Error object.
* @param {unknown} unknownError - An unknown error value.
* @returns {Error} Converted Error object.
*/
private convertToErrorObject;
/**
* Checks whether properties has been changed and calls all event listeners
*/
private checkPropertyChange;
/**
* Gets installed voicemeeter type.
* Means Voicemeeter(normal,banana,potato)
*/
private getVoicemeeterType;
/**
* Returns the installed voicemeeter version
*/
private getVoicemeeterVersion;
/**
* Gets a parameter of voicemeeter
* @param {'Strip'|'Bus'} selector Strip or Bus
* @param {number} index Number of strip or bus
* @param {StripProperties|BusProperties} property Property which should be read
*/
private getParameter;
/**
* Sets a parameter of a bus or Strip
* @param {'Strip'|'Bus'} selector
* @param {number} index Number of strip or bus
* @param {StripProperties|BusProperties} property Propertyname which should be changed
* @param {any} value Property value
*/
private setParameter;
/**
* Gets realtime audio level see the VoicemeeterRemote API: [VoicemeeterRemote.h GetLevel](https://github.com/mirror/equalizerapo/blob/7aece1b788fce5aa11873f3842a0d01f7c78454b/VoicemeeterClient/VoicemeeterRemote.h#L284),
* for more details about the parameters
* @param {0|1|2|3} type 0 = pre fader input levels. 1 = post fader input levels. 2= post Mute input levels. 3= output levels
* @param channel audio channel zero based index
* @returns {float} Current audio level
*/
getLevel: (type: 0 | 1 | 2 | 3, channel: number) => number;
}