[beast: 2/6] BST: Make use of Source.request_probes() and Source.get_mix_freq()



commit 9a6cec6e66bda54cde74deb5877f4fe54f33a74e
Author: Tim Janik <timj gnu org>
Date:   Tue Oct 3 00:37:31 2017 +0200

    BST: Make use of Source.request_probes() and Source.get_mix_freq()
    
    Signed-off-by: Tim Janik <timj gnu org>

 beast-gtk/bstbuseditor.cc    |   36 +++++++++-------------
 beast-gtk/bstbuseditor.hh    |    1 +
 beast-gtk/bstscrollgraph.cc  |   46 +++++++++++++---------------
 beast-gtk/bstscrollgraph.hh  |    1 +
 beast-gtk/bstsnifferscope.cc |   67 ++++++++++++++++-------------------------
 beast-gtk/bstsnifferscope.hh |    1 +
 6 files changed, 65 insertions(+), 87 deletions(-)
---
diff --git a/beast-gtk/bstbuseditor.cc b/beast-gtk/bstbuseditor.cc
index 213797f..d5eb613 100644
--- a/beast-gtk/bstbuseditor.cc
+++ b/beast-gtk/bstbuseditor.cc
@@ -75,26 +75,20 @@ bus_editor_release_item (SfiProxy      item,
 }
 
 static void
-bus_probes_notify (SfiProxy     bus,
-                   SfiSeq      *sseq,
-                   gpointer     data)
+bus_probes_notify (BstBusEditor *self, const Bse::ProbeSeq &pseq)
 {
-  BstBusEditor *self = BST_BUS_EDITOR (data);
-  BseProbeSeq *pseq = bse_probe_seq_from_seq (sseq);
-  BseProbe *lprobe = NULL, *rprobe = NULL;
-  guint i;
-  for (i = 0; i < pseq->n_probes && (!lprobe || !rprobe); i++)
-    if (pseq->probes[i]->channel_id == 0)
-      lprobe = pseq->probes[i];
-    else if (pseq->probes[i]->channel_id == 1)
-      rprobe = pseq->probes[i];
-  if (self->lbeam && lprobe && lprobe->probe_features->probe_energie)
+  const Bse::Probe *lprobe = NULL, *rprobe = NULL;
+  for (size_t i = 0; i < pseq.size() && (!lprobe || !rprobe); i++)
+    if (pseq[i].channel == 0)
+      lprobe = &pseq[i];
+    else if (pseq[i].channel == 1)
+      rprobe = &pseq[i];
+  if (self->lbeam && lprobe && lprobe->probe_features.probe_energie)
     bst_db_beam_set_value (self->lbeam, lprobe->energie);
-  if (self->rbeam && rprobe && rprobe->probe_features->probe_energie)
+  if (self->rbeam && rprobe && rprobe->probe_features.probe_energie)
     bst_db_beam_set_value (self->rbeam, rprobe->energie);
   bst_source_queue_probe_request (self->item, 0, BST_SOURCE_PROBE_ENERGIE, 20.0);
   bst_source_queue_probe_request (self->item, 1, BST_SOURCE_PROBE_ENERGIE, 20.0);
-  bse_probe_seq_free (pseq);
 }
 
 static GtkWidget*
