Commit 99e7bb513bb2907ffa6a19fb55e1f8bad5383b19

Thomas de Grivel 2020-05-08T17:53:52

rtbuf-gtk slider

diff --git a/gtk/rtbuf_input_widget.c b/gtk/rtbuf_input_widget.c
index f521272..03b7902 100644
--- a/gtk/rtbuf_input_widget.c
+++ b/gtk/rtbuf_input_widget.c
@@ -194,23 +194,46 @@ rtbuf_input_widget_get_check (RtbufInputWidget *widget)
   return NULL;
 }
 
+void rtbuf_input_widget_slider_value_changed (RtbufInputWidgetPrivate *priv)
+{
+  double value;
+  char str[64];
+  value = gtk_range_get_value(GTK_RANGE(priv->slider));
+  snprintf(str, sizeof(str), "%lg", value);
+  gtk_entry_set_text(GTK_ENTRY(priv->value), str);
+}
+ 
 void
 rtbuf_input_widget_update_rtbuf_in (RtbufInputWidget *widget)
 {
   static const char *sym_double = NULL;
-  const RtbufInputWidgetPrivate *priv =
+  RtbufInputWidgetPrivate *priv =
     rtbuf_input_widget_get_instance_private(widget);
+  if (!sym_double)
+    sym_double = symbol_intern("double");
   if (priv && priv->rtbuf && priv->in >= 0) {
     const s_rtbuf_proc *proc = priv->rtbuf->proc;
+    const s_rtbuf_proc_in *in = &proc->in[priv->in];
     const char *label;
+    char min[64];
+    char max[64];
+    char value[64];
+    double unbound_value;
     assert((long long) priv->in < (long long) proc->in_n);
-    label = proc->in[priv->in].name;
+    label = in->name_type;
     gtk_label_set_text(GTK_LABEL(priv->label), label);
-    if (!sym_double)
-      sym_double = symbol_intern("double");
-    if (proc->in[priv->in].type->name == sym_double) {
-      printf("%lf\n", proc->in[priv->in].def);
-    }
+    snprintf(min, sizeof(min), "%lg", in->min);
+    gtk_entry_set_text(GTK_ENTRY(priv->min), min);
+    snprintf(max, sizeof(max), "%lg", in->max);
+    gtk_entry_set_text(GTK_ENTRY(priv->max), max);
+    unbound_value = *rtbuf_in_unbound_value(priv->rtbuf, priv->in);
+    snprintf(value, sizeof(value), "%lg", unbound_value);
+    gtk_entry_set_text(GTK_ENTRY(priv->value), value);
+    gtk_range_set_range(GTK_RANGE(priv->slider), in->min, in->max);
+    gtk_range_set_value(GTK_RANGE(priv->slider), unbound_value);
+    g_signal_connect_swapped(priv->slider, "value-changed",
+                             G_CALLBACK(rtbuf_input_widget_slider_value_changed),
+                             priv);
   }
 }
 
diff --git a/gtk/rtbuf_input_widget.ui b/gtk/rtbuf_input_widget.ui
index 450a8a3..50ec52c 100644
--- a/gtk/rtbuf_input_widget.ui
+++ b/gtk/rtbuf_input_widget.ui
@@ -34,11 +34,14 @@
       </packing>
     </child>
     <child>
-      <object class="GtkLabel" id="value">
+      <object class="GtkEntry" id="value">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">0.5</property>
+        <property name="can_focus">True</property>
+        <property name="has_frame">False</property>
         <property name="width_chars">9</property>
+        <property name="text" translatable="yes">0.0</property>
+        <property name="caps_lock_warning">False</property>
+        <property name="input_purpose">number</property>
       </object>
       <packing>
         <property name="expand">False</property>
@@ -64,6 +67,7 @@
     </child>
     <child>
       <object class="GtkScale" id="slider">
+        <property name="width_request">128</property>
         <property name="visible">True</property>
         <property name="can_focus">True</property>
         <property name="round_digits">1</property>
@@ -84,6 +88,7 @@
         <property name="has_frame">False</property>
         <property name="width_chars">9</property>
         <property name="text" translatable="yes">1.0</property>
+        <property name="caps_lock_warning">False</property>
         <property name="input_purpose">number</property>
       </object>
       <packing>
diff --git a/gtk/rtbuf_output_widget.c b/gtk/rtbuf_output_widget.c
index fb3cdb9..0b9ab36 100644
--- a/gtk/rtbuf_output_widget.c
+++ b/gtk/rtbuf_output_widget.c
@@ -188,7 +188,7 @@ rtbuf_output_widget_update (RtbufOutputWidget *widget)
     const s_rtbuf_proc *proc = priv->rtbuf->proc;
     const char *label;
     assert((long long) priv->out < (long long) proc->out_n);
-    label = proc->out[priv->out].name;
+    label = proc->out[priv->out].name_type;
     gtk_label_set_text(GTK_LABEL(priv->label), label);
   }
 }
