22 #ifndef LVTK_PLUGIN_HPP 23 #define LVTK_PLUGIN_HPP 31 #include <lv2/lv2plug.in/ns/lv2core/lv2.h> 33 #include <lvtk/feature.hpp> 34 #include <lvtk/ext/common.h> 35 #include <lvtk/ext/bufsize.hpp> 36 #include <lvtk/ext/resize_port.hpp> 37 #include <lvtk/ext/state.hpp> 38 #include <lvtk/ext/worker.hpp> 40 #include "private/debug.hpp" 96 class DescList :
public vector<LV2_Descriptor> {
155 template <
class Derived,
156 class Ext1 = end,
class Ext2 = end,
class Ext3 = end,
157 class Ext4 = end,
class Ext5 = end,
class Ext6 = end,
158 class Ext7 = end,
class Ext8 = end,
class Ext9 = end>
159 class Plugin :
public MixinTree<Derived, Ext1, Ext2, Ext3,
172 : m_ports(ports, 0), m_ok(true)
174 m_features = s_features;
175 m_bundle_path = s_bundle_path;
182 Derived::map_feature_handlers (hmap);
184 for (
const Feature*
const* iter = m_features; *iter != 0; ++iter)
186 FeatureHandlerMap::iterator miter;
187 miter = hmap.find((*iter)->URI);
189 if (miter != hmap.end())
191 miter->second (static_cast<Derived*>(
this), (*iter)->data);
208 m_ports[port] = data_location;
226 void run(uint32_t sample_count) { }
250 std::memset(&desc, 0,
sizeof(LV2_Descriptor));
251 desc.URI = strdup (uri);
252 desc.instantiate = &Derived::_create_plugin_instance;
253 desc.connect_port = &Derived::_connect_port;
254 desc.activate = &Derived::_activate;
255 desc.run = &Derived::_run;
256 desc.deactivate = &Derived::_deactivate;
257 desc.cleanup = &Derived::_delete_plugin_instance;
258 desc.extension_data = &Derived::extension_data;
259 get_lv2_descriptors().push_back (desc);
261 return get_lv2_descriptors().size() - 1;
273 return m_ok && MixinTree<Derived,
274 Ext1, Ext2, Ext3, Ext4, Ext5,
275 Ext6, Ext7, Ext8, Ext9>::check_ok();
291 template <
typename T> T*&
294 return reinterpret_cast<T*&
>(m_ports[port]);
302 return reinterpret_cast<float*&
>(m_ports[port]);
311 return m_bundle_path;
331 std::vector<void*> m_ports;
338 static void _connect_port(LV2_Handle instance, uint32_t port,
339 void* data_location) {
340 reinterpret_cast<Derived*
>(instance)->connect_port(port, data_location);
346 static void _activate(LV2_Handle instance) {
347 reinterpret_cast<Derived*
>(instance)->activate();
353 static void _run(LV2_Handle instance, uint32_t sample_count) {
354 reinterpret_cast<Derived*
>(instance)->run(sample_count);
360 static void _deactivate(LV2_Handle instance) {
361 reinterpret_cast<Derived*
>(instance)->deactivate();
368 static LV2_Handle _create_plugin_instance(
const LV2_Descriptor* descriptor,
370 const char* bundle_path,
371 const LV2_Feature*
const*
376 s_features = features;
377 s_bundle_path = bundle_path;
381 std::clog<<
"[plugin] Instantiating plugin...\n" 382 <<
" Bundle path: "<<bundle_path<<
"\n" 386 while (
const Feature* feature = feats.next())
387 std::clog <<
" "<< feature->URI <<
"\n";
389 std::clog<<
" Creating plugin object...\n";
392 Derived* t =
new Derived (sample_rate);
394 if (LVTK_DEBUG) { std::clog<<
" Validating...\n"; }
398 std::clog<<
" Done!"<<std::endl;
399 return reinterpret_cast<LV2_Handle
>(t);
403 std::clog<<
" Failed!\n" 404 <<
" Deleting object."<<std::endl;
415 static void _delete_plugin_instance(LV2_Handle instance) {
416 delete reinterpret_cast<Derived*
> (instance);
426 Feature const*
const* m_features;
432 char const* m_bundle_path;
438 static Feature const*
const* s_features;
444 static char const* s_bundle_path;
457 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
458 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
460 Plugin<Derived, Ext1, Ext2, Ext3, Ext4,
461 Ext5, Ext6, Ext7, Ext8, Ext9>::s_features = 0;
463 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
464 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
466 Plugin<Derived, Ext1, Ext2, Ext3, Ext4,
467 Ext5, Ext6, Ext7, Ext8, Ext9>::s_bundle_path = 0;
void set_ok(bool ok)
Definition: plugin.hpp:323
const char * bundle_path() const
Definition: plugin.hpp:309
void activate()
Definition: plugin.hpp:214
Definition: plugin.hpp:96
void connect_port(uint32_t port, void *data_location)
Definition: plugin.hpp:207
void deactivate()
Definition: plugin.hpp:232
void run(uint32_t sample_count)
Definition: plugin.hpp:226
LV2_Feature Feature
Definition: feature.hpp:41
Plugin(uint32_t ports)
Definition: plugin.hpp:171
Definition: feature.hpp:34
Definition: plugin.hpp:159
T *& p(uint32_t port)
Definition: plugin.hpp:292
float *& p(uint32_t port)
Definition: plugin.hpp:301
static unsigned register_class(const char *uri)
Definition: plugin.hpp:247
Definition: feature.hpp:59
map< string, FeatureHandler > FeatureHandlerMap
Definition: feature.hpp:57