forked from obsproject/obs-vst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
obs-vst.cpp
267 lines (215 loc) · 8.19 KB
/
obs-vst.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*****************************************************************************
Copyright (C) 2016-2017 by Colin Edwards.
Additional Code Copyright (C) 2016-2017 by c3r1c3 <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "headers/VSTPlugin.h"
#define OPEN_VST_SETTINGS "open_vst_settings"
#define CLOSE_VST_SETTINGS "close_vst_settings"
#define OPEN_WHEN_ACTIVE_VST_SETTINGS "open_when_active_vst_settings"
#define PLUG_IN_NAME obs_module_text("VstPlugin")
#define OPEN_VST_TEXT obs_module_text("OpenPluginInterface")
#define CLOSE_VST_TEXT obs_module_text("ClosePluginInterface")
#define OPEN_WHEN_ACTIVE_VST_TEXT obs_module_text("OpenInterfaceWhenActive")
OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE("obs-vst", "en-US")
static bool open_editor_button_clicked(obs_properties_t *props, obs_property_t *property, void *data)
{
VSTPlugin *vstPlugin = (VSTPlugin *)data;
vstPlugin->openEditor();
obs_property_set_visible(obs_properties_get(props, OPEN_VST_SETTINGS), false);
obs_property_set_visible(obs_properties_get(props, CLOSE_VST_SETTINGS), true);
UNUSED_PARAMETER(props);
UNUSED_PARAMETER(property);
UNUSED_PARAMETER(data);
return true;
}
static bool close_editor_button_clicked(obs_properties_t *props, obs_property_t *property, void *data)
{
VSTPlugin *vstPlugin = (VSTPlugin *)data;
vstPlugin->closeEditor();
obs_property_set_visible(obs_properties_get(props, OPEN_VST_SETTINGS), true);
obs_property_set_visible(obs_properties_get(props, CLOSE_VST_SETTINGS), false);
UNUSED_PARAMETER(property);
return true;
}
static const char *vst_name(void *unused)
{
UNUSED_PARAMETER(unused);
return PLUG_IN_NAME;
}
static void vst_destroy(void *data)
{
VSTPlugin *vstPlugin = (VSTPlugin *)data;
vstPlugin->closeEditor();
delete vstPlugin;
}
static void vst_update(void *data, obs_data_t *settings)
{
VSTPlugin *vstPlugin = (VSTPlugin *)data;
vstPlugin->openInterfaceWhenActive = obs_data_get_bool(settings, OPEN_WHEN_ACTIVE_VST_SETTINGS);
const char *path = obs_data_get_string(settings, "plugin_path");
if (strcmp(path, "") == 0) {
return;
}
vstPlugin->loadEffectFromPath(std::string(path));
const char *chunkData = obs_data_get_string(settings, "chunk_data");
if (chunkData && strlen(chunkData) > 0) {
vstPlugin->setChunk(std::string(chunkData));
}
}
static void *vst_create(obs_data_t *settings, obs_source_t *filter)
{
VSTPlugin *vstPlugin = new VSTPlugin(filter);
vst_update(vstPlugin, settings);
return vstPlugin;
}
static void vst_save(void *data, obs_data_t *settings)
{
VSTPlugin *vstPlugin = (VSTPlugin *)data;
obs_data_set_string(settings, "chunk_data", vstPlugin->getChunk().c_str());
}
static struct obs_audio_data *vst_filter_audio(void *data, struct obs_audio_data *audio)
{
VSTPlugin *vstPlugin = (VSTPlugin *)data;
vstPlugin->process(audio);
/*
* OBS can only guarantee getting the filter source's parent and own name
* in this call, so we grab it and return the results for processing
* by the EditorWidget.
*/
vstPlugin->getSourceNames();
return audio;
}
static void fill_out_plugins(obs_property_t *list)
{
QStringList dir_list;
#ifdef __APPLE__
dir_list << "/Library/Audio/Plug-Ins/VST/"
<< "~/Library/Audio/Plug-ins/VST/";
#elif WIN32
#ifndef _WIN64
HANDLE hProcess = GetCurrentProcess();
BOOL isWow64;
IsWow64Process(hProcess, &isWow64);
if (!isWow64) {
#endif
dir_list << qEnvironmentVariable("ProgramFiles") + "/Steinberg/VstPlugins/"
<< qEnvironmentVariable("CommonProgramFiles") + "/Steinberg/Shared Components/"
<< qEnvironmentVariable("CommonProgramFiles") + "/VST2"
<< qEnvironmentVariable("CommonProgramFiles") + "/Steinberg/VST2"
<< qEnvironmentVariable("CommonProgramFiles") + "/VSTPlugins/"
<< qEnvironmentVariable("ProgramFiles") + "/VSTPlugins/";
#ifndef _WIN64
} else {
dir_list << qEnvironmentVariable("ProgramFiles(x86)") + "/Steinberg/VstPlugins/"
<< qEnvironmentVariable("CommonProgramFiles(x86)") + "/Steinberg/Shared Components/"
<< qEnvironmentVariable("CommonProgramFiles(x86)") + "/VST2"
<< qEnvironmentVariable("CommonProgramFiles(x86)") + "/VSTPlugins/"
<< qEnvironmentVariable("ProgramFiles(x86)") + "/VSTPlugins/";
}
#endif
#elif __linux__
// If the user has set the VST_PATH environmental
// variable, then use it. Else default to a list
// of common locations.
char *vstPathEnv;
vstPathEnv = getenv("VST_PATH");
if (vstPathEnv != nullptr) {
dir_list << vstPathEnv;
} else {
// Choose the most common locations
dir_list << "/usr/lib/vst/"
<< "/usr/lib/lxvst/"
<< "/usr/lib/linux_vst/"
<< "/usr/lib64/vst/"
<< "/usr/lib64/lxvst/"
<< "/usr/lib64/linux_vst/"
<< "/usr/local/lib/vst/"
<< "/usr/local/lib/lxvst/"
<< "/usr/local/lib/linux_vst/"
<< "/usr/local/lib64/vst/"
<< "/usr/local/lib64/lxvst/"
<< "/usr/local/lib64/linux_vst/"
<< "~/.vst/"
<< "~/.lxvst/";
}
#endif
QStringList filters;
#ifdef __APPLE__
filters << "*.vst";
#elif WIN32
filters << "*.dll";
#elif __linux__
filters << "*.so"
<< "*.o";
#endif
QStringList vst_list;
// Read all plugins into a list...
for (int a = 0; a < dir_list.size(); ++a) {
QDir search_dir(dir_list[a]);
search_dir.setNameFilters(filters);
QDirIterator it(search_dir, QDirIterator::Subdirectories);
while (it.hasNext()) {
QString path = it.next();
QString name = it.fileName();
#ifdef __APPLE__
name.remove(QRegExp("(\\.vst)"));
#elif WIN32
name.remove(QRegExp("(\\.dll)"));
#elif __linux__
name.remove(QRegExp("(\\.so|\\.o)"));
#endif
name.append("=").append(path);
vst_list << name;
}
}
// Now sort list alphabetically (still case-sensitive though).
std::stable_sort(vst_list.begin(), vst_list.end(), std::less<QString>());
// Now add said list to the plug-in list of OBS
obs_property_list_add_string(list, "{Please select a plug-in}", nullptr);
for (int b = 0; b < vst_list.size(); ++b) {
QString vst_sorted = vst_list[b];
obs_property_list_add_string(list,
vst_sorted.left(vst_sorted.indexOf('=')).toStdString().c_str(),
vst_sorted.mid(vst_sorted.indexOf('=') + 1).toStdString().c_str());
}
}
static obs_properties_t *vst_properties(void *data)
{
obs_properties_t *props = obs_properties_create();
obs_property_t * list = obs_properties_add_list(
props, "plugin_path", PLUG_IN_NAME, OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
fill_out_plugins(list);
obs_properties_add_button(props, OPEN_VST_SETTINGS, OPEN_VST_TEXT, open_editor_button_clicked);
obs_properties_add_button(props, CLOSE_VST_SETTINGS, CLOSE_VST_TEXT, close_editor_button_clicked);
obs_property_set_visible(obs_properties_get(props, CLOSE_VST_SETTINGS), false);
obs_properties_add_bool(props, OPEN_WHEN_ACTIVE_VST_SETTINGS, OPEN_WHEN_ACTIVE_VST_TEXT);
UNUSED_PARAMETER(data);
return props;
}
bool obs_module_load(void)
{
struct obs_source_info vst_filter = {};
vst_filter.id = "vst_filter";
vst_filter.type = OBS_SOURCE_TYPE_FILTER;
vst_filter.output_flags = OBS_SOURCE_AUDIO;
vst_filter.get_name = vst_name;
vst_filter.create = vst_create;
vst_filter.destroy = vst_destroy;
vst_filter.update = vst_update;
vst_filter.filter_audio = vst_filter_audio;
vst_filter.get_properties = vst_properties;
vst_filter.save = vst_save;
obs_register_source(&vst_filter);
return true;
}