#include <ladspaplugin.hpp>
Public Member Functions | |
virtual | ~LADSPAPlugin () |
We need a virtual destructor since we have virtual member functions. | |
virtual void | connect_port (unsigned long port, LADSPA_Data *data_location) |
Connects the ports. | |
virtual void | activate () |
Override this function if you need to do anything on activation. | |
virtual void | run (unsigned long sample_count) |
This is the process callback which should fill all output port buffers. | |
virtual void | deactivate () |
Override this function if you need to do anything on deactivation. | |
Protected Attributes | |
std::vector< LADSPA_Data * > | m_ports |
This vector contains pointers to all port buffers. | |
Friends | |
template<class T> | |
size_t | register_ladspa (unsigned long uid, const std::string &label, LADSPA_Properties properties, const std::string &name, const std::string &maker, const std::string ©right, const LADSPAPortList &ports) |
This is the function you should use to register your LADSPA plugin class. |
It has default implementations for all functions, so you only have to implement the functions that you need (for example run()). Any subclass must have a constructor that takes a single unsigned long
as parameter, otherwise it will not work with the template function register_ladspa(). The host will use this parameter to pass the sample rate when it creates a new instance of the plugin.
Here's an example of a plugin that simply copies the input to the output:
#include "ladspaplugin.hpp" class TestLADSPA : public LADSPAPlugin { public: TestLADSPA(unsigned long) { } void run(unsigned long sample_count) { memcpy(m_ports[1], m_ports[0], sample_count * sizeof(LADSPA_Data)); } }; void initialise() __attribute__((constructor)); void initialise() { LADSPAPortList ports; ports.add_port(LADSPA_PORT_AUDIO | LADSPA_PORT_INPUT, "Input"); ports.add_port(LADSPA_PORT_AUDIO | LADSPA_PORT_OUTPUT, "Output"); register_ladspa<TestLADSPA>(667, "test_ladspa_ll", 0, "Test LADSPA", "Lars Luthman", "GPL", ports); }
If the above code is compiled and linked with -lladspa_plugin
into a shared module, it should be a fully functional (but not very useful) LADSPA plugin.
The line void initialise() __attribute__((constructor));
tells GCC that the function initialise()
should be executed when the plugin is loaded. You should use this method instead of naming the function _init()
, which is deprecated. For other compilers you may have to do something different.
If you want to be less compiler dependent you could do something like
static struct Init { Init() { LADSPAPortList ports; ports.add_port(LADSPA_PORT_AUDIO | LADSPA_PORT_INPUT, "Input"); ports.add_port(LADSPA_PORT_AUDIO | LADSPA_PORT_OUTPUT, "Output"); register_ladspa<TestLADSPA>(667, "test_ladspa_ll", 0, "Test LADSPA", "Lars Luthman", "GPL", ports); } } init;
|
We need a virtual destructor since we have virtual member functions.
|
|
Override this function if you need to do anything on activation. This is always called before the host starts using the run() function. You should reset your plugin to it's initial state here. |
|
Connects the ports. You shouldn't have to override this, just use m_ports[port] to access the port buffers. |
|
Override this function if you need to do anything on deactivation. The host calls this when it does not plan to make any more calls to run() (unless it calls activate() again). |
|
This is the process callback which should fill all output port buffers. You most likely want to override it. |
|
This is the function you should use to register your LADSPA plugin class. It should be called when the library is loaded, so you can write an initialisation function with the constructor attribute and put it there. Since this is a template function but the template type isn't one of the parameters, you need to give it explicitly like this:
register_dssi<MyPluginClass>(666, "my_plugin", 0, "My Plugin", "Me", "GPL", my_ports);
|
|
This vector contains pointers to all port buffers. Use it to access the port buffers in your run() function. |