[beast: 5/7] BSE: replace old procedure with Server::sample_file_info()



commit b7ef3abeaa0ef1cb114ca71c5e64f6c080f48a1b
Author: Tim Janik <timj gnu org>
Date:   Wed Nov 4 20:07:02 2015 +0100

    BSE: replace old procedure with Server::sample_file_info()
    
    Signed-off-by: Tim Janik <timj gnu org>

 beast-gtk/bsttreestores.cc |   29 ++++++++++++-------------
 bse/bseapi.idl             |   18 +++++++++++++--
 bse/bsebasics.idl          |    8 -------
 bse/bseserver.cc           |   25 ++++++++++++++++++++++
 bse/bseserver.hh           |    1 +
 bse/bsewaverepo.proc       |   50 --------------------------------------------
 6 files changed, 55 insertions(+), 76 deletions(-)
---
diff --git a/beast-gtk/bsttreestores.cc b/beast-gtk/bsttreestores.cc
index 4940e38..dee5c60 100644
--- a/beast-gtk/bsttreestores.cc
+++ b/beast-gtk/bsttreestores.cc
@@ -60,17 +60,16 @@ file_store_idle_handler (gpointer data)
       GtkTreePath *path = gtk_tree_path_new_from_indices (n_completed, -1);
       const gchar *filename = NULL;
       GtkTreeIter iter;
-      BseSampleFileInfo *info;
-      const gchar *loader, *name = NULL;
+      String loader, name;
       gchar *nstr = NULL;
       gtk_tree_model_get_iter (model, &iter, path);
       gtk_tree_path_free (path);
       gtk_tree_model_get (model, &iter,
                           BST_FILE_STORE_COL_FILE, &filename,
                           -1);
-      info = bse_sample_file_info (filename);
+      Bse::SampleFileInfo info = bse_server.sample_file_info (filename);
       const gchar *dsep = strrchr (filename, G_DIR_SEPARATOR);
-      if (info->error == Bse::ERROR_FILE_IS_DIR)
+      if (info.error == Bse::ERROR_FILE_IS_DIR)
         {
           loader = "Directory";
           name = dsep ? dsep + 1 : filename;    /* fallback wave name */
@@ -78,9 +77,9 @@ file_store_idle_handler (gpointer data)
       else
         {
           name = dsep ? dsep + 1 : filename;    /* fallback wave name */
-          loader = info->error ? Bse::error_blurb (Bse::ErrorType (info->error)) : info->loader;
+          loader = info.error ? Bse::error_blurb (info.error) : info.loader;
           guint l = strlen (filename);
-          if (info->error == Bse::ERROR_FORMAT_UNKNOWN &&
+          if (info.error == Bse::ERROR_FORMAT_UNKNOWN &&
               l >= 4 && strcasecmp (filename + l - 4, ".bse") == 0)
             {
               nstr = bst_file_scan_find_key (filename, "container-child", NULL);
@@ -91,21 +90,21 @@ file_store_idle_handler (gpointer data)
                     {
                       name = col + 1;
                       loader = "BSE Project";
-                      info->error = 0;
+                      info.error = Bse::ErrorType (0);
                     }
                 }
             }
         }
-      if (info->waves->n_strings)
-        name = info->waves->strings[0];
-      gchar *tstr = sfi_time_to_string (info->mtime);
+      if (info.waves.size())
+        name = info.waves[0];
+      gchar *tstr = sfi_time_to_string (info.mtime);
       gtk_tree_store_set (store, &iter,
-                          BST_FILE_STORE_COL_WAVE_NAME, name,   /* real wave name */
-                          BST_FILE_STORE_COL_SIZE, (guint) info->size,
-                          BST_FILE_STORE_COL_TIME_USECS, info->mtime,
+                          BST_FILE_STORE_COL_WAVE_NAME, name.c_str(),   /* real wave name */
+                          BST_FILE_STORE_COL_SIZE, size_t (info.size),
+                          BST_FILE_STORE_COL_TIME_USECS, info.mtime,
                           BST_FILE_STORE_COL_TIME_STR, tstr,
-                          BST_FILE_STORE_COL_LOADER, loader,
-                          BST_FILE_STORE_COL_LOADABLE, info->error == 0 && info->loader,
+                          BST_FILE_STORE_COL_LOADER, loader.c_str(),
+                          BST_FILE_STORE_COL_LOADABLE, info.error == 0 && !info.loader.empty(),
                           -1);
       g_free (tstr);
       g_free (nstr);
diff --git a/bse/bseapi.idl b/bse/bseapi.idl
index 583f820..39de56d 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -7,6 +7,7 @@
 namespace Bse {
 
 // == Type Constants ==
+Const MAXINT63   = +9223372036854775807;
 Const MAXINT32   = +4294967295;
 Const MAXINT31   = +2147483647;
 Const MININT31   = -2147483648;
@@ -604,6 +605,16 @@ interface Song : SNet {
   };
 };
 
+///< Structure containing meta data for multi wave samples.
+record SampleFileInfo {
+  String     file    = String ("Filename", "", STANDARD);
+  int64      size    = Range ("File Size", "File size in bytes", ":readwrite", 0, MAXINT63);
+  int64      mtime   = Range ("MTime", "Last modification time in µseconds", ":readwrite", 0, MAXINT63);
+  String     loader  = String ("Loader", "Sample loader implementation", STANDARD);
+  StringSeq  waves   = Sequence ("Waves", "List of embedded waves", STANDARD);
+  ErrorType  error   = Enum ("Error", "Indicator for errors during sample operation", STANDARD);
+};
+
 /// Interface for editable PCM wave samples.
 interface EditableSample : Item {
 };
@@ -704,9 +715,10 @@ 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.
+  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.
+  SampleFileInfo sample_file_info  (String file_name); ///< Load sample file info from file.
 };
 
 } // Bse
