[beast: 4/49] BSE: move ServerImpl::use_new_project() to bseapi.idl and remove bseserver.proc



commit 0c40cd026fdfe124efbdff78f18a196085e68f94
Author: Tim Janik <timj gnu org>
Date:   Sat Jun 20 03:42:54 2015 +0200

    BSE: move ServerImpl::use_new_project() to bseapi.idl and remove bseserver.proc

 HACKING.md                 |    2 +
 beast-gtk/bstapp.cc        |    4 +-
 beast-gtk/bstfiledialog.cc |    2 +-
 beast-gtk/bstmain.cc       |    6 ++--
 beast-gtk/bstplayback.cc   |    2 +-
 bse/Makefile.am            |    2 +-
 bse/bseapi.idl             |   10 +++---
 bse/bseserver.cc           |   20 ++++++++++++++
 bse/bseserver.hh           |    3 +-
 bse/bseserver.proc         |   61 --------------------------------------------
 10 files changed, 37 insertions(+), 75 deletions(-)
---
diff --git a/HACKING.md b/HACKING.md
index eaf3a96..e473f1f 100644
--- a/HACKING.md
+++ b/HACKING.md
@@ -65,6 +65,8 @@ Conversion between object handles works as follows:
   // In bse/
   BseServer *server = server_impl->as<BseObject*>();
   ServerImpl *server_impl = server->as<ServerImpl*>();
+  ServerIface *server_iface = server->as<ServerIface*>();
+  ServerIfaceP server_iface_p = shared_ptr_cast<ServerIface> (server_iface);
   // In beast-gtk/
   ServerIface *server_iface;
   ObjectIfaceP server_iface->from_proxy (proxyid);
