]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/grob.hh
release: 1.5.19
[lilypond.git] / lily / include / grob.hh
1 /*
2   grob.hh -- declare Grob
3
4   (c) 1996-1999--2001 Han-Wen Nienhuys
5 */
6
7 #ifndef STAFFELEM_HH
8 #define STAFFELEM_HH
9
10 #include "parray.hh"
11 #include "virtual-methods.hh"
12 #include "lily-guile.hh"
13 #include "lily-proto.hh"
14 #include "smobs.hh"
15 #include "dimension-cache.hh"
16
17 /**
18     for administration of what was done already
19     */
20 enum Grob_status {
21   ORPHAN=0,                     // not yet added to Paper_score
22   VIRGIN,       
23   PRECALCING,
24   PRECALCED,            // calcs before spacing done
25   POSTCALCING,          // busy calculating. This is used to trap cyclic deps.
26   POSTCALCED,           // after spacing calcs done
27 };
28
29 typedef void (Grob::*Grob_method_pointer) (void);
30
31
32 #define get_grob_property(x) internal_get_grob_property(ly_symbol2scm(x))
33 #define set_grob_property(x,y) internal_set_grob_property(ly_symbol2scm(x),y)
34
35 /*
36    Basic output object.
37 */
38 class Grob  {
39 public:
40   SCM immutable_property_alist_;
41
42   // rename me to ``property_alist_''
43   SCM mutable_property_alist_;
44   
45   Grob *original_l_;
46
47   /**
48     Administration: Where are we?. This is mainly used by Super_element and
49     Grob::calcalute_dependencies ()
50
51     0 means ORPHAN,
52    */
53   char status_c_;
54   String name () const;
55
56   /*
57     IDEA: make this a global variable. This is the same for all
58     elements, I think it is safe to assume that we will not have
59     scores being formatted multithreadedly.
60    */
61   Paper_score *pscore_l_;
62
63   Grob (SCM basic_props);
64   Grob (Grob const&);
65
66   /*
67     properties
68    */
69   SCM internal_get_grob_property (SCM) const;
70   void internal_set_grob_property (SCM, SCM val);
71   
72 #if 0
73   void set_immutable_grob_property (const char * , SCM val);
74   void set_immutable_grob_property (SCM key, SCM val);
75 #endif
76   
77   void set_elt_pointer (const char*, SCM val);
78   friend class Property_engraver; //  UGHUGHUGH.
79   SCM remove_grob_property (const char* nm);
80
81   /*
82     related classes.
83    */
84   Paper_def *paper_l () const;
85
86   /**
87     add a dependency. It may be the 0 pointer, in which case, it is ignored.
88     */
89   void add_dependency (Grob*);    
90   virtual Line_of_score * line_l () const;
91   bool linked_b () const;
92
93
94   VIRTUAL_COPY_CONS (Grob);
95  
96   /**
97      Recursively track all dependencies of this Grob.  The
98      status_c_ field is used as a mark-field.  It is marked with
99      #busy# during execution of this function, and marked with #final#
100      when finished.
101
102      #funcptr# is the function to call to update this element.
103    */
104   void calculate_dependencies (int final, int busy, SCM funcname);
105   static SCM handle_broken_grobs(SCM, SCM criterion);
106
107   virtual void do_break_processing ();
108   virtual Grob *find_broken_piece (Line_of_score*) const;
109   virtual void discretionary_processing ();
110   virtual SCM do_derived_mark ();
111
112   Molecule * get_molecule () const;
113   SCM get_uncached_molecule () const;
114   
115   void suicide ();
116   
117   DECLARE_SCHEME_CALLBACK (preset_extent, (SCM smob, SCM axis));
118   DECLARE_SCHEME_CALLBACK (point_dimension_callback, (SCM smob, SCM axis));
119   DECLARE_SCHEME_CALLBACK (molecule_extent, (SCM smob, SCM axis));
120
121
122   static SCM ly_set_grob_property (SCM, SCM,SCM);
123   static SCM ly_get_grob_property (SCM, SCM);  
124
125   bool has_interface (SCM intf);
126   void set_interface (SCM intf);
127
128   virtual void handle_broken_dependencies ();
129   virtual void handle_prebroken_dependencies ();
130
131
132   DECLARE_SMOBS (Grob,foo);
133
134   void init ();
135
136   Dimension_cache dim_cache_[NO_AXES];
137
138 public:
139   bool empty_b (Axis a) const;
140
141   Interval extent (Grob * refpoint, Axis) const;
142  
143   /**
144     translate in one direction
145     */
146     
147   void translate_axis (Real, Axis);
148
149   /**
150      Find the offset relative to D.  If   D equals THIS, then it is 0.
151      Otherwise, it recursively defd as
152
153      OFFSET_ + PARENT_L_->relative_coordinate (D)
154    */
155   Real relative_coordinate (Grob const* refp, Axis) const;
156   /**
157     Find the group-element which has both #this# and #s#
158    */
159   Grob*common_refpoint (Grob const* s, Axis a) const;
160   Grob*common_refpoint (SCM elt_list, Axis a) const;
161
162   // duh. slim down interface here. (todo)
163   bool has_offset_callback_b (SCM callback, Axis)const;
164   void add_offset_callback (SCM callback, Axis);
165   bool has_extent_callback_b (SCM, Axis)const;  
166   void set_extent_callback (SCM , Axis);
167   bool has_extent_callback_b (Axis) const;
168
169   
170   /**
171     Invoke callbacks to get offset relative to parent.
172    */
173   Real get_offset (Axis a) const;
174   /**
175      Set the  parent refpoint of THIS to E
176    */
177   void set_parent (Grob* e, Axis);
178   
179   Grob *parent_l (Axis a) const {   return  dim_cache_[a].parent_l_; }
180   DECLARE_SCHEME_CALLBACK (fixup_refpoint, (SCM));
181 };
182
183 DECLARE_UNSMOB(Grob,grob);
184
185 #endif // STAFFELEM_HH
186