BEAST - Free Software Audio Synthesizer and Tracker  0.9.2
bseitem.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_ITEM_H__
3 #define __BSE_ITEM_H__
4 
5 #include <bse/bseobject.hh>
6 #include <bse/bseundostack.hh>
7 
8 G_BEGIN_DECLS
9 
10 
11 /* --- object type macros --- */
12 #define BSE_TYPE_ITEM (BSE_TYPE_ID (BseItem))
13 #define BSE_ITEM(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), BSE_TYPE_ITEM, BseItem))
14 #define BSE_ITEM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), BSE_TYPE_ITEM, BseItemClass))
15 #define BSE_IS_ITEM(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), BSE_TYPE_ITEM))
16 #define BSE_IS_ITEM_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), BSE_TYPE_ITEM))
17 #define BSE_ITEM_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), BSE_TYPE_ITEM, BseItemClass))
18 
19 
20 /* --- BseItem member macros --- */
21 #define BSE_ITEM_SINGLETON(object) ((BSE_OBJECT_FLAGS (object) & BSE_ITEM_FLAG_SINGLETON) != 0)
22 #define BSE_ITEM_INTERNAL(item) ((BSE_OBJECT_FLAGS (item) & BSE_ITEM_FLAG_INTERN_BRANCH) != 0)
23 
24 
25 /* --- bse item flags --- */
26 typedef enum /*< skip >*/
27 {
28  BSE_ITEM_FLAG_SINGLETON = 1 << (BSE_OBJECT_FLAGS_USHIFT + 0),
29  BSE_ITEM_FLAG_INTERN = 1 << (BSE_OBJECT_FLAGS_USHIFT + 1),
30  BSE_ITEM_FLAG_INTERN_BRANCH = 1 << (BSE_OBJECT_FLAGS_USHIFT + 2)
31 } BseItemFlags;
32 #define BSE_ITEM_FLAGS_USHIFT (BSE_OBJECT_FLAGS_USHIFT + 3)
33 
34 struct BseItem : BseObject {
35  guint use_count;
36  BseItem *parent;
37  BseParasite *parasite;
38 };
39 
41  void (*get_candidates) (BseItem *item,
42  guint param_id,
43  BsePropertyCandidates *pc,
44  GParamSpec *pspec);
45  void (*set_parent) (BseItem *item,
46  BseItem *parent);
47  gboolean (*needs_storage) (BseItem *item,
48  BseStorage *storage);
49  void (*compat_setup) (BseItem *item,
50  guint vmajor,
51  guint vminor,
52  guint vmicro);
53  guint (*get_seqid) (BseItem *item);
54  BseUndoStack* (*get_undo) (BseItem *item);
55 };
56 
57 typedef void (*BseItemUncross) (BseItem *owner,
58  BseItem *link);
59 typedef gboolean (*BseItemCheckContainer) (BseContainer *container,
60  BseItem *item,
61  gpointer data);
62 typedef gboolean (*BseItemCheckProxy) (BseItem *proxy,
63  BseItem *item,
64  gpointer data);
65 
66 
67 /* --- prototypes --- */
68 BseItemSeq* bse_item_gather_items (BseItem *item,
69  BseItemSeq *iseq,
70  GType base_type,
71  BseItemCheckContainer ccheck,
72  BseItemCheckProxy pcheck,
73  gpointer data);
74 BseItemSeq* bse_item_gather_items_typed (BseItem *item,
75  BseItemSeq *iseq,
76  GType proxy_type,
77  GType container_type,
78  gboolean allow_ancestor);
79 gboolean bse_item_get_candidates (BseItem *item,
80  const gchar *property,
81  BsePropertyCandidates *pc);
82 void bse_item_set_internal (gpointer item,
83  gboolean internal);
84 gboolean bse_item_needs_storage (BseItem *item,
85  BseStorage *storage);
86 void bse_item_compat_setup (BseItem *item,
87  guint vmajor,
88  guint vminor,
89  guint vmicro);
90 guint bse_item_get_seqid (BseItem *item);
91 void bse_item_queue_seqid_changed (BseItem *item);
92 BseSuper* bse_item_get_super (BseItem *item);
93 BseSNet* bse_item_get_snet (BseItem *item);
94 BseProject* bse_item_get_project (BseItem *item);
95 BseItem* bse_item_get_toplevel (BseItem *item);
96 gboolean bse_item_has_ancestor (BseItem *item,
97  BseItem *ancestor);
98 BseItem* bse_item_common_ancestor (BseItem *item1,
99  BseItem *item2);
100 void bse_item_cross_link (BseItem *owner,
101  BseItem *link,
102  BseItemUncross uncross_func);
103 void bse_item_cross_unlink (BseItem *owner,
104  BseItem *link,
105  BseItemUncross uncross_func);
106 void bse_item_uncross_links (BseItem *owner,
107  BseItem *link);
108 BseItem* bse_item_use (BseItem *item);
109 void bse_item_unuse (BseItem *item);
110 void bse_item_set_parent (BseItem *item,
111  BseItem *parent);
112 Bse::ErrorType bse_item_exec (gpointer item,
113  const gchar *procedure,
114  ...);
115 Bse::ErrorType bse_item_exec_void (gpointer item,
116  const gchar *procedure,
117  ...); /* ignore return values */
118 /* undo-aware functions */
119 void bse_item_set_valist_undoable (gpointer object,
120  const gchar *first_property_name,
121  va_list var_args);
122 void bse_item_set_undoable (gpointer object,
123  const gchar *first_property_name,
124  ...) G_GNUC_NULL_TERMINATED;
125 void bse_item_set_property_undoable (BseItem *self,
126  const gchar *name,
127  const GValue *value);
128 /* undo admin functions */
129 BseUndoStack* bse_item_undo_open_str (void *item, const std::string &string);
130 #define bse_item_undo_open(item,...) bse_item_undo_open_str (item, Rapicorn::string_format (__VA_ARGS__).c_str())
131 void bse_item_undo_close (BseUndoStack *ustack);
132 /* undo helper functions */
133 void bse_item_push_undo_proc (gpointer item,
134  const gchar *procedure,
135  ...);
136 void bse_item_push_redo_proc (gpointer item,
137  const gchar *procedure,
138  ...);
139 void bse_item_backup_to_undo (BseItem *self,
140  BseUndoStack *ustack);
141 void bse_item_push_undo_storage (BseItem *self,
142  BseUndoStack *ustack,
143  BseStorage *storage);
144 /* convenience */
145 #define bse_item_set bse_item_set_undoable
146 #define bse_item_get g_object_get
147 BseMusicalTuningType bse_item_current_musical_tuning (BseItem *self);
148 
149 G_END_DECLS
150 
151 namespace Bse {
152 
153 class ItemImpl : public ObjectImpl, public virtual ItemIface {
155 private:
156  void push_item_undo (const String &blurb, const UndoLambda &lambda);
157  struct UndoDescriptorData {
158  ptrdiff_t projectid;
159  String upath;
160  UndoDescriptorData() : projectid (0) {}
161  };
162  UndoDescriptorData make_undo_descriptor_data (ItemImpl &item);
163  ItemImpl& resolve_undo_descriptor_data (const UndoDescriptorData &udd);
164 protected:
165  virtual ~ItemImpl ();
166 public:
167  explicit ItemImpl (BseObject*);
168  ContainerImpl* parent ();
169  virtual ItemIfaceP common_ancestor (ItemIface &other) override;
171  template<typename ItemT, typename... FuncArgs, typename... CallArgs> void
172  push_undo (const String &blurb, ItemT &self, ErrorType (ItemT::*function) (FuncArgs...), CallArgs... args)
173  {
174  assert_return (this == &self);
175  UndoLambda lambda = [function, args...] (ItemImpl &item, BseUndoStack *ustack) {
176  ItemT &self = dynamic_cast<ItemT&> (item);
177  return (self.*function) (args...);
178  };
179  push_item_undo (blurb, lambda);
180  }
181  template<typename ItemT, typename R, typename... FuncArgs, typename... CallArgs> void
182  push_undo (const String &blurb, ItemT &self, R (ItemT::*function) (FuncArgs...), CallArgs... args)
183  {
184  assert_return (this == &self);
185  UndoLambda lambda = [function, args...] (ItemImpl &item, BseUndoStack *ustack) {
186  ItemT &self = dynamic_cast<ItemT&> (item);
187  (self.*function) (args...); // ignoring return type R
188  return ERROR_NONE;
189  };
190  push_item_undo (blurb, lambda);
191  }
192  template<typename ItemT, typename ItemTLambda> void
193  push_undo (const String &blurb, ItemT &self, const ItemTLambda &itemt_lambda)
194  {
195  const std::function<ErrorType (ItemT &item, BseUndoStack *ustack)> &undo_lambda = itemt_lambda;
196  assert_return (this == &self);
197  UndoLambda lambda = [undo_lambda] (ItemImpl &item, BseUndoStack *ustack) {
198  ItemT &self = dynamic_cast<ItemT&> (item);
199  return undo_lambda (self, ustack);
200  };
201  push_item_undo (blurb, lambda);
202  }
203  template<typename ItemT, typename ItemTLambda> void
204  push_undo_to_redo (const String &blurb, ItemT &self, const ItemTLambda &itemt_lambda)
205  { // push itemt_lambda as undo step when this undo step is executed (i.e. itemt_lambda is for redo)
206  const std::function<ErrorType (ItemT &item, BseUndoStack *ustack)> &undo_lambda = itemt_lambda;
207  assert_return (this == &self);
208  auto lambda = [blurb, undo_lambda] (ItemT &self, BseUndoStack *ustack) -> ErrorType {
209  self.push_undo (blurb, self, undo_lambda);
210  return ERROR_NONE;
211  };
212  push_undo (blurb, self, lambda);
213  }
215  template<class Obj>
217  friend class ItemImpl;
218  UndoDescriptorData data_;
219  UndoDescriptor (const UndoDescriptorData &d) : data_ (d) {}
220  public:
221  typedef Obj Type;
222  };
224  template<class Obj>
225  UndoDescriptor<Obj> undo_descriptor (Obj &item) { return UndoDescriptor<Obj> (make_undo_descriptor_data (item)); }
227  template<class Obj>
228  Obj& undo_resolve (UndoDescriptor<Obj> udo) { return dynamic_cast<Obj&> (resolve_undo_descriptor_data (udo.data_)); }
229 };
230 
231 } // Bse
232 
233 #endif /* __BSE_ITEM_H__ */
UndoDescriptor - type safe object handle to persist undo/redo steps.
Definition: bseitem.hh:216
void bse_item_cross_unlink(BseItem *owner, BseItem *link, BseItemUncross uncross_func)
Definition: bseitem.cc:595
Definition: bsecontainer.hh:108
Definition: bsecontainer.hh:26
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:67
virtual ItemIfaceP common_ancestor(ItemIface &other) override
See Item::common_ancestor()
Definition: bseitem.cc:1339
STL namespace.
Definition: bsesnet.hh:36
Definition: bsesuper.hh:25
STL class.
Definition: bseobject.hh:60
void bse_item_uncross_links(BseItem *owner, BseItem *link)
Definition: bseitem.cc:623
UndoDescriptor< Obj > undo_descriptor(Obj &item)
Create an object descriptor that persists undo/redo steps.
Definition: bseitem.hh:225
BseItemSeq * bse_item_gather_items_typed(BseItem *item, BseItemSeq *iseq, GType proxy_type, GType container_type, gboolean allow_ancestor)
Definition: bseitem.cc:389
Obj & undo_resolve(UndoDescriptor< Obj > udo)
Resolve an undo descriptor back to an object, see also undo_descriptor().
Definition: bseitem.hh:228
Definition: bseobject.hh:93
BseMusicalTuningType bse_item_current_musical_tuning(BseItem *self)
Definition: bseitem.cc:706
Definition: bseitem.hh:153
Definition: bseitem.hh:40
Definition: bsestorage.hh:49
void bse_item_cross_link(BseItem *owner, BseItem *link, BseItemUncross uncross_func)
Definition: bseitem.cc:566
Definition: bseobject.hh:9
Definition: bseproject.hh:26
See also the corresponding IDL class Item.
Definition: bseserverapi.hh:455
Definition: bseitem.hh:34
void push_undo(const String &blurb, ItemT &self, ErrorType(ItemT::*function)(FuncArgs...), CallArgs...args)
Push handler onto the undo stack, self must match this.
Definition: bseitem.hh:172
link