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