Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

LADSPAPlugin Class Reference

This is a base class for LADSPA plugins. More...

#include <ladspaplugin.hpp>

List of all members.

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 &copyright, const LADSPAPortList &ports)
 This is the function you should use to register your LADSPA plugin class.


Detailed Description

This is a base class for LADSPA plugins.

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;


Constructor & Destructor Documentation

virtual LADSPAPlugin::~LADSPAPlugin  )  [inline, virtual]
 

We need a virtual destructor since we have virtual member functions.


Member Function Documentation

virtual void LADSPAPlugin::activate  )  [inline, virtual]
 

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.

virtual void LADSPAPlugin::connect_port unsigned long  port,
LADSPA_Data *  data_location
[inline, virtual]
 

Connects the ports.

You shouldn't have to override this, just use m_ports[port] to access the port buffers.

virtual void LADSPAPlugin::deactivate  )  [inline, virtual]
 

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).

virtual void LADSPAPlugin::run unsigned long  sample_count  )  [inline, virtual]
 

This is the process callback which should fill all output port buffers.

You most likely want to override it.


Friends And Related Function Documentation

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 &  copyright,
const LADSPAPortList ports
[friend]
 

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);

Parameters:
uid The unique LADSPA ID for this plugin. If you are planning to distribute this plugin you need to reserve your ID from the contact given at http://www.ladspa.org to avoid clashes.
label The LADSPA label for this plugin
properties The LADSPA properties for this plugin
name The LADSPA name for this plugin
maker Your name!
copyright The copyright for this plugin (for example "GPL")
ports The port list for this DSSI plugin.


Member Data Documentation

std::vector<LADSPA_Data*> LADSPAPlugin::m_ports [protected]
 

This vector contains pointers to all port buffers.

Use it to access the port buffers in your run() function.


The documentation for this class was generated from the following file:
Generated on Wed Mar 1 17:12:44 2006 for DSSI support libraries by  doxygen 1.4.4