u-he-preset-randomizer
Version:
Create random u-he synth presets through randomization and merging of your existing presets.
76 lines (75 loc) • 2.85 kB
TypeScript
/**
* @file Preset parser and serializer for u-he preset files.
* Provides functions to read, parse, modify, and write .h2p preset files.
*/
export interface Preset {
/** Relative filePath to preset folder */
filePath: string;
/** Preset file name, without file extension or sub-folders */
presetName: string;
categories: string[];
meta: PresetMetaEntry[];
params: PresetParam[];
binary?: string;
}
export interface PresetMetaEntry {
key: string;
value: string | string[];
}
export interface PresetParam {
id: string;
key: string;
section: string;
value: string | number;
index: number;
type: 'string' | 'float' | 'integer';
}
/**
* Parses a u-he preset file and returns a Preset object.
*
* @param fileString - The content of the preset file as a string.
* @param filePath - The path to the preset file.
* @param binary - A boolean indicating whether to include the binary section of the preset file.
* @returns The parsed Preset object.
*/
export declare function parseUhePreset(fileString: string, filePath: string, binary: boolean): Preset;
/**
* Retrieves the metadata entries from the given u-he preset file string.
*
* @param fileString - The string representation of the file.
* @returns An array of PresetMetaEntry objects representing the metadata entries.
*/
export declare function getPresetMetadata(fileString: string): PresetMetaEntry[];
/**
* Extracts and parses parameter data from a u-he preset file string.
*
* @param fileString - The content of the preset file as a string.
* @param presetPath - The path to the preset file (used for warnings).
* @returns An array of PresetParam objects representing all parameters.
*/
export declare function getPresetParams(fileString: string, presetPath: string): PresetParam[];
/**
* Extracts the binary section from a u-he preset file.
* The binary section contains advanced settings like MSEG curves.
*
* @param fileString - The content of the preset file as a string.
* @returns The binary section as a string, or empty string if not present.
*/
export declare function getPresetBinarySection(fileString: string): string;
/**
* Serializes a Preset object back to u-he preset file format (.h2p).
*
* @param preset - The Preset object to serialize.
* @returns The serialized preset as a string in .h2p format.
*/
export declare function serializePresetToFile(preset: Preset): string;
/**
* Validates that a preset has required data and no corrupted values.
* Logs warnings for invalid presets.
*
* @param preset - The Preset object to validate.
* @returns True if the preset is valid, false otherwise.
*/
export declare function isValidPreset(preset: Preset): boolean;
export declare function isInt(value: unknown): boolean;
export declare function isNumeric(value: unknown): boolean;