diff --git a/beast-gtk/bstapp.cc b/beast-gtk/bstapp.cc
index 00b4125..e212ceb 100644
--- a/beast-gtk/bstapp.cc
+++ b/beast-gtk/bstapp.cc
@@ -708,7 +708,7 @@ demo_play_song (gpointer data,
                 size_t   callback_action)
 {
   const gchar *file_name = demo_entries[callback_action - BST_ACTION_LOAD_DEMO_0000].file;
-  SfiProxy project = bse_server_use_new_project (BSE_SERVER, file_name);
+  SfiProxy project = bse_server.use_new_project (file_name).proxy_id();
   BseErrorType error = bst_project_restore_from_file (project, file_name, TRUE, TRUE);
   if (error)
     bst_status_eprintf (error, _("Opening project `%s'"), file_name);
@@ -862,7 +862,7 @@ app_action_exec (gpointer data,
     case BST_ACTION_NEW_PROJECT:
       if (1)
         {
-          SfiProxy project = bse_server_use_new_project (BSE_SERVER, "Untitled.bse");
+          SfiProxy project = bse_server.use_new_project ("Untitled.bse").proxy_id();
           BstApp *new_app;
 
           bse_project_get_wave_repo (project);
diff --git a/beast-gtk/bstfiledialog.cc b/beast-gtk/bstfiledialog.cc
index 186c14f..ce29c6a 100644
--- a/beast-gtk/bstfiledialog.cc
+++ b/beast-gtk/bstfiledialog.cc
@@ -410,7 +410,7 @@ static gboolean
 bst_file_dialog_open_project (BstFileDialog *self,
                              const gchar   *file_name)
 {
-  SfiProxy project = bse_server_use_new_project (BSE_SERVER, file_name);
+  SfiProxy project = bse_server.use_new_project (file_name).proxy_id();
   BseErrorType error = bst_project_restore_from_file (project, file_name, TRUE, TRUE);
 
   if (error)
diff --git a/beast-gtk/bstmain.cc b/beast-gtk/bstmain.cc
index 969da80..72205fd 100644
--- a/beast-gtk/bstmain.cc
+++ b/beast-gtk/bstmain.cc
@@ -260,7 +260,7 @@ main (int   argc,
            }
           else
            {
-             SfiProxy project = bse_server_use_new_project (BSE_SERVER, "Untitled.bse");
+             SfiProxy project = bse_server.use_new_project ("Untitled.bse").proxy_id();
              SfiProxy wrepo = bse_project_get_wave_repo (project);
              BseErrorType error = bse_wave_repo_load_file (wrepo, argv[i]);
              if (!error)
@@ -281,7 +281,7 @@ main (int   argc,
       // load/merge projects
       if (!app || !merge_with_last)
         {
-          SfiProxy project = bse_server_use_new_project (BSE_SERVER, argv[i]);
+          SfiProxy project = bse_server.use_new_project (argv[i]).proxy_id();
           BseErrorType error = bst_project_restore_from_file (project, argv[i], TRUE, TRUE);
           if (rewrite_bse_file)
             {
@@ -322,7 +322,7 @@ main (int   argc,
    */
   if (!app)
     {
-      SfiProxy project = bse_server_use_new_project (BSE_SERVER, "Untitled.bse");
+      SfiProxy project = bse_server.use_new_project ("Untitled.bse").proxy_id();
 
       bse_project_get_wave_repo (project);
       app = bst_app_new (project);
diff --git a/beast-gtk/bstplayback.cc b/beast-gtk/bstplayback.cc
index d3819a3..e2e6929 100644
--- a/beast-gtk/bstplayback.cc
+++ b/beast-gtk/bstplayback.cc
@@ -19,7 +19,7 @@ bst_play_back_handle_new (void)
   BstPlayBackHandle *handle;
 
   handle = g_new0 (BstPlayBackHandle, 1);
-  handle->project = bse_server_use_new_project (BSE_SERVER, "# BEAST Play Back");
+  handle->project = bse_server.use_new_project ("# BEAST Play Back").proxy_id();
   if (BST_DBG_EXT)
     gxk_idle_show_widget (GTK_WIDGET (bst_app_new (handle->project)));
 
diff --git a/bse/Makefile.am b/bse/Makefile.am
index f033438..ff6de9a 100644
--- a/bse/Makefile.am
+++ b/bse/Makefile.am
@@ -115,7 +115,7 @@ idl_dummy_files = $(strip   \
 bse_proc_sources = $(strip \
        bsecategories.proc      bsecontainer.proc       bsedatapocket.proc      bseeditablesample.proc  
bseenums.proc   bsemidinotifier.proc    \
        bsejanitor.proc         bsepart.proc            bseparasite.proc        bseprocedure.proc       
bseproject.proc bsescripthelper.proc    \
-       bseserver.proc          bsesong.proc            bsebus.proc             bsesource.proc          
bsecsynth.proc  bsesnet.proc            \
+                               bsesong.proc            bsebus.proc             bsesource.proc          
bsecsynth.proc  bsesnet.proc            \
        bsetrack.proc           bseitem.proc            bsewave.proc            bsewaveosc.proc         
bsewaverepo.proc                        \
 )
 bse_proc_gen_sources = $(bse_proc_sources:.proc=.genprc.cc)
diff --git a/bse/bseapi.idl b/bse/bseapi.idl
index b366aaa..1a29ed6 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -35,6 +35,10 @@ record UserMessage {
   String          label;        ///< Message class label, used to enable/disable this type of message.
 };
 
+/// Projects support loading, saving, playback and act as containers for all other sound objects.
+interface Project : Object {
+};
+
 /** Main Bse remote origin object.
  * The Bse::Server object controls the main BSE thread and keeps track of all objects
  * used in the BSE context.
@@ -63,11 +67,7 @@ interface Server : Object {
   int32         n_scripts();                 ///< Return the number of scripts currently running on this 
server.
   bool          can_load (String file_name); ///< Check whether a loader can be found for a wave file.
   void          start_recording (String wave_file, float64 n_seconds); ///< Start recording to a WAV file.
-  // Project    use_new_project (String project_name);  ///< Create a new project, owned by the caller (name 
is modified to be unique if necessary.
-};
-
-/// Projects support loading, saving, playback and act as containers for all other sound objects.
-interface Project : Object {
+  Project       use_new_project (String project_name);  ///< Create a new project, owned by the caller (name 
is modified to be unique if necessary.
 };
 
 } // Bse
diff --git a/bse/bseserver.cc b/bse/bseserver.cc
index e6759e0..589684b 100644
--- a/bse/bseserver.cc
+++ b/bse/bseserver.cc
@@ -1460,4 +1460,24 @@ ServerImpl::can_load (const String &file_name)
   return finfo != NULL;
 }
 
+ProjectIfaceP
+ServerImpl::use_new_project (const String &project_name)
+{
+  BseServer *server = as<BseServer*>();
+  /* enforce unique name */
+  guint num = 1;
+  gchar *uname = g_strdup (project_name.c_str());
+  while (bse_server_find_project (server, uname))
+    {
+      g_free (uname);
+      uname = g_strdup_format ("%s-%u", project_name.c_str(), num++);
+    }
+  /* create project */
+  BseProject *project = bse_server_create_project (server, uname);
+  g_free (uname);
+  bse_item_use (BSE_ITEM (project));
+  g_object_unref (project);
+  return shared_ptr_cast<ProjectIface> (project->as<ProjectIface*>());
+}
+
 } // Bse
diff --git a/bse/bseserver.hh b/bse/bseserver.hh
index d10cf5d..a57e1f7 100644
--- a/bse/bseserver.hh
+++ b/bse/bseserver.hh
@@ -126,7 +126,8 @@ public:
   virtual void   register_scripts        () override;
   virtual bool   preferences_locked      () override;
   virtual int    n_scripts               () override;
-  virtual bool   can_load                (const std::string &file_name) override;
+  virtual bool   can_load                (const String &file_name) override;
+  virtual ProjectIfaceP use_new_project  (const String &project_name) override;
   void                  send_user_message   (const UserMessage &umsg);
   static ServerImpl&    instance            ();
 };


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