lfocontrolsource: make chainable
authorStefan Sauer <ensonic@users.sf.net>
Sun, 1 Jan 2012 14:16:06 +0000 (15:16 +0100)
committerStefan Sauer <ensonic@users.sf.net>
Sun, 1 Jan 2012 15:08:01 +0000 (16:08 +0100)
Now the properties of this controlsource are in turn controlable. Add an example
to show the usage.

libs/gst/controller/gstlfocontrolsource.c
tests/examples/controller/control-sources.c

index 7ebd525..a35c916 100644 (file)
@@ -95,17 +95,11 @@ waveform_sine_get (GstLFOControlSource * self, GstClockTime timestamp,
     gdouble * value)
 {
   GstLFOControlSourcePrivate *priv = self->priv;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
 
+  gst_object_sync_values (GST_OBJECT (self), timestamp);
   g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
-
-  *value = _sine_get (self, amp, off, timeshift, period, frequency, timestamp);
+  *value = _sine_get (self, priv->amplitude, priv->offset, priv->timeshift,
+      priv->period, priv->frequency, timestamp);
   g_mutex_unlock (self->lock);
   return TRUE;
 }
@@ -118,22 +112,16 @@ waveform_sine_get_value_array (GstLFOControlSource * self,
   GstLFOControlSourcePrivate *priv = self->priv;
   guint i;
   GstClockTime ts = timestamp;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
-
-  g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
 
   for (i = 0; i < n_values; i++) {
-    *values = _sine_get (self, amp, off, timeshift, period, frequency, ts);
+    gst_object_sync_values (GST_OBJECT (self), ts);
+    g_mutex_lock (self->lock);
+    *values = _sine_get (self, priv->amplitude, priv->offset, priv->timeshift,
+        priv->period, priv->frequency, ts);
+    g_mutex_unlock (self->lock);
     ts += interval;
     values++;
   }
-  g_mutex_unlock (self->lock);
   return TRUE;
 }
 
@@ -160,18 +148,11 @@ waveform_square_get (GstLFOControlSource * self, GstClockTime timestamp,
     gdouble * value)
 {
   GstLFOControlSourcePrivate *priv = self->priv;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
 
+  gst_object_sync_values (GST_OBJECT (self), timestamp);
   g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
-
-  *value =
-      _square_get (self, amp, off, timeshift, period, frequency, timestamp);
+  *value = _square_get (self, priv->amplitude, priv->offset, priv->timeshift,
+      priv->period, priv->frequency, timestamp);
   g_mutex_unlock (self->lock);
   return TRUE;
 }
@@ -184,22 +165,16 @@ waveform_square_get_value_array (GstLFOControlSource * self,
   GstLFOControlSourcePrivate *priv = self->priv;
   guint i;
   GstClockTime ts = timestamp;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
-
-  g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
 
   for (i = 0; i < n_values; i++) {
-    *values = _square_get (self, amp, off, timeshift, period, frequency, ts);
+    gst_object_sync_values (GST_OBJECT (self), ts);
+    g_mutex_lock (self->lock);
+    *values = _square_get (self, priv->amplitude, priv->offset, priv->timeshift,
+        priv->period, priv->frequency, ts);
+    g_mutex_unlock (self->lock);
     ts += interval;
     values++;
   }
-  g_mutex_unlock (self->lock);
   return TRUE;
 }
 
@@ -225,17 +200,11 @@ waveform_saw_get (GstLFOControlSource * self, GstClockTime timestamp,
     gdouble * value)
 {
   GstLFOControlSourcePrivate *priv = self->priv;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
 
+  gst_object_sync_values (GST_OBJECT (self), timestamp);
   g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
-
-  *value = _saw_get (self, amp, off, timeshift, period, frequency, timestamp);
+  *value = _saw_get (self, priv->amplitude, priv->offset, priv->timeshift,
+      priv->period, priv->frequency, timestamp);
   g_mutex_unlock (self->lock);
   return TRUE;
 }
@@ -248,22 +217,16 @@ waveform_saw_get_value_array (GstLFOControlSource * self,
   GstLFOControlSourcePrivate *priv = self->priv;
   guint i;
   GstClockTime ts = timestamp;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
-
-  g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
 
   for (i = 0; i < n_values; i++) {
-    *values = _saw_get (self, amp, off, timeshift, period, frequency, ts);
+    gst_object_sync_values (GST_OBJECT (self), ts);
+    g_mutex_lock (self->lock);
+    *values = _saw_get (self, priv->amplitude, priv->offset, priv->timeshift,
+        priv->period, priv->frequency, ts);
+    g_mutex_unlock (self->lock);
     ts += interval;
     values++;
   }
-  g_mutex_unlock (self->lock);
   return TRUE;
 }
 