diff --git a/librtbuf/include/rtbuf/proc.h b/librtbuf/include/rtbuf/proc.h
index a5eaadf..e372688 100644
--- a/librtbuf/include/rtbuf/proc.h
+++ b/librtbuf/include/rtbuf/proc.h
@@ -22,6 +22,7 @@
 
 struct rtbuf_proc_in {
   symbol name;
+  const char *name_type;
   s_rtbuf_type *type;
   double def;
   double min;
@@ -31,6 +32,7 @@ struct rtbuf_proc_in {
 
 struct rtbuf_proc_out {
   symbol name;
+  const char *name_type;
   s_rtbuf_type *type;
   unsigned int offset;
 };
diff --git a/librtbuf/include/rtbuf/rtbuf.h b/librtbuf/include/rtbuf/rtbuf.h
index 34b45b4..c29a31d 100644
--- a/librtbuf/include/rtbuf/rtbuf.h
+++ b/librtbuf/include/rtbuf/rtbuf.h
@@ -63,7 +63,6 @@ void  rtbuf_bind (unsigned int src, unsigned int out,
 int   rtbuf_out_find (s_rtbuf *rtb, symbol sym);
 int   rtbuf_data_set (s_rtbuf *rtb, symbol name, void *value,
                       unsigned int size);
-void *rtbuf_in_unbound_value (s_rtbuf *rtb, unsigned int in);
 void  rtbuf_sort ();
 int   rtbuf_start ();
 int   rtbuf_run ();
@@ -74,6 +73,8 @@ void  rtbuf_print_sorted ();
 
 int  rtbuf_out_int (s_rtbuf *rtb, unsigned int out, int default_value);
 
+double * rtbuf_in_unbound_value (s_rtbuf *rtb, unsigned int in);
+
 double min (double a, double b);
 double max (double a, double b);
 double clamp (double inf, double x, double sup);
diff --git a/librtbuf/rtbuf.c b/librtbuf/rtbuf.c
index 098f33a..5e19779 100644
--- a/librtbuf/rtbuf.c
+++ b/librtbuf/rtbuf.c
@@ -56,9 +56,6 @@ int rtbuf_new (s_rtbuf_proc *rp)
   s_rtbuf *rtb;
   void *data;
   unsigned int j;
-  static const char *sym_double = NULL;
-  if (!sym_double)
-    sym_double = symbol_intern("double");
   assert(rp);
   assert(g_rtbuf);
   data = data_new(&rp->alloc);
@@ -79,10 +76,8 @@ int rtbuf_new (s_rtbuf_proc *rp)
   }
   j = 0;
   while (j < rp->in_n) {
-    if (rp->in[j].type->name == sym_double) {
-      memcpy(rtbuf_in_unbound_value(rtb, j), &rp->in[j].def,
-             sizeof(double));
-    }
+    double *uv = rtbuf_in_unbound_value(rtb, j);
+    *uv = rp->in[j].def;
     j++;
   }
   g_rtbuf_sort = 1;
@@ -597,7 +592,7 @@ int rtbuf_err (const char *msg)
   return -1;
 }
 
-void * rtbuf_in_unbound_value (s_rtbuf *rtb, unsigned int in)
+double * rtbuf_in_unbound_value (s_rtbuf *rtb, unsigned int in)
 {
   unsigned int offset;
   void *p;
@@ -607,5 +602,5 @@ void * rtbuf_in_unbound_value (s_rtbuf *rtb, unsigned int in)
   offset = rtb->proc->in[in].offset;
   assert(offset < rtb->proc->bytes);
   p = rtb->data + offset;
-  return p;
+  return (double*) p;
 }
diff --git a/librtbuf/rtbuf_lib.c b/librtbuf/rtbuf_lib.c
index 644f474..6416ea1 100644
--- a/librtbuf/rtbuf_lib.c
+++ b/librtbuf/rtbuf_lib.c
@@ -206,11 +206,14 @@ void rtbuf_lib_proc_in_init_proc (s_rtbuf_proc *proc,
       unsigned int size;
       v->name = symbol_intern(in->name);
       v->type = rtbuf_type(in->type);
+      v->name_type = g_str;
+      g_str_append(v->name, strlen(v->name));
+      g_str_append(": ", 2);
+      g_str_append(v->type->name, strlen(v->type->name) + 1);
       v->def = in->def;
       v->min = in->min;
       v->max = in->max;
-      assert(v->type);
-      size = (v->type->t.bits + 7) / 8;
+      size = sizeof(double);
       offset = add_padding(offset, size);
       v->offset = offset;
       offset += size;
@@ -241,6 +244,10 @@ void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
       unsigned int size;
       o->name = symbol_intern(out->name);
       o->type = rtbuf_type(out->type);
+      o->name_type = g_str;
+      g_str_append(o->name, strlen(o->name));
+      g_str_append(": ", 2);
+      g_str_append(o->type->name, strlen(o->type->name) + 1);
       assert(o->type);
       size = (o->type->t.bits + 7) / 8;
       offset = add_padding(offset, size);