[beast: 5/9] BST: make use of Bse::PropertyCandidates and convert where neccessary



commit be1b99bd813e06e1d65a7d982f3e5e860765cc2f
Author: Tim Janik <timj gnu org>
Date:   Fri Sep 29 00:58:27 2017 +0200

    BST: make use of Bse::PropertyCandidates and convert where neccessary
    
    Signed-off-by: Tim Janik <timj gnu org>

 beast-gtk/bstparam-item-seq.cc |   22 +++++++-----
 beast-gtk/bstparam.cc          |    1 +
 beast-gtk/bsttrackview.cc      |   73 ++++++++++++++++++++++++----------------
 3 files changed, 58 insertions(+), 38 deletions(-)
---
diff --git a/beast-gtk/bstparam-item-seq.cc b/beast-gtk/bstparam-item-seq.cc
index bdb7d66..e8affbe 100644
--- a/beast-gtk/bstparam-item-seq.cc
+++ b/beast-gtk/bstparam-item-seq.cc
@@ -29,11 +29,13 @@ param_item_seq_popup_editor (GtkWidget *widget,
       Bse::PropertyCandidates pc = item.get_property_candidates (param->pspec->name);
       SfiSeq *seq = (SfiSeq*) g_value_get_boxed (&param->value);
       BseIt3mSeq *iseq = bse_it3m_seq_from_seq (seq);
+      BseIt3mSeq *pc_items = bst_it3m_seq_from_item_seq (pc.items);
       bst_item_seq_dialog_popup (widget, proxy,
-                                 pc.label.c_str(), pc.tooltip.c_str(), pc.items,
+                                 pc.label.c_str(), pc.tooltip.c_str(), pc_items,
                                  g_param_spec_get_nick (param->pspec), g_param_spec_get_blurb 
(param->pspec), iseq,
                                  param_item_seq_changed,
                                  param, NULL);
+      bse_it3m_seq_free (pc_items);
       bse_it3m_seq_free (iseq);
     }
 }
@@ -86,7 +88,8 @@ param_item_seq_update (GxkParam  *param,
   gchar *content = NULL;
   if (proxy)
     {
-      BsePropertyCandidates *pc = bse_item_get_property_candidates (proxy, param->pspec->name);
+      Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (proxy));
+      Bse::PropertyCandidates pc = item.get_property_candidates (param->pspec->name);
       SfiSeq *seq = (SfiSeq*) g_value_get_boxed (&param->value);
       BseIt3mSeq *iseq = seq ? bse_it3m_seq_from_seq (seq) : NULL;
       if (iseq)
@@ -96,28 +99,29 @@ param_item_seq_update (GxkParam  *param,
               Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (iseq->items[0]));
               content = g_strdup (item.get_name_or_type().c_str());
             }
-          else if (iseq->n_items > 1 && (!pc->partitions || pc->partitions->n_types == 0))
+          else if (iseq->n_items > 1 && pc.partitions.empty())
             content = g_strdup_format ("#%u", iseq->n_items);
           else if (iseq->n_items > 1) /* && partitions->n_types */
             {
-              guint i, j, other = 0, *partitions = g_newa (guint, pc->partitions->n_types);
-              memset (partitions, 0, pc->partitions->n_types * sizeof (partitions[0]));
+              guint i, other = 0, *partitions = g_newa (guint, pc.partitions.size());
+              memset (partitions, 0, pc.partitions.size() * sizeof (guint));
               for (i = 0; i < iseq->n_items; i++)
                 {
-                  for (j = 0; j < pc->partitions->n_types; j++)
+                  size_t j;
+                  for (j = 0; j < pc.partitions.size(); j++)
                     {
                       Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (iseq->items[i]));
-                      if (item.check_is_a (pc->partitions->types[j]))
+                      if (item.check_is_a (pc.partitions[j]))
                         {
                           partitions[j]++;
                           break;
                         }
                     }
-                  if (j >= pc->partitions->n_types)
+                  if (j >= pc.partitions.size())
                     other++;
                 }
               GString *gstring = g_string_new ("");
-              for (j = 0; j < pc->partitions->n_types; j++)
+              for (size_t j = 0; j < pc.partitions.size(); j++)
                 g_string_append_printf (gstring, "%s#%u", j ? " & " : "", partitions[j]);
               if (other)
                 g_string_append_printf (gstring, " & #%u", other);
diff --git a/beast-gtk/bstparam.cc b/beast-gtk/bstparam.cc
index 60e2840..cfa9fe6 100644
--- a/beast-gtk/bstparam.cc
+++ b/beast-gtk/bstparam.cc
@@ -1,6 +1,7 @@
 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
 #include "bstparam.hh"
 #include "bstxframe.hh"
