@audio/host 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +56 -0
  2. package/package.json +35 -0
package/index.js ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @module audio-host
3
+ * Universal audio plugin host — load VST3, CLAP (and more) through one API.
4
+ */
5
+
6
+ const hosts = {}
7
+
8
+ /* Discover installed format hosts */
9
+ for (const [ext, pkg] of [
10
+ ['.vst3', '@audio/host-vst'],
11
+ ['.clap', '@audio/host-clap'],
12
+ ]) {
13
+ try { hosts[ext] = await import(pkg) } catch {}
14
+ }
15
+
16
+ function hostFor(path) {
17
+ for (const [ext, mod] of Object.entries(hosts)) {
18
+ if (path.endsWith(ext)) return mod
19
+ }
20
+ const known = Object.keys(hosts).join(', ') || 'none installed'
21
+ throw new Error(`Unsupported plugin format: ${path}\nInstalled: ${known}`)
22
+ }
23
+
24
+ /**
25
+ * Load any audio plugin by path. Format detected from extension.
26
+ *
27
+ * const plugin = load('reverb.vst3')
28
+ * const gain = load('gain.clap')
29
+ */
30
+ export function load(path, opts) {
31
+ return hostFor(path).load(path, opts)
32
+ }
33
+
34
+ /**
35
+ * Register any plugin as AudioWorkletProcessor. Format detected from extension.
36
+ *
37
+ * await ctx.audioWorklet.addModule(register('reverb.vst3', AudioWorkletProcessor))
38
+ */
39
+ export function register(path, BaseClass, opts) {
40
+ return hostFor(path).register(path, BaseClass, opts)
41
+ }
42
+
43
+ /**
44
+ * Scan system for all installed plugins across all formats.
45
+ * Returns array of { path, name, vendor, format }.
46
+ */
47
+ export function scan(dirs) {
48
+ const results = []
49
+ for (const mod of Object.values(hosts)) {
50
+ if (mod.scan) results.push(...mod.scan(dirs))
51
+ }
52
+ return results
53
+ }
54
+
55
+ /** Supported format extensions (based on installed host packages) */
56
+ export const formats = Object.keys(hosts)
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@audio/host",
3
+ "version": "0.1.0",
4
+ "description": "Universal audio plugin host — VST3, CLAP, and more",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "files": [
9
+ "index.js",
10
+ "index.d.ts"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./index.d.ts",
15
+ "default": "./index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "test": "node test.js"
20
+ },
21
+ "optionalDependencies": {
22
+ "@audio/host-vst": ">=0.1.0",
23
+ "@audio/host-clap": ">=0.1.0"
24
+ },
25
+ "license": "MIT",
26
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/audiojs/host.git",
33
+ "directory": "packages/host"
34
+ }
35
+ }