25 #ifndef LVTK_LV2_PLUGIN_HPP
26 #define LVTK_LV2_PLUGIN_HPP
34 #include <lv2/lv2plug.in/ns/lv2core/lv2.h>
36 #include <lvtk/feature.hpp>
37 #include <lvtk/ext/common.h>
38 #include <lvtk/ext/bufsize.hpp>
39 #include <lvtk/ext/resize_port.hpp>
40 #include <lvtk/ext/state.hpp>
41 #include <lvtk/ext/worker.hpp>
43 #include "private/debug.hpp"
99 class DescList :
public vector<LV2_Descriptor> {
158 template <
class Derived,
159 class Ext1 = end,
class Ext2 = end,
class Ext3 = end,
160 class Ext4 = end,
class Ext5 = end,
class Ext6 = end,
161 class Ext7 = end,
class Ext8 = end,
class Ext9 = end>
162 class Plugin :
public MixinTree<Derived, Ext1, Ext2, Ext3,
175 : m_ports(ports, 0), m_ok(true)
177 m_features = s_features;
178 m_bundle_path = s_bundle_path;
185 Derived::map_feature_handlers (hmap);
187 for (
const Feature*
const* iter = m_features; *iter != 0; ++iter)
189 FeatureHandlerMap::iterator miter;
190 miter = hmap.find((*iter)->URI);
192 if (miter != hmap.end())
194 miter->second (static_cast<Derived*>(
this), (*iter)->data);
211 m_ports[port] = data_location;
229 void run(uint32_t sample_count) { }
253 std::memset(&desc, 0,
sizeof(LV2_Descriptor));
254 desc.URI = strdup (uri);
255 desc.instantiate = &Derived::_create_plugin_instance;
256 desc.connect_port = &Derived::_connect_port;
257 desc.activate = &Derived::_activate;
258 desc.run = &Derived::_run;
259 desc.deactivate = &Derived::_deactivate;
260 desc.cleanup = &Derived::_delete_plugin_instance;
261 desc.extension_data = &Derived::extension_data;
262 get_lv2_descriptors().push_back (desc);
264 return get_lv2_descriptors().size() - 1;
276 return m_ok && MixinTree<Derived,
277 Ext1, Ext2, Ext3, Ext4, Ext5,
278 Ext6, Ext7, Ext8, Ext9>::check_ok();
294 template <
typename T> T*&
297 return reinterpret_cast<T*&
>(m_ports[port]);
305 return reinterpret_cast<float*&
>(m_ports[port]);
314 return m_bundle_path;
334 std::vector<void*> m_ports;
341 static void _connect_port(LV2_Handle instance, uint32_t port,
342 void* data_location) {
343 reinterpret_cast<Derived*
>(instance)->
connect_port(port, data_location);
349 static void _activate(LV2_Handle instance) {
350 reinterpret_cast<Derived*
>(instance)->
activate();
356 static void _run(LV2_Handle instance, uint32_t sample_count) {
357 reinterpret_cast<Derived*
>(instance)->
run(sample_count);
363 static void _deactivate(LV2_Handle instance) {
364 reinterpret_cast<Derived*
>(instance)->
deactivate();
371 static LV2_Handle _create_plugin_instance(
const LV2_Descriptor* descriptor,
374 const LV2_Feature*
const*
379 s_features = features;
384 std::clog<<
"[plugin] Instantiating plugin...\n"
385 <<
" Bundle path: "<<bundle_path<<
"\n"
388 FeatureIter feats (features);
389 while (
const Feature* feature = feats.next())
390 std::clog <<
" "<< feature->URI <<
"\n";
392 std::clog<<
" Creating plugin object...\n";
395 Derived* t =
new Derived (sample_rate);
397 if (LVTK_DEBUG) { std::clog<<
" Validating...\n"; }
401 std::clog<<
" Done!"<<std::endl;
402 return reinterpret_cast<LV2_Handle
>(t);
406 std::clog<<
" Failed!\n"
407 <<
" Deleting object."<<std::endl;
418 static void _delete_plugin_instance(LV2_Handle instance) {
419 delete reinterpret_cast<Derived*
> (instance);
429 Feature const*
const* m_features;
435 char const* m_bundle_path;
441 static Feature const*
const* s_features;
447 static char const* s_bundle_path;
460 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
461 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
463 Plugin<Derived, Ext1, Ext2, Ext3, Ext4,
464 Ext5, Ext6, Ext7, Ext8, Ext9>::s_features = 0;
466 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
467 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
469 Plugin<Derived, Ext1, Ext2, Ext3, Ext4,
470 Ext5, Ext6, Ext7, Ext8, Ext9>::s_bundle_path = 0;