diff options
Diffstat (limited to 'src/client/PluginModel.cpp')
-rw-r--r-- | src/client/PluginModel.cpp | 109 |
1 files changed, 55 insertions, 54 deletions
diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp index f0e3c3a0..333bf568 100644 --- a/src/client/PluginModel.cpp +++ b/src/client/PluginModel.cpp @@ -17,23 +17,20 @@ #include "ingen/client/PluginModel.hpp" #include "ingen/Atom.hpp" -#include "ingen/client/GraphModel.hpp" #include "ingen/client/PluginUI.hpp" -#include "raul/Path.hpp" -#include "ingen_config.h" - -#include <boost/optional/optional.hpp> +#include "lilv/lilv.h" +#include "lv2/core/lv2.h" +#include "raul/Symbol.hpp" #include <cctype> #include <cstring> -#include <iosfwd> +#include <memory> #include <string> #include <utility> using std::string; -namespace ingen { -namespace client { +namespace ingen::client { LilvWorld* PluginModel::_lilv_world = nullptr; const LilvPlugins* PluginModel::_lilv_plugins = nullptr; @@ -46,13 +43,12 @@ PluginModel::PluginModel(URIs& uris, const Properties& properties) : Resource(uris, uri) , _type(type) - , _fetched(false) { if (!_type.is_valid()) { if (uri.string().find("ingen-internals") != string::npos) { - _type = uris.ingen_Internal.urid; + _type = uris.ingen_Internal.urid_atom(); } else { - _type = uris.lv2_Plugin.urid; // Assume LV2 and hope for the best... + _type = uris.lv2_Plugin.urid_atom(); // Assume LV2 and hope for the best... } } @@ -112,33 +108,39 @@ PluginModel::get_property(const URI& key) const } str = str.substr(last_delim + 1); - std::string symbol = Raul::Symbol::symbolify(str); + const std::string symbol = raul::Symbol::symbolify(str); set_property(_uris.lv2_symbol, _uris.forge.alloc(symbol)); return get_property(key); } if (_lilv_plugin) { - boost::optional<const Atom&> ret; - LilvNode* lv2_pred = lilv_new_uri(_lilv_world, key.c_str()); - LilvNodes* values = lilv_plugin_get_value(_lilv_plugin, lv2_pred); + const Atom* ret = nullptr; + LilvNode* lv2_pred = lilv_new_uri(_lilv_world, key.c_str()); + LilvNodes* values = lilv_plugin_get_value(_lilv_plugin, lv2_pred); lilv_node_free(lv2_pred); - LILV_FOREACH(nodes, i, values) { - const LilvNode* val = lilv_nodes_get(values, i); - if (lilv_node_is_uri(val)) { - ret = set_property( - key, _uris.forge.make_urid(URI(lilv_node_as_uri(val)))); + LILV_FOREACH (nodes, i, values) { + const LilvNode* value = lilv_nodes_get(values, i); + if (lilv_node_is_uri(value)) { + ret = &set_property( + key, _uris.forge.make_urid(URI(lilv_node_as_uri(value)))); break; - } else if (lilv_node_is_string(val)) { - ret = set_property( - key, _uris.forge.alloc(lilv_node_as_string(val))); + } + + if (lilv_node_is_string(value)) { + ret = &set_property( + key, _uris.forge.alloc(lilv_node_as_string(value))); break; - } else if (lilv_node_is_float(val)) { - ret = set_property( - key, _uris.forge.make(lilv_node_as_float(val))); + } + + if (lilv_node_is_float(value)) { + ret = &set_property( + key, _uris.forge.make(lilv_node_as_float(value))); break; - } else if (lilv_node_is_int(val)) { - ret = set_property( - key, _uris.forge.make(lilv_node_as_int(val))); + } + + if (lilv_node_is_int(value)) { + ret = &set_property( + key, _uris.forge.make(lilv_node_as_int(value))); break; } } @@ -153,7 +155,7 @@ PluginModel::get_property(const URI& key) const } void -PluginModel::set(SPtr<PluginModel> p) +PluginModel::set(const std::shared_ptr<PluginModel>& p) { _type = p->_type; @@ -161,7 +163,7 @@ PluginModel::set(SPtr<PluginModel> p) _lilv_plugin = p->_lilv_plugin; } - for (auto v : p->properties()) { + for (const auto& v : p->properties()) { Resource::set_property(v.first, v.second); _signal_property.emit(v.first, v.second); } @@ -176,15 +178,15 @@ PluginModel::add_preset(const URI& uri, const std::string& label) _signal_preset.emit(uri, label); } -Raul::Symbol +raul::Symbol PluginModel::default_block_symbol() const { const Atom& name_atom = get_property(_uris.lv2_symbol); if (name_atom.is_valid() && name_atom.type() == _uris.forge.String) { - return Raul::Symbol::symbolify(name_atom.ptr<char>()); - } else { - return Raul::Symbol("_"); + return raul::Symbol::symbolify(name_atom.ptr<char>()); } + + return raul::Symbol("_"); } string @@ -193,18 +195,18 @@ PluginModel::human_name() const const Atom& name_atom = get_property(_uris.doap_name); if (name_atom.type() == _uris.forge.String) { return name_atom.ptr<char>(); - } else { - return default_block_symbol().c_str(); } + + return default_block_symbol().c_str(); } string -PluginModel::port_human_name(uint32_t i) const +PluginModel::port_human_name(const uint32_t index) const { if (_lilv_plugin) { - const LilvPort* port = lilv_plugin_get_port_by_index(_lilv_plugin, i); + const LilvPort* port = lilv_plugin_get_port_by_index(_lilv_plugin, index); LilvNode* name = lilv_port_get_name(_lilv_plugin, port); - const string ret(lilv_node_as_string(name)); + string ret(lilv_node_as_string(name)); lilv_node_free(name); return ret; } @@ -212,14 +214,14 @@ PluginModel::port_human_name(uint32_t i) const } PluginModel::ScalePoints -PluginModel::port_scale_points(uint32_t i) const +PluginModel::port_scale_points(const uint32_t index) const { // TODO: Non-float scale points ScalePoints points; if (_lilv_plugin) { - const LilvPort* port = lilv_plugin_get_port_by_index(_lilv_plugin, i); + const LilvPort* port = lilv_plugin_get_port_by_index(_lilv_plugin, index); LilvScalePoints* sp = lilv_port_get_scale_points(_lilv_plugin, port); - LILV_FOREACH(scale_points, i, sp) { + LILV_FOREACH (scale_points, i, sp) { const LilvScalePoint* p = lilv_scale_points_get(sp, i); points.emplace( lilv_node_as_float(lilv_scale_point_get_value(p)), @@ -241,12 +243,12 @@ PluginModel::has_ui() const return false; } -SPtr<PluginUI> -PluginModel::ui(ingen::World& world, - SPtr<const BlockModel> block) const +std::shared_ptr<PluginUI> +PluginModel::ui(ingen::World& world, + const std::shared_ptr<const BlockModel>& block) const { if (!_lilv_plugin) { - return SPtr<PluginUI>(); + return nullptr; } return PluginUI::create(world, block, _lilv_plugin); @@ -258,9 +260,9 @@ heading(const std::string& text, bool html, unsigned level) if (html) { const std::string tag = std::string("h") + std::to_string(level); return std::string("<") + tag + ">" + text + "</" + tag + ">\n"; - } else { - return text + ":\n\n"; } + + return text + ":\n\n"; } static std::string @@ -268,13 +270,13 @@ link(const std::string& addr, bool html) { if (html) { return std::string("<a href=\"") + addr + "\">" + addr + "</a>"; - } else { - return addr; } + + return addr; } std::string -PluginModel::get_documentation(const LilvNode* subject, bool html) const +PluginModel::get_documentation(const LilvNode* subject, bool html) { std::string doc; @@ -358,5 +360,4 @@ PluginModel::set_lilv_world(LilvWorld* world) _lilv_plugins = lilv_world_get_all_plugins(_lilv_world); } -} // namespace client -} // namespace ingen +} // namespace ingen::client |