diff --git a/README.md b/README.md index 1096524..db8cd15 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # u-he-preset-randomizer Create random [u-he](https://u-he.com/) synth presets through randomization and merging of your existing presets. -In theory it should work with all u-he synths, but so far I haven't tested this (also, I don't own all of them). +Its build very generically and should work with all u-he synths, but some may work better due to their simpler architecture (u-he Diva, Hive). Bazille, Zebra also works, but you may get more "varied" results. Currently it can generate random presets in three different modes: * Generate fully random presets based on real values in your preset library diff --git a/package-lock.json b/package-lock.json index 4f92c34..e1a5feb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "u-he-preset-randomizer", - "version": "0.5.0", + "version": "0.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "u-he-preset-randomizer", - "version": "0.5.0", + "version": "0.5.1", "license": "MIT", "dependencies": { "enquirer": "^2.4.1", diff --git a/package.json b/package.json index c1b1b70..2e0d41b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "u-he-preset-randomizer", - "version": "0.5.0", + "version": "0.5.1", "description": "Create random u-he synth presets through randomization and merging of your existing presets.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/presetLibrary.ts b/src/presetLibrary.ts index d6bd2ed..c274da0 100644 --- a/src/presetLibrary.ts +++ b/src/presetLibrary.ts @@ -25,34 +25,42 @@ export function loadPresetLibrary(synth: SynthName): PresetLibrary { // Load preset library const libraryPresets = fg.sync(["**/*.h2p"], { cwd: presetLibrary.presetsFolder }); - for (const presetPath of libraryPresets) { - try { - const presetString = fs - .readFileSync(path.join( presetLibrary.presetsFolder, presetPath)) - .toString(); - const parsedPreset = parseUhePreset(presetString, presetPath) - if (parsedPreset.params.length && parsedPreset.meta.length) { - presetLibrary.presets.push(parsedPreset); + if (libraryPresets.length > 0) { + for (const presetPath of libraryPresets) { + try { + const presetString = fs + .readFileSync(path.join( presetLibrary.presetsFolder, presetPath)) + .toString(); + const parsedPreset = parseUhePreset(presetString, presetPath) + if (parsedPreset.params.length && parsedPreset.meta.length) { + presetLibrary.presets.push(parsedPreset); + } + } catch (err) { + log.warn(`Could not load and parse preset: ${presetPath}`, err) } - } catch (err) { - log.warn(`Could not load and parse preset: ${presetPath}`, err) } + } else { + log.warn(`Could not find presets in library: ${presetLibrary.presetsFolder}`) } // Load user preset library const userPresets = fg.sync(["**/*.h2p"], { cwd: presetLibrary.userPresetsFolder }); - for (const presetPath of userPresets) { - try { - const presetString = fs - .readFileSync(path.join(presetLibrary.userPresetsFolder, presetPath)) - .toString(); - const parsedPreset = parseUhePreset(presetString, presetPath) - if (parsedPreset.params.length && parsedPreset.meta.length) { - presetLibrary.presets.push(parsedPreset); + if (userPresets.length > 0) { + for (const presetPath of userPresets) { + try { + const presetString = fs + .readFileSync(path.join(presetLibrary.userPresetsFolder, presetPath)) + .toString(); + const parsedPreset = parseUhePreset(presetString, presetPath) + if (parsedPreset.params.length && parsedPreset.meta.length) { + presetLibrary.presets.push(parsedPreset); + } + } catch (err) { + log.warn(`Could not load and parse preset: ${presetPath}`, err) } - } catch (err) { - log.warn(`Could not load and parse preset: ${presetPath}`, err) } + } else { + log.warn(`Could not find presets in user library: ${presetLibrary.userPresetsFolder}`) } if (presetLibrary.presets.length === 0) { diff --git a/src/utils/detector.ts b/src/utils/detector.ts index 8db889c..b860d5e 100644 --- a/src/utils/detector.ts +++ b/src/utils/detector.ts @@ -14,13 +14,35 @@ const uheSynthNames = ["Diva", "Zebra2", "ZebraHZ", "Hive", "Repro-1", "Bazille" /** * Detects Preset Library locations - * - * TODO: Currently no MacOS support. */ export function detectPresetLibraryLocations(synthName?: string): DetectedPresetLibraries { const detectedPresetLibraries: DetectedPresetLibraries = {} + const synthNamesToTry = synthName ? [synthName] : uheSynthNames; + + // TODO: MacOS support is not tested and might not work. + if (process.platform === 'darwin') { + const userLocationsToTry = [ + path.join(os.homedir(),`/Library/Audio/Presets/u-he/__SynthName__/`) + ] + for (const synthName of synthNamesToTry) { + for (const location of userLocationsToTry) { + const pathToCheck = location.replace('__SynthName__', synthName) + if (fs.existsSync(pathToCheck)) { + detectedPresetLibraries[synthName] = { + root: pathToCheck, + presets: `/Library/Audio/Presets/u-he/__SynthName__/`, + userPresets: path.join(pathToCheck, `/UserPresets/${synthName}`), + } + break; + } + } + } + return detectedPresetLibraries; + } + + // Otherwise try Windows file system conventions const locationsToTry = [ path.join(os.homedir(),`/Documents/u-he/__SynthName__.data/`), `C:/Program Files/Common Files/VST3/__SynthName__.data/`, @@ -29,8 +51,6 @@ export function detectPresetLibraryLocations(synthName?: string): DetectedPreset `C:/VstPlugins/u-he/__SynthName__.data/`, ] - const synthNamesToTry = synthName ? [synthName] : uheSynthNames; - for (const synthName of synthNamesToTry) { for (const location of locationsToTry) { const pathToCheck = location.replace('__SynthName__', synthName)