[beast: 3/12] BSE: move BseSNet procedures into bseapi.idl



commit fe7198f711b9361172adb867a02cb67bfb47cb40
Author: Tim Janik <timj gnu org>
Date:   Tue Sep 22 18:23:52 2015 +0200

    BSE: move BseSNet procedures into bseapi.idl

 bse/Makefile.am  |    2 +-
 bse/bseapi.idl   |    6 ++-
 bse/bsesnet.cc   |   58 +++++++++++++++++++++++++
 bse/bsesnet.hh   |    9 +++-
 bse/bsesnet.proc |  125 ------------------------------------------------------
 5 files changed, 70 insertions(+), 130 deletions(-)
---
diff --git a/bse/Makefile.am b/bse/Makefile.am
index a5dde2f..f7204ad 100644
--- a/bse/Makefile.am
+++ b/bse/Makefile.am
@@ -117,7 +117,7 @@ idl_dummy_files = $(strip   \
 bse_proc_sources = $(strip \
        bsecategories.proc      bsecontainer.proc       bsedatapocket.proc      bseeditablesample.proc  \
        bsejanitor.proc                                 bseparasite.proc        bseprocedure.proc       
bseproject.proc \
-                               bsesong.proc                                    bsesource.proc          
bsesnet.proc \
+                               bsesong.proc                                    bsesource.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 1ca4005..7e9b591 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -451,7 +451,11 @@ interface Super : Container {
 
 /// Base interface type for all kinds of synthesis networks.
 interface SNet : Super {
-  bool supports_user_synths (); ///< Check whether users may edit synthesis modules of this network.
+  bool        supports_user_synths ();                ///< Check whether users may edit synthesis modules of 
this network.
+  ErrorType   can_create_source (String module_type); ///< Check whether inserting a new module into a 
synthesis network is possible.
+  Source      create_source     (String module_type); ///< Insert a new module into a synthesis network.
+  ErrorType   remove_source     (Source module);      ///< Remove an existing module from its synthesis 
network.
+  signal void port_unregistered ();                   ///< Signal that notifies when a named output port is 
unregistered.
 };
 
 /// Customizable synthesis (filter) network container.
diff --git a/bse/bsesnet.cc b/bse/bsesnet.cc
index 5180baf..19ab6f2 100644
--- a/bse/bsesnet.cc
+++ b/bse/bsesnet.cc
@@ -966,4 +966,62 @@ SNetImpl::supports_user_synths ()
   return BSE_SNET_USER_SYNTH (self);
 }
 
+ErrorType
+SNetImpl::can_create_source (const String &module_type)
+{
+  BseSNet *self = as<BseSNet*>();
+  GType type = g_type_from_name (module_type.c_str());
+  ErrorType error = ERROR_NONE;
+  if (!BSE_SNET_USER_SYNTH (self) && !BSE_DBG_EXT)
+    error = ERROR_NOT_OWNER;
+  else if (!g_type_is_a (type, BSE_TYPE_SOURCE) ||
+          g_type_is_a (type, BSE_TYPE_CONTAINER))
+    error = ERROR_SOURCE_TYPE_INVALID;
+  return error;
+}
+
+SourceIfaceP
+SNetImpl::create_source (const String &module_type)
+{
+  BseSNet *self = as<BseSNet*>();
+  if (can_create_source (module_type) != ERROR_NONE)
+    return NULL;
+  BseUndoStack *ustack = bse_item_undo_open (self, __func__);
+  BseSource *child = (BseSource*) bse_container_new_child (self, g_type_from_name (module_type.c_str()), 
NULL);
+  if (child)
+    {
+      // an undo lambda is needed for wrapping object argument references
+      UndoDescriptor<SourceImpl> child_descriptor = undo_descriptor (*child->as<SourceImpl*>());
+      auto lambda = [child_descriptor] (SNetImpl &self, BseUndoStack *ustack) -> ErrorType {
+        return self.remove_source (self.undo_resolve (child_descriptor));
+      };
+      push_undo (__func__, *this, lambda);
+    }
+  bse_item_undo_close (ustack);
+  return child ? child->as<SourceIfaceP>() : NULL;
+}
+
+ErrorType
+SNetImpl::remove_source (SourceIface &module)
+{
+  BseSNet *self = as<BseSNet*>();
+  BseSource *child = module.as<BseSource*>();
+  Bse::ErrorType error = Bse::ERROR_NONE;
+  if (!BSE_IS_SOURCE (child) || child->parent != self || (!BSE_SNET_USER_SYNTH (self) && !BSE_DBG_EXT))
+    return ERROR_PROC_PARAM_INVAL;
+  BseUndoStack *ustack = bse_item_undo_open (self, string_format ("%s: %s", __func__, bse_object_debug_name 
(child)).c_str());
+  bse_container_uncross_undoable (self, child);
+  {
+    // an undo lambda is needed for wrapping object argument references
+    UndoDescriptor<SourceImpl> child_descriptor = undo_descriptor (*child->as<SourceImpl*>());
+    auto lambda = [child_descriptor] (SNetImpl &self, BseUndoStack *ustack) -> ErrorType {
+      return self.remove_source (self.undo_resolve (child_descriptor));
+    };
+    push_undo_to_redo (__func__, *this, lambda); // how to get rid of the item once backed up
+  }
+  bse_container_remove_backedup (BSE_CONTAINER (self), child, ustack); // remove (without redo queueing)
+  bse_item_undo_close (ustack);
+  return error;
+}
+
 } // Bse
diff --git a/bse/bsesnet.hh b/bse/bsesnet.hh
index c1abe94..8dc99fe 100644
--- a/bse/bsesnet.hh
+++ b/bse/bsesnet.hh
@@ -108,10 +108,13 @@ namespace Bse {
 
 class SNetImpl : public SuperImpl, public virtual SNetIface {
 protected:
-  virtual              ~SNetImpl             ();
+  virtual             ~SNetImpl             ();
 public:
-  explicit              SNetImpl             (BseObject*);
-  virtual bool          supports_user_synths () override;
+  explicit             SNetImpl             (BseObject*);
+  virtual bool         supports_user_synths () override;
+  virtual ErrorType    can_create_source    (const String &module_type) override;
+  virtual SourceIfaceP create_source        (const String &module_type) override;
+  virtual ErrorType    remove_source        (SourceIface &module) override;
 };
 
 } // Bse


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