LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 > Class Template Reference

#include <lv2plugin.hpp>

Inheritance diagram for LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >:

LV2::Synth< V, D, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7 >

List of all members.

Public Member Functions

 Plugin (uint32_t ports)
void connect_port (uint32_t port, void *data_location)
void activate ()
void run (uint32_t sample_count)
void deactivate ()

Static Public Member Functions

static unsigned register_class (const std::string &uri)

Protected Member Functions

template<typename T>
T *& p (uint32_t port)
float *& p (uint32_t port)
const char * bundle_path () const
void set_ok (bool ok)


Detailed Description

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
class LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >

This is a template base class for LV2 plugins. It has default implementations for all functions, so you only have to implement the functions that you need (for example run()). All subclasses must have a constructor whose signature matches the one in the example code below, otherwise it will not work with the register_class() function. The host will use this double parameter to pass the sample rate that the plugin should run at when it creates a new instance of the plugin.

This is a template so that simulated dynamic binding can be used for the callbacks. This is not all that useful for simple plugins but it may come in handy when using mixins and it doesn't add any additional vtable lookup and function call costs, like real dynamic binding would.

      #include <cstring>
      #include <lv2plugin.hpp>
      
      class TestLV2 : public LV2::Plugin<TestLV2> {
      public:
        TestLV2(double) : LV2::Plugin<TestLV2>(2) { }
        void run(uint32_t sample_count) {
          std::memcpy(p(1), p(0), sample_count * sizeof(float));
        }
      };
      
      static unsigned _ = TestLV2::register_class("http://ll-plugins.sf.net/plugins/TestLV2");

If the above code is compiled and linked with -llv2_plugin into a shared module, it could form the shared object part of a fully functional (but not very useful) LV2 plugin with one audio input port and one audio output port that just copies the input to the output.

You can extend your plugin classes, for example adding support for LV2 extensions, by passing mixin classes as template parameters to Plugin (second template parameter and onwards).

If you want to write a synth plugin you should probably inherit the Synth class instead of this one.


Constructor & Destructor Documentation

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::Plugin ( uint32_t  ports  )  [inline]

This constructor is needed to initialise the port vector with the correct number of ports, and to check if all the required features are provided. This must be called as the first item in the initialiser list for your plugin class.

Parameters:
ports The number of ports in this plugin.


Member Function Documentation

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
void LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::connect_port ( uint32_t  port,
void *  data_location 
) [inline]

Connects the ports. You shouldn't have to override this, just use p() to access the port buffers.

If you do override this function, remember that if you want your plugin to be realtime safe this function may not block, allocate memory or otherwise take a long time to return.

Parameters:
port The index of the port to connect.
data_location The buffer to connect it to.

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
void LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::activate (  )  [inline]

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.

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
void LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::run ( uint32_t  sample_count  )  [inline]

This is the process callback which should fill all output port buffers. You most likely want to override it - the default implementation does nothing.

Remember that if you want your plugin to be realtime safe, this function may not block, allocate memory or take more than O(sample_count) time to execute.

Parameters:
sample_count The number of audio frames to process/generate in this call.

Reimplemented in LV2::Synth< V, D, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7 >.

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
void LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::deactivate (  )  [inline]

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

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
static unsigned LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::register_class ( const std::string &  uri  )  [inline, static]

Use this function to register your plugin class so that the host can find it. You need to do this when the shared library is loaded by the host. One portable way of doing that is to put the function call in the initialiser for a global variable, like this:

unsigned _ =  MyPluginClass::register_class("http://my.plugin.class");

The return value is not important, it's just there so you can use that trick.

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
template<typename T>
T*& LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::p ( uint32_t  port  )  [inline, protected]

Use this function to access and cast port buffers, for example like this:

LV2_Event_Buffer* midibuffer = p<LV2_Event_Buffer>(midiport_index);

If you want to access a port buffer as a pointer-to-float (i.e. an audio or control port) you can use the non-template version instead.

Parameters:
port The index of the port whose buffer you want to access.

Reimplemented in LV2::Synth< V, D, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7 >, and LV2::Synth< V, D, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7 >.

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
float*& LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::p ( uint32_t  port  )  [inline, protected]

Use this function to access data buffers for control or audio ports.

Parameters:
port The index of the port whose buffer you want to access.

Reimplemented in LV2::Synth< V, D, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7 >, and LV2::Synth< V, D, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7 >.

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
const char* LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::bundle_path (  )  const [inline, protected]

Returns the filesystem path to the bundle that contains this plugin. This may only be called after the Plugin constructor is done executing.

template<class Derived, class Ext1 = End, class Ext2 = End, class Ext3 = End, class Ext4 = End, class Ext5 = End, class Ext6 = End, class Ext7 = End, class Ext8 = End, class Ext9 = End>
void LV2::Plugin< Derived, Ext1, Ext2, Ext3, Ext4, Ext5, Ext6, Ext7, Ext8, Ext9 >::set_ok ( bool  ok  )  [inline, protected]

Sets the OK state of the plugin. If it's true (which is the default) the plugin has been instantiated OK, if false it has not and the host will discard it. You can call this in the constructor for your plugin class if you need to check some condition that isn't taken care of by a mixin.

Parameters:
ok True if the plugin instance is OK and can be used, false if it should be discarded.


The documentation for this class was generated from the following file:

Generated on Tue Apr 8 19:10:57 2008 by  doxygen 1.5.5