diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/.clang-tidy | 3 | ||||
-rw-r--r-- | src/client/BlockModel.cpp | 83 | ||||
-rw-r--r-- | src/client/ClientStore.cpp | 123 | ||||
-rw-r--r-- | src/client/GraphModel.cpp | 69 | ||||
-rw-r--r-- | src/client/ObjectModel.cpp | 31 | ||||
-rw-r--r-- | src/client/PluginModel.cpp | 80 | ||||
-rw-r--r-- | src/client/PluginUI.cpp | 64 | ||||
-rw-r--r-- | src/client/PortModel.cpp | 50 | ||||
-rw-r--r-- | src/client/ingen_client.cpp | 13 | ||||
-rw-r--r-- | src/client/meson.build | 50 | ||||
-rw-r--r-- | src/client/wscript | 24 |
11 files changed, 321 insertions, 269 deletions
diff --git a/src/client/.clang-tidy b/src/client/.clang-tidy new file mode 100644 index 00000000..2561514f --- /dev/null +++ b/src/client/.clang-tidy @@ -0,0 +1,3 @@ +Checks: > + -google-readability-todo, +InheritParentConfig: true diff --git a/src/client/BlockModel.cpp b/src/client/BlockModel.cpp index cdfb3fcd..beef0117 100644 --- a/src/client/BlockModel.cpp +++ b/src/client/BlockModel.cpp @@ -14,17 +14,21 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/client/BlockModel.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/URIs.hpp" -#include "ingen/client/PluginModel.hpp" -#include "ingen/client/PortModel.hpp" -#include "lilv/lilv.h" -#include "lv2/core/lv2.h" -#include "raul/Path.hpp" -#include "raul/Symbol.hpp" +#include <ingen/client/BlockModel.hpp> + +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/client/ObjectModel.hpp> +#include <ingen/client/PluginModel.hpp> +#include <ingen/client/PortModel.hpp> +#include <lilv/lilv.h> +#include <lv2/core/lv2.h> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> + +#include <sigc++/signal.h> #include <algorithm> #include <cassert> @@ -35,8 +39,7 @@ #include <string> #include <utility> -namespace ingen { -namespace client { +namespace ingen::client { BlockModel::BlockModel(URIs& uris, const std::shared_ptr<PluginModel>& plugin, @@ -47,8 +50,7 @@ BlockModel::BlockModel(URIs& uris, , _num_values(0) , _min_values(nullptr) , _max_values(nullptr) -{ -} +{} BlockModel::BlockModel(URIs& uris, URI plugin_uri, const raul::Path& path) : ObjectModel(uris, path) @@ -56,8 +58,7 @@ BlockModel::BlockModel(URIs& uris, URI plugin_uri, const raul::Path& path) , _num_values(0) , _min_values(nullptr) , _max_values(nullptr) -{ -} +{} BlockModel::BlockModel(const BlockModel& copy) : ObjectModel(copy) @@ -78,23 +79,26 @@ BlockModel::~BlockModel() void BlockModel::remove_port(const std::shared_ptr<PortModel>& port) { - for (auto i = _ports.begin(); i != _ports.end(); ++i) { - if ((*i) == port) { - _ports.erase(i); - break; - } + const auto i = std::find_if(_ports.begin(), + _ports.end(), + [&port](const auto& p) { return p == port; }); + + if (i != _ports.end()) { + _ports.erase(i); + _signal_removed_port.emit(port); } - _signal_removed_port.emit(port); } void BlockModel::remove_port(const raul::Path& port_path) { - for (auto i = _ports.begin(); i != _ports.end(); ++i) { - if ((*i)->path() == port_path) { - _ports.erase(i); - break; - } + const auto i = + std::find_if(_ports.begin(), _ports.end(), [&port_path](const auto& p) { + return p->path() == port_path; + }); + + if (i != _ports.end()) { + _ports.erase(i); } } @@ -206,8 +210,9 @@ BlockModel::default_port_value_range( } if (port->port_property(_uris.lv2_sampleRate)) { - min *= srate; - max *= srate; + const auto frate = static_cast<float>(srate); + min *= frate; + max *= frate; } } @@ -221,7 +226,7 @@ BlockModel::port_value_range(const std::shared_ptr<const PortModel>& port, default_port_value_range(port, min, max); - // Possibly overriden + // Possibly overridden const Atom& min_atom = port->get_property(_uris.lv2_minimum); const Atom& max_atom = port->get_property(_uris.lv2_maximum); if (min_atom.type() == _uris.forge.Float) { @@ -236,8 +241,9 @@ BlockModel::port_value_range(const std::shared_ptr<const PortModel>& port, } if (port->port_property(_uris.lv2_sampleRate)) { - min *= srate; - max *= srate; + const auto frate = static_cast<float>(srate); + min *= frate; + max *= frate; } } @@ -247,11 +253,13 @@ BlockModel::label() const const Atom& name_property = get_property(_uris.lv2_name); if (name_property.type() == _uris.forge.String) { return name_property.ptr<char>(); - } else if (plugin_model()) { + } + + if (plugin_model()) { return plugin_model()->human_name(); - } else { - return symbol().c_str(); } + + return symbol().c_str(); } std::string @@ -293,5 +301,4 @@ BlockModel::set(const std::shared_ptr<ObjectModel>& model) ObjectModel::set(model); } -} // namespace client -} // namespace ingen +} // namespace ingen::client diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index d8238c8a..9f224db3 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -14,26 +14,28 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/client/ClientStore.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Log.hpp" -#include "ingen/Node.hpp" -#include "ingen/Properties.hpp" -#include "ingen/Resource.hpp" -#include "ingen/URIs.hpp" -#include "ingen/client/ArcModel.hpp" -#include "ingen/client/BlockModel.hpp" -#include "ingen/client/GraphModel.hpp" -#include "ingen/client/ObjectModel.hpp" -#include "ingen/client/PluginModel.hpp" -#include "ingen/client/PortModel.hpp" -#include "ingen/client/SigClientInterface.hpp" -#include "ingen/paths.hpp" -#include "raul/Path.hpp" - -#include <boost/variant/apply_visitor.hpp> +#include <ingen/client/ClientStore.hpp> + +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Log.hpp> +#include <ingen/Message.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/client/ArcModel.hpp> +#include <ingen/client/BlockModel.hpp> +#include <ingen/client/GraphModel.hpp> +#include <ingen/client/ObjectModel.hpp> +#include <ingen/client/PluginModel.hpp> +#include <ingen/client/PortModel.hpp> +#include <ingen/client/SigClientInterface.hpp> +#include <ingen/paths.hpp> +#include <raul/Path.hpp> +#include <sigc++/signal.h> + #include <sigc++/functors/mem_fun.h> #include <cassert> @@ -41,9 +43,9 @@ #include <memory> #include <string> #include <utility> +#include <variant> -namespace ingen { -namespace client { +namespace ingen::client { ClientStore::ClientStore(URIs& uris, Log& log, @@ -76,12 +78,12 @@ ClientStore::add_object(const std::shared_ptr<ObjectModel>& object) std::dynamic_pointer_cast<ObjectModel>(existing->second)->set(object); } else { if (!object->path().is_root()) { - std::shared_ptr<ObjectModel> parent = _object(object->path().parent()); + const std::shared_ptr<ObjectModel> parent = _object(object->path().parent()); if (parent) { assert(object->path().is_child_of(parent->path())); object->set_parent(parent); parent->add_child(object); - assert(parent && (object->parent() == parent)); + assert(object->parent() == parent); (*this)[object->path()] = object; _signal_new_object.emit(object); @@ -103,7 +105,7 @@ std::shared_ptr<ObjectModel> ClientStore::remove_object(const raul::Path& path) { // Find the object, the "top" of the tree to remove - const iterator top = find(path); + const auto top = find(path); if (top == end()) { return nullptr; } @@ -142,7 +144,7 @@ ClientStore::remove_object(const raul::Path& path) std::shared_ptr<PluginModel> ClientStore::_plugin(const URI& uri) { - const Plugins::iterator i = _plugins->find(uri); + const auto i = _plugins->find(uri); return (i == _plugins->end()) ? std::shared_ptr<PluginModel>() : (*i).second; } @@ -152,7 +154,7 @@ ClientStore::_plugin(const Atom& uri) /* FIXME: Should probably be stored with URIs rather than strings, to make this a fast case. */ - const Plugins::iterator i = _plugins->find(URI(_uris.forge.str(uri, false))); + const auto i = _plugins->find(URI(_uris.forge.str(uri, false))); return (i == _plugins->end()) ? std::shared_ptr<PluginModel>() : (*i).second; } @@ -165,15 +167,15 @@ ClientStore::plugin(const URI& uri) const std::shared_ptr<ObjectModel> ClientStore::_object(const raul::Path& path) { - const iterator i = find(path); + const auto i = find(path); if (i == end()) { return nullptr; - } else { - auto model = std::dynamic_pointer_cast<ObjectModel>(i->second); - assert(model); - assert(model->path().is_root() || model->parent()); - return model; } + + auto model = std::dynamic_pointer_cast<ObjectModel>(i->second); + assert(model); + assert(model->path().is_root() || model->parent()); + return model; } std::shared_ptr<const ObjectModel> @@ -187,9 +189,9 @@ ClientStore::_resource(const URI& uri) { if (uri_is_path(uri)) { return _object(uri_to_path(uri)); - } else { - return _plugin(uri); } + + return _plugin(uri); } std::shared_ptr<const Resource> @@ -201,7 +203,7 @@ ClientStore::resource(const URI& uri) const void ClientStore::add_plugin(const std::shared_ptr<PluginModel>& pm) { - std::shared_ptr<PluginModel> existing = _plugin(pm->uri()); + const std::shared_ptr<PluginModel> existing = _plugin(pm->uri()); if (existing) { existing->set(pm); } else { @@ -235,7 +237,7 @@ ClientStore::operator()(const Copy&) void ClientStore::operator()(const Move& msg) { - const iterator top = find(msg.old_path); + const auto top = find(msg.old_path); if (top != end()) { rename(top, msg.new_path); } @@ -244,14 +246,12 @@ ClientStore::operator()(const Move& msg) void ClientStore::message(const Message& msg) { - boost::apply_visitor(*this, msg); + std::visit(*this, msg); } void ClientStore::operator()(const Put& msg) { - using Iterator = Properties::const_iterator; - const auto& uri = msg.uri; const auto& properties = msg.properties; @@ -263,12 +263,12 @@ ClientStore::operator()(const Put& msg) is_graph, is_block, is_port, is_output); // Check for specially handled types - const Iterator t = properties.find(_uris.rdf_type); + const auto t = properties.find(_uris.rdf_type); if (t != properties.end()) { const Atom& type(t->second); if (_uris.pset_Preset == type) { - const Iterator p = properties.find(_uris.lv2_appliesTo); - const Iterator l = properties.find(_uris.rdfs_label); + const auto p = properties.find(_uris.lv2_appliesTo); + const auto l = properties.find(_uris.rdfs_label); std::shared_ptr<PluginModel> plug; if (p == properties.end()) { _log.error("Preset <%1%> with no plugin\n", uri.c_str()); @@ -283,10 +283,12 @@ ClientStore::operator()(const Put& msg) plug->add_preset(uri, l->second.ptr<char>()); } return; - } else if (_uris.ingen_Graph == type) { + } + + if (_uris.ingen_Graph == type) { is_graph = true; } else if (_uris.ingen_Internal == type || _uris.lv2_Plugin == type) { - std::shared_ptr<PluginModel> p(new PluginModel(uris(), uri, type, properties)); + const std::shared_ptr<PluginModel> p{new PluginModel(uris(), uri, type, properties)}; add_plugin(p); return; } @@ -310,7 +312,7 @@ ClientStore::operator()(const Put& msg) } if (is_graph) { - std::shared_ptr<GraphModel> model(new GraphModel(uris(), path)); + const std::shared_ptr<GraphModel> model{new GraphModel(uris(), path)}; model->set_properties(properties); add_object(model); } else if (is_block) { @@ -331,23 +333,23 @@ ClientStore::operator()(const Put& msg) add_plugin(plug); } - std::shared_ptr<BlockModel> bm(new BlockModel(uris(), plug, path)); + const std::shared_ptr<BlockModel> bm{new BlockModel(uris(), plug, path)}; bm->set_properties(properties); add_object(bm); } else { _log.warn("Block %1% has no prototype\n", path.c_str()); } } else if (is_port) { - PortModel::Direction pdir = (is_output) + const PortModel::Direction pdir = (is_output) ? PortModel::Direction::OUTPUT : PortModel::Direction::INPUT; - uint32_t index = 0; - const Iterator i = properties.find(_uris.lv2_index); + uint32_t index = 0; + const auto i = properties.find(_uris.lv2_index); if (i != properties.end() && i->second.type() == _uris.forge.Int) { index = i->second.get<int32_t>(); } - std::shared_ptr<PortModel> p(new PortModel(uris(), path, index, pdir)); + const std::shared_ptr<PortModel> p{new PortModel(uris(), path, index, pdir)}; p->set_properties(properties); add_object(p); } else { @@ -371,7 +373,7 @@ ClientStore::operator()(const Delta& msg) const raul::Path path(uri_to_path(uri)); - std::shared_ptr<ObjectModel> obj = _object(path); + const std::shared_ptr<ObjectModel> obj = _object(path); if (obj) { obj->remove_properties(msg.remove); obj->add_properties(msg.add); @@ -392,7 +394,7 @@ ClientStore::operator()(const SetProperty& msg) predicate.c_str(), _uris.forge.str(value, false)); return; } - std::shared_ptr<Resource> subject = _resource(subject_uri); + const std::shared_ptr<Resource> subject = _resource(subject_uri); if (subject) { if (predicate == _uris.ingen_activity) { /* Activity is transient, trigger any live actions (like GUI @@ -402,7 +404,7 @@ ClientStore::operator()(const SetProperty& msg) subject->set_property(predicate, value, msg.ctx); } } else { - std::shared_ptr<PluginModel> plugin = _plugin(subject_uri); + const std::shared_ptr<PluginModel> plugin = _plugin(subject_uri); if (plugin) { plugin->set_property(predicate, value); } else if (predicate != _uris.ingen_activity) { @@ -450,14 +452,14 @@ ClientStore::attempt_connection(const raul::Path& tail_path, auto head = std::dynamic_pointer_cast<PortModel>(_object(head_path)); if (tail && head) { - std::shared_ptr<GraphModel> graph = connection_graph(tail_path, head_path); - std::shared_ptr<ArcModel> arc(new ArcModel(tail, head)); + const std::shared_ptr<GraphModel> graph = connection_graph(tail_path, head_path); + const std::shared_ptr<ArcModel> arc(new ArcModel(tail, head)); graph->add_arc(arc); return true; - } else { - _log.warn("Failed to connect %1% => %2%\n", tail_path, head_path); - return false; } + + _log.warn("Failed to connect %1% => %2%\n", tail_path, head_path); + return false; } void @@ -501,5 +503,4 @@ ClientStore::operator()(const DisconnectAll& msg) } } -} // namespace client -} // namespace ingen +} // namespace ingen::client diff --git a/src/client/GraphModel.cpp b/src/client/GraphModel.cpp index d4104742..fe119361 100644 --- a/src/client/GraphModel.cpp +++ b/src/client/GraphModel.cpp @@ -14,15 +14,17 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/client/GraphModel.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/URIs.hpp" -#include "ingen/client/ArcModel.hpp" -#include "ingen/client/BlockModel.hpp" -#include "ingen/client/ObjectModel.hpp" -#include "ingen/client/PortModel.hpp" -#include "raul/Path.hpp" +#include <ingen/client/GraphModel.hpp> + +#include <ingen/Atom.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/client/ArcModel.hpp> +#include <ingen/client/BlockModel.hpp> +#include <ingen/client/ObjectModel.hpp> +#include <ingen/client/PortModel.hpp> +#include <raul/Path.hpp> +#include <sigc++/signal.h> #include <cassert> #include <map> @@ -31,7 +33,15 @@ #include <utility> namespace ingen { -namespace client { +class Node; +} // namespace ingen + +namespace ingen::client { + +GraphModel::GraphModel(URIs& uris, const raul::Path& graph_path) + : BlockModel{uris, static_cast<const URI&>(uris.ingen_Graph), graph_path} +{ +} void GraphModel::add_child(const std::shared_ptr<ObjectModel>& c) @@ -75,7 +85,7 @@ GraphModel::remove_arcs_on(const std::shared_ptr<PortModel>& p) { // Remove any connections which referred to this object, // since they can't possibly exist anymore - for (auto j = _arcs.begin(); j != _arcs.end();) { + for (auto j = _graph_arcs.begin(); j != _graph_arcs.end();) { auto next = j; ++next; @@ -85,7 +95,7 @@ GraphModel::remove_arcs_on(const std::shared_ptr<PortModel>& p) || arc->head_path().parent() == p->path() || arc->head_path() == p->path()) { _signal_removed_arc.emit(arc); - _arcs.erase(j); // Cuts our reference + _graph_arcs.erase(j); // Cuts our reference } j = next; } @@ -94,23 +104,23 @@ GraphModel::remove_arcs_on(const std::shared_ptr<PortModel>& p) void GraphModel::clear() { - _arcs.clear(); + _graph_arcs.clear(); BlockModel::clear(); - assert(_arcs.empty()); + assert(_graph_arcs.empty()); assert(_ports.empty()); } std::shared_ptr<ArcModel> GraphModel::get_arc(const Node* tail, const Node* head) { - auto i = _arcs.find(std::make_pair(tail, head)); - if (i != _arcs.end()) { + auto i = _graph_arcs.find(std::make_pair(tail, head)); + if (i != _graph_arcs.end()) { return std::dynamic_pointer_cast<ArcModel>(i->second); - } else { - return nullptr; } + + return nullptr; } /** Add a connection to this graph. @@ -135,15 +145,16 @@ GraphModel::add_arc(const std::shared_ptr<ArcModel>& arc) assert(arc->head()->parent().get() == this || arc->head()->parent()->parent().get() == this); - std::shared_ptr<ArcModel> existing = get_arc( + const std::shared_ptr<ArcModel> existing = get_arc( arc->tail().get(), arc->head().get()); if (existing) { assert(arc->tail() == existing->tail()); assert(arc->head() == existing->head()); } else { - _arcs.emplace(std::make_pair(arc->tail().get(), arc->head().get()), - arc); + _graph_arcs.emplace(std::make_pair(arc->tail().get(), + arc->head().get()), + arc); _signal_new_arc.emit(arc); } } @@ -151,11 +162,11 @@ GraphModel::add_arc(const std::shared_ptr<ArcModel>& arc) void GraphModel::remove_arc(const Node* tail, const Node* head) { - auto i = _arcs.find(std::make_pair(tail, head)); - if (i != _arcs.end()) { + auto i = _graph_arcs.find(std::make_pair(tail, head)); + if (i != _graph_arcs.end()) { auto arc = std::dynamic_pointer_cast<ArcModel>(i->second); _signal_removed_arc.emit(arc); - _arcs.erase(i); + _graph_arcs.erase(i); } } @@ -173,12 +184,4 @@ GraphModel::internal_poly() const return poly.is_valid() ? poly.get<int32_t>() : 1; } -bool -GraphModel::polyphonic() const -{ - const Atom& poly = get_property(_uris.ingen_polyphonic); - return poly.is_valid() && poly.get<int32_t>(); -} - -} // namespace client -} // namespace ingen +} // namespace ingen::client diff --git a/src/client/ObjectModel.cpp b/src/client/ObjectModel.cpp index c172c445..4baa895c 100644 --- a/src/client/ObjectModel.cpp +++ b/src/client/ObjectModel.cpp @@ -14,14 +14,17 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/client/ObjectModel.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/Node.hpp" -#include "ingen/Properties.hpp" -#include "ingen/Resource.hpp" -#include "ingen/URIs.hpp" -#include "ingen/paths.hpp" +#include <ingen/client/ObjectModel.hpp> + +#include <ingen/Atom.hpp> +#include <ingen/Node.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URIs.hpp> +#include <ingen/paths.hpp> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> +#include <sigc++/signal.h> #include <cassert> #include <cstdint> @@ -29,23 +32,20 @@ #include <string> #include <utility> -namespace ingen { -namespace client { +namespace ingen::client { ObjectModel::ObjectModel(URIs& uris, const raul::Path& path) : Node(uris, path) , _path(path) , _symbol((path == "/") ? "root" : path.symbol()) -{ -} +{} ObjectModel::ObjectModel(const ObjectModel& copy) : Node(copy) , _parent(copy._parent) , _path(copy._path) , _symbol(copy._symbol) -{ -} +{} bool ObjectModel::is_a(const URIs::Quark& type) const @@ -115,5 +115,4 @@ ObjectModel::set_parent(const std::shared_ptr<ObjectModel>& p) _parent = p; } -} // namespace client -} // namespace ingen +} // namespace ingen::client diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp index 4dddd147..f4dfccd2 100644 --- a/src/client/PluginModel.cpp +++ b/src/client/PluginModel.cpp @@ -14,25 +14,29 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/client/PluginModel.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/client/PluginUI.hpp" -#include "lv2/core/lv2.h" - -#include <boost/optional/optional.hpp> +#include <ingen/client/PluginModel.hpp> + +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/client/PluginUI.hpp> +#include <lilv/lilv.h> +#include <lv2/core/lv2.h> +#include <raul/Symbol.hpp> +#include <sigc++/signal.h> #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; @@ -45,13 +49,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_atom(); } else { - _type = uris.lv2_Plugin.urid_atom(); // Assume LV2 and hope for the best... + _type = uris.lv2_Plugin.urid_atom(); // Assume LV2 and hope for the best... } } @@ -106,37 +109,43 @@ PluginModel::get_property(const URI& key) const size_t last_delim = last_uri_delim(str); while (last_delim != string::npos && !contains_alpha_after(str, last_delim)) { - str = str.substr(0, last_delim); + str.resize(last_delim); last_delim = last_uri_delim(str); } 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) { + LILV_FOREACH (nodes, i, values) { const LilvNode* value = lilv_nodes_get(values, i); if (lilv_node_is_uri(value)) { - ret = set_property( + ret = &set_property( key, _uris.forge.make_urid(URI(lilv_node_as_uri(value)))); break; - } else if (lilv_node_is_string(value)) { - ret = set_property( + } + + 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(value)) { - ret = set_property( + } + + 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(value)) { - ret = set_property( + } + + if (lilv_node_is_int(value)) { + ret = &set_property( key, _uris.forge.make(lilv_node_as_int(value))); break; } @@ -181,9 +190,9 @@ 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("_"); } string @@ -192,9 +201,9 @@ 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 @@ -218,7 +227,7 @@ PluginModel::port_scale_points(const uint32_t index) const if (_lilv_plugin) { 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)), @@ -257,9 +266,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 @@ -267,9 +276,9 @@ link(const std::string& addr, bool html) { if (html) { return std::string("<a href=\"") + addr + "\">" + addr + "</a>"; - } else { - return addr; } + + return addr; } std::string @@ -357,5 +366,4 @@ PluginModel::set_lilv_world(LilvWorld* world) _lilv_plugins = lilv_world_get_all_plugins(_lilv_world); } -} // namespace client -} // namespace ingen +} // namespace ingen::client diff --git a/src/client/PluginUI.cpp b/src/client/PluginUI.cpp index 7292d8b2..c4aa748f 100644 --- a/src/client/PluginUI.cpp +++ b/src/client/PluginUI.cpp @@ -14,20 +14,24 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/client/PluginUI.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Log.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "ingen/client/BlockModel.hpp" -#include "ingen/client/PortModel.hpp" -#include "lv2/atom/atom.h" -#include "lv2/core/lv2.h" -#include "lv2/ui/ui.h" -#include "raul/Symbol.hpp" +#include <ingen/client/PluginUI.hpp> + +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/LV2Features.hpp> +#include <ingen/Log.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/client/BlockModel.hpp> +#include <ingen/client/PortModel.hpp> +#include <lilv/lilv.h> +#include <lv2/atom/atom.h> +#include <lv2/core/lv2.h> +#include <lv2/ui/ui.h> +#include <raul/Symbol.hpp> +#include <suil/suil.h> #include <sigc++/signal.h> @@ -36,8 +40,7 @@ #include <string> #include <utility> -namespace ingen { -namespace client { +namespace ingen::client { SuilHost* PluginUI::ui_host = nullptr; @@ -78,7 +81,7 @@ lv2_ui_write(SuilController controller, const float value = *static_cast<const float*>(buffer); if (port->value().type() == uris.atom_Float && value == port->value().get<float>()) { - return; // Ignore feedback + return; // Ignore feedback } ui->signal_property_changed()( @@ -89,9 +92,9 @@ lv2_ui_write(SuilController controller, } else if (format == uris.atom_eventTransfer.urid()) { const auto* atom = static_cast<const LV2_Atom*>(buffer); - Atom val = Forge::alloc(atom->size, - atom->type, - LV2_ATOM_BODY_CONST(atom)); + const Atom val = + Forge::alloc(atom->size, atom->type, LV2_ATOM_BODY_CONST(atom)); + ui->signal_property_changed()(port->uri(), uris.ingen_activity, val, @@ -123,8 +126,8 @@ lv2_ui_subscribe(SuilController controller, uint32_t protocol, const LV2_Feature* const* features) { - auto* const ui = static_cast<PluginUI*>(controller); - std::shared_ptr<const PortModel> port = get_port(ui, port_index); + auto* const ui = static_cast<PluginUI*>(controller); + const std::shared_ptr<const PortModel> port = get_port(ui, port_index); if (!port) { return 1; } @@ -166,17 +169,15 @@ PluginUI::PluginUI(ingen::World& world, const LilvNode* ui_type) : _world(world) , _block(std::move(block)) - , _instance(nullptr) , _uis(uis) , _ui(ui) , _ui_node(lilv_node_duplicate(lilv_ui_get_uri(ui))) , _ui_type(lilv_node_duplicate(ui_type)) -{ -} +{} PluginUI::~PluginUI() { - for (uint32_t i : _subscribed_ports) { + for (const uint32_t i : _subscribed_ports) { lv2_ui_unsubscribe(this, i, 0, nullptr); } suil_instance_free(_instance); @@ -205,7 +206,7 @@ PluginUI::create(ingen::World& world, LilvUIs* uis = lilv_plugin_get_uis(plugin); const LilvUI* ui = nullptr; const LilvNode* ui_type = nullptr; - LILV_FOREACH(uis, u, uis) { + LILV_FOREACH (uis, u, uis) { const LilvUI* this_ui = lilv_uis_get(uis, u); if (lilv_ui_is_supported(this_ui, suil_ui_supported, @@ -247,7 +248,7 @@ PluginUI::instantiate() LilvNode* ui_plugin = lilv_new_uri(lworld, LV2_UI__plugin); LilvNodes* notes = lilv_world_find_nodes( lworld, lilv_ui_get_uri(_ui), ui_portNotification, nullptr); - LILV_FOREACH(nodes, n, notes) { + LILV_FOREACH (nodes, n, notes) { const LilvNode* note = lilv_nodes_get(notes, n); const LilvNode* sym = lilv_world_get(lworld, note, uris.lv2_symbol, nullptr); const LilvNode* plug = lilv_world_get(lworld, note, ui_plugin, nullptr); @@ -262,7 +263,7 @@ PluginUI::instantiate() plugin_uri, lilv_node_as_string(_ui_node)); } else if (!strcmp(lilv_node_as_uri(plug), plugin_uri.c_str())) { // Notification is valid and for this plugin - uint32_t index = lv2_ui_port_index(this, lilv_node_as_string(sym)); + const uint32_t index = lv2_ui_port_index(this, lilv_node_as_string(sym)); if (index != LV2UI_INVALID_PORT_INDEX) { lv2_ui_subscribe(this, index, 0, nullptr); _subscribed_ports.insert(index); @@ -296,7 +297,7 @@ PluginUI::instantiate() if (!_instance) { _world.log().error("Failed to instantiate LV2 UI\n"); // Cancel any subscriptions - for (uint32_t i : _subscribed_ports) { + for (const uint32_t i : _subscribed_ports) { lv2_ui_unsubscribe(this, i, 0, nullptr); } return false; @@ -346,5 +347,4 @@ PluginUI::is_resizable() const return !fs_matches && !nrs_matches; } -} // namespace client -} // namespace ingen +} // namespace ingen::client diff --git a/src/client/PortModel.cpp b/src/client/PortModel.cpp index 0d695a54..14a5297e 100644 --- a/src/client/PortModel.cpp +++ b/src/client/PortModel.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard <http://drobilla.net/> + Copyright 2007-2024 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -14,21 +14,22 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/client/PortModel.hpp" +#include <ingen/client/PortModel.hpp> -#include "ingen/Properties.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "ingen/client/ObjectModel.hpp" -#include "lv2/urid/urid.h" +#include <ingen/Properties.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/client/ObjectModel.hpp> +#include <lv2/urid/urid.h> +#include <sigc++/signal.h> +#include <algorithm> #include <cstdint> +#include <exception> #include <map> #include <memory> -#include <utility> -namespace ingen { -namespace client { +namespace ingen::client { void PortModel::on_property(const URI& uri, const Atom& value) @@ -61,14 +62,24 @@ PortModel::port_property(const URIs::Quark& uri) const bool PortModel::is_uri() const { - // FIXME: Resource::has_property doesn't work, URI != URID - for (const auto& p : properties()) { - if (p.second.type() == _uris.atom_URID && - static_cast<LV2_URID>(p.second.get<int32_t>()) == _uris.atom_URID) { - return true; - } - } - return false; + return std::any_of( + properties().begin(), properties().end(), [this](const auto& p) { + return (p.second.type() == _uris.atom_URID && + static_cast<LV2_URID>(p.second.template get<int32_t>()) == + _uris.atom_URID); + }); +} + +void +PortModel::add_child(const std::shared_ptr<ObjectModel>&) +{ + std::terminate(); +} + +bool +PortModel::remove_child(const std::shared_ptr<ObjectModel>&) +{ + std::terminate(); } void @@ -84,5 +95,4 @@ PortModel::set(const std::shared_ptr<ObjectModel>& model) } } -} // namespace client -} // namespace ingen +} // namespace ingen::client diff --git a/src/client/ingen_client.cpp b/src/client/ingen_client.cpp index f4d6bbc7..88619115 100644 --- a/src/client/ingen_client.cpp +++ b/src/client/ingen_client.cpp @@ -14,24 +14,19 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/Module.hpp" +#include <ingen/Module.hpp> -namespace ingen { - -class World; - -namespace client { +namespace ingen::client { struct ClientModule : public ingen::Module { void load(ingen::World& world) override {} }; -} // namespace client -} // namespace ingen +} // namespace ingen::client extern "C" { -ingen::Module* +INGEN_MODULE_EXPORT ingen::Module* ingen_module_load() { return new ingen::client::ClientModule(); diff --git a/src/client/meson.build b/src/client/meson.build new file mode 100644 index 00000000..7c040634 --- /dev/null +++ b/src/client/meson.build @@ -0,0 +1,50 @@ +# Copyright 2022 David Robillard <d@drobilla.net> +# SPDX-License-Identifier: 0BSD OR GPL-3.0-or-later + +################ +# Dependencies # +################ + +sigcpp_dep = dependency('sigc++-2.0', include_type: 'system') + +########## +# Module # +########## + +client_sources = files( + 'BlockModel.cpp', + 'ClientStore.cpp', + 'GraphModel.cpp', + 'ObjectModel.cpp', + 'PluginModel.cpp', + 'PluginUI.cpp', + 'PortModel.cpp', + 'ingen_client.cpp', +) + +client_dependencies = [ + boost_dep, + ingen_dep, + lilv_dep, + lv2_dep, + raul_dep, + sigcpp_dep, + suil_dep, +] + +libingen_client = shared_library( + 'ingen_client', + client_sources, + cpp_args: cpp_suppressions + platform_defines + ['-DINGEN_CLIENT_INTERNAL'], + dependencies: client_dependencies, + gnu_symbol_visibility: 'hidden', + implicit_include_directories: false, + include_directories: ingen_include_dirs, + install: true, + install_dir: ingen_module_dir, +) + +ingen_client_dep = declare_dependency( + dependencies: client_dependencies, + link_with: libingen_client, +) diff --git a/src/client/wscript b/src/client/wscript deleted file mode 100644 index d63fb56c..00000000 --- a/src/client/wscript +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python - - -def build(bld): - obj = bld(features = 'cxx cxxshlib', - cflags = ['-fvisibility=hidden'], - includes = ['../../', '../../include'], - export_includes = ['../../include'], - name = 'libingen_client', - target = 'ingen_client', - install_path = '${LIBDIR}', - use = 'libingen', - uselib = 'GLIBMM LV2 LILV SUIL RAUL SERD SORD SIGCPP') - - obj.source = ''' - BlockModel.cpp - ClientStore.cpp - GraphModel.cpp - ObjectModel.cpp - PluginModel.cpp - PluginUI.cpp - PortModel.cpp - ingen_client.cpp - ''' |