+#include "bstbseutils.hh"
 
 
 /* --- prototypes --- */
diff --git a/beast-gtk/bsttrackview.cc b/beast-gtk/bsttrackview.cc
index 7816f74..1abe655 100644
--- a/beast-gtk/bsttrackview.cc
+++ b/beast-gtk/bsttrackview.cc
@@ -210,32 +210,37 @@ track_view_synth_edited (BstTrackView *self,
   if (strpath)
     {
       gint row = gxk_tree_spath_index0 (strpath);
-      SfiProxy item = bst_item_view_get_proxy (BST_ITEM_VIEW (self), row);
+      SfiProxy itemid = bst_item_view_get_proxy (BST_ITEM_VIEW (self), row);
       if (text)
        {
          SfiProxy proxy = 0;
          GSList *slist = NULL;
+          Bse::PropertyCandidates pc;
          /* list possible snet/wave/sound_font_preset candidates */
-          BsePropertyCandidates *pc = bse_item_get_property_candidates (item, "snet");
-         slist = g_slist_append (slist, pc->items);
-          pc = bse_item_get_property_candidates (item, "wave");
-         slist = g_slist_append (slist, pc->items);
-         pc = bse_item_get_property_candidates (item, "sound_font_preset");
-          slist = g_slist_append (slist, pc->items);
+          Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (itemid));
+          pc = item.get_property_candidates ("snet");
+          auto snet_i3s = std::unique_ptr<BseIt3mSeq> (bst_it3m_seq_from_item_seq (pc.items));
+         slist = g_slist_append (slist, snet_i3s.get());
+          pc = item.get_property_candidates ("wave");
+          auto wave_i3s = std::unique_ptr<BseIt3mSeq> (bst_it3m_seq_from_item_seq (pc.items));
+         slist = g_slist_append (slist, wave_i3s.get());
+          pc = item.get_property_candidates ("sound_font_preset");
+          auto sfpr_i3s = std::unique_ptr<BseIt3mSeq> (bst_it3m_seq_from_item_seq (pc.items));
+          slist = g_slist_append (slist, sfpr_i3s.get());
          /* find best match */
          proxy = bst_item_seq_list_match (slist, text);
          g_slist_free (slist);
          if (proxy && BSE_IS_SNET (proxy))
-           bse_proxy_set (item, "snet", proxy, NULL);
+           bse_proxy_set (itemid, "snet", proxy, NULL);
          else if (proxy && BSE_IS_WAVE (proxy))
-           bse_proxy_set (item, "wave", proxy, NULL);
+           bse_proxy_set (itemid, "wave", proxy, NULL);
          else if (proxy && BSE_IS_SOUND_FONT_PRESET (proxy))
-           bse_proxy_set (item, "sound_font_preset", proxy, NULL);
+           bse_proxy_set (itemid, "sound_font_preset", proxy, NULL);
          else
-           bse_proxy_set (item, "snet", 0, "wave", 0, "sound_font_preset", 0, NULL);
+           bse_proxy_set (itemid, "snet", 0, "wave", 0, "sound_font_preset", 0, NULL);
        }
       else
-       bse_proxy_set (item, "snet", 0, "wave", 0, "sound_font_preset", 0, NULL);
+       bse_proxy_set (itemid, "snet", 0, "wave", 0, "sound_font_preset", 0, NULL);
     }
 }
 
@@ -249,24 +254,27 @@ track_view_post_synth_edited (BstTrackView *self,
   if (strpath)
     {
       gint row = gxk_tree_spath_index0 (strpath);
-      SfiProxy item = bst_item_view_get_proxy (BST_ITEM_VIEW (self), row);
+      SfiProxy itemid = bst_item_view_get_proxy (BST_ITEM_VIEW (self), row);
       if (text)
        {
          SfiProxy proxy = 0;
          GSList *slist = NULL;
          /* list possible snet candidates */
-          BsePropertyCandidates *pc = bse_item_get_property_candidates (item, "pnet");
-         slist = g_slist_append (slist, pc->items);
+
+          Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (itemid));
+          Bse::PropertyCandidates pc = item.get_property_candidates ("pnet");
+          auto snet_i3s = std::unique_ptr<BseIt3mSeq> (bst_it3m_seq_from_item_seq (pc.items));
+         slist = g_slist_append (slist, snet_i3s.get());
          /* find best match */
          proxy = bst_item_seq_list_match (slist, text);
          g_slist_free (slist);
          if (proxy && BSE_IS_SNET (proxy))
-           bse_proxy_set (item, "pnet", proxy, NULL);
+           bse_proxy_set (itemid, "pnet", proxy, NULL);
          else
-           bse_proxy_set (item, "pnet", 0, NULL);
+           bse_proxy_set (itemid, "pnet", 0, NULL);
        }
       else
-       bse_proxy_set (item, "pnet", 0, NULL);
+       bse_proxy_set (itemid, "pnet", 0, NULL);
     }
 }
 
