u-he-preset-randomizer
Version:
Create random u-he synth presets through randomization and merging of your existing presets.
140 lines • 6.18 kB
JavaScript
/**
* @file u-he synth detection utilities.
* Provides functions to detect installed u-he synths and their preset library locations.
*/
import os from 'node:os';
import path from 'node:path';
import chalk from 'chalk';
import fs from 'fs-extra';
export const uheSynthNames = [
'ACE',
'Bazille',
'Diva',
'Hive',
'Repro-1',
'Repro-5',
'Zebra2',
'ZebraHZ',
'Zebralette3',
'Zebra3',
'TyrellN6',
'Podolski',
'TripleCheese',
'TestSynth',
];
export function getWslWindowsUserPresetRoots(usersRoot = '/mnt/c/Users') {
if (process.platform !== 'linux' || !fs.existsSync(usersRoot)) {
return [];
}
const roots = [];
for (const entry of fs.readdirSync(usersRoot, { withFileTypes: true })) {
if (!entry.isDirectory()) {
continue;
}
roots.push(path.join(usersRoot, entry.name, 'Documents', 'u-he'));
roots.push(path.join(usersRoot, entry.name, 'My Documents', 'u-he'));
roots.push(path.join(usersRoot, entry.name, 'AppData', 'Roaming', 'u-he'));
}
return roots;
}
/**
* Detects Preset Library locations
*/
export function detectPresetLibraryLocations(config, locationsTried = []) {
const detectedPresetLibraries = [];
if (process.platform === 'darwin') {
if (config.customFolder) {
locationsTried.push(`${config.customFolder}/__SynthName__/`);
locationsTried.push(`${config.customFolder}/../__SynthName__/`);
}
locationsTried.push(path.join(os.homedir(), `/Library/Audio/Presets/u-he/__SynthName__/`));
for (const synthName of uheSynthNames) {
for (const location of locationsTried) {
const pathToCheck = location.replace('__SynthName__', synthName);
if (fs.existsSync(pathToCheck)) {
detectedPresetLibraries.push({
synthName: synthName,
root: pathToCheck,
presets: `/Library/Audio/Presets/u-he/${synthName}/`,
userPresets: path.join(pathToCheck, `/UserPresets/${synthName}`),
});
if (synthName === 'Repro-1') {
detectedPresetLibraries.push({
synthName: 'Repro-5',
root: pathToCheck,
presets: `/Library/Audio/Presets/u-he/Repro-5/`,
userPresets: path.join(pathToCheck, `/UserPresets/Repro-5`),
});
if (config.debug) {
console.debug(chalk.gray(`> Found synth Repro-5 in ${pathToCheck}`));
}
}
if (config.debug) {
console.debug(chalk.gray(`> Found synth ${synthName} in ${pathToCheck}`));
}
break;
}
}
}
return detectedPresetLibraries;
}
// Otherwise try Windows or Linux file system conventions
if (config.customFolder) {
locationsTried.push(`${config.customFolder}/__SynthName__.data/`);
locationsTried.push(path.resolve(`${config.customFolder}/../__SynthName__.data/`));
}
// Windows locations
locationsTried.push(path.join(os.homedir(), `/Documents/u-he/__SynthName__.data/`));
locationsTried.push(`C:/Program Files/Common Files/VST3/__SynthName__.data/`);
locationsTried.push(`C:/Program Files/VSTPlugins/__SynthName__.data/`);
locationsTried.push(`C:/Program Files/Common Files/CLAP/u-he/__SynthName__.data/`);
locationsTried.push(`C:/VstPlugins/u-he/__SynthName__.data/`);
// Linux locations ?
locationsTried.push(path.join(os.homedir(), `/.u-he/__SynthName__.data/`));
locationsTried.push(`C:/users/VstPlugins/__SynthName__.data/`); // Wine
// WSL2 locations (Windows filesystem mounted in Linux)
if (process.platform === 'linux' && fs.existsSync('/mnt/c/')) {
locationsTried.push(`/mnt/c/Program Files/Common Files/VST3/__SynthName__.data/`);
locationsTried.push(`/mnt/c/Program Files/VSTPlugins/__SynthName__.data/`);
locationsTried.push(`/mnt/c/Program Files/Common Files/CLAP/u-he/__SynthName__.data/`);
locationsTried.push(`/mnt/c/VstPlugins/u-he/__SynthName__.data/`);
for (const windowsPresetRoot of getWslWindowsUserPresetRoots()) {
locationsTried.push(`${windowsPresetRoot}/__SynthName__.data/`);
}
}
// Custom Google Drive location (check last as it may not be mounted)
// Only add if the drive appears to be accessible
if (process.platform === 'linux' && fs.existsSync('/mnt/g/My Drive/')) {
locationsTried.push(`/mnt/g/My Drive/Musik/u-he/__SynthName__.data/`);
}
for (const synthName of uheSynthNames) {
for (const location of locationsTried) {
const pathToCheck = location.replace('__SynthName__', synthName);
if (fs.existsSync(pathToCheck)) {
if (config.debug) {
console.debug(chalk.gray(`> Found synth ${synthName} in ${pathToCheck}`));
}
detectedPresetLibraries.push({
synthName: synthName,
root: pathToCheck,
presets: path.join(pathToCheck, `/Presets/${synthName}`),
userPresets: path.join(pathToCheck, `/UserPresets/${synthName}`),
});
if (synthName === 'Repro-1') {
detectedPresetLibraries.push({
synthName: 'Repro-5',
root: pathToCheck,
presets: path.join(pathToCheck, `/Presets/Repro-5`),
userPresets: path.join(pathToCheck, `/UserPresets/Repro-5`),
});
if (config.debug) {
console.debug(chalk.gray(`> Found synth Repro-5 in ${pathToCheck}`));
}
}
break;
}
}
}
return detectedPresetLibraries;
}
//# sourceMappingURL=detector.js.map