[beast: 3/7] BSE: implement list_module_types, find_module_type, module_type_icon on ServerImpl



commit 06912a0c92e6bc3778c41d44586d5699572a6671
Author: Tim Janik <timj gnu org>
Date:   Fri Sep 25 15:10:12 2015 +0200

    BSE: implement list_module_types, find_module_type, module_type_icon on ServerImpl

 bse/bseapi.idl       |   19 +++++++++++++
 bse/bsecategories.cc |   21 ++++++++++++++-
 bse/bseserver.cc     |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++
 bse/bseserver.hh     |    8 ++++-
 4 files changed, 116 insertions(+), 3 deletions(-)
---
diff --git a/bse/bseapi.idl b/bse/bseapi.idl
index 2571420..583f820 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -295,6 +295,11 @@ Const NOTEHINTS     = STANDARD ":note";
 Const FINETUNEHINTS = STANDARD ":finetune";
 Const VELOCITYHINTS = STANDARD ":velocity";
 
+/// Stringeq - a variable length list of test strings.
+sequence StringSeq {
+  String string;
+};
+
 /// Representation of an image pixel sequence in ARGB format.
 sequence PixelSeq {
   int32 argb = Num ("ARGB", "ARGB Format: (alpha << 24) | (red << 16) | (green << 8) | blue", STANDARD);
@@ -307,6 +312,17 @@ record Icon {
   PixelSeq pixels = Sequence ("Pixels", "Array of width*height ARGB pixels", STANDARD);
 };
 
+/// AuxData - record to describe entity attributes with "key=value" strings.
+record AuxData {
+  String    entity;             ///< Entity that has an auxillary data list.
+  StringSeq attributes;         ///< List of "key=value" auxillary data strings.
+};
+
+/// AuxDataSeq - a variable length list of AuxData records.
+sequence AuxDataSeq {
+  AuxData aux_data;
+};
+
 /// Object to carry out IDL, API, signal, etc tests.
 interface TestObject {
   int32         echo_test       (String msg);   ///< Echo custom message to stdout.
@@ -688,6 +704,9 @@ interface Server : Object {
   void          start_recording (String wave_file, float64 n_seconds); ///< Start recording to a WAV file.
   Project       create_project (String project_name); ///< Create a new project (name is modified to be 
unique if necessary.
   void          destroy_project (Project project);    ///< Destroy a previously created new project.
+  AuxDataSeq  list_module_types ();                   ///< A list of Source type names for create_source().
+  AuxData     find_module_type  (String module_type); ///< Retrieve info about a Source type names.
+  Icon        module_type_icon  (String module_type); ///< Retrieve the icon associated with a module type.
 };
 
 } // Bse
diff --git a/bse/bsecategories.cc b/bse/bsecategories.cc
index 68338d4..79984b5 100644
--- a/bse/bsecategories.cc
+++ b/bse/bsecategories.cc
@@ -1,7 +1,7 @@
 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
 #include "bsecategories.hh"
-
 #include "bseutils.hh"
+#include "bseserver.hh"
 #include <string.h>
 
 
@@ -192,6 +192,25 @@ bse_categories_register (const gchar  *category,
       else
         centry->icon = NULL;
     }
+  if (g_type_is_a (centry->type, BSE_TYPE_SOURCE))
+    {
+      // parse "/Modules////tag1/tag2/tag3///Title" into tags and title
+      const char *name = i18n_category;
+      if (strncmp (name, "/Modules/", 9) == 0)
+        name += 9;
+      while (name[0] == '/')
+        ++name;
+      const char *title = strrchr (name, '/'), *end = title ? title : name;
+      title = title ? title + 1 : name;
+      while (end > name && end[-1] == '/')
+        --end;
+      Rapicorn::StringVector tags;
+      if (name < end)
+        tags = Rapicorn::string_split (String (name, end - name), "/");
+      Bse::ServerImpl::register_source_module (g_type_name (centry->type), title,
+                                               Rapicorn::string_join (";", tags),
+                                               pixstream);
+    }
 }
 
 void