@@ -311,11 +319,12 @@ track_view_synth_popup (BstTrackView         *self,
       Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (itemid));
       if (item.editable_property ("snet"))
         {
-          BsePropertyCandidates *pc = bse_item_get_property_candidates (itemid, "snet");
+          Bse::PropertyCandidates pc = item.get_property_candidates ("snet");
+          BseIt3mSeq *pc_items = bst_it3m_seq_from_item_seq (pc.items);
           SynthPopup sdata = { self, pcell, };
           Bse::ProjectH project = item.get_project();
           GtkWidget *dialog = bst_track_synth_dialog_popup (self, itemid,
-                                                            pc->label, pc->tooltip, pc->items,
+                                                            pc.label.c_str(), pc.tooltip.c_str(), pc_items,
                                                             _("Available Waves"),
                                                             _("List of available waves to choose a track 
instrument from"),
                                                             project.get_wave_repo().proxy_id(),
@@ -323,6 +332,7 @@ track_view_synth_popup (BstTrackView         *self,
                                                            _("List of available sound fonts to choose track 
instrument from"),
                                                            project.get_sound_font_repo().proxy_id(),
                                                             track_view_synth_popup_cb, g_memdup (&sdata, 
sizeof (sdata)), track_view_synth_popup_cleanup);
+          bse_it3m_seq_free (pc_items);
           gxk_cell_renderer_popup_dialog (pcell, dialog);
         }
       else
@@ -345,13 +355,15 @@ track_view_post_synth_popup (BstTrackView         *self,
       Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (itemid));
       if (item.editable_property ("pnet"))
         {
-          BsePropertyCandidates *pc = bse_item_get_property_candidates (itemid, "pnet");
+          Bse::PropertyCandidates pc = item.get_property_candidates ("pnet");
+          BseIt3mSeq *pc_items = bst_it3m_seq_from_item_seq (pc.items);
           SynthPopup sdata = { self, pcell, };
           GtkWidget *dialog = bst_track_synth_dialog_popup (self, itemid,
-                                                            pc->label, pc->tooltip, pc->items,
+                                                            pc.label.c_str(), pc.tooltip.c_str(), pc_items,
                                                             NULL, NULL, 0,
                                                            NULL, NULL, 0,
                                                             track_view_synth_popup_cb, g_memdup (&sdata, 
sizeof (sdata)), track_view_synth_popup_cleanup);
+          bse_it3m_seq_free (pc_items);
           gxk_cell_renderer_popup_dialog (pcell, dialog);
         }
       else
@@ -398,17 +410,20 @@ track_view_outputs_popup (BstTrackView         *self,
   if (strpath)
     {
       gint row = gxk_tree_spath_index0 (strpath);
-      SfiProxy item = bst_item_view_get_proxy (BST_ITEM_VIEW (self), row);
-      BsePropertyCandidates *pc = bse_item_get_property_candidates (item, "outputs");
-      GParamSpec *pspec = bse_proxy_get_pspec (item, "outputs");
-      const GValue *value = bse_proxy_get_property (item, "outputs");
+      SfiProxy itemid = bst_item_view_get_proxy (BST_ITEM_VIEW (self), row);
+      Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (itemid));
+      Bse::PropertyCandidates pc = item.get_property_candidates ("outputs");
+      GParamSpec *pspec = bse_proxy_get_pspec (item.proxy_id(), "outputs");
+      const GValue *value = bse_proxy_get_property (item.proxy_id(), "outputs");
       SfiSeq *seq = (SfiSeq*) g_value_get_boxed (value);
       BseIt3mSeq *iseq = bse_it3m_seq_from_seq (seq);
-      OutputsPopup odata = { self, pcell, item };
-      GtkWidget *dialog = bst_item_seq_dialog_popup (self, item,
-                                                     pc->label, pc->tooltip, pc->items,
+      OutputsPopup odata = { self, pcell, item.proxy_id() };
+      BseIt3mSeq *pc_items = bst_it3m_seq_from_item_seq (pc.items);
+      GtkWidget *dialog = bst_item_seq_dialog_popup (self, item.proxy_id(),
+                                                     pc.label.c_str(), pc.tooltip.c_str(), pc_items,
                                                      g_param_spec_get_nick (pspec), g_param_spec_get_blurb 
(pspec), iseq,
                                                      track_view_outputs_changed, g_memdup (&odata, sizeof 
(odata)), track_view_outputs_cleanup);
+      bse_it3m_seq_free (pc_items);
       bse_it3m_seq_free (iseq);
       gxk_cell_renderer_popup_dialog (pcell, dialog);
     }


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