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