diff --git a/Makefile.am b/Makefile.am
index 4a64722..c573925 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -43,16 +43,17 @@ bin_PROGRAMS += rtbuf-gtk
rtbuf_gtk_CFLAGS = ${GTK3_CFLAGS}
rtbuf_gtk_LDADD = ${GTK3_LIBS} librtbuf.la
rtbuf_gtk_SOURCES = \
- rtbuf_lib.c \
rtbuf_gtk.c \
rtbuf_gtk_resources.c \
+ rtbuf_input_widget.c \
+ rtbuf_lib.c \
rtbuf_widget.c
include_HEADERS += \
rtbuf_lib.h
rtbuf_gtk_UI = \
- rtbuf_input.ui \
+ rtbuf_input_widget.ui \
rtbuf_modular.ui \
- rtbuf_output.ui \
+ rtbuf_output_widget.ui \
rtbuf_widget.ui
rtbuf_gtk_resources.c: rtbuf_gtk.gresource.xml ${rtbuf_gtk_UI}
glib-compile-resources rtbuf_gtk.gresource.xml --target=rtbuf_gtk_resources.c --generate-source
diff --git a/rtbuf_input_widget.c b/rtbuf_input_widget.c
new file mode 100644
index 0000000..93634d1
--- /dev/null
+++ b/rtbuf_input_widget.c
@@ -0,0 +1,208 @@
+/*
+ * Copyright 2020 Thomas de Grivel <thoxdg@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <assert.h>
+#include <gtk/gtk.h>
+#include "rtbuf_input_widget.h"
+#include "rtbuf.h"
+
+struct _RtbufInputWidgetPrivate {
+ s_rtbuf *rtbuf;
+ int in;
+ GtkWidget *check;
+ GtkWidget *label;
+ GtkWidget *value;
+ GtkWidget *min;
+ GtkWidget *slider;
+ GtkWidget *max;
+};
+
+enum {
+ PROP_0,
+ PROP_RTBUF,
+ PROP_IN,
+ LAST_PROP
+};
+
+static GParamSpec *rtbuf_input_widget_props[LAST_PROP];
+
+static void rtbuf_input_widget_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void rtbuf_input_widget_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void rtbuf_input_widget_finalize (GObject *object);
+
+G_DEFINE_TYPE_WITH_PRIVATE (RtbufInputWidget, rtbuf_input_widget, GTK_TYPE_BOX)
+
+static void
+rtbuf_input_widget_class_init (RtbufInputWidgetClass *klass)
+{
+ GObjectClass *gobject_class = (GObjectClass*) klass;
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+ printf("rtbuf_input_widget class init\n");
+ gobject_class->finalize = rtbuf_input_widget_finalize;
+ gobject_class->set_property = rtbuf_input_widget_set_property;
+ gobject_class->get_property = rtbuf_input_widget_get_property;
+ rtbuf_input_widget_props[PROP_RTBUF] =
+ g_param_spec_pointer("rtbuf",
+ "Rtbuf",
+ "Pointer to a s_rtbuf",
+ G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ rtbuf_input_widget_props[PROP_IN] =
+ g_param_spec_uint("in",
+ "Input",
+ "rtbuf input index",
+ 0, /* min */
+ RTBUF_PROC_IN_MAX, /* max */
+ -1, /* default */
+ G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ g_object_class_install_properties(gobject_class, LAST_PROP, rtbuf_input_widget_props);
+ gtk_widget_class_set_template_from_resource(widget_class,
+ "/rtbuf/rtbuf_input_widget.ui");
+ gtk_widget_class_bind_template_child_private(widget_class,
+ RtbufInputWidget, check);
+ gtk_widget_class_bind_template_child_private(widget_class,
+ RtbufInputWidget, label);
+ gtk_widget_class_bind_template_child_private(widget_class,
+ RtbufInputWidget, value);
+ gtk_widget_class_bind_template_child_private(widget_class,
+ RtbufInputWidget, min);
+ gtk_widget_class_bind_template_child_private(widget_class,
+ RtbufInputWidget, slider);
+ gtk_widget_class_bind_template_child_private(widget_class,
+ RtbufInputWidget, max);
+}
+
+static void
+rtbuf_input_widget_init (RtbufInputWidget *widget)
+{
+ printf("rtbuf_input_widget init\n");
+ gtk_widget_init_template(GTK_WIDGET(widget));
+}
+
+static void
+rtbuf_input_widget_set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ RtbufInputWidget *widget = RTBUF_INPUT_WIDGET(object);
+ RtbufInputWidgetPrivate *priv =
+ rtbuf_input_widget_get_instance_private(widget);
+ switch (prop_id) {
+ case PROP_RTBUF:
+ priv->rtbuf = g_value_get_pointer(value);
+ rtbuf_input_widget_update(widget);
+ break;
+ case PROP_IN:
+ priv->in = g_value_get_uint(value);
+ rtbuf_input_widget_update(widget);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+rtbuf_input_widget_get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ RtbufInputWidget *widget = RTBUF_INPUT_WIDGET(object);
+ RtbufInputWidgetPrivate *priv =
+ rtbuf_input_widget_get_instance_private(widget);
+ switch (prop_id) {
+ case PROP_RTBUF:
+ g_value_set_pointer(value, priv->rtbuf);
+ break;
+ case PROP_IN:
+ g_value_set_uint(value, priv->in);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+rtbuf_input_widget_finalize (GObject *object)
+{
+ RtbufInputWidget *widget = RTBUF_INPUT_WIDGET(object);
+ RtbufInputWidgetPrivate *priv =
+ rtbuf_input_widget_get_instance_private(widget);
+ g_clear_object(&priv->check);
+ g_clear_object(&priv->label);
+ g_clear_object(&priv->value);
+ g_clear_object(&priv->min);
+ g_clear_object(&priv->slider);
+ g_clear_object(&priv->max);
+ G_OBJECT_CLASS(rtbuf_input_widget_parent_class)->finalize(object);
+}
+
+RtbufInputWidget *
+rtbuf_input_widget_new (s_rtbuf *rtbuf, unsigned int in)
+{
+ return (RtbufInputWidget*) g_object_new(RTBUF_INPUT_WIDGET_TYPE,
+ "rtbuf", rtbuf,
+ "in", in,
+ NULL);
+}
+
+s_rtbuf *
+rtbuf_input_widget_get_rtbuf (RtbufInputWidget *widget)
+{
+ RtbufInputWidgetPrivate *priv =
+ rtbuf_input_widget_get_instance_private(widget);
+ if (priv)
+ return priv->rtbuf;
+ return NULL;
+}
+
+unsigned int
+rtbuf_input_widget_get_in (RtbufInputWidget *widget)
+{
+ RtbufInputWidgetPrivate *priv =
+ rtbuf_input_widget_get_instance_private(widget);
+ if (priv)
+ return priv->in;
+ return 0;
+}
+
+GtkWidget *
+rtbuf_input_widget_get_check (RtbufInputWidget *widget)
+{
+ RtbufInputWidgetPrivate *priv =
+ rtbuf_input_widget_get_instance_private(widget);
+ if (priv)
+ return priv->check;
+ return NULL;
+}
+
+void
+rtbuf_input_widget_update (RtbufInputWidget *widget)
+{
+ const RtbufInputWidgetPrivate *priv =
+ rtbuf_input_widget_get_instance_private(widget);
+ if (priv && priv->rtbuf && priv->in >= 0) {
+ const s_rtbuf_proc *proc = priv->rtbuf->proc;
+ const char *label;
+ assert(priv->in < proc->in_n);
+ label = proc->in[priv->in].name;
+ gtk_label_set_text(GTK_LABEL(priv->label), label);
+ }
+}
diff --git a/rtbuf_input_widget.h b/rtbuf_input_widget.h
new file mode 100644
index 0000000..c183b41
--- /dev/null
+++ b/rtbuf_input_widget.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2020 Thomas de Grivel <thoxdg@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef RTBUF_INPUT_WIDGET_H
+#define RTBUF_INPUT_WIDGET_H
+
+#include "rtbuf.h"
+
+#define RTBUF_INPUT_WIDGET_TYPE \
+ (rtbuf_input_widget_get_type())
+
+#define RTBUF_INPUT_WIDGET(object) \
+ (G_TYPE_CHECK_INSTANCE_CAST((object), RTBUF_INPUT_WIDGET_TYPE, \
+ RtbufInputWidget))
+
+#define RTBUF_INPUT_WIDGET_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), RTBUF_INPUT_WIDGET_TYPE, \
+ RtbufInputWidgetClass))
+
+#define IS_RTBUF_INPUT_WIDGET(object) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((object), RTBUF_INPUT_WIDGET_TYPE))
+
+#define IS_RTBUF_INPUT_WIDGET_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), RTBUF_INPUT_WIDGET_TYPE))
+
+#define RTBUF_INPUT_WIDGET_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), RTBUF_INPUT_WIDGET_TYPE, \
+ RtbufInputWidgetClass))
+
+typedef struct _RtbufInputWidget RtbufInputWidget;
+typedef struct _RtbufInputWidgetClass RtbufInputWidgetClass;
+typedef struct _RtbufInputWidgetPrivate RtbufInputWidgetPrivate;
+
+struct _RtbufInputWidget {
+ GtkBox box;
+};
+
+struct _RtbufInputWidgetClass {
+ GtkBoxClass parent_class;
+};
+
+GType rtbuf_input_widget_get_type (void) G_GNUC_CONST;
+RtbufInputWidget * rtbuf_input_widget_new (s_rtbuf *rtbuf,
+ unsigned int in);
+s_rtbuf * rtbuf_input_widget_get_rtbuf (RtbufInputWidget *widget);
+unsigned int rtbuf_input_widget_get_in (RtbufInputWidget *widget);
+GtkWidget * rtbuf_input_widget_get_check (RtbufInputWidget *widget);
+void rtbuf_input_widget_update (RtbufInputWidget *widget);
+
+#endif
diff --git a/rtbuf_widget.c b/rtbuf_widget.c
index 1c1dfe4..8059684 100644
--- a/rtbuf_widget.c
+++ b/rtbuf_widget.c
@@ -14,7 +14,9 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <assert.h>
#include <gtk/gtk.h>
+#include "rtbuf_input_widget.h"
#include "rtbuf_widget.h"
#include "rtbuf.h"
@@ -86,6 +88,8 @@ static void
rtbuf_widget_init (RtbufWidget *widget)
{
RtbufWidgetPrivate *priv;
+ s_rtbuf_proc *proc;
+ unsigned int i = 0;
printf("rtbuf_widget init\n");
priv = rtbuf_widget_get_instance_private(widget);
gtk_widget_init_template(GTK_WIDGET(widget));
@@ -104,7 +108,7 @@ rtbuf_widget_set_property (GObject *object, guint prop_id,
rtbuf_widget_set_label(widget, g_value_get_string(value));
break;
case PROP_RTBUF:
- priv->rtbuf = g_value_get_pointer(value);
+ rtbuf_widget_set_rtbuf(widget, g_value_get_pointer(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -164,6 +168,42 @@ rtbuf_widget_new (s_rtbuf *rtb, const gchar *label)
NULL);
}
+void gtk_container_clear_widget (GtkWidget *widget,
+ gpointer data)
+{
+ GtkContainer *container = (GtkContainer*) data;
+ gtk_container_remove(container, widget);
+}
+
+void gtk_container_clear (GtkContainer *container)
+{
+ gtk_container_foreach(container,
+ gtk_container_clear_widget,
+ container);
+}
+
+void rtbuf_widget_set_rtbuf (RtbufWidget *widget, s_rtbuf *rtbuf)
+{
+
+ RtbufWidgetPrivate *priv = rtbuf_widget_get_instance_private(widget);
+ GtkContainer *inputs;
+ s_rtbuf_proc *proc;
+ unsigned int i;
+ printf("rtbuf_widget set rtbuf\n");
+ priv->rtbuf = rtbuf;
+ proc = rtbuf->proc;
+ inputs = GTK_CONTAINER(priv->inputs);
+ gtk_container_clear(inputs);
+ for (i = 0; i < proc->in_n; i++) {
+ RtbufInputWidget *input_widget =
+ rtbuf_input_widget_new(priv->rtbuf, i);
+ gtk_container_add(inputs, GTK_WIDGET(input_widget));
+ i++;
+ }
+ for (i = 0; i < proc->out_n; i++) {
+ }
+}
+
void rtbuf_widget_set_label (RtbufWidget *widget,
const gchar *label)
{
diff --git a/rtbuf_widget.h b/rtbuf_widget.h
index 5497a66..bb42165 100644
--- a/rtbuf_widget.h
+++ b/rtbuf_widget.h
@@ -54,6 +54,8 @@ struct _RtbufWidgetClass {
GType rtbuf_widget_get_type (void) G_GNUC_CONST;
RtbufWidget * rtbuf_widget_new (s_rtbuf *rtbuf, const gchar *label);
+void rtbuf_widget_set_rtbuf (RtbufWidget *widget,
+ s_rtbuf *rtbuf);
void rtbuf_widget_set_label (RtbufWidget *widget,
const gchar *label);
const gchar * rtbuf_widget_get_label (RtbufWidget *widget);