UNPKG

u-he-preset-randomizer

Version:

Create random u-he synth presets through randomization and merging of your existing presets.

187 lines 5.89 kB
/** * @file Configuration management and CLI argument parsing. * Handles CLI argument parsing with yargs and provides configuration defaults. */ import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; export function getDefaultConfig() { return { debug: false, }; } let config = getDefaultConfig(); export function buildCliArgParser(argv = hideBin(process.argv)) { return yargs(argv) .scriptName('u-he-preset-randomizer') .usage('$0 [options]') .example('$0 --synth Diva --amount 3', 'Generate 3 fully random Diva presets') .example('$0 --synth Diva --preset "HS Greek Horn" --randomness 20 --amount 5', 'Create 5 randomized variants of an existing preset') .example('$0 --synth Diva --merge "HS Greek Horn" --merge "HS Strumpet" --amount 5', 'Merge existing presets into 5 new variants') .epilogue('Run without --synth to start interactive mode.') .option('synth', { type: 'string', describe: 'Choose the u-he synth, for example Diva or Repro-1.', }) .option('amount', { type: 'number', describe: 'How many presets to generate.', }) .option('randomness', { type: 'number', describe: 'Randomness percentage for preset variation or merge output.', }) .option('preset', { type: 'string', array: true, describe: 'Base preset name to randomize. Repeat to randomize multiple.', }) .option('merge', { type: 'string', array: true, describe: 'Preset name to merge. Repeat the flag to add more presets.', }) .option('pattern', { type: 'string', describe: 'Glob pattern used to narrow the preset library.', }) .option('binary', { type: 'boolean', describe: 'Keep binary preset sections when generating new presets.', }) .option('stable', { type: 'boolean', describe: 'Use the safer, more stable randomization mode.', }) .option('creative', { type: 'boolean', describe: 'Use the more experimental randomization mode.', }) .option('category', { type: 'string', describe: 'Filter presets by category metadata.', }) .option('dictionary', { type: 'boolean', describe: 'Generate preset names from the existing library dictionary.', }) .option('author', { type: 'string', describe: 'Filter presets by author metadata.', }) .option('folder', { type: 'string', describe: 'Filter presets by folder. Use /Local/ or /User/ as a base.', }) .option('favorites', { type: 'string', array: true, describe: 'Filter presets by .uhe-fav favorites file. Repeat if needed.', }) .option('custom-folder', { type: 'string', describe: 'Custom base folder for the u-he installation or presets.', }) .option('binary-template', { type: 'boolean', describe: 'Use curated binary templates instead of random binary data.', }) .option('debug', { type: 'boolean', describe: 'Print debug output and dump the analyzed params model.', }) .alias('h', 'help') .alias('v', 'version') .help() .version(); } function parseCliArgs() { return buildCliArgParser().parse(); } function parseOptionalNumber(value) { if (typeof value === 'number') { return value; } if (typeof value === 'string' && value.trim() !== '') { return Number.parseInt(value, 10); } return undefined; } export function getConfigFromParameters(overrides) { const argv = overrides ?? parseCliArgs(); // Create a new config object instead of mutating the module-level one const newConfig = { ...getDefaultConfig() }; if (argv.synth) { newConfig.synth = argv.synth; } if (argv.debug) { newConfig.debug = true; } const amount = parseOptionalNumber(argv.amount); if (amount !== undefined) { newConfig.amount = amount; } if (argv.preset) { newConfig.preset = argv.preset; } const randomness = parseOptionalNumber(argv.randomness); if (randomness !== undefined) { newConfig.randomness = randomness; } if (argv.merge) { newConfig.merge = argv.merge; } if (argv.pattern) { newConfig.pattern = argv.pattern; } if (argv.binary) { newConfig.binary = argv.binary; } if (argv.stable) { newConfig.stable = argv.stable; } if (argv.creative) { newConfig.creative = argv.creative; } if (argv.category) { newConfig.category = argv.category; } if (argv.author) { newConfig.author = argv.author; } if (argv.folder) { newConfig.folder = argv.folder; } if (argv.dictionary) { newConfig.dictionary = argv.dictionary; } if (argv.favorites) { newConfig.favorites = argv.favorites; } if (argv['custom-folder']) { newConfig.customFolder = argv['custom-folder']; } if (argv['binary-template']) { newConfig.binaryTemplate = argv['binary-template']; } // Default binaryTemplate to true for Zebralette3 if not specified if (newConfig.synth === 'Zebralette3' && newConfig.binaryTemplate === undefined) { newConfig.binaryTemplate = true; } // Update module-level config for backward compatibility with getConfig/setConfig config = newConfig; return newConfig; } export function getConfig() { return config; } export function setConfig(newConfig) { config = { ...config, ...newConfig, }; } export function resetConfig() { config = getDefaultConfig(); } //# sourceMappingURL=config.js.map