-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.cpp
82 lines (58 loc) · 1.81 KB
/
core.cpp
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
#include "core.h"
#include "vstmodule.h"
namespace En
{
Core* Core::s_instance = 0;
void Core::scanVstDir(QDir dir)
{
//qDebug() << "scanning" << dir << dir.count();
Q_FOREACH (QString entry, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
// better way to do type detection?
QRegExp re("(.+)(\\.vst|\\.vst3)");
if (!re.exactMatch(entry)) {
scanVstDir(QDir(dir.filePath(entry)));
}
// better way to get the 'vst name' for the module?
QString vstName = re.capturedTexts()[1];
if (m_vstInfoMap.find(vstName) != m_vstInfoMap.end()) {
// this vst name was already picked up in a directory
// with higher precedence.
continue;
}
VstInfo info;
info.name = vstName;
info.moduleFileName = dir.filePath(entry);
m_vstInfoMap[vstName] = info;
}
}
void Core::scanVstDirs()
{
// FML!
QList<QDir> dirs;
dirs << QDir(QDir(QDir::homePath()).absoluteFilePath("Library/Audio/Plug-Ins/VST3"));
dirs << QDir(QDir(QDir::homePath()).absoluteFilePath("Library/Audio/Plug-Ins/VST"));
dirs << QDir("/Library/Audio/Plug-Ins/VST3");
dirs << QDir("/Library/Audio/Plug-Ins/VST");
Q_FOREACH (QDir dir, dirs) {
scanVstDir(dir);
}
}
VstModule* Core::vstModule(const QString& vstName)
{
if (m_vstModuleMap.find(vstName) != m_vstModuleMap.end()) {
return m_vstModuleMap[vstName]; // already loaded
}
if (m_vstInfoMap.find(vstName) == m_vstInfoMap.end()) {
return 0; // no idea how to load
}
En::VstModule* module = new En::VstModule(m_vstInfoMap[vstName].moduleFileName);
m_vstModuleMap[vstName] = module;
return module;
}
Core::~Core()
{
Q_FOREACH (VstModule* module, m_vstModuleMap) {
delete module;
}
}
}