/
vst2-plugin.cpp
66 lines (56 loc) · 2.54 KB
/
vst2-plugin.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
// yabridge: a Wine VST bridge
// Copyright (C) 2020-2021 Robbert van der Helm
//
// 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 3 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 <https://www.gnu.org/licenses/>.
#include <vestige/aeffectx.h>
#include <iostream>
#include <memory>
#include "../common/logging/common.h"
#include "bridges/vst2.h"
#define VST_EXPORT __attribute__((visibility("default")))
// The main entry point for VST2 plugins should be called `VSTPluginMain``. The
// other one exist for legacy reasons since some old hosts might still use them.
// There's also another possible legacy entry point just called `main`, but GCC
// will refuse to compile a function called `main` that's not a regular C++ main
// function.
/**
* The main VST2 plugin entry point. We first set up a bridge that connects to a
* Wine process that hosts the Windows VST2 plugin. We then create and return a
* VST plugin struct that acts as a passthrough to the bridge.
*
* To keep this somewhat contained this is the only place where we're doing
* manual memory management. Clean up is done when we receive the `effClose`
* opcode from the VST2 host (i.e. opcode 1).`
*/
extern "C" VST_EXPORT AEffect* VSTPluginMain(
audioMasterCallback host_callback) {
try {
// This is the only place where we have to use manual memory management.
// The bridge's destructor is called when the `effClose` opcode is
// received.
Vst2PluginBridge* bridge = new Vst2PluginBridge(host_callback);
return &bridge->plugin;
} catch (const std::exception& error) {
Logger logger = Logger::create_from_environment();
logger.log("Error during initialization:");
logger.log(error.what());
// Also show a desktop notification most people likely won't see the
// above message
send_notification("Failed to initialize VST2 plugin", error.what());
return nullptr;
}
}
extern "C" VST_EXPORT AEffect* main_plugin(audioMasterCallback audioMaster) {
return VSTPluginMain(audioMaster);
}