diff --git a/bse/bseserver.cc b/bse/bseserver.cc
index 744e0c8..98c5a4d 100644
--- a/bse/bseserver.cc
+++ b/bse/bseserver.cc
@@ -1475,4 +1475,75 @@ ServerImpl::destroy_project (ProjectIface &project_iface)
     critical ("%s: project not found", __func__);
 }
 
+struct AuxDataAndIcon : AuxData {
+  Icon icon;
+};
+
+static std::vector<AuxDataAndIcon> registered_module_types;
+
+/// Register a synthesis module type at program startup.
+void
+ServerImpl::register_source_module (const String &type, const String &title, const String &tags, const uint8 
*pixstream)
+{
+  assert_return (type.empty() == false);
+  registered_module_types.push_back (AuxDataAndIcon());
+  AuxDataAndIcon &ad = registered_module_types.back();
+  ad.entity = type;
+  if (!title.empty())
+    ad.attributes.push_back ("title=" + title);
+  if (!tags.empty())
+    ad.attributes.push_back ("tags=" + tags);
+  if (pixstream)
+    ad.icon = icon_from_pixstream (pixstream);
+  GType gtypeid = g_type_from_name (type.c_str());
+  if (gtypeid)
+    {
+      const char *txt;
+      txt = bse_type_get_blurb (gtypeid);
+      if (txt)
+        ad.attributes.push_back ("blurb=" + String (txt));
+      txt = bse_type_get_authors (gtypeid);
+      if (txt)
+        ad.attributes.push_back ("authors=" + String (txt));
+      txt = bse_type_get_license (gtypeid);
+      if (txt)
+        ad.attributes.push_back ("license=" + String (txt));
+      txt = bse_type_get_options (gtypeid);
+      if (txt)
+        ad.attributes.push_back ("hints=" + String (txt));
+    }
+  if (0)
+    printerr ("%s\n  %s\n  tags=%s\n  icon=...%s\n",
+              type,
+              title,
+              Rapicorn::string_join (", ", Rapicorn::string_split_any (tags, ":;")),
+              ad.icon.width && ad.icon.height ? string_format ("%ux%u", ad.icon.width, ad.icon.height) : 
"0");
+}
+
+AuxDataSeq
+ServerImpl::list_module_types ()
+{
+  AuxDataSeq ads;
+  ads.insert (ads.end(), registered_module_types.begin(), registered_module_types.end());
+  return ads;
+}
+
+AuxData
+ServerImpl::find_module_type (const String &module_type)
+{
+  for (const auto &ad : registered_module_types)
+    if (ad.entity == module_type)
+      return ad;
+  return AuxData();
+}
+
+Icon
+ServerImpl::module_type_icon (const String &module_type)
+{
+  for (const AuxDataAndIcon &ad : registered_module_types)
+    if (ad.entity == module_type)
+      return ad.icon;
+  return Icon();
+}
+
 } // Bse
diff --git a/bse/bseserver.hh b/bse/bseserver.hh
index 7226a50..f29a55c 100644
--- a/bse/bseserver.hh
+++ b/bse/bseserver.hh
@@ -128,8 +128,12 @@ public:
   virtual bool   can_load                (const String &file_name) override;
   virtual ProjectIfaceP create_project   (const String &project_name) override;
   virtual void          destroy_project  (ProjectIface &project) override;
-  void                  send_user_message   (const UserMessage &umsg);
-  static ServerImpl&    instance            ();
+  virtual AuxDataSeq list_module_types      () override;
+  virtual AuxData    find_module_type       (const String &module_type) override;
+  virtual Icon       module_type_icon       (const String &module_type) override;
+  void               send_user_message      (const UserMessage &umsg);
+  static void        register_source_module (const String &type, const String &title, const String &tags, 
const uint8 *pixstream);
+  static ServerImpl& instance               ();
 };
 
 } // Bse


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