[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src/3rdparty/slv2 slv2/gui.h slv2/plug...
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src/3rdparty/slv2 slv2/gui.h slv2/plug... |
Date: |
Tue, 06 Nov 2007 18:28:41 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 07/11/06 18:28:41
Added files:
src/3rdparty/slv2/slv2: gui.h pluginguiinstance.h
src/3rdparty/slv2/src: pluginguiinstance.c
Log message:
added in version 0.2.0
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/3rdparty/slv2/slv2/gui.h?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/3rdparty/slv2/slv2/pluginguiinstance.h?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/3rdparty/slv2/src/pluginguiinstance.c?cvsroot=traverso&rev=1.1
Patches:
Index: slv2/gui.h
===================================================================
RCS file: slv2/gui.h
diff -N slv2/gui.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ slv2/gui.h 6 Nov 2007 18:28:41 -0000 1.1
@@ -0,0 +1,60 @@
+/* SLV2
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __SLV2_GUI_H__
+#define __SLV2_GUI_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <slv2/types.h>
+#include <slv2/port.h>
+#include <slv2/values.h>
+
+/** \defgroup gui Plugin GUI helpers
+ *
+ * SLV2 provides access to plugin GUIs, but does not depend on any widget sets
+ * itself. Paths to libraries and opaque pointers to objects are returned, but
+ * the GUI extension itself (the URI of which can be had with slv2_gui_get_uri)
+ * defines the specifics of how to use these objects/files/etc.
+ *
+ * @{
+ */
+
+/** Return the URI of the GUI type (ontology) this GUI corresponds to.
+ *
+ * Returned string is shared and must not be freed by the caller.
+ *
+ * Time = O(1)
+ */
+const char*
+slv2_gui_type_get_uri(SLV2GUIType type);
+
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SLV2_GUI_H__ */
+
Index: slv2/pluginguiinstance.h
===================================================================
RCS file: slv2/pluginguiinstance.h
diff -N slv2/pluginguiinstance.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ slv2/pluginguiinstance.h 6 Nov 2007 18:28:41 -0000 1.1
@@ -0,0 +1,126 @@
+/* SLV2
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ * Author: Lars Luthman
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __SLV2_PLUGINGUIINSTANCE_H__
+#define __SLV2_PLUGINGUIINSTANCE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <assert.h>
+#include <slv2/lv2-gtk2gui.h>
+#include <slv2/plugin.h>
+
+/** \defgroup lib Plugin GUI library access
+ *
+ * An SLV2GUIInstance is an instantiated GUI for a SLV2Plugin. GUI instances
+ * are loaded from dynamically loaded libraries. These functions interact
+ * with the GUI code in the binary library only, they do not read data files
+ * in any way.
+ *
+ * @{
+ */
+
+
+typedef struct _SLV2GUIInstanceImpl* SLV2GUIInstanceImpl;
+
+
+struct _GtkWidget;
+
+
+/** Instance of a plugin GUI.
+ *
+ * All details are in hidden in the pimpl member to avoid making the
+ * implementation a part of the ABI.
+ */
+typedef struct _SLV2GUIInstance {
+ SLV2GUIInstanceImpl pimpl; ///< Private implementation
+}* SLV2GUIInstance;
+
+
+
+/** Instantiate a plugin GUI.
+ *
+ * The returned object represents shared library objects loaded into memory,
+ * it must be cleaned up with slv2_gui_instance_free when no longer
+ * needed.
+ *
+ * \a plugin is not modified or directly referenced by the returned object
+ * (instances store only a copy of the plugin's URI).
+ *
+ * \a host_features NULL-terminated array of features the host supports.
+ * NULL may be passed if the host supports no additional features (unlike
+ * the LV2 specification - SLV2 takes care of it).
+ *
+ * \return NULL if instantiation failed.
+ */
+SLV2GUIInstance
+slv2_plugin_gtk2_gui_instantiate(SLV2Plugin plugin,
+ SLV2Value gui,
+ LV2UI_Set_Control_Function control_function,
+ LV2UI_Controller controller,
+ const LV2_Host_Feature** host_features);
+
+
+/** Free a plugin GUI instance.
+ *
+ * \a instance is invalid after this call.
+ */
+void
+slv2_gtk2_gui_instance_free(SLV2GUIInstance instance);
+
+
+/** Get the GTK+ 2.0 widget for the GUI instance.
+ */
+struct _GtkWidget*
+slv2_gtk2_gui_instance_get_widget(SLV2GUIInstance instance);
+
+
+/** Get the LV2UI_Descriptor of the plugin GUI instance.
+ *
+ * Normally hosts should not need to access the LV2UI_Descriptor directly,
+ * use the slv2_gui_instance_* functions.
+ *
+ * The returned descriptor is shared and must not be deleted.
+ */
+const LV2UI_Descriptor*
+slv2_gtk2_gui_instance_get_descriptor(SLV2GUIInstance instance);
+
+
+/** Get the LV2UI_Handle of the plugin GUI instance.
+ *
+ * Normally hosts should not need to access the LV2UI_Handle directly,
+ * use the slv2_gui_instance_* functions.
+ *
+ * The returned handle is shared and must not be deleted.
+ */
+LV2_Handle
+slv2_gtk2_gui_instance_get_handle(SLV2GUIInstance instance);
+
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __SLV2_PLUGINGUIINSTANCE_H__ */
+
Index: src/pluginguiinstance.c
===================================================================
RCS file: src/pluginguiinstance.c
diff -N src/pluginguiinstance.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/pluginguiinstance.c 6 Nov 2007 18:28:41 -0000 1.1
@@ -0,0 +1,169 @@
+/* SLV2
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ * Author: Lars Luthman
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _XOPEN_SOURCE 500
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <dlfcn.h>
+#include <slv2/types.h>
+#include <slv2/plugin.h>
+#include <slv2/pluginguiinstance.h>
+#include <slv2/util.h>
+#include "slv2_internal.h"
+
+
+SLV2GUIInstance
+slv2_plugin_gtk2_gui_instantiate(SLV2Plugin plugin,
+ SLV2Value gui,
+ LV2UI_Set_Control_Function control_function,
+ LV2UI_Controller controller,
+ const LV2_Host_Feature** host_features)
+{
+ assert(gui->type == SLV2_VALUE_GUI);
+
+ if (gui->val.gui_type_val != SLV2_GUI_TYPE_GTK2)
+ return NULL;
+
+ struct _SLV2GUIInstance* result = NULL;
+
+ bool local_host_features = (host_features == NULL);
+ if (local_host_features) {
+ host_features = malloc(sizeof(LV2_Host_Feature));
+ host_features[0] = NULL;
+ }
+
+ const char* const lib_uri =
slv2_value_as_uri(slv2_plugin_get_gui_library_uri(plugin, gui));
+ const char* const lib_path = slv2_uri_to_path(lib_uri);
+
+ if (!lib_path)
+ return NULL;
+
+ dlerror();
+ void* lib = dlopen(lib_path, RTLD_NOW);
+ if (!lib) {
+ fprintf(stderr, "Unable to open GUI library %s (%s)\n",
lib_path, dlerror());
+ return NULL;
+ }
+
+ LV2UI_DescriptorFunction df = dlsym(lib, "lv2ui_descriptor");
+
+ if (!df) {
+ fprintf(stderr, "Could not find symbol 'lv2ui_descriptor', "
+ "%s is not a LV2 plugin GUI.\n", lib_path);
+ dlclose(lib);
+ return NULL;
+ } else {
+ // Search for plugin by URI
+
+ // FIXME: Bundle in plugin GUI only, boo
+ const char* bundle_path =
slv2_uri_to_path(slv2_plugin_get_bundle_uri(plugin));
+ printf("GUI bundle path: %s\n", bundle_path);
+
+ for (uint32_t i=0; 1; ++i) {
+
+ const LV2UI_Descriptor* ld = df(i);
+
+ if (!ld) {
+ fprintf(stderr, "Did not find GUI %s in %s\n",
+ slv2_value_as_uri(gui),
lib_path);
+ dlclose(lib);
+ break; // return NULL
+ } else if (!strcmp(ld->URI, slv2_value_as_uri(gui))) {
+
+ printf("Found GUI %s at index %u in:\n\t%s\n\n",
+
librdf_uri_as_string(plugin->plugin_uri), i, lib_path);
+
+ assert(ld->instantiate);
+
+ // Create SLV2GUIInstance to return
+ result = malloc(sizeof(struct
_SLV2GUIInstance));
+ struct _SLV2GUIInstanceImpl* impl =
malloc(sizeof(struct _SLV2GUIInstanceImpl));
+ impl->lv2ui_descriptor = ld;
+ impl->lv2ui_handle = ld->instantiate(ld,
+ slv2_plugin_get_uri(plugin),
+ (char*)bundle_path,
+ control_function,
+ controller,
+ (struct
_GtkWidget**)&impl->widget,
+ host_features);
+ impl->lib_handle = lib;
+ result->pimpl = impl;
+ break;
+ }
+ }
+ }
+
+ assert(result);
+ assert(slv2_plugin_get_num_ports(plugin) > 0);
+
+ // Failed to instantiate
+ if (result->pimpl->lv2ui_handle == NULL) {
+ //printf("Failed to instantiate %s\n", plugin->plugin_uri);
+ free(result);
+ return NULL;
+ }
+
+ // Failed to create a widget, but still got a handle - this means that
+ // the plugin is buggy
+ if (result->pimpl->widget == NULL) {
+ slv2_gtk2_gui_instance_free(result);
+ return NULL;
+ }
+
+ if (local_host_features)
+ free(host_features);
+
+ return result;
+}
+
+
+void
+slv2_gtk2_gui_instance_free(SLV2GUIInstance instance)
+{
+ struct _SLV2GUIInstance* i = (struct _SLV2GUIInstance*)instance;
+ i->pimpl->lv2ui_descriptor->cleanup(i->pimpl->lv2ui_handle);
+ i->pimpl->lv2ui_descriptor = NULL;
+ dlclose(i->pimpl->lib_handle);
+ i->pimpl->lib_handle = NULL;
+ free(i->pimpl);
+ i->pimpl = NULL;
+ free(i);
+}
+
+
+struct _GtkWidget*
+slv2_gtk2_gui_instance_get_widget(SLV2GUIInstance instance) {
+ return instance->pimpl->widget;
+}
+
+
+const LV2UI_Descriptor*
+slv2_gtk2_gui_instance_get_descriptor(SLV2GUIInstance instance) {
+ return instance->pimpl->lv2ui_descriptor;
+}
+
+
+LV2_Handle
+slv2_gtk2_gui_instance_get_handle(SLV2GUIInstance instance) {
+ return instance->pimpl->lv2ui_handle;
+}
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src/3rdparty/slv2 slv2/gui.h slv2/plug...,
Remon Sijrier <=