BEAST: use project methods
authorTim Janik <timj@gnu.org>
Wed, 12 Oct 2016 21:15:38 +0000 (23:15 +0200)
committerTim Janik <timj@gnu.org>
Wed, 12 Oct 2016 23:10:43 +0000 (01:10 +0200)
Signed-off-by: Tim Janik <timj@gnu.org>
beast-gtk/bstapp.cc
beast-gtk/bstfiledialog.cc
beast-gtk/bstmain.cc
beast-gtk/bstmenus.cc
beast-gtk/bstmenus.hh
beast-gtk/bstplayback.cc
beast-gtk/bsttrackview.cc

index 32ddb1e..8e44848 100644 (file)
@@ -707,9 +707,8 @@ demo_play_song (gpointer data,
     }
   else
     {
-      BstApp *app;
-      bse_project_get_wave_repo (project.proxy_id());
-      app = bst_app_new (project);
+      project.get_wave_repo();
+      BstApp *app = bst_app_new (project);
       gxk_status_window_push (app);
       bst_status_eprintf (error, _("Opening project `%s'"), file_name);
       gxk_status_window_pop ();
@@ -854,9 +853,8 @@ app_action_exec (gpointer data,
       if (1)
         {
           Bse::ProjectH project = bse_server.create_project ("Untitled.bse");
-          bse_project_get_wave_repo (project.proxy_id());
+          project.get_wave_repo();
           BstApp *new_app = bst_app_new (project);
-
           gxk_idle_show_widget (GTK_WIDGET (new_app));
         }
       break;
@@ -891,26 +889,28 @@ app_action_exec (gpointer data,
       break;
     case BST_ACTION_NEW_SONG:
       bse_item_group_undo (self->project.proxy_id(), "Create Song");
-      proxy = bse_project_create_song (self->project.proxy_id(), NULL);
       {
-        Bse::SongH song = Bse::SongH::down_cast (bse_server.from_proxy (proxy));
+        Bse::SongH song = self->project.create_song ("");
         song.ensure_master_bus();
       }
       bse_item_ungroup_undo (self->project.proxy_id());
       self->select_unseen_super = TRUE;
       break;
     case BST_ACTION_NEW_CSYNTH:
-      proxy = bse_project_create_csynth (self->project.proxy_id(), NULL);
+      self->project.create_csynth ("");
       self->select_unseen_super = TRUE;
       break;
     case BST_ACTION_NEW_MIDI_SYNTH:
-      proxy = bse_project_create_midi_synth (self->project.proxy_id(), NULL);
+      self->project.create_midi_synth ("");
       self->select_unseen_super = TRUE;
       break;
     case BST_ACTION_REMOVE_SYNTH:
       proxy = bst_app_get_current_super (self);
       if (BSE_IS_SNET (proxy) && !self->project.is_active())
-        bse_project_remove_snet (self->project.proxy_id(), proxy);
+        {
+          Bse::SNetH snet = Bse::SNetH::down_cast (bse_server.from_proxy (proxy));
+          self->project.remove_snet (snet);
+        }
       self->select_unseen_super = FALSE;
       break;
     case BST_ACTION_CLEAR_UNDO:
index 584a63c..9c7d01e 100644 (file)
@@ -421,7 +421,7 @@ bst_file_dialog_open_project (BstFileDialog *self,
     }
   else
     {
-      bse_project_get_wave_repo (project.proxy_id());
+      project.get_wave_repo();
       BstApp *app = bst_app_new (project);
       gxk_status_window_push (app);
       bst_status_eprintf (error, _("Opening project `%s'"), file_name);
@@ -480,12 +480,13 @@ bst_file_dialog_import_midi (BstFileDialog *self,
   return TRUE;
 }
 
-static gboolean
-store_bse_file (Bse::ProjectH project, SfiProxy super, const gchar *file_name, const gchar *saving_message_format,
-                gboolean self_contained, gboolean want_overwrite)
+static bool
+store_bse_file (Bse::ProjectH project, SfiProxy super_proxy, const String &file_name, const String &saving_message_format,
+                bool self_contained, bool want_overwrite)
 {
-  Bse::Error error = bse_project_store_bse (project.proxy_id(), super, file_name, self_contained);
-  gchar *title = g_strdup_format (saving_message_format, bse_item_get_name (super ? super : project.proxy_id()));
+  Bse::SuperH super = Bse::SuperH::down_cast (bse_server.from_proxy (super_proxy));
+  Bse::Error error = project.store_bse (super, file_name, self_contained);
+  const String title = Rapicorn::string_format (saving_message_format.c_str(), bse_item_get_name (super_proxy ? super_proxy : project.proxy_id()));
   gboolean handled = TRUE;
   gchar *msg = NULL;
   /* handle file exists cases */
@@ -513,7 +514,7 @@ store_bse_file (Bse::ProjectH project, SfiProxy super, const gchar *file_name, c
               temp_file = g_strdup_format ("%s.tmp%06xyXXXXXX", file_name, rand() & 0xfffffd);
               char *result = mktemp (temp_file); /* this is save, due to use of: O_CREAT | O_EXCL */
               (void) result;
-              error = bse_project_store_bse (project.proxy_id(), super, temp_file, self_contained);
+              error = project.store_bse (super, temp_file, self_contained);
             }
           /* replace file by temporary file */
           if (error != Bse::Error::NONE)
@@ -521,7 +522,7 @@ store_bse_file (Bse::ProjectH project, SfiProxy super, const gchar *file_name, c
               unlink (temp_file); /* error != Bse::Error::FILE_EXISTS */
               msg = g_strdup_format (_("Failed to save to file\n`%s'\ndue to:\n%s"), file_name, Bse::error_blurb (error));
             }
-          else if (rename (temp_file, file_name) < 0)
+          else if (rename (temp_file, file_name.c_str()) < 0)
             {
               unlink (temp_file);
               msg = g_strdup_format (_("Failed to replace file\n`%s'\ndue to:\n%s"), file_name, g_strerror (errno));
@@ -548,7 +549,6 @@ store_bse_file (Bse::ProjectH project, SfiProxy super, const gchar *file_name, c
     }
   else if (handled) /* no error */
     bst_status_eprintf (Bse::Error::NONE, "%s", title);
-  g_free (title);
   return handled;
 }
 
index 1bc3d8c..06732d8 100644 (file)
@@ -371,10 +371,9 @@ main_open_files (int filesc, char **filesv)
        {
          if (app)
            {
-             SfiProxy wrepo = bse_project_get_wave_repo (app->project.proxy_id());
+              Bse::WaveRepoH wrepo = app->project.get_wave_repo ();
              gxk_status_printf (GXK_STATUS_WAIT, NULL, _("Loading \"%s\""), filesv[i]);
-              Bse::WaveRepoH repo = Bse::WaveRepoH::down_cast (bse_server.from_proxy (wrepo));
-              Bse::Error error = repo.load_file (filesv[i]);
+              Bse::Error error = wrepo.load_file (filesv[i]);
               bst_status_eprintf (error, _("Loading \"%s\""), filesv[i]);
               if (error != 0)
                 sfi_error (_("Failed to load wave file \"%s\": %s"), filesv[i], Bse::error_blurb (error));
@@ -382,9 +381,8 @@ main_open_files (int filesc, char **filesv)
           else
            {
               Bse::ProjectH project = bse_server.create_project ("Untitled.bse");
-             SfiProxy wrepo = bse_project_get_wave_repo (project.proxy_id());
-              Bse::WaveRepoH repo = Bse::WaveRepoH::down_cast (bse_server.from_proxy (wrepo));
-              Bse::Error error = repo.load_file (filesv[i]);
+              Bse::WaveRepoH wrepo = project.get_wave_repo ();
+              Bse::Error error = wrepo.load_file (filesv[i]);
              if (error == 0)
                {
                  app = bst_app_new (project);
@@ -414,7 +412,8 @@ main_open_files (int filesc, char **filesv)
                   perror (Rapicorn::string_format ("%s: failed to remove", filesv[i]).c_str());
                   exit (2);
                 }
-              error = bse_project_store_bse (project.proxy_id(), 0, filesv[i], TRUE);
+              Bse::SuperH any_super; // FIXME: bad API here
+              error = project.store_bse (any_super, filesv[i], TRUE);
               Rapicorn::printerr ("%s: writing: %s\n", filesv[i], Bse::error_blurb (error));
               if (error != 0)
                 exit (3);
@@ -446,7 +445,7 @@ static BstApp*
 main_open_default_window ()
 {
   Bse::ProjectH project = bse_server.create_project ("Untitled.bse");
-  bse_project_get_wave_repo (project.proxy_id());
+  project.get_wave_repo();
   BstApp *app = bst_app_new (project);
   gxk_idle_show_widget (GTK_WIDGET (app));
   if (beast_splash)
index 8d8ed00..a26bda0 100644 (file)
@@ -6,9 +6,9 @@
 /* --- structures --- */
 struct BstChoice {
   BstChoiceFlags type_and_flags;
-  const gchar   *icon_stock_id;
+  String         icon_stock_id;
   Bse::Icon      bseicon;
-  const gchar   *name;
+  String         name;
   void          *p_id;
   BstChoice() : type_and_flags (BST_CHOICE_TYPE_SEPARATOR), icon_stock_id (NULL), name (NULL), p_id (NULL) {}
 };
@@ -22,11 +22,7 @@ static GtkWidget *current_popup_menu = NULL;
 
 /* --- functions --- */
 BstChoice*
-bst_choice_alloc (BstChoiceFlags type,
-                 const gchar   *choice_name,
-                 gpointer       choice_id,
-                 const gchar   *icon_stock_id,
-                 const Bse::Icon &bseicon)
+bst_choice_alloc (BstChoiceFlags type, const String &choice_name, void *choice_id, const String &icon_stock_id, const Bse::Icon &bseicon)
 {
   BstChoice *choice = new BstChoice();
   choice->type_and_flags = type;
@@ -131,13 +127,13 @@ bst_choice_menu_add_choice_and_free (GtkWidget *menu,
     gxk_menu_attach_as_submenu (GTK_MENU (choice->p_id), GTK_MENU_ITEM (item));
   else
     menu_item_add_activator (item, (void*) menu_choice_activate);
-  if (choice->name)
+  if (! choice->name.empty())
     {
       GtkWidget *any;
 
-      if (choice->icon_stock_id)
+      if (! choice->icon_stock_id.empty())
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
-                                      gxk_stock_image (choice->icon_stock_id, GXK_ICON_SIZE_MENU));
+                                      gxk_stock_image (choice->icon_stock_id.c_str(), GXK_ICON_SIZE_MENU));
       any = gtk_widget_new (GTK_TYPE_ACCEL_LABEL,
                            "visible", TRUE,
                            "label", choice->name,
@@ -276,9 +272,9 @@ bst_choice_dialog_createv (BstChoice *first_choice,
          gtk_widget_set (dialog, "title", choice->name, NULL);
          break;
        case BST_CHOICE_TYPE_ITEM:
-         any = gxk_dialog_action_multi (GXK_DIALOG (dialog), choice->name,
+         any = gxk_dialog_action_multi (GXK_DIALOG (dialog), choice->name.c_str(),
                                         (void*) button_choice_activate, choice->p_id,
-                                        choice->icon_stock_id,
+                                        choice->icon_stock_id.c_str(),
                                         (choice_flags & BST_CHOICE_FLAG_DEFAULT) ? GXK_DIALOG_MULTI_DEFAULT : GxkDialogMultiFlags (0));
          if (choice_flags & BST_CHOICE_FLAG_INSENSITIVE)
            gtk_widget_set_sensitive (any, FALSE);
index 250f8de..591eee9 100644 (file)
@@ -66,9 +66,9 @@ typedef enum
   BST_CHOICE_FLAG_MASK         = (~BST_CHOICE_TYPE_MASK)
 } BstChoiceFlags;
 BstChoice* bst_choice_alloc               (BstChoiceFlags          type,
-                                          const gchar            *choice_name,
-                                          gpointer                choice_id,
-                                          const gchar            *icon_stock_id,
+                                          const String           &choice_name,
+                                          void                   *choice_id,
+                                          const String           &icon_stock_id,
                                           const Bse::Icon        &bseicon);
 
 G_END_DECLS
index fe333f4..0e8a410 100644 (file)
@@ -22,8 +22,7 @@ bst_play_back_handle_new (void)
   if (BST_DBG_EXT)
     gxk_idle_show_widget (GTK_WIDGET (bst_app_new (handle->project)));
 
-  SfiProxy snet_proxy = bse_project_create_csynth (handle->project.proxy_id(), NULL);
-  handle->snet = Bse::SNetH::down_cast (bse_server.from_proxy (snet_proxy));
+  handle->snet = handle->project.create_csynth ("");
   handle->snet.auto_activate (true);
   handle->speaker = handle->snet.create_source ("BsePcmOutput").proxy_id();
   handle->wosc1 = handle->snet.create_source ("BseWaveOsc").proxy_id();
index 51337bb..63f63ae 100644 (file)
@@ -277,11 +277,12 @@ track_view_synth_popup (BstTrackView         *self,
         {
           BsePropertyCandidates *pc = bse_item_get_property_candidates (item, "snet");
           SynthPopup sdata = { self, pcell, };
+          Bse::ProjectH project = Bse::ProjectH::down_cast (bse_server.from_proxy (bse_item_get_project (item)));
           GtkWidget *dialog = bst_track_synth_dialog_popup (self, item,
                                                             pc->label, pc->tooltip, pc->items,
                                                             _("Available Waves"),
                                                             _("List of available waves to choose a track instrument from"),
-                                                            bse_project_get_wave_repo (bse_item_get_project (item)),
+                                                            project.get_wave_repo().proxy_id(),
                                                             track_view_synth_popup_cb, g_memdup (&sdata, sizeof (sdata)), track_view_synth_popup_cleanup);
           gxk_cell_renderer_popup_dialog (pcell, dialog);
         }