@@ -289,17 +252,11 @@ waveform_rsaw_get (GstLFOControlSource * self, GstClockTime timestamp,
     gdouble * value)
 {
   GstLFOControlSourcePrivate *priv = self->priv;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
 
+  gst_object_sync_values (GST_OBJECT (self), timestamp);
   g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
-
-  *value = _rsaw_get (self, amp, off, timeshift, period, frequency, timestamp);
+  *value = _rsaw_get (self, priv->amplitude, priv->offset, priv->timeshift,
+      priv->period, priv->frequency, timestamp);
   g_mutex_unlock (self->lock);
   return TRUE;
 }
@@ -312,22 +269,16 @@ waveform_rsaw_get_value_array (GstLFOControlSource * self,
   GstLFOControlSourcePrivate *priv = self->priv;
   guint i;
   GstClockTime ts = timestamp;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
-
-  g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
 
   for (i = 0; i < n_values; i++) {
-    *values = _rsaw_get (self, amp, off, timeshift, period, frequency, ts);
+    gst_object_sync_values (GST_OBJECT (self), ts);
+    g_mutex_lock (self->lock);
+    *values = _rsaw_get (self, priv->amplitude, priv->offset, priv->timeshift,
+        priv->period, priv->frequency, ts);
+    g_mutex_unlock (self->lock);
     ts += interval;
     values++;
   }
-  g_mutex_unlock (self->lock);
   return TRUE;
 }
 
@@ -366,18 +317,11 @@ waveform_triangle_get (GstLFOControlSource * self, GstClockTime timestamp,
     gdouble * value)
 {
   GstLFOControlSourcePrivate *priv = self->priv;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
 
+  gst_object_sync_values (GST_OBJECT (self), timestamp);
   g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
-
-  *value =
-      _triangle_get (self, amp, off, timeshift, period, frequency, timestamp);
+  *value = _triangle_get (self, priv->amplitude, priv->offset, priv->timeshift,
+      priv->period, priv->frequency, timestamp);
   g_mutex_unlock (self->lock);
   return TRUE;
 }
@@ -390,22 +334,17 @@ waveform_triangle_get_value_array (GstLFOControlSource * self,
   GstLFOControlSourcePrivate *priv = self->priv;
   guint i;
   GstClockTime ts = timestamp;
-  gdouble amp, off, frequency;
-  GstClockTime timeshift, period;
-
-  g_mutex_lock (self->lock);
-  amp = priv->amplitude;
-  off = priv->offset;
-  timeshift = priv->timeshift;
-  period = priv->period;
-  frequency = priv->frequency;
 
   for (i = 0; i < n_values; i++) {
-    *values = _triangle_get (self, amp, off, timeshift, period, frequency, ts);
+    gst_object_sync_values (GST_OBJECT (self), ts);
+    g_mutex_lock (self->lock);
+    *values =
+        _triangle_get (self, priv->amplitude, priv->offset, priv->timeshift,
+        priv->period, priv->frequency, ts);
+    g_mutex_unlock (self->lock);
     ts += interval;
     values++;
   }
-  g_mutex_unlock (self->lock);
   return TRUE;
 }
 
