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