From c8b942918517fdeefd9886bfbae1d00ec62d47b0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 17 Dec 2016 22:32:34 -0500 Subject: Add C++ bindings --- lv2/lv2plug.in/ns/lv2core/Feature.hpp | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 lv2/lv2plug.in/ns/lv2core/Feature.hpp (limited to 'lv2/lv2plug.in/ns/lv2core/Feature.hpp') diff --git a/lv2/lv2plug.in/ns/lv2core/Feature.hpp b/lv2/lv2plug.in/ns/lv2core/Feature.hpp new file mode 100644 index 0000000..81be218 --- /dev/null +++ b/lv2/lv2plug.in/ns/lv2core/Feature.hpp @@ -0,0 +1,74 @@ +/* + Copyright 2015 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef LV2_FEATURE_HPP +#define LV2_FEATURE_HPP + +#include + +#include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/lv2plug.in/ns/ext/urid/urid.h" + +namespace lv2 { + +/** + Feature. + + Features allow hosts to make additional functionality available to plugins + without requiring modification to the LV2 API. Extensions may define new + features and specify the `URI` and `data` to be used if necessary. + Some features, such as lv2:isLive, do not require the host to pass data. +*/ +template +class Feature +{ +public: + /** + Initialize feature by retrieving data from the host. + + @param features Feature array passed by the host. + @param uri URI of this feature. + @param valid Set to false iff feature is required but unsupported. + */ + Feature(const LV2_Feature*const* features, + const char* uri, + bool* valid) + : m_data(nullptr) + , m_supported(false) + { + for (const LV2_Feature*const* f = features; *f; ++f) { + if (!strcmp((*f)->URI, uri)) { + m_data = (Data*)(*f)->data; + m_supported = true; + break; + } + } + if (Required && !m_supported) { + *valid = false; + } + } + + Data* data() const { return m_data; } + bool supported() const { return m_supported; } + +protected: + Data* m_data; + bool m_supported; +}; + +} // namespace lv2 + +#endif // LV2_URID_HPP -- cgit v1.2.1