-
Notifications
You must be signed in to change notification settings - Fork 0
/
vstmodule.h
93 lines (74 loc) · 2.19 KB
/
vstmodule.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <CoreFoundation/CoreFoundation.h>
#include "en.h"
namespace En
{
class VstModule: public QObject {
Q_OBJECT
private:
CFBundleRef m_bundle;
PluginEntryProc m_mainProc;
public:
VstModule(const QString& fileName) : m_bundle(0), m_mainProc(0) {
load(fileName);
}
virtual ~VstModule() {
unload();
}
AEffect* createVstInstance() {
if (!m_mainProc) {
qDebug("createVstInstance failure: no main proc");
return 0;
}
AEffect* effect = m_mainProc(hostCallback);
if (!effect) {
qDebug("createVstInstance failure: couldn't create vst instance");
return 0;
}
return effect;
}
private:
bool load(const QString& fileName) {
CFStringRef fileNameString = CFStringCreateWithCString(0, fileName.toUtf8(), kCFStringEncodingUTF8);
if (fileNameString == 0) {
qDebug("bad filename");
return false;
}
CFURLRef url = CFURLCreateWithFileSystemPath (0, fileNameString, kCFURLPOSIXPathStyle, false);
CFRelease(fileNameString);
if (url == 0) {
qDebug("bad url");
return false;
}
m_bundle = CFBundleCreate(0, url);
CFRelease(url);
if (!m_bundle) {
qDebug("couldn't create bundle");
return false;
}
if (CFBundleLoadExecutable(m_bundle) == false) {
qDebug("couldn't load executable for bundle");
unload();
return false;
}
m_mainProc = (PluginEntryProc)CFBundleGetFunctionPointerForName(m_bundle, CFSTR("VSTPluginMain"));
if (!m_mainProc) {
m_mainProc = (PluginEntryProc)CFBundleGetFunctionPointerForName(m_bundle, CFSTR("main_macho"));
}
if (!m_mainProc) {
qDebug("couldn't get main proc");
unload();
return false;
}
qDebug("vst mainproc is: %p", m_mainProc);
return true;
}
void unload() {
if (m_bundle) {
CFBundleUnloadExecutable(m_bundle);
CFRelease(m_bundle);
}
m_mainProc = 0;
}
};
} // namespace En