mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Handle freeing resources when closing the plugin
This commit is contained in:
+11
-1
@@ -17,12 +17,22 @@ intptr_t Bridge::dispatch(AEffect* /*plugin*/,
|
|||||||
void* result,
|
void* result,
|
||||||
float /*option*/) {
|
float /*option*/) {
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
case effClose:
|
||||||
|
// TODO: Gracefully close the editor?
|
||||||
|
|
||||||
|
// The VST API does not have an explicit function for releasing
|
||||||
|
// resources, so we'll have to do it here. The actual plugin
|
||||||
|
// instance gets freed by the host, or at least I think it does.
|
||||||
|
delete this;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
case effGetEffectName:
|
case effGetEffectName:
|
||||||
const std::string plugin_name("Hello, world!");
|
const std::string plugin_name("Hello, world!");
|
||||||
std::copy(plugin_name.begin(), plugin_name.end(),
|
std::copy(plugin_name.begin(), plugin_name.end(),
|
||||||
static_cast<char*>(result));
|
static_cast<char*>(result));
|
||||||
|
|
||||||
// return 1; // TODO: Why?
|
return 1; // TODO: Why?
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-19
@@ -28,27 +28,28 @@ void setParameter(AEffect*, int32_t, float);
|
|||||||
float getParameter(AEffect*, int32_t);
|
float getParameter(AEffect*, int32_t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the bridge instance stored in an unused pointer from a VST plugin.
|
* Fetch the bridge instance stored in an unused pointer from a VST plugin. This
|
||||||
* This is sadly needed as a workaround to avoid using globals since we need
|
* is sadly needed as a workaround to avoid using globals since we need free
|
||||||
* free function pointers to interface with the VST API.
|
* function pointers to interface with the VST C API.
|
||||||
*/
|
*/
|
||||||
Bridge* get_bridge_instance(const AEffect& plugin) {
|
Bridge& get_bridge_instance(const AEffect& plugin) {
|
||||||
return static_cast<Bridge*>(plugin.ptr3);
|
return *static_cast<Bridge*>(plugin.ptr3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main VST plugin entry point. This finds the Windows VST plugin that
|
* The main VST plugin entry point. We first set up a bridge that connects to a
|
||||||
* should be run, executes it in our VST host inside Wine, and sets up
|
* Wine process that hosts the Windows VST plugin. We then create and return a
|
||||||
* communication between the two processes.
|
* VST plugin struct that acts as a passthrough to the bridge.
|
||||||
*
|
*
|
||||||
* This is a bit of a mess since we're interacting with an external C API. To
|
* To keep this somewhat contained this is the only place where we're doing
|
||||||
* keep this somewhat contained this is the only place where we're doing manual
|
* manual memory management. Clean up is done when we receive the `effClose`
|
||||||
* memory management.
|
* opcode from the VST host (i.e. opcode 1).`
|
||||||
*/
|
*/
|
||||||
VST_EXPORT AEffect* VSTPluginMain(audioMasterCallback /*audioMaster*/) {
|
VST_EXPORT AEffect* VSTPluginMain(audioMasterCallback /*audioMaster*/) {
|
||||||
// TODO: Since we are returning raw pointers, how does cleanup work?
|
Bridge* bridge = new Bridge();
|
||||||
|
|
||||||
AEffect* plugin = new AEffect();
|
AEffect* plugin = new AEffect();
|
||||||
plugin->ptr3 = new Bridge();
|
plugin->ptr3 = bridge;
|
||||||
|
|
||||||
plugin->dispatcher = dispatch;
|
plugin->dispatcher = dispatch;
|
||||||
plugin->process = process;
|
plugin->process = process;
|
||||||
@@ -73,22 +74,22 @@ intptr_t dispatch(AEffect* plugin,
|
|||||||
intptr_t value,
|
intptr_t value,
|
||||||
void* result,
|
void* result,
|
||||||
float option) {
|
float option) {
|
||||||
return get_bridge_instance(*plugin)->dispatch(plugin, opcode, parameter,
|
return get_bridge_instance(*plugin).dispatch(plugin, opcode, parameter,
|
||||||
value, result, option);
|
value, result, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
void process(AEffect* plugin,
|
void process(AEffect* plugin,
|
||||||
float** inputs,
|
float** inputs,
|
||||||
float** outputs,
|
float** outputs,
|
||||||
int32_t sample_frames) {
|
int32_t sample_frames) {
|
||||||
return get_bridge_instance(*plugin)->process(plugin, inputs, outputs,
|
return get_bridge_instance(*plugin).process(plugin, inputs, outputs,
|
||||||
sample_frames);
|
sample_frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setParameter(AEffect* plugin, int32_t index, float value) {
|
void setParameter(AEffect* plugin, int32_t index, float value) {
|
||||||
return get_bridge_instance(*plugin)->set_parameter(plugin, index, value);
|
return get_bridge_instance(*plugin).set_parameter(plugin, index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
float getParameter(AEffect* plugin, int32_t index) {
|
float getParameter(AEffect* plugin, int32_t index) {
|
||||||
return get_bridge_instance(*plugin)->get_parameter(plugin, index);
|
return get_bridge_instance(*plugin).get_parameter(plugin, index);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user