aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-11-17 17:59:48 -0500
committerDavid Robillard <d@drobilla.net>2024-11-24 19:07:21 -0500
commit30ec5250ca9963ecbab37a6103fdbd2ea0fcdc90 (patch)
tree960648ac973fd6f96ab1d53518c0934eae112c4a /src
parente00df6c4764e2eb0fcef8bbe2b052680cd8fb02a (diff)
downloadjalv-30ec5250ca9963ecbab37a6103fdbd2ea0fcdc90.tar.gz
jalv-30ec5250ca9963ecbab37a6103fdbd2ea0fcdc90.tar.bz2
jalv-30ec5250ca9963ecbab37a6103fdbd2ea0fcdc90.zip
Move general model query functions to a separate file
Diffstat (limited to 'src')
-rw-r--r--src/jalv.c57
-rw-r--r--src/jalv_gtk.c4
-rw-r--r--src/jalv_internal.h4
-rw-r--r--src/jalv_qt.cpp3
-rw-r--r--src/query.c53
-rw-r--r--src/query.h30
6 files changed, 95 insertions, 56 deletions
diff --git a/src/jalv.c b/src/jalv.c
index 9a73169..88115dd 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -14,6 +14,7 @@
#include "mapper.h"
#include "nodes.h"
#include "port.h"
+#include "query.h"
#include "state.h"
#include "string_utils.h"
#include "types.h"
@@ -89,28 +90,6 @@ feature_is_supported(const Jalv* jalv, const char* uri)
return false;
}
-static bool
-has_designation(const JalvNodes* const nodes,
- const LilvPlugin* const plugin,
- const JalvPort* const port,
- const LilvNode* const designation)
-{
- LilvNodes* const designations =
- lilv_port_get_value(plugin, port->lilv_port, nodes->lv2_designation);
-
- bool found = false;
- LILV_FOREACH (nodes, n, designations) {
- const LilvNode* const node = lilv_nodes_get(designations, n);
- if (lilv_node_equals(node, designation)) {
- found = true;
- break;
- }
- }
-
- lilv_nodes_free(designations);
- return found;
-}
-
/**
Create a port structure from data description.
@@ -192,8 +171,8 @@ create_port(Jalv* jalv, uint32_t port_index)
// Set primary flag for designated control port
if (port->type == TYPE_EVENT &&
- has_designation(
- &jalv->nodes, jalv->plugin, port, jalv->nodes.lv2_control)) {
+ jalv_port_has_designation(
+ &jalv->nodes, jalv->plugin, port->lilv_port, jalv->nodes.lv2_control)) {
port->is_primary = true;
if (port->flow == FLOW_INPUT && jalv->control_in == UINT32_MAX) {
jalv->control_in = port->index;
@@ -204,8 +183,10 @@ create_port(Jalv* jalv, uint32_t port_index)
if (port->flow == FLOW_OUTPUT && port->type == TYPE_CONTROL &&
(lilv_port_has_property(
jalv->plugin, port->lilv_port, jalv->nodes.lv2_reportsLatency) ||
- has_designation(
- &jalv->nodes, jalv->plugin, port, jalv->nodes.lv2_latency))) {
+ jalv_port_has_designation(&jalv->nodes,
+ jalv->plugin,
+ port->lilv_port,
+ jalv->nodes.lv2_latency))) {
port->reports_latency = true;
}
@@ -491,30 +472,6 @@ jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent)
#endif
}
-bool
-jalv_ui_is_resizable(Jalv* jalv)
-{
- if (!jalv->ui) {
- return false;
- }
-
- const LilvNode* s = lilv_ui_get_uri(jalv->ui);
- LilvNode* p = lilv_new_uri(jalv->world, LV2_CORE__optionalFeature);
- LilvNode* fs = lilv_new_uri(jalv->world, LV2_UI__fixedSize);
- LilvNode* nrs = lilv_new_uri(jalv->world, LV2_UI__noUserResize);
-
- LilvNodes* fs_matches = lilv_world_find_nodes(jalv->world, s, p, fs);
- LilvNodes* nrs_matches = lilv_world_find_nodes(jalv->world, s, p, nrs);
-
- lilv_nodes_free(nrs_matches);
- lilv_nodes_free(fs_matches);
- lilv_node_free(nrs);
- lilv_node_free(fs);
- lilv_node_free(p);
-
- return !fs_matches && !nrs_matches;
-}
-
void
jalv_init_ui(Jalv* jalv)
{
diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c
index 165243c..97d078b 100644
--- a/src/jalv_gtk.c
+++ b/src/jalv_gtk.c
@@ -6,6 +6,7 @@
#include "jalv_internal.h"
#include "log.h"
#include "options.h"
+#include "query.h"
#include "state.h"
#include "types.h"
@@ -1491,7 +1492,8 @@ jalv_frontend_open(Jalv* jalv)
GtkWidget* widget = (GtkWidget*)suil_instance_get_widget(jalv->ui_instance);
gtk_container_add(GTK_CONTAINER(ui_box), widget);
- gtk_window_set_resizable(GTK_WINDOW(window), jalv_ui_is_resizable(jalv));
+ gtk_window_set_resizable(GTK_WINDOW(window),
+ jalv_ui_is_resizable(jalv->world, jalv->ui));
gtk_widget_show_all(vbox);
gtk_widget_grab_focus(widget);
} else {
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 17d2b33..df5af10 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -158,10 +158,6 @@ jalv_init_ui(Jalv* jalv);
void
jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent);
-/// Return true if the plugin UI isn't declared as non-resizable
-bool
-jalv_ui_is_resizable(Jalv* jalv);
-
/// Periodically update user interface
int
jalv_update(Jalv* jalv);
diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp
index 2718da8..7761f10 100644
--- a/src/jalv_qt.cpp
+++ b/src/jalv_qt.cpp
@@ -7,6 +7,7 @@
#include "nodes.h"
#include "options.h"
#include "port.h"
+#include "query.h"
#include "lilv/lilv.h"
#include "suil/suil.h"
@@ -699,7 +700,7 @@ jalv_frontend_open(Jalv* jalv)
jalv_init_ui(jalv);
win->show();
- if (jalv->ui_instance && !jalv_ui_is_resizable(jalv)) {
+ if (jalv->ui_instance && !jalv_ui_is_resizable(jalv->world, jalv->ui)) {
widget->setMinimumSize(widget->width(), widget->height());
widget->setMaximumSize(widget->width(), widget->height());
win->adjustSize();
diff --git a/src/query.c b/src/query.c
new file mode 100644
index 0000000..f3b9724
--- /dev/null
+++ b/src/query.c
@@ -0,0 +1,53 @@
+// Copyright 2012-2024 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#include "query.h"
+
+#include "lv2/core/lv2.h"
+#include "lv2/ui/ui.h"
+
+bool
+jalv_port_has_designation(const JalvNodes* const nodes,
+ const LilvPlugin* const plugin,
+ const LilvPort* const port,
+ const LilvNode* const designation)
+{
+ LilvNodes* const designations =
+ lilv_port_get_value(plugin, port, nodes->lv2_designation);
+
+ bool found = false;
+ LILV_FOREACH (nodes, n, designations) {
+ const LilvNode* const node = lilv_nodes_get(designations, n);
+ if (lilv_node_equals(node, designation)) {
+ found = true;
+ break;
+ }
+ }
+
+ lilv_nodes_free(designations);
+ return found;
+}
+
+bool
+jalv_ui_is_resizable(LilvWorld* const world, const LilvUI* const ui)
+{
+ if (!ui) {
+ return false;
+ }
+
+ const LilvNode* s = lilv_ui_get_uri(ui);
+ LilvNode* p = lilv_new_uri(world, LV2_CORE__optionalFeature);
+ LilvNode* fs = lilv_new_uri(world, LV2_UI__fixedSize);
+ LilvNode* nrs = lilv_new_uri(world, LV2_UI__noUserResize);
+
+ LilvNodes* fs_matches = lilv_world_find_nodes(world, s, p, fs);
+ LilvNodes* nrs_matches = lilv_world_find_nodes(world, s, p, nrs);
+
+ lilv_nodes_free(nrs_matches);
+ lilv_nodes_free(fs_matches);
+ lilv_node_free(nrs);
+ lilv_node_free(fs);
+ lilv_node_free(p);
+
+ return !fs_matches && !nrs_matches;
+}
diff --git a/src/query.h b/src/query.h
new file mode 100644
index 0000000..e39d12e
--- /dev/null
+++ b/src/query.h
@@ -0,0 +1,30 @@
+// Copyright 2012-2024 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef JALV_MODEL_H
+#define JALV_MODEL_H
+
+#include "attributes.h"
+#include "nodes.h"
+
+#include "lilv/lilv.h"
+
+#include <stdbool.h>
+
+// Lilv query utilities
+JALV_BEGIN_DECLS
+
+/// Return whether a port has a given designation
+bool
+jalv_port_has_designation(const JalvNodes* nodes,
+ const LilvPlugin* plugin,
+ const LilvPort* port,
+ const LilvNode* designation);
+
+/// Return whether a UI is described as resizable
+bool
+jalv_ui_is_resizable(LilvWorld* world, const LilvUI* ui);
+
+JALV_END_DECLS
+
+#endif // JALV_MODEL_H