@@ -128,9 +122,8 @@ bst_bus_editor_set_bus (BstBusEditor *self,
     assert_return (BSE_IS_BUS (item));
   if (self->item)
     {
-      bse_proxy_disconnect (self->item,
-                            "any_signal::probes", bus_probes_notify, self,
-                            NULL);
+      Bse::SourceH source = Bse::SourceH::down_cast (bse_server.from_proxy (self->item));
+      source.sig_probes() -= self->probes_handler;
       bse_proxy_disconnect (self->item,
                             "any-signal", bus_editor_release_item, self,
                             NULL);
@@ -183,9 +176,10 @@ bst_bus_editor_set_bus (BstBusEditor *self,
       for (ring = self->params; ring; ring = sfi_ring_walk (ring, self->params))
         gxk_param_update ((GxkParam*) ring->data);
       /* setup scope */
-      bse_proxy_connect (self->item,
-                         "signal::probes", bus_probes_notify, self,
-                         NULL);
+      Bse::SourceH source = Bse::SourceH::down_cast (bse_server.from_proxy (self->item));
+      self->probes_handler = source.sig_probes() += [self] (const Bse::ProbeSeq &pseq) {
+        return bus_probes_notify (self, pseq);
+      };
       bst_source_queue_probe_request (self->item, 0, BST_SOURCE_PROBE_ENERGIE, 20.0);
       bst_source_queue_probe_request (self->item, 1, BST_SOURCE_PROBE_ENERGIE, 20.0);
     }
diff --git a/beast-gtk/bstbuseditor.hh b/beast-gtk/bstbuseditor.hh
index e4a363d..fa452fc 100644
--- a/beast-gtk/bstbuseditor.hh
+++ b/beast-gtk/bstbuseditor.hh
@@ -21,6 +21,7 @@ struct _BstBusEditor
 {
   GtkAlignment      parent_object;
   SfiProxy          item;
+  size_t            probes_handler = 0;
   SfiRing          *params;
   BstDBBeam        *lbeam, *rbeam;
 };
diff --git a/beast-gtk/bstscrollgraph.cc b/beast-gtk/bstscrollgraph.cc
index 95badaf..82bc8ba 100644
--- a/beast-gtk/bstscrollgraph.cc
+++ b/beast-gtk/bstscrollgraph.cc
@@ -384,48 +384,42 @@ bst_scrollgraph_clear (BstScrollgraph *self)
 }
 
 static void
-bst_scrollgraph_probes_notify (SfiProxy     source,
-                               SfiSeq      *sseq,
-                               gpointer     data)
+bst_scrollgraph_probes_notify (BstScrollgraph *self, const Bse::ProbeSeq &pseq)
 {
-  BstScrollgraph *self = BST_SCROLLGRAPH (data);
-  BseProbeSeq *pseq = bse_probe_seq_from_seq (sseq);
-  BseProbe *probe = NULL;
-  guint i;
-  for (i = 0; i < pseq->n_probes && !probe; i++)
-    if (uint (pseq->probes[i]->channel_id) == self->ochannel)
+  const Bse::Probe *probe = NULL;
+  for (size_t i = 0; i < pseq.size() && !probe; i++)
+    if (pseq[i].channel == int (self->ochannel))
       {
-        BseProbe *candidate = pseq->probes[i];
-        if (candidate->probe_features->probe_fft &&
-            candidate->fft_data->n_values == self->window_size)
-          probe = candidate;
+        const Bse::Probe &candidate = pseq[i];
+        if (candidate.probe_features.probe_fft &&
+            candidate.fft_data.size() == self->window_size)
+          probe = &candidate;
       }
   if (probe && probe->mix_freq != self->mix_freq && probe->mix_freq > 0)
     {
       self->mix_freq = probe->mix_freq;
       bst_scrollgraph_resize_values (self, self->direction);
     }
-  if (probe && probe->probe_features->probe_fft && probe->fft_data->n_values == self->window_size)
+  if (probe && probe->probe_features.probe_fft && probe->fft_data.size() == self->window_size)
     {
       gfloat *bar = BAR (self, self->n_bars - 1); /* update last bar */
-      BseFlo4tSeq *fft = probe->fft_data;
-      for (i = 0; i < MIN (self->n_points, FFTSZ2POINTS (fft->n_values)); i++)
+      const Bse::FloatSeq &fft = probe->fft_data;
+      for (size_t i = 0; i < MIN (self->n_points, FFTSZ2POINTS (fft.size())); i++)
         {
           gfloat re, im;
           if (i == 0)
-            re = fft->values[0], im = 0;
-          else if (i == fft->n_values / 2)
-            re = fft->values[1], im = 0;
+            re = fft[0], im = 0;
+          else if (i == fft.size() / 2)
+            re = fft[1], im = 0;
           else
-            re = fft->values[i * 2], im = fft->values[i * 2 + 1];
+            re = fft[i * 2], im = fft[i * 2 + 1];
           bar[i] = sqrt (re * re + im * im); // FIXME: speed up
         }
       bst_scrollgraph_scroll_bars (self); /* last bar becomes bar0 */
       if (GTK_WIDGET_DRAWABLE (self))
         bst_scrollgraph_draw_bar (self, 0);
     }
-  bse_probe_seq_free (pseq);
-  float mix_freq = bse_source_get_mix_freq (self->source.proxy_id());
+  float mix_freq = self->source.get_mix_freq();
   bst_source_queue_probe_request (self->source.proxy_id(), self->ochannel, BST_SOURCE_PROBE_FFT, mix_freq / 
self->window_size);
 }
 
@@ -457,9 +451,9 @@ bst_scrollgraph_set_source (BstScrollgraph *self, Bse::SourceH source, uint ocha
   assert_return (BST_IS_SCROLLGRAPH (self));
   if (self->source)
     {
+      self->source.sig_probes() -= self->probes_handler;
       bse_proxy_disconnect (self->source.proxy_id(),
                             "any-signal", bst_scrollgraph_release_item, self,
-                            "any-signal", bst_scrollgraph_probes_notify, self,
                             "any-signal", bst_scrollgraph_io_changed, self,
                             NULL);
     }
@@ -468,12 +462,14 @@ bst_scrollgraph_set_source (BstScrollgraph *self, Bse::SourceH source, uint ocha
   if (self->source)
     {
       /* setup scope */
+      self->probes_handler = self->source.sig_probes() += [self] (const Bse::ProbeSeq &pseq) {
+        return bst_scrollgraph_probes_notify (self, pseq);
+      };
       bse_proxy_connect (self->source.proxy_id(),
                          "signal::release", bst_scrollgraph_release_item, self,
-                         "signal::probes", bst_scrollgraph_probes_notify, self,
                          "swapped-signal::io_changed", bst_scrollgraph_io_changed, self,
                          NULL);
-      float mix_freq = bse_source_get_mix_freq (self->source.proxy_id());
+      float mix_freq = self->source.get_mix_freq();
       bst_source_queue_probe_request (self->source.proxy_id(), self->ochannel, BST_SOURCE_PROBE_FFT, 
mix_freq / self->window_size);
       bst_scrollgraph_io_changed (self);
     }
diff --git a/beast-gtk/bstscrollgraph.hh b/beast-gtk/bstscrollgraph.hh
index 33605a5..46f0fc4 100644
--- a/beast-gtk/bstscrollgraph.hh
+++ b/beast-gtk/bstscrollgraph.hh
@@ -31,6 +31,7 @@ struct _BstScrollgraph
   GdkPixbuf      *pixbuf;     /* n_points wide or high */
   GdkWindow      *canvas;
   Bse::SourceH    source;
+  size_t          probes_handler = 0;
   guint           ochannel;
 };
 struct _BstScrollgraphClass
diff --git a/beast-gtk/bstsnifferscope.cc b/beast-gtk/bstsnifferscope.cc
index 6cc9037..d09bac0 100644
--- a/beast-gtk/bstsnifferscope.cc
+++ b/beast-gtk/bstsnifferscope.cc
@@ -212,22 +212,17 @@ sniffer_scope_shift (BstSnifferScope *self)
 }
 
 static void
-scope_probes_notify (SfiProxy     proxy,
-                     SfiSeq      *sseq,
-                     gpointer     data)
+scope_probes_notify (BstSnifferScope *self, const Bse::ProbeSeq &pseq)
 {
-  BstSnifferScope *self = BST_SNIFFER_SCOPE (data);
   if (GTK_WIDGET_DRAWABLE (self))
     {
-      BseProbeSeq *pseq = bse_probe_seq_from_seq (sseq);
-      BseProbe *lprobe = NULL, *rprobe = NULL;
-      guint i;
-      for (i = 0; i < pseq->n_probes && (!lprobe || !rprobe); i++)
-        if (pseq->probes[i]->channel_id == 0)
-          lprobe = pseq->probes[i];
-        else if (pseq->probes[i]->channel_id == 1)
-          rprobe = pseq->probes[i];
-      if (lprobe && lprobe->probe_features->probe_range && rprobe && rprobe->probe_features->probe_range)
+      const Bse::Probe *lprobe = NULL, *rprobe = NULL;
+      for (size_t i = 0; i < pseq.size() && (!lprobe || !rprobe); i++)
+        if (pseq[i].channel == 0)
+          lprobe = &pseq[i];
+        else if (pseq[i].channel == 1)
+          rprobe = &pseq[i];
+      if (lprobe && lprobe->probe_features.probe_range && rprobe && rprobe->probe_features.probe_range)
         {
           sniffer_scope_shift (self);
           self->lvalues[0] = MAX (ABS (lprobe->min), ABS (lprobe->max));
@@ -238,7 +233,6 @@ scope_probes_notify (SfiProxy     proxy,
           sniffer_scope_rregion (self, &x, &width);
           sniffer_scope_draw_bar (self, x, self->rvalues[0]);
         }
-      bse_probe_seq_free (pseq);
     }
   bst_source_queue_probe_request (self->source.proxy_id(), 0, BST_SOURCE_PROBE_RANGE, 20.0);
   bst_source_queue_probe_request (self->source.proxy_id(), 1, BST_SOURCE_PROBE_RANGE, 20.0);
@@ -271,34 +265,28 @@ bst_sniffer_scope_set_sniffer (BstSnifferScope *self, Bse::SourceH source)
         source = Bse::SourceH();
     }
   if (self->source)
-    {
-      bse_proxy_disconnect (self->source.proxy_id(),
-                            "any_signal::probes", scope_probes_notify, self,
-                            NULL);
-    }
+    self->source.sig_probes() -= self->probes_handler;
   self->source = source;
   if (self->source)
     {
-      bse_proxy_connect (self->source.proxy_id(),
-                         "signal::probes", scope_probes_notify, self,
-                         NULL);
+      self->probes_handler = self->source.sig_probes() += [self] (const Bse::ProbeSeq &pseq) {
+        return scope_probes_notify (self, pseq);
+      };
       bst_source_queue_probe_request (self->source.proxy_id(), 0, BST_SOURCE_PROBE_RANGE, 20.0);
       bst_source_queue_probe_request (self->source.proxy_id(), 1, BST_SOURCE_PROBE_RANGE, 20.0);
     }
 }
 
-static BseProbeRequestSeq *probe_request_seq = NULL;
+static Bse::ProbeRequestSeq probe_request_seq;
+
 static gboolean
 source_probe_idle_request (gpointer data)
 {
   GDK_THREADS_ENTER ();
-  BseProbeRequestSeq *prs = probe_request_seq;
-  probe_request_seq = NULL;
-  if (prs)
-    {
-      bse_source_mass_request (prs);
-      bse_probe_request_seq_free (prs);
-    }
+  Bse::ProbeRequestSeq prs;
+  prs.swap (probe_request_seq);
+  if (prs.size())
+    Bse::SourceH::down_cast (prs[0].source).request_probes (prs);
   GDK_THREADS_LEAVE ();
   return FALSE;
 }
@@ -309,22 +297,19 @@ bst_source_queue_probe_request (SfiProxy              source,
                                 BstSourceProbeFeature pfeature,
                                 gfloat                frequency)
 {
-  BseProbeFeatures features = { 0, };
+  Bse::ProbeFeatures features;
   features.probe_range = 0 != (pfeature & BST_SOURCE_PROBE_RANGE);
   features.probe_energie = 0 != (pfeature & BST_SOURCE_PROBE_ENERGIE);
   features.probe_samples = 0 != (pfeature & BST_SOURCE_PROBE_SAMPLES);
   features.probe_fft = 0 != (pfeature & BST_SOURCE_PROBE_FFT);
-  BseProbeRequest request = { 0, };
-  request.source = source;
-  request.channel_id = ochannel_id;
-  request.probe_features = &features;
+  Bse::ProbeRequest request;
+  request.source = Bse::SourceH::down_cast (bse_server.from_proxy (source));
+  request.channel = ochannel_id;
+  request.probe_features = features;
   request.frequency = frequency;
   if (BST_GCONFIG (slow_scopes) && !(features.probe_samples || features.probe_fft))
     request.frequency = MIN (request.frequency, 4);
-  if (!probe_request_seq)
-    {
-      g_idle_add_full (G_PRIORITY_LOW + 5, source_probe_idle_request, NULL, NULL);  // GTK_PRIORITY_REDRAW + 
5
-      probe_request_seq = bse_probe_request_seq_new();
-    }
-  bse_probe_request_seq_append (probe_request_seq, &request);
+  if (probe_request_seq.size() == 0)
+    g_idle_add_full (G_PRIORITY_LOW + 5, source_probe_idle_request, NULL, NULL);  // GTK_PRIORITY_REDRAW + 5
+  probe_request_seq.push_back (std::move (request));
 }
diff --git a/beast-gtk/bstsnifferscope.hh b/beast-gtk/bstsnifferscope.hh
index 1597758..c2f7c70 100644
--- a/beast-gtk/bstsnifferscope.hh
+++ b/beast-gtk/bstsnifferscope.hh
@@ -16,6 +16,7 @@
 typedef struct {
   GtkWidget    parent_instance;
   Bse::SourceH source;
+  size_t       probes_handler;
   guint        n_values;
   float       *lvalues;
   float       *rvalues;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]