34 #include <lv2_uri_map.h>
35 #include <lv2_saverestore.h>
36 #include <lv2_event.h>
37 #include <lv2_contexts.h>
38 #include <lv2types.hpp>
79 class DescList :
public std::vector<LV2_Descriptor> {
88 DescList& get_lv2_descriptors();
131 template <
class Derived,
132 class Ext1 = End,
class Ext2 = End,
class Ext3 = End,
133 class Ext4 = End,
class Ext5 = End,
class Ext6 = End,
134 class Ext7 = End,
class Ext8 = End,
class Ext9 = End>
136 Ext1, Ext2, Ext3, Ext4, Ext5,
137 Ext6, Ext7, Ext8, Ext9> {
149 m_features = s_features;
150 m_bundle_path = s_bundle_path;
154 FeatureHandlerMap hmap;
155 Derived::map_feature_handlers(hmap);
156 for (
const Feature*
const* iter = m_features; *iter != 0; ++iter) {
157 FeatureHandlerMap::iterator miter;
158 miter = hmap.find((*iter)->URI);
159 if (miter != hmap.end())
160 miter->second(
static_cast<Derived*
>(
this), (*iter)->data);
175 m_ports[port] = data_location;
193 void run(uint32_t sample_count) { }
215 std::memset(&desc, 0,
sizeof(LV2_Descriptor));
216 char* c_uri =
new char[uri.size() + 1];
217 std::memcpy(c_uri, uri.c_str(), uri.size() + 1);
219 desc.instantiate = &Derived::_create_plugin_instance;
220 desc.connect_port = &Derived::_connect_port;
221 desc.activate = &Derived::_activate;
222 desc.run = &Derived::_run;
223 desc.deactivate = &Derived::_deactivate;
224 desc.cleanup = &Derived::_delete_plugin_instance;
225 desc.extension_data = &Derived::extension_data;
226 get_lv2_descriptors().push_back(desc);
227 return get_lv2_descriptors().size() - 1;
239 return m_ok && MixinTree<Derived,
240 Ext1, Ext2, Ext3, Ext4, Ext5,
241 Ext6, Ext7, Ext8, Ext9>::check_ok();
257 template <
typename T> T*&
p(uint32_t port) {
258 return reinterpret_cast<T*&
>(m_ports[port]);
264 float*&
p(uint32_t port) {
265 return reinterpret_cast<float*&
>(m_ports[port]);
272 return m_bundle_path;
290 std::vector<void*> m_ports;
297 static void _connect_port(LV2_Handle instance, uint32_t port,
298 void* data_location) {
299 reinterpret_cast<Derived*
>(instance)->
connect_port(port, data_location);
305 static void _activate(LV2_Handle instance) {
306 reinterpret_cast<Derived*
>(instance)->
activate();
312 static void _run(LV2_Handle instance, uint32_t sample_count) {
313 reinterpret_cast<Derived*
>(instance)->
run(sample_count);
319 static void _deactivate(LV2_Handle instance) {
320 reinterpret_cast<Derived*
>(instance)->
deactivate();
327 static LV2_Handle _create_plugin_instance(
const LV2_Descriptor* descriptor,
330 const Feature*
const*
335 s_features = features;
338 Derived* t =
new Derived(sample_rate);
340 return reinterpret_cast<LV2_Handle
>(t);
349 static void _delete_plugin_instance(LV2_Handle instance) {
350 delete reinterpret_cast<Derived*
>(instance);
360 LV2::Feature
const*
const* m_features;
366 char const* m_bundle_path;
372 static LV2::Feature
const*
const* s_features;
378 static char const* s_bundle_path;
391 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
392 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
393 LV2::Feature
const*
const*
394 Plugin<Derived, Ext1, Ext2, Ext3, Ext4,
395 Ext5, Ext6, Ext7, Ext8, Ext9>::s_features = 0;
397 template<
class Derived,
class Ext1,
class Ext2,
class Ext3,
class Ext4,
398 class Ext5,
class Ext6,
class Ext7,
class Ext8,
class Ext9>
400 Plugin<Derived, Ext1, Ext2, Ext3, Ext4,
401 Ext5, Ext6, Ext7, Ext8, Ext9>::s_bundle_path = 0;
429 template <
bool Required = true>
436 template <
class Derived>
struct I : Extension<Required> {
439 I() : m_buffer_size(0) { }
442 static void map_feature_handlers(FeatureHandlerMap& hmap) {
443 hmap[
"http://tapas.affenbande.org/lv2/ext/fixed-buffersize"] =
448 static void handle_feature(
void* instance,
void* data) {
449 Derived* d =
reinterpret_cast<Derived*
>(instance);
451 fe->m_buffer_size = *
reinterpret_cast<uint32_t*
>(data);
462 uint32_t m_buffer_size;
476 template <
bool Required = true>
483 template <
class Derived>
struct I : Extension<Required> {
486 I() : m_buffer_size(0) { }
489 static void map_feature_handlers(FeatureHandlerMap& hmap) {
490 hmap[
"http://tapas.affenbande.org/lv2/ext/power-of-two-buffersize"] =
495 static void handle_feature(
void* instance,
void* data) {
496 Derived* d =
reinterpret_cast<Derived*
>(instance);
498 fe->m_buffer_size = *
reinterpret_cast<uint32_t*
>(data);
509 uint32_t m_buffer_size;
522 template <
bool Required = true>
529 template <
class Derived>
struct I : Extension<Required> {
535 static void map_feature_handlers(FeatureHandlerMap& hmap) {
540 static void handle_feature(
void* instance,
void* data) {
541 Derived* d =
reinterpret_cast<Derived*
>(instance);
547 static const void* extension_data(
const char* uri) {
548 if (!std::strcmp(uri, LV2_SAVERESTORE_URI)) {
568 char*
save(
const char* directory, LV2SR_File*** files) {
return 0; }
576 char*
restore(
const LV2SR_File** files) {
return 0; }
582 static char* _save(LV2_Handle h,
583 const char* directory, LV2SR_File*** files) {
584 return reinterpret_cast<Derived*
>(h)->
save(directory, files);
589 static char* _restore(LV2_Handle h,
const LV2SR_File** files) {
590 return reinterpret_cast<Derived*
>(h)->
restore(files);
603 template <
bool Required = true>
610 template <
class Derived>
struct I : Extension<Required> {
613 I() : m_callback_data(0), m_ref_func(0), m_unref_func(0) { }
616 static void map_feature_handlers(FeatureHandlerMap& hmap) {
621 static void handle_feature(
void* instance,
void* data) {
622 Derived* d =
reinterpret_cast<Derived*
>(instance);
624 LV2_Event_Feature* ef =
reinterpret_cast<LV2_Event_Feature*
>(data);
625 fe->m_callback_data = ef->callback_data;
626 fe->m_ref_func = ef->lv2_event_ref;
627 fe->m_unref_func = ef->lv2_event_unref;
643 return m_ref_func(m_callback_data, event);
651 return m_unref_func(m_callback_data, event);
654 LV2_Event_Callback_Data m_callback_data;
655 uint32_t (*m_ref_func)(LV2_Event_Callback_Data, LV2_Event*);
656 uint32_t (*m_unref_func)(LV2_Event_Callback_Data, LV2_Event*);
670 template <
bool Required = true>
677 template <
class Derived>
struct I : Extension<Required> {
683 static void map_feature_handlers(FeatureHandlerMap& hmap) {
688 static void handle_feature(
void* instance,
void* data) {
689 Derived* d =
reinterpret_cast<Derived*
>(instance);
695 static const void* extension_data(
const char* uri) {
696 if (!std::strcmp(uri, LV2_CONTEXT_MESSAGE)) {
708 bool blocking_run(uint8_t* outputs_written) {
return false; }
714 static bool _blocking_run(LV2_Handle h, uint8_t* outputs_written) {
715 return reinterpret_cast<Derived*
>(h)->blocking_run(outputs_written);
720 static void _connect_port(LV2_Handle h, uint32_t port,
void* buffer) {
721 reinterpret_cast<Derived*
>(h)->connect_port(port, buffer);
Definition: lv2plugin.hpp:137
void run(uint32_t sample_count)
Definition: lv2plugin.hpp:193
T *& p(uint32_t port)
Definition: lv2plugin.hpp:257
void activate()
Definition: lv2plugin.hpp:181
void set_ok(bool ok)
Definition: lv2plugin.hpp:283
void connect_port(uint32_t port, void *data_location)
Definition: lv2plugin.hpp:174
void deactivate()
Definition: lv2plugin.hpp:199
float *& p(uint32_t port)
Definition: lv2plugin.hpp:264
const char * bundle_path() const
Definition: lv2plugin.hpp:271
static unsigned register_class(const std::string &uri)
Definition: lv2plugin.hpp:213
Plugin(uint32_t ports)
Definition: lv2plugin.hpp:146
Definition: lv2plugin.hpp:610
uint32_t event_unref(LV2_Event *event)
Definition: lv2plugin.hpp:650
uint32_t event_ref(LV2_Event *event)
Definition: lv2plugin.hpp:642
Definition: lv2plugin.hpp:604
Definition: lv2plugin.hpp:436
uint32_t get_buffer_size() const
Definition: lv2plugin.hpp:460
Definition: lv2plugin.hpp:430
Definition: lv2plugin.hpp:483
uint32_t get_buffer_size() const
Definition: lv2plugin.hpp:507
Definition: lv2plugin.hpp:477
Definition: lv2plugin.hpp:677
Definition: lv2plugin.hpp:529
char * restore(const LV2SR_File **files)
Definition: lv2plugin.hpp:576
char * save(const char *directory, LV2SR_File ***files)
Definition: lv2plugin.hpp:568
Definition: lv2plugin.hpp:523