@@ -642,7 +581,7 @@ gst_lfo_control_source_class_init (GstLFOControlSourceClass * klass)
   g_object_class_install_property (gobject_class, PROP_FREQUENCY,
       g_param_spec_double ("frequency", "Frequency",
           "Frequency of the waveform", 0.0, G_MAXDOUBLE, 1.0,
-          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+          G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
 
   /**
    * GstLFOControlSource:timeshift
@@ -657,7 +596,7 @@ gst_lfo_control_source_class_init (GstLFOControlSourceClass * klass)
   g_object_class_install_property (gobject_class, PROP_TIMESHIFT,
       g_param_spec_uint64 ("timeshift", "Timeshift",
           "Timeshift of the waveform to the right", 0, G_MAXUINT64, 0,
-          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+          G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
 
   /**
    * GstLFOControlSource:amplitude
@@ -666,8 +605,8 @@ gst_lfo_control_source_class_init (GstLFOControlSourceClass * klass)
    */
   g_object_class_install_property (gobject_class, PROP_AMPLITUDE,
       g_param_spec_double ("amplitude", "Amplitude",
-          "Amplitude of the waveform", 0.0, G_MAXDOUBLE, 1.0,
-          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+          "Amplitude of the waveform", 0.0, 1.0, 1.0,
+          G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
 
   /**
    * GstLFOControlSource:offset
@@ -676,5 +615,6 @@ gst_lfo_control_source_class_init (GstLFOControlSourceClass * klass)
    */
   g_object_class_install_property (gobject_class, PROP_OFFSET,
       g_param_spec_double ("offset", "Offset", "Offset of the waveform",
-          0.0, G_MAXDOUBLE, 1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+          0.0, 1.0, 1.0,
+          G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
 }
index b2b3d40..2c03e15 100644 (file)
@@ -6,6 +6,7 @@
  * Needs gnuplot for plotting.
  * plot "ctrl_i1.dat" using 1:2 with points title 'none', "" using 1:3 with points title 'linear', "" using 1:4 with points title 'cubic', "ctrl_i2.dat" using 1:2 with lines title 'none', "" using 1:3 with lines title 'linear', "" using 1:4 with lines title 'cubic'
  * plot "ctrl_l1.dat" using 1:2 with points title 'sine', "" using 1:3 with points title 'saw', "" using 1:4 with points title 'square', "" using 1:5 with points title 'triangle', "ctrl_l2.dat" using 1:2 with lines title 'sine', "" using 1:3 with lines title 'saw', "" using 1:4 with lines title 'square', "" using 1:5 with lines title 'triangle'
+ * plot "ctrl_cl1.dat" using 1:2 with points title 'sine', "ctrl_cl2.dat" using 1:2 with lines title 'sine'
  */
 
 #include <stdio.h>
@@ -344,6 +345,7 @@ test_lfo (void)
   g_free (v1);
   g_free (v2);
   g_free (v3);
+  g_free (v4);
 
   fclose (f);
 
@@ -351,6 +353,76 @@ test_lfo (void)
   gst_object_unref (e);
 }
 
+static void
+test_chained_lfo (void)
+{
+  GstObject *e;
+  GstLFOControlSource *lfocs1, *lfocs2;
+  GstControlSource *cs1, *cs2;
+  gint t, i1;
+  GValue *v1;
+  gint n_values;
+  FILE *f;
+
+  e = (GstObject *) gst_element_factory_make ("testobj", NULL);
+
+  lfocs1 = gst_lfo_control_source_new ();
+  cs1 = (GstControlSource *) lfocs1;
+
+  gst_object_set_control_source (e, "int", cs1);
+
+  g_object_set (lfocs1,
+      "waveform", GST_LFO_WAVEFORM_SINE,
+      "frequency", (gdouble) 0.05,
+      "timeshift", (GstClockTime) 0, "offset", (gdouble) 0.5, NULL);
+
+  lfocs2 = gst_lfo_control_source_new ();
+  cs2 = (GstControlSource *) lfocs2;
+
+  gst_object_set_control_source ((GstObject *) lfocs1, "amplitude", cs2);
+
+  g_object_set (lfocs2,
+      "waveform", GST_LFO_WAVEFORM_SINE,
+      "frequency", (gdouble) 0.05,
+      "timeshift", (GstClockTime) 0,
+      "amplitude", (gdouble) 0.5, "offset", (gdouble) 0.5, NULL);
+
+  /* test single values */
+  if (!(f = fopen ("ctrl_cl1.dat", "w")))
+    exit (-1);
+  fprintf (f, "# Time Sine\n");
+
+  for (t = 0; t < 40; t++) {
+    gst_object_sync_values (e, t * GST_SECOND);
+    i1 = GST_TEST_OBJ (e)->val_int;
+
+    fprintf (f, "%4.1f %d\n", (gfloat) t, i1);
+  }
+
+  fclose (f);
+
+  /* test value arrays */
+  if (!(f = fopen ("ctrl_cl2.dat", "w")))
+    exit (-1);
+  fprintf (f, "# Time Sine\n");
+  n_values = 40 * 10;
+
+  v1 = g_new0 (GValue, n_values);
+  gst_object_get_value_array (e, "int", 0, GST_SECOND / 10, n_values, v1);
+
+  for (t = 0; t < n_values; t++) {
+    i1 = g_value_get_int (&v1[t]);
+    fprintf (f, "%4.1f %d\n", (gfloat) t / 10.0, i1);
+    g_value_unset (&v1[t]);
+  }
+  g_free (v1);
+
+  fclose (f);
+
+  gst_object_unref (lfocs1);
+  gst_object_unref (lfocs2);
+  gst_object_unref (e);
+}
 
 gint
 main (gint argc, gchar ** argv)
@@ -362,5 +434,7 @@ main (gint argc, gchar ** argv)
   test_interpolation ();
   test_lfo ();
 
+  test_chained_lfo ();
+
   return 0;
 }