#include <dssiplugin.hpp>
Public Member Functions | |
Instantiation class | |
virtual | ~DSSIPlugin () |
A virtual destructor is needed since we have virtual member functions. | |
virtual void | activate () |
Override this function if you need to do something on activation. | |
virtual void | deactivate () |
Override this function if you need to do something on deactivation. | |
Control class | |
virtual char * | configure (const char *key, const char *value) |
Override this function if you use configuration keys. | |
virtual int | get_midi_controller_for_port (unsigned long port) |
If you want to map MIDI controllers to your control ports you will need to override this function. | |
virtual const DSSI_Program_Descriptor * | get_program (unsigned long index) |
Override this function if your plugin supports programs. | |
virtual bool | shm_attached (void *shm, size_t size) |
Override this function if your plugin uses shared memory. | |
virtual void | shm_detach_request (void *shm) |
This function is called when the GUI no longer wants to use the shared memory segment pointed to by shm . | |
Audio class | |
virtual void | run (unsigned long sample_count) |
This function is only used if you have not set the DSSI_RECEIVES_MIDI flag for your plugin, or if the host for some reason decides to use it instead of run_synth(). | |
virtual void | run_synth (unsigned long sample_count, snd_seq_event_t *events, unsigned long event_count) |
This function does the actual work. | |
virtual void | select_program (unsigned long bank, unsigned long program) |
This function allows the host to select the synth program. | |
virtual void | connect_port (unsigned long port, LADSPA_Data *data_location) |
This function copies the pointer data_location to the port array. | |
Protected Member Functions | |
void | shm_detach (void *shm) |
This function detaches a shared memory segment previously given as an argument to shm_attached(). | |
Protected Attributes | |
std::vector< LADSPA_Data * > | m_ports |
This vector holds the pointers to the port buffers for this plugin instance. | |
Friends | |
template<class T> | |
size_t | register_dssi (const std::string &label, LADSPA_Properties properties, const std::string &name, const std::string &maker, const std::string ©right, const DSSIPortList &ports, DSSIFeatureMask features) |
This is the function you should use to register your DSSI plugin class. |
It has default implementations for all functions, so you only have to implement the functions that you need (for example run_synth()). Any subclass must have a constructor that takes a single unsigned long
as parameter, otherwise it will not work with the template function register_dssi().
The virtual member functions are divided into three groups; instantiation, control, and audio. These functions should obey the rules described in the DSSI RFC. Two functions, shm_attached() and shm_detach_request(), are not described in the RFC - they are a part of the memory handling mechanism that allows you to create shared memory segments in the UI and pass them to the plugin so you can do things like waveform displays and VU-meters in the UI. These functions should obey the same rules as the other control functions.
Here's an example of a plugin that simply copies the input to the output:
#include <cstring> #include "dssiplugin.hpp" class MyPlugin : public DSSIPlugin { public: MyPlugin(unsigned long) { } void run(unsigned long sample_count) { std::memcpy(m_ports[1], m_ports[0], sizeof(LADSPA_Data) * sample_count); } }; void initialise() __attribute__((constructor)); void initialise() { DSSIPortList ports; ports.add_port(LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO, "Input"); ports.add_port(LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO, "Output"); register_dssi<MyPlugin>("my_plugin", 0, "My plugin", "Lars Luthman", "GPL", ports, DSSI_NO_FEATURES); }
If the above code is compiled and linked with -ldssi_plugin
into a shared module, it should be a fully functional (but not very useful) DSSI 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() { DSSIPortList ports; ports.add_port(LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO, "Input"); ports.add_port(LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO, "Output"); register_dssi<MyPlugin>("my_plugin", 0, "My plugin", "Lars Luthman", "GPL", ports, DSSI_NO_FEATURES); } } init;
|
A virtual destructor is needed since we have virtual member functions.
|
|
Override this function if you need to do something on activation.
|
|
Override this function if you use configuration keys.
|
|
This function copies the pointer You shouldn't override this unless you know what you are doing. |
|
Override this function if you need to do something on deactivation.
|
|
If you want to map MIDI controllers to your control ports you will need to override this function. If the flag DSSI_RECEIVES_MIDI is not set it will never be called. |
|
Override this function if your plugin supports programs. It should return a pointer to a DSSI_Program_Descriptor for the given index, or NULL if there is no program with that index. If the flag DSSI_HAS_PROGRAMS is not set, this function will never be called. |
|
This function is only used if you have not set the DSSI_RECEIVES_MIDI flag for your plugin, or if the host for some reason decides to use it instead of run_synth(). The default implementation simply calls run_synth() with no MIDI events - only override it if you are writing a plugin that doesn't use MIDI. |
|
This function does the actual work. You most likely want to override it (unless your plugin does not handle MIDI events, in which case you should override run() instead). If the flag DSSI_RECEIVES_MIDI is not set, this function will never be called. |
|
This function allows the host to select the synth program. Override it only if your plugin supports programs. If the flag DSSI_HAS_PROGRAMS is not set, this function will never be called. |
|
Override this function if your plugin uses shared memory.
It is called when the plugin has received a request from the GUI to attach to a shared memory segment. |
|
This function detaches a shared memory segment previously given as an argument to shm_attached(). Do not override it unless you really know what you are doing. |
|
This function is called when the GUI no longer wants to use the shared memory segment pointed to by The default implementation calls shm_detach() to detach the segment immediately. If you are using the segment in audio class functions this may not be what you want, since an audio class function running concurrently with this function may be using the segment right now. In that case you need to mark the segment for detachment somehow and call shm_detach() later when you are sure that the segment is not being used. Any shared segments that haven't been detached when this plugin object is destroyed will then be detached automatically in the destructor. |
|
This is the function you should use to register your DSSI 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>("my_plugin", 0, "My Plugin", "Me", "GPL", my_ports);
|
|
This vector holds the pointers to the port buffers for this plugin instance. It is protected because the subclasses need to access it. |