summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Parser.cpp24
-rw-r--r--src/client/BlockModel.cpp25
-rw-r--r--src/gui/BreadCrumbs.cpp35
-rw-r--r--src/server/ingen_lv2.cpp25
4 files changed, 58 insertions, 51 deletions
diff --git a/src/Parser.cpp b/src/Parser.cpp
index 2a22c31b..04a10f23 100644
--- a/src/Parser.cpp
+++ b/src/Parser.cpp
@@ -36,6 +36,7 @@
#include "sord/sord.h"
#include "sord/sordmm.hpp"
+#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstring>
@@ -633,19 +634,18 @@ Parser::parse_file(ingen::World& world,
return false;
}
- /* Choose the graph to load. If this is a manifest, then there should only
- be one, but if this is a graph file, subgraphs will be returned as well.
- In this case, choose the one with the file URI. */
- URI uri;
- for (const ResourceRecord& r : resources) {
- if (r.uri == URI(manifest_path)) {
- uri = r.uri;
- file_path = r.filename;
- break;
- }
- }
+ // Try to find the graph with the manifest path for a URI
+ const auto m = std::find_if(resources.begin(),
+ resources.end(),
+ [manifest_path](const auto& r) {
+ return r.uri == URI(manifest_path);
+ });
- if (uri.empty()) {
+ URI uri;
+ if (m != resources.end()) {
+ uri = m->uri;
+ file_path = m->filename;
+ } else {
// Didn't find a graph with the same URI as the file, use the first
uri = (*resources.begin()).uri;
file_path = (*resources.begin()).filename;
diff --git a/src/client/BlockModel.cpp b/src/client/BlockModel.cpp
index dce30655..8ba446ab 100644
--- a/src/client/BlockModel.cpp
+++ b/src/client/BlockModel.cpp
@@ -75,23 +75,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);
}
}
diff --git a/src/gui/BreadCrumbs.cpp b/src/gui/BreadCrumbs.cpp
index 476b9996..982c3b06 100644
--- a/src/gui/BreadCrumbs.cpp
+++ b/src/gui/BreadCrumbs.cpp
@@ -26,6 +26,7 @@
#include <sigc++/adaptors/bind.h>
#include <sigc++/functors/mem_fun.h>
+#include <algorithm>
#include <string>
#include <variant>
@@ -46,13 +47,13 @@ BreadCrumbs::BreadCrumbs(App& app)
std::shared_ptr<GraphView>
BreadCrumbs::view(const raul::Path& path)
{
- for (const auto& b : _breadcrumbs) {
- if (b->path() == path) {
- return b->view();
- }
- }
+ const auto b = std::find_if(_breadcrumbs.begin(),
+ _breadcrumbs.end(),
+ [&path](const auto* crumb) {
+ return crumb->path() == path;
+ });
- return nullptr;
+ return b == _breadcrumbs.end() ? nullptr : (*b)->view();
}
/** Sets up the crumbs to display `path`.
@@ -202,15 +203,19 @@ BreadCrumbs::message(const Message& msg)
void
BreadCrumbs::object_destroyed(const URI& uri)
{
- for (auto i = _breadcrumbs.begin(); i != _breadcrumbs.end(); ++i) {
- if ((*i)->path() == uri.c_str()) {
- // Remove all crumbs after the removed one (inclusive)
- for (auto j = i; j != _breadcrumbs.end(); ) {
- BreadCrumb* bc = *j;
- j = _breadcrumbs.erase(j);
- remove(*bc);
- }
- break;
+ const auto i = std::find_if(_breadcrumbs.begin(),
+ _breadcrumbs.end(),
+ [&uri](const auto& b) {
+ return b->path() == uri.c_str();
+ });
+
+ if (i != _breadcrumbs.end()) {
+ // Remove all crumbs after the removed one (inclusive)
+ for (auto j = i; j != _breadcrumbs.end();) {
+ BreadCrumb* const bc = *j;
+
+ j = _breadcrumbs.erase(j);
+ remove(*bc);
}
}
}
diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp
index 76bdcb54..f12262c1 100644
--- a/src/server/ingen_lv2.cpp
+++ b/src/server/ingen_lv2.cpp
@@ -216,13 +216,12 @@ public:
virtual GraphImpl* root_graph() { return _root_graph; }
EnginePort* get_port(const raul::Path& path) override {
- for (auto& p : _ports) {
- if (p->graph_port()->path() == path) {
- return p;
- }
- }
+ const auto i =
+ std::find_if(_ports.begin(), _ports.end(), [&path](const auto& p) {
+ return p->graph_port()->path() == path;
+ });
- return nullptr;
+ return i == _ports.end() ? nullptr : *i;
}
/** Add a port. Called only during init or restore. */
@@ -522,13 +521,13 @@ ingen_instantiate(const LV2_Descriptor* descriptor,
const Lib::Graphs graphs = find_graphs(URI(reinterpret_cast<const char*>(manifest_node.buf)));
serd_node_free(&manifest_node);
- const LV2Graph* graph = nullptr;
- for (const auto& g : graphs) {
- if (g->uri == descriptor->URI) {
- graph = g.get();
- break;
- }
- }
+ const auto g = std::find_if(graphs.begin(),
+ graphs.end(),
+ [&descriptor](const auto& graph) {
+ return graph->uri == descriptor->URI;
+ });
+
+ const LV2Graph* const graph = g == graphs.end() ? nullptr : g->get();
if (!graph) {
lv2_log_error(&logger, "could not find graph <%s>\n", descriptor->URI);