UNPKG

@aptrn/parameters-ts

Version:

Typescript library to manage MaxMsp UI

135 lines (134 loc) 6.25 kB
export { ParametersUI }; /** * Type derived from ParamsType that contains a boolean for each parameter. * Used to check if a parameter exists in the patch according to the ParamsType. */ type containsParam<ParamsType> = { [K in keyof ParamsType as `has_${K & string}`]: boolean; } & { [key: `has_${string}`]: boolean; }; /** * Class to interact with patcher parameters UI. */ declare class ParametersUI<ParamsType> { values: ParamsType; gui: Patcher | undefined; id: string; uniqueId: string; iter: number; paramsD: Dict | undefined; paramsObj: Maxobj | undefined; recallD: Dict | undefined; recallObj: Maxobj | undefined; updateObj: Maxobj | undefined; isHeadless: boolean; isAbleton: boolean; /** * Generates a random 8-character string of uppercase letters and numbers * @returns {string} Random 8-character string */ private generateRandomId; /** * Constructor for headless mode - only manages values without UI infrastructure * @param newValues Object of type ParamsType containing values */ static headless<ParamsType>(newValues: ParamsType, instanceName?: string): ParametersUI<ParamsType>; /** * Constructor of the UI infrastructure. Checks if infrastructure exists, creates it if not found or broken. * Once created recalls parameters with the params argument object. * @param localpatcher The patcher containing the UI elements * @param patcherID ID string used for naming the infrastructure elements * @param newValues Object of type ParamsType containing values to recall * @param instanceName If a non-empty string is provided, it will be used as a unique prefix for send object. useful to get updates via a receive object with value "instanceName_update" * @param isHeadless If true, operates in headless mode without UI infrastructure */ constructor(localpatcher: Patcher | undefined, patcherID: string, newValues: ParamsType, instanceName?: string, isHeadless?: boolean); /** * Attempts to find existing unique prefix from dict objects in the patcher * @returns {string | null} The existing prefix if found, null otherwise */ private getExistingUniquePrefix; /** * This function checks if the infrastructure exists ("id" Dict, "id_recall" Dict and "update" Send objects). * @returns {boolean} True if infrastructure exists, false otherwise */ infrastructureExists(): boolean; /** * This function creates a "Dict" object named "id", a "Dict" object named "id_recall" and a Send object with target "update" * @param uniquePrefix If a non-empty string is provided, it will be used as a unique prefix for infrastructure elements * @returns {void} */ createInfrastructure(uniquePrefix?: string): void; getUniqueId(): string; /** * This function should clear "id" Dict, "id_recall" Dict and "update" Send objects. * @returns {void} */ cleanInfrastructure(): void; /** * Creates an Object of type containtsParam<ParamsType> with all properties set to false. * @returns Object of type containtsParam<ParamsType> used to check if parameters are existing. */ createContainsParam(): containsParam<ParamsType>; /** * Sets a value in the hasParams object. * @param hasParams Object of type containtsParam<ParamsType> used to check if parameters are existing. * @param paramName Property name. * @param exists Boolean value to set. */ setParamExists<K extends keyof ParamsType>(hasParams: containsParam<ParamsType>, paramName: string, exists: boolean): void; /** * Gets a value in the hasParams object. * @param hasParams Object of type containtsParam<ParamsType> used to check if parameters are existing. * @param paramName Property name. * @returns Boolean value of the property. */ getParamExists<K extends keyof ParamsType>(hasParams: containsParam<ParamsType>, paramName: string): boolean; /** * Returns true if all properties in the hasParams object are set to true, false otherwise. * @param hasParams Object of type containtsParam<ParamType> used to check if parameters are existing. * @returns Boolean value, true if all parameters exist, false otherwise. */ allParamsExist<ParamType>(hasParams: containsParam<ParamType>): boolean; /** * This function checks if parameters exist in the Patcher ("pvar", "dict.unpacks" and "prepend" objects). * @returns Return true if parameters exist, false otherwise */ parametersExist(): boolean; /** * This function creates, for each property in this.params object, a "pvar" object named as the proeperty and relative parameter infrastructure as "prepend"s and "dict.unpack"s to receive from "id_recall" Dict and send to "id" Dict. * Automatically recalls and then gets parameters values using recallParams() and getParams() functions. * @param newParams Optional new parameter values * @returns {void} */ createParameters(newParams?: ParamsType): void; /** * This function should clear all "pvar" objects and relative parameter infrastructure. * @returns {void} */ cleanParameters(): void; /** * This function gets parameter values * @returns {ParamsType} */ fetch(): ParamsType; /** * This function sets parameter values * @param newParams New parameter values * @returns {void} */ set(newParams: ParamsType, update?: boolean): void; /** * This function sets a live parameter to the dial object. * @param dial Maxobj object or Patcher that contains the parameter * @param name Parameter name * @param min Minimum value * @param max Maximum value * @param defaultValue Default value * @param enums Optional array of strings. This automatically sets parameter type to "enum" * @param isFloat Optional boolean. Sets parameter type to "float" if true, integer otherwise */ setLiveParameter(dial: Maxobj | Patcher, name: string, min: number, max: number, defaultValue: number, mode?: number, // 0: float, 1: int, 2: enum enums?: string[]): void; }