Skip to content

Commit

Permalink
Maybe support OSX? Could not test it, it's just a try.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Heimler committed May 5, 2024
1 parent 8889b78 commit 40fb5b9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
48 changes: 28 additions & 20 deletions src/presetLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 24 additions & 4 deletions src/utils/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/`,
Expand All @@ -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)
Expand Down

0 comments on commit 40fb5b9

Please sign in to comment.