Beast - Music Synthesizer and Composer  0.11.1+10.g2da35
bseobject.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __BSE_OBJECT_H__
3 #define __BSE_OBJECT_H__
4 
5 #include <bse/bseparam.hh>
6 
7 namespace Bse {
8 
9 class ObjectImpl : public virtual ObjectIface, public virtual DataListContainer {
10  BseObject *gobject_;
11 public:
12  explicit ObjectImpl (BseObject*);
13  virtual ~ObjectImpl ();
14  virtual std::string debug_name () override;
15  virtual int64_t proxy_id () override;
16  void changed (const String &what);
17  operator BseObject* () { return gobject_; }
18  // template<class BseObjectPtr> BseObjectPtr as (); // provided by ObjectIface
19  virtual BseObject* as_bse_object () override { return gobject_; }
20 };
22 
23 } // Bse
24 
25 
26 /* --- BSE type macros --- */
27 #define BSE_TYPE_OBJECT (BSE_TYPE_ID (BseObject))
28 #define BSE_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), BSE_TYPE_OBJECT, BseObject))
29 #define BSE_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), BSE_TYPE_OBJECT, BseObjectClass))
30 #define BSE_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), BSE_TYPE_OBJECT))
31 #define BSE_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), BSE_TYPE_OBJECT))
32 #define BSE_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), BSE_TYPE_OBJECT, BseObjectClass))
33 
34 /* --- object member/convenience macros --- */
35 #define BSE_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object))
36 #define BSE_OBJECT_TYPE_NAME(object) (g_type_name (BSE_OBJECT_TYPE (object)))
37 #define BSE_OBJECT_UNAME(object) ((gchar*) g_datalist_id_get_data (&((GObject*) (object))->qdata, bse_quark_uname))
38 #define BSE_OBJECT_FLAGS(object) (((BseObject*) (object))->flags)
39 #define BSE_OBJECT_SET_FLAGS(object, f) (BSE_OBJECT_FLAGS (object) |= (f))
40 #define BSE_OBJECT_UNSET_FLAGS(object, f) (BSE_OBJECT_FLAGS (object) &= ~(f))
41 #define BSE_OBJECT_IS_LOCKED(object) (((BseObject*) (object))->lock_count > 0)
42 #define BSE_OBJECT_DISPOSING(object) ((BSE_OBJECT_FLAGS (object) & BSE_OBJECT_FLAG_DISPOSING) > 0)
43 #define BSE_OBJECT_IN_RESTORE(object) ((BSE_OBJECT_FLAGS (object) & BSE_OBJECT_FLAG_IN_RESTORE) > 0)
44 #define BSE_OBJECT_ID(object) (((BseObject*) (object))->unique_id)
45 
46 /* --- object flags --- */
47 typedef enum /*< skip >*/
48 {
49  BSE_OBJECT_FLAG_FIXED_UNAME = 1 << 0,
50  BSE_OBJECT_FLAG_DISPOSING = 1 << 1,
51  BSE_OBJECT_FLAG_IN_RESTORE = 1 << 2
52 } BseObjectFlags;
53 #define BSE_OBJECT_FLAGS_USHIFT (3)
54 #define BSE_OBJECT_FLAGS_MAX_SHIFT (16)
55 
56 /* --- typedefs & structures --- */
57 struct BseObject : GObject {
58  Bse::ObjectImpl *cxxobject_;
59  Bse::ObjectImplP *cxxobjref_; // shared_ptr that keeps a reference on cxxobject_ until dispose()
60  guint16 flags;
61  guint16 lock_count;
62  guint unique_id;
63  operator Bse::ObjectImpl* () { return cxxobject_; }
64  // DERIVES_shared_ptr (uses void_t to prevent errors for T without shared_ptr's typedefs)
65  template<class T, typename = void> struct DERIVES_shared_ptr : std::false_type {};
66  template<class T> struct DERIVES_shared_ptr<T, Rapicorn::void_t< typename T::element_type > > :
67  std::is_base_of< std::shared_ptr<typename T::element_type>, T > {};
68  // as<T*>()
69  template<class ObjectImplPtr, typename ::std::enable_if<std::is_pointer<ObjectImplPtr>::value, bool>::type = true>
70  ObjectImplPtr as ()
71  {
72  static_assert (std::is_pointer<ObjectImplPtr>::value, "");
73  typedef typename std::remove_pointer<ObjectImplPtr>::type ObjectImplT;
75  return dynamic_cast<ObjectImplPtr> (cxxobject_);
76  }
77  // as<shared_ptr<T>>()
78  template<class ObjectImplP, typename ::std::enable_if<DERIVES_shared_ptr<ObjectImplP>::value, bool>::type = true>
79  ObjectImplP as ()
80  {
81  typedef typename ObjectImplP::element_type ObjectImplT;
83  ObjectImplT *impl = this && cxxobject_ ? as<ObjectImplT*>() : NULL;
84  return impl ? Rapicorn::shared_ptr_cast<ObjectImplT> (impl) : NULL;
85  }
86 };
87 
88 struct BseObjectClass : GObjectClass {
89  gboolean (*editable_property) (BseObject *object, /* for set_property/get_property implementations */
90  guint param_id,
91  GParamSpec *pspec);
92  /* custom methods for specific object needs, most of them require chaining */
93  gboolean (*check_pspec_editable) (BseObject *object, /* for containers */
94  GParamSpec *pspec);
95  void (*set_uname) (BseObject *object,
96  const gchar *uname);
97  void (*store_private) (BseObject *object,
98  BseStorage *storage);
99  void (*restore_start) (BseObject *object,
100  BseStorage *storage);
101  GTokenType (*restore_private) (BseObject *object,
102  BseStorage *storage,
103  GScanner *scanner);
104  void (*restore_finish) (BseObject *object,
105  guint vmajor,
106  guint vminor,
107  guint vmicro);
108  void (*unlocked) (BseObject *object);
109  Bse::Icon (*get_icon) (BseObject *object);
110 };
111 
112 /* --- object class API ---*/
113 void bse_object_class_add_property (BseObjectClass *oclass,
114  const gchar *property_group,
115  guint property_id,
116  GParamSpec *pspec);
117 void bse_object_class_add_grouped_property (BseObjectClass *oclass,
118  guint property_id,
119  GParamSpec *pspec);
120 #define bse_object_class_add_param bse_object_class_add_property
121 guint bse_object_class_add_signal (BseObjectClass *oclass,
122  const gchar *signal_name,
123  GType return_type,
124  guint n_params,
125  ...);
126 guint bse_object_class_add_asignal (BseObjectClass *oclass,
127  const gchar *signal_name,
128  GType return_type,
129  guint n_params,
130  ...);
131 guint bse_object_class_add_dsignal (BseObjectClass *oclass,
132  const gchar *signal_name,
133  GType return_type,
134  guint n_params,
135  ...);
136 
137 
138 /* --- object API --- */
139 GObject* bse_object_new (GType object_type, const gchar *first_property_name, ...);
140 GObject* bse_object_new_valist (GType object_type, const gchar *first_property_name, va_list var_args);
141 void bse_object_lock (gpointer object);
142 void bse_object_unlock (gpointer object);
143 gboolean bse_object_editable_property (gpointer object,
144  const gchar *property);
145 Bse::Icon bse_object_get_icon (BseObject *object);
146 void bse_object_notify_icon_changed (BseObject *object);
147 BseObject* bse_object_from_id (guint unique_id);
148 GList* bse_objects_list (GType type);
149 GList* bse_objects_list_by_uname (GType type,
150  const gchar *uname);
151 const gchar* bse_object_debug_name (gpointer object);
152 gchar* bse_object_strdup_debug_handle (gpointer object);
153 void bse_object_restore_start (BseObject *object,
154  BseStorage *storage);
155 void bse_object_restore_finish (BseObject *object,
156  guint vmajor,
157  guint vminor,
158  guint vmicro);
159 void bse_object_reemit_signal (gpointer src_object,
160  const gchar *src_signal,
161  gpointer dest_obejct,
162  const gchar *dest_signal);
163 void bse_object_remove_reemit (gpointer src_object,
164  const gchar *src_signal,
165  gpointer dest_object,
166  const gchar *dest_signal);
167 static inline void
168 bse_object_proxy_notifies (gpointer src_object,
169  gpointer dest_object,
170  const gchar *dest_signal)
171 {
172  bse_object_reemit_signal (src_object, "notify::uname", dest_object, dest_signal);
173  bse_object_reemit_signal (src_object, "icon-changed", dest_object, dest_signal);
174 }
175 static inline void
176 bse_object_unproxy_notifies (gpointer src_object,
177  gpointer dest_object,
178  const gchar *dest_signal)
179 {
180  bse_object_remove_reemit (src_object, "notify::uname", dest_object, dest_signal);
181  bse_object_remove_reemit (src_object, "icon-changed", dest_object, dest_signal);
182 }
183 
184 
185 /* --- implementation details --- */
186 extern GQuark bse_quark_uname;
187 void bse_object_marshal_signal (GClosure *closure,
188  GValue /*out*/ *return_value,
189  guint n_param_values,
190  const GValue *param_values,
191  gpointer invocation_hint,
192  gpointer marshal_data);
193 
194 #endif /* __BSE_OBJECT_H__ */
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:91
typedef int64_t
Representation of an icon pixel image.
Definition: bseapi.idl:387
gchar * bse_object_strdup_debug_handle(gpointer object)
Definition: bseobject.cc:117
STL class.
Definition: bseobject.hh:57
Definition: bseobject.hh:88
Definition: bsestorage.hh:45
Definition: bseobject.hh:65
uname