diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/BlockModel.cpp | 56 | ||||
-rw-r--r-- | src/client/ClientStore.cpp | 65 | ||||
-rw-r--r-- | src/client/GraphModel.cpp | 38 | ||||
-rw-r--r-- | src/client/ObjectModel.cpp | 19 | ||||
-rw-r--r-- | src/client/PluginModel.cpp | 22 | ||||
-rw-r--r-- | src/client/PluginUI.cpp | 48 | ||||
-rw-r--r-- | src/client/PortModel.cpp | 44 | ||||
-rw-r--r-- | src/client/ingen_client.cpp | 11 |
8 files changed, 170 insertions, 133 deletions
diff --git a/src/client/BlockModel.cpp b/src/client/BlockModel.cpp index 998c118d..beef0117 100644 --- a/src/client/BlockModel.cpp +++ b/src/client/BlockModel.cpp @@ -14,18 +14,23 @@ 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> #include <cmath> #include <cstdlib> @@ -74,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); } } @@ -218,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) { diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index c492d3e6..9f224db3 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -14,24 +14,27 @@ 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 <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> @@ -75,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); @@ -200,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 { @@ -285,7 +288,7 @@ ClientStore::operator()(const Put& msg) 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; } @@ -309,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) { @@ -330,14 +333,14 @@ 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; @@ -346,7 +349,7 @@ ClientStore::operator()(const Put& msg) 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 { @@ -370,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); @@ -391,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 @@ -401,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) { @@ -449,8 +452,8 @@ 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; } diff --git a/src/client/GraphModel.cpp b/src/client/GraphModel.cpp index 2a998fdf..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> @@ -30,8 +32,17 @@ #include <string> #include <utility> +namespace ingen { +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) { @@ -134,7 +145,7 @@ 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) { @@ -173,11 +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 ingen::client diff --git a/src/client/ObjectModel.cpp b/src/client/ObjectModel.cpp index 86ffa821..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> diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp index 4371132c..f4dfccd2 100644 --- a/src/client/PluginModel.cpp +++ b/src/client/PluginModel.cpp @@ -14,11 +14,19 @@ 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 <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> @@ -101,12 +109,12 @@ 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); } diff --git a/src/client/PluginUI.cpp b/src/client/PluginUI.cpp index f0c3834a..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> @@ -88,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, @@ -122,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; } @@ -173,7 +177,7 @@ PluginUI::PluginUI(ingen::World& world, 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); @@ -259,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); @@ -293,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; diff --git a/src/client/PortModel.cpp b/src/client/PortModel.cpp index 73f273c7..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,18 +14,20 @@ 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::client { @@ -60,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 diff --git a/src/client/ingen_client.cpp b/src/client/ingen_client.cpp index 63705ebc..88619115 100644 --- a/src/client/ingen_client.cpp +++ b/src/client/ingen_client.cpp @@ -14,20 +14,15 @@ 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" { |