aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-08-27 23:46:20 -0400
committerDavid Robillard <d@drobilla.net>2017-02-26 14:59:00 +0100
commit6b5eedca8ed4c761de2202a5d4fe7711af7be198 (patch)
treeefd5b755f60bd9d5d7beff07f9a0a22e663b63fe
parentc8b942918517fdeefd9886bfbae1d00ec62d47b0 (diff)
downloadlv2-6b5eedca8ed4c761de2202a5d4fe7711af7be198.tar.xz
Use template mixins for extensions
-rw-r--r--lv2/lv2plug.in/ns/lv2core/Plugin.hpp36
-rw-r--r--plugins/eg-midiamp.lv2/midiamp.cpp9
2 files changed, 35 insertions, 10 deletions
diff --git a/lv2/lv2plug.in/ns/lv2core/Plugin.hpp b/lv2/lv2plug.in/ns/lv2core/Plugin.hpp
index f671640..597dd38 100644
--- a/lv2/lv2plug.in/ns/lv2core/Plugin.hpp
+++ b/lv2/lv2plug.in/ns/lv2core/Plugin.hpp
@@ -1,5 +1,5 @@
/*
- Copyright 2015 David Robillard <http://drobilla.net>
+ Copyright 2015-2016 David Robillard <http://drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -46,7 +46,7 @@ namespace lv2 {
The destructor will be called when the host cleans up the plugin.
*/
template<class Derived>
-class Plugin
+class PluginBase
{
public:
/**
@@ -79,10 +79,10 @@ public:
@return A handle for the new plugin instance, or NULL if instantiation
has failed.
*/
- Plugin(double sample_rate,
- const char* bundle_path,
- const LV2_Feature*const* features,
- bool* valid)
+ PluginBase(double sampcle_rate,
+ const char* bundle_path,
+ const LV2_Feature*const* features,
+ bool* valid)
{}
/**
@@ -215,7 +215,7 @@ public:
&s_run,
&s_deactivate,
&s_cleanup,
- &Plugin::extension_data };
+ &PluginBase::extension_data };
return desc;
}
@@ -254,6 +254,28 @@ private:
}
};
+template<class Derived, template<class S> class First=PluginBase, template<class S> class... Rest>
+struct Plugin : public First< Plugin<Derived, Rest...> > {
+ Plugin(double rate,
+ const char* bundle_path,
+ const LV2_Feature* const* features,
+ bool* valid)
+ : First< Plugin<Derived, Rest...> >(rate, bundle_path, features, valid)
+ {}
+
+};
+
+template<class Derived, template<class S> class First>
+struct Plugin<Derived, First> : public First< PluginBase<Derived> > {
+ Plugin(double rate,
+ const char* bundle_path,
+ const LV2_Feature* const* features,
+ bool* valid)
+ : First< PluginBase<Derived> >(rate, bundle_path, features, valid)
+ {}
+
+};
+
} /* namespace lv2 */
#endif /* LV2_PLUGIN_HPP */
diff --git a/plugins/eg-midiamp.lv2/midiamp.cpp b/plugins/eg-midiamp.lv2/midiamp.cpp
index 2fff4e7..ac3d055 100644
--- a/plugins/eg-midiamp.lv2/midiamp.cpp
+++ b/plugins/eg-midiamp.lv2/midiamp.cpp
@@ -1,5 +1,5 @@
/*
- Copyright 2015 David Robillard <d@drobilla.net>
+ Copyright 2015-2016 David Robillard <d@drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -23,14 +23,17 @@
#include "lv2/lv2plug.in/ns/lv2core/Lib.hpp"
#include "lv2/lv2plug.in/ns/lv2core/Plugin.hpp"
+class MidiAmp;
+typedef typename lv2::Plugin<MidiAmp> Base;
+
/** MIDI-controlled amplifier. */
-class MidiAmp : public lv2::Plugin<MidiAmp> {
+class MidiAmp : public Base {
public:
MidiAmp(double rate,
const char* bundle_path,
const LV2_Feature* const* features,
bool* valid)
- : Plugin(rate, bundle_path, features, valid)
+ : Base(rate, bundle_path, features, valid)
, m_map(features, valid)
, m_vol(1.0f)
{