BEAST - Free Software Audio Synthesizer and Tracker  0.10.0
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 };
38 
40  void (*get_candidates) (BseItem *item,
41  guint param_id,
42  BsePropertyCandidates *pc,
43  GParamSpec *pspec);
44  void (*set_parent) (BseItem *item,
45  BseItem *parent);
46  gboolean (*needs_storage) (BseItem *item,
47  BseStorage *storage);
48  void (*compat_setup) (BseItem *item,
49  guint vmajor,
50  guint vminor,
51  guint vmicro);
52  guint (*get_seqid) (BseItem *item);
53  BseUndoStack* (*get_undo) (BseItem *item);
54 };
55 
56 typedef void (*BseItemUncross) (BseItem *owner,
57  BseItem *link);
58 typedef gboolean (*BseItemCheckContainer) (BseContainer *container,
59  BseItem *item,
60  gpointer data);
61 typedef gboolean (*BseItemCheckProxy) (BseItem *proxy,
62  BseItem *item,
63  gpointer data);
64 
65 
66 /* --- prototypes --- */
67 BseIt3mSeq* bse_item_gather_items (BseItem *item,
68  BseIt3mSeq *iseq,
69  GType base_type,
70  BseItemCheckContainer ccheck,
71  BseItemCheckProxy pcheck,
72  gpointer data);
73 BseIt3mSeq* bse_item_gather_items_typed (BseItem *item,
74  BseIt3mSeq *iseq,
75  GType proxy_type,
76  GType container_type,
77  gboolean allow_ancestor);
78 gboolean bse_item_get_candidates (BseItem *item,
79  const gchar *property,
80  BsePropertyCandidates *pc);
81 void bse_item_set_internal (gpointer item,
82  gboolean internal);
83 gboolean bse_item_needs_storage (BseItem *item,
84  BseStorage *storage);
85 void bse_item_compat_setup (BseItem *item,
86  guint vmajor,
87  guint vminor,
88  guint vmicro);
89 guint bse_item_get_seqid (BseItem *item);
90 void bse_item_queue_seqid_changed (BseItem *item);
91 BseSuper* bse_item_get_super (BseItem *item);
92 BseSNet* bse_item_get_snet (BseItem *item);
93 BseProject* bse_item_get_project (BseItem *item);
94 BseItem* bse_item_get_toplevel (BseItem *item);
95 gboolean bse_item_has_ancestor (BseItem *item,
96  BseItem *ancestor);
97 BseItem* bse_item_common_ancestor (BseItem *item1,
98  BseItem *item2);
99 void bse_item_cross_link (BseItem *owner,
100  BseItem *link,
101  BseItemUncross uncross_func);
102 void bse_item_cross_unlink (BseItem *owner,
103  BseItem *link,
104  BseItemUncross uncross_func);
105 void bse_item_uncross_links (BseItem *owner,
106  BseItem *link);
107 BseItem* bse_item_use (BseItem *item);
108 void bse_item_unuse (BseItem *item);
109 void bse_item_set_parent (BseItem *item,
110  BseItem *parent);
111 Bse::Error bse_item_exec (gpointer item,
112  const gchar *procedure,
113  ...);
114 Bse::Error bse_item_exec_void (gpointer item,
115  const gchar *procedure,
116  ...); /* ignore return values */
117 /* undo-aware functions */
118 void bse_item_set_valist_undoable (gpointer object,
119  const gchar *first_property_name,
120  va_list var_args);
121 void bse_item_set_undoable (gpointer object,
122  const gchar *first_property_name,
123  ...) G_GNUC_NULL_TERMINATED;
124 void bse_item_set_property_undoable (BseItem *self,
125  const gchar *name,
126  const GValue *value);
127 /* undo admin functions */
128 BseUndoStack* bse_item_undo_open_str (void *item, const std::string &string);
129 #define bse_item_undo_open(item,...) bse_item_undo_open_str (item, Rapicorn::string_format (__VA_ARGS__).c_str())
130 void bse_item_undo_close (BseUndoStack *ustack);
131 /* undo helper functions */
132 void bse_item_push_undo_proc (gpointer item,
133  const gchar *procedure,
134  ...);
135 void bse_item_push_redo_proc (gpointer item,
136  const gchar *procedure,
137  ...);
138 void bse_item_backup_to_undo (BseItem *self,
139  BseUndoStack *ustack);
140 void bse_item_push_undo_storage (BseItem *self,
141  BseUndoStack *ustack,
142  BseStorage *storage);
143 /* convenience */
144 #define bse_item_set bse_item_set_undoable
145 #define bse_item_get g_object_get
146 Bse::MusicalTuning bse_item_current_musical_tuning (BseItem *self);
147 
148 G_END_DECLS
149 
150 namespace Bse {
151 
152 class ItemImpl : public ObjectImpl, public virtual ItemIface {
154 private:
155  void push_item_undo (const String &blurb, const UndoLambda &lambda);
156  struct UndoDescriptorData {
157  ptrdiff_t projectid;
158  String upath;
159  UndoDescriptorData() : projectid (0) {}
160  };
161  UndoDescriptorData make_undo_descriptor_data (ItemImpl &item);
162  ItemImpl& resolve_undo_descriptor_data (const UndoDescriptorData &udd);
163 protected:
164  virtual ~ItemImpl ();
165 public:
166  explicit ItemImpl (BseObject*);
167  ContainerImpl* parent ();
168  virtual ItemIfaceP common_ancestor (ItemIface &other) override;
169  virtual Icon icon () const override;
170  virtual void icon (const Icon&) override;
172  void push_property_undo (const String &property_name);
174  template<typename ItemT, typename... FuncArgs, typename... CallArgs> void
175  push_undo (const String &blurb, ItemT &self, Error (ItemT::*function) (FuncArgs...), CallArgs... args)
176  {
177  RAPICORN_ASSERT_RETURN (this == &self);
178  UndoLambda lambda = [function, args...] (ItemImpl &item, BseUndoStack *ustack) {
179  ItemT &self = dynamic_cast<ItemT&> (item);
180  return (self.*function) (args...);
181  };
182  push_item_undo (blurb, lambda);
183  }
185  template<typename ItemT, typename R, typename... FuncArgs, typename... CallArgs> void
186  push_undo (const String &blurb, ItemT &self, R (ItemT::*function) (FuncArgs...), CallArgs... args)
187  {
188  RAPICORN_ASSERT_RETURN (this == &self);
189  UndoLambda lambda = [function, args...] (ItemImpl &item, BseUndoStack *ustack) {
190  ItemT &self = dynamic_cast<ItemT&> (item);
191  (self.*function) (args...); // ignoring return type R
192  return Error::NONE;
193  };
194  push_item_undo (blurb, lambda);
195  }
197  template<typename ItemT, typename ItemTLambda> void
198  push_undo (const String &blurb, ItemT &self, const ItemTLambda &itemt_lambda)
199  {
200  const std::function<Error (ItemT &item, BseUndoStack *ustack)> &undo_lambda = itemt_lambda;
201  RAPICORN_ASSERT_RETURN (this == &self);
202  UndoLambda lambda = [undo_lambda] (ItemImpl &item, BseUndoStack *ustack) {
203  ItemT &self = dynamic_cast<ItemT&> (item);
204  return undo_lambda (self, ustack);
205  };
206  push_item_undo (blurb, lambda);
207  }
209  template<typename ItemT, typename ItemTLambda> void
210  push_undo_to_redo (const String &blurb, ItemT &self, const ItemTLambda &itemt_lambda)
211  { // push itemt_lambda as undo step when this undo step is executed (i.e. itemt_lambda is for redo)
212  const std::function<Error (ItemT &item, BseUndoStack *ustack)> &undo_lambda = itemt_lambda;
213  RAPICORN_ASSERT_RETURN (this == &self);
214  auto lambda = [blurb, undo_lambda] (ItemT &self, BseUndoStack *ustack) -> Error {
215  self.push_undo (blurb, self, undo_lambda);
216  return Error::NONE;
217  };
218  push_undo (blurb, self, lambda);
219  }
221  template<class Obj>
223  friend class ItemImpl;
224  UndoDescriptorData data_;
225  UndoDescriptor (const UndoDescriptorData &d) : data_ (d) {}
226  public:
227  typedef Obj Type;
228  };
230  template<class Obj>
231  UndoDescriptor<Obj> undo_descriptor (Obj &item) { return UndoDescriptor<Obj> (make_undo_descriptor_data (item)); }
233  template<class Obj>
234  Obj& undo_resolve (UndoDescriptor<Obj> udo) { return dynamic_cast<Obj&> (resolve_undo_descriptor_data (udo.data_)); }
235 };
236 
237 } // Bse
238 
239 #endif /* __BSE_ITEM_H__ */
UndoDescriptor - type safe object handle to persist undo/redo steps.
Definition: bseitem.hh:222
virtual Icon icon() const override
See Item::icon.
Definition: bseitem.cc:1362
void bse_item_cross_unlink(BseItem *owner, BseItem *link, BseItemUncross uncross_func)
Definition: bseitem.cc:590
Definition: bsecontainer.hh:108
Definition: bsecontainer.hh:26
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:88
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:198
virtual ItemIfaceP common_ancestor(ItemIface &other) override
See Item::common_ancestor()
Definition: bseitem.cc:1353
Representation of an icon pixel image.
Definition: bseapi.idl:387
STL namespace.
Definition: bsesnet.hh:36
Definition: bsesuper.hh:25
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:210
BseIt3mSeq * bse_item_gather_items_typed(BseItem *item, BseIt3mSeq *iseq, GType proxy_type, GType container_type, gboolean allow_ancestor)
Definition: bseitem.cc:384
STL class.
Definition: bseobject.hh:61
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:231
Obj & undo_resolve(UndoDescriptor< Obj > udo)
Resolve an undo descriptor back to an object, see also undo_descriptor().
Definition: bseitem.hh:234
Definition: bseobject.hh:94
void push_property_undo(const String &property_name)
Save the value of property_name onto the undo stack.
Definition: bseitem.cc:1334
Definition: bseitem.hh:152
Definition: bseitem.hh:39
Definition: bsestorage.hh:49
void bse_item_cross_link(BseItem *owner, BseItem *link, BseItemUncross uncross_func)
Definition: bseitem.cc:561
Definition: bseobject.hh:9
Definition: bseproject.hh:26
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:175
See also the corresponding IDL class Item.
Definition: bseserverapi.hh:656
Definition: bseitem.hh:34
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:186
Bse::MusicalTuning bse_item_current_musical_tuning(BseItem *self)
Definition: bseitem.cc:701
link