-
Notifications
You must be signed in to change notification settings - Fork 17
/
vst_linux.go
71 lines (60 loc) · 1.34 KB
/
vst_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// +build !plugin
package vst2
// #cgo LDFLAGS: -ldl
// #include <dlfcn.h>
// #include <stdlib.h>
import "C"
import (
"fmt"
"os"
"path/filepath"
"unsafe"
)
const (
// FileExtension of VST2 files in Windows.
FileExtension = ".so"
)
var (
// ScanPaths of Vst2 files
scanPaths = []string{
"/usr/local/lib/vst",
"/usr/lib/vst",
}
)
func init() {
home := os.Getenv("HOME")
scanPaths = append(scanPaths,
filepath.Join(home, ".vst"),
filepath.Join(home, "vst"),
)
}
// Open loads the plugin entry point into memory. It's SO in linux.
func Open(path string) (*VST, error) {
handle := C.dlopen(stringToCString(path), C.RTLD_LAZY)
if handle == nil {
return nil, fmt.Errorf("failed loading vst: %v", dlerror())
}
// clear previous errors as stated in the man.
C.dlerror()
m := C.dlsym(handle, stringToCString(main))
if m == nil {
return nil, fmt.Errorf("failed finding vst main: %v", dlerror())
}
return &VST{
main: pluginMain(m),
handle: uintptr(handle),
Name: filepath.Base(path[:len(path)-len(filepath.Ext(path))]),
}, nil
}
func dlerror() string {
CError := C.dlerror()
defer C.free(unsafe.Pointer(CError))
return C.GoString(CError)
}
// Close frees plugin handle.
func (m *VST) Close() error {
if C.dlclose(unsafe.Pointer(m.handle)) != 0 {
return fmt.Errorf("error unloading vst: %v", dlerror())
}
return nil
}