diff --git a/bse/bsebasics.idl b/bse/bsebasics.idl
index bdb43b9..2ef8905 100644
--- a/bse/bsebasics.idl
+++ b/bse/bsebasics.idl
@@ -391,14 +391,6 @@ record TrackPart {
 sequence TrackPartSeq {
   TrackPart tparts;
 };
-record SampleFileInfo {
-  SfiString     file    = SfiString ("Filename", "", "", STANDARD);
-  Int           size    = SfiInt ("File Size", "", 0, 0, G_MAXINT, 0, STANDARD);
-  Num           mtime   = SfiNum ("Modification Time", "", 0, 0, SFI_MAXNUM, 0, STANDARD);
-  SfiString     loader  = SfiString ("Loader", "", "", STANDARD);
-  Str1ngSeq     waves   = SfiSeq ("", "", STANDARD);
-  Int           error   = SfiInt ("BseErrorType", "", 0, 0, G_MAXINT, 0, STANDARD); // FIXME: use 
BseErrorType here
-};
 interface Janitor;
 
 // == BSE Global Config ==
diff --git a/bse/bseserver.cc b/bse/bseserver.cc
index 98c5a4d..d34ff3d 100644
--- a/bse/bseserver.cc
+++ b/bse/bseserver.cc
@@ -18,6 +18,7 @@
 #include "bseladspa.hh"
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
@@ -1546,4 +1547,28 @@ ServerImpl::module_type_icon (const String &module_type)
   return Icon();
 }
 
+SampleFileInfo
+ServerImpl::sample_file_info (const String &filename)
+{
+  SampleFileInfo info;
+  info.file = filename;
+  struct stat sbuf = { 0, };
+  if (stat (filename.c_str(), &sbuf) < 0)
+    info.error = bse_error_from_errno (errno, Bse::ERROR_FILE_OPEN_FAILED);
+  else
+    {
+      info.size = sbuf.st_size;
+      info.mtime = sbuf.st_mtime * SFI_USEC_FACTOR;
+      BseWaveFileInfo *wfi = bse_wave_file_info_load (filename.c_str(), &info.error);
+      if (wfi)
+       {
+         for (size_t i = 0; i < wfi->n_waves; i++)
+           info.waves.push_back (wfi->waves[i].name);
+         info.loader = bse_wave_file_info_loader (wfi);
+          bse_wave_file_info_unref (wfi);
+        }
+    }
+  return info;
+}
+
 } // Bse
diff --git a/bse/bseserver.hh b/bse/bseserver.hh
index f29a55c..bc893a2 100644
--- a/bse/bseserver.hh
+++ b/bse/bseserver.hh
@@ -131,6 +131,7 @@ public:
   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;
+  virtual SampleFileInfo sample_file_info   (const String &filename) 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               ();
diff --git a/bse/bsewaverepo.proc b/bse/bsewaverepo.proc
index 0eb1f02..152835e 100644
--- a/bse/bsewaverepo.proc
+++ b/bse/bsewaverepo.proc
@@ -115,53 +115,3 @@ METHOD (BseWaveRepo, remove-wave) {
 
   return Bse::ERROR_NONE;
 }
-
-PROCEDURE (bse-sample-file-info, "Sample File Info") {
-  HELP = "Load sample file info from file";
-  IN   = sfi_pspec_string ("file_name", "File Name", "The file to load info from",
-                           NULL, SFI_PARAM_STANDARD);
-  OUT   = bse_param_spec_boxed ("sample_file_info", NULL, NULL, BSE_TYPE_SAMPLE_FILE_INFO, 
SFI_PARAM_STANDARD);
-}
-BODY (BseProcedureClass *proc,
-      const GValue      *in_values,
-      GValue            *out_values)
-{
-  /* extract parameter values */
-  const char *filename = sfi_value_get_string (in_values++);
-  BseWaveFileInfo *wfi = NULL;
-  struct stat sbuf = { 0, };
-
-  /* check parameters */
-  if (!filename)
-    return Bse::ERROR_PROC_PARAM_INVAL;
-
-  /* construct info */
-  BseSampleFileInfo info = { 0, };
-  info.file = (char*) filename;
-  info.waves = bse_str1ng_seq_new ();
-  if (stat (filename, &sbuf) < 0)
-    info.error = bse_error_from_errno (errno, Bse::ERROR_FILE_OPEN_FAILED);
-  else
-    {
-      info.size = sbuf.st_size;
-      info.mtime = sbuf.st_mtime * SFI_USEC_FACTOR;
-      wfi = bse_wave_file_info_load (filename, (Bse::ErrorType*) &info.error);
-      if (wfi)
-       {
-         guint i;
-         for (i = 0; i < wfi->n_waves; i++)
-           bse_str1ng_seq_append (info.waves, wfi->waves[i].name);
-         info.loader = (gchar*) bse_wave_file_info_loader (wfi);
-       }
-    }
-
-  /* set output parameters */
-  bse_value_set_boxed (out_values++, &info);
-
-  /* cleanup */
-  bse_str1ng_seq_free (info.waves);
-  if (wfi)
-    bse_wave_file_info_unref (wfi);
-
-  return Bse::ERROR_NONE;
-}


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