]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
release: 1.3.54
[lilypond.git] / lily / include / score-element.hh
1 /*
2   score-element.hh -- declare Score_element
3
4   (c) 1996-1999--2000 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 typedef Interval (*Extent_callback)(Score_element const *,Axis);
18 typedef Real (*Offset_callback)(Score_element const *,Axis);
19
20
21 /**
22     for administration of what was done already
23     */
24 enum Score_element_status {
25   ORPHAN=0,                     // not yet added to pstaff
26   VIRGIN,                       // added to pstaff
27   PRECALCING,
28   PRECALCED,            // calcs before spacing done
29   POSTCALCING,          // busy calculating. This is used to trap cyclic deps.
30   POSTCALCED,           // after spacing calcs done
31   BREWING,
32   BREWED,
33 };
34
35 typedef void (Score_element::*Score_element_method_pointer) (void);
36
37 /**
38    Basic output object.
39
40     Element Properties:
41
42    transparent -- boolean: if true, do not print anything black.
43
44    dependencies -- list of score-element pointers that indicate who to
45    compute first.
46
47    interfaces -- list of symbols indicating the interfaces supported
48    by this object.
49
50    extra-offset -- pair of reals (a cons) forcing an extra offset
51    before outputting
52
53    glyph -- afm character name to output.
54    
55 */
56 class Score_element  {
57   /**
58      The lookup, determined by the font size. Cache this value.
59    */
60   Lookup * lookup_l_;
61 public:
62   /**
63      properties specific for this element. Destructor will not call
64      scm_unprotect, so as to allow more flexible GC arrangements.  The
65      real alist is in (cdr element_property_alist_), to reduce the
66      need for more scm_protect calls.
67
68   */
69   SCM element_property_alist_;
70   
71   Score_element *original_l_;
72
73   /**
74     Administration: Where are we?. This is mainly used by Super_element and
75     Score_element::calcalute_dependencies ()
76
77     0 means ORPHAN,
78    */
79   char status_i_;
80   /**
81      Set this if anyone points to me, or if I point to anyone.
82
83      JUNKME.
84    */
85   bool used_b_;
86   
87   char const * name () const;
88
89   /*
90     IDEA: make this a global variable. This is the same for all
91     elements, I think it is safe to assume that we will not have
92     scores being formatted multithreadedly.
93    */
94   Paper_score *pscore_l_;
95
96   Score_element ();
97   Score_element (Score_element const&);
98
99   /*
100     properties
101    */
102   SCM get_elt_property (String nm) const;
103   void set_elt_property (String, SCM val);
104
105   /**
106      UGH! JUNKME ?
107
108      This gets messy because it changes state
109
110      calling 
111
112      Bar::proc ()
113      {
114        s->remove_elt_property ("foo")
115      } 
116
117      twice may do weird things if Bar::foo has a default set.
118      
119    */
120   SCM remove_elt_property (String nm);
121
122   /*
123     related classes.
124    */
125   Paper_def *paper_l () const;
126   Lookup const *lookup_l () const;
127
128   void add_processing ();
129
130   /**
131     add a dependency. It may be the 0 pointer, in which case, it is ignored.
132     */
133   void add_dependency (Score_element*);    
134   virtual Line_of_score * line_l () const;
135   bool linked_b () const;
136
137
138   VIRTUAL_COPY_CONS(Score_element);
139  
140   /**
141      Recursively track all dependencies of this Score_element.  The
142      status_i_ field is used as a mark-field.  It is marked with
143      #busy# during execution of this function, and marked with #final#
144      when finished.
145
146      #funcptr# is the function to call to update this element.
147    */
148   void calculate_dependencies (int final, int busy, Score_element_method_pointer funcptr);
149
150
151   static SCM handle_broken_smobs (SCM, SCM criterion);
152
153   virtual void do_break_processing ();
154   virtual Score_element *find_broken_piece (Line_of_score*) const;
155   /// generate rods & springs
156   virtual void do_space_processing ();
157   virtual void discretionary_processing ();
158
159   /// do calculations before determining horizontal spacing
160   virtual void before_line_breaking ();
161   /// do calculations after determining horizontal spacing
162   virtual void after_line_breaking ();
163
164   Molecule get_molecule () const;
165   void suicide ();
166   
167   static Interval preset_extent (Score_element const*,Axis);
168   static Interval point_dimension_callback (Score_element const*,Axis );
169   static Interval molecule_extent (Score_element const*,Axis);
170
171 protected:
172
173   /**
174     Junk score element. This is protected because this is supposed to
175     be handled by GUILE gc.  */
176   virtual ~Score_element ();
177   
178   /// generate the molecule    
179   virtual Molecule do_brew_molecule () const;
180   ///executed directly after the item is added to the Paper_score
181   virtual void do_add_processing ();
182     
183   static Interval dim_cache_callback (Dimension_cache const*);
184   
185 public:
186   static SCM ly_set_elt_property (SCM, SCM,SCM);
187   static SCM ly_get_elt_property (SCM, SCM);  
188
189   virtual void handle_broken_dependencies ();
190   virtual void handle_prebroken_dependencies ();
191
192
193   DECLARE_SMOBS;
194
195   void init ();
196
197   Dimension_cache dim_cache_[NO_AXES];
198
199 public:
200   bool empty_b (Axis a) const;
201   Interval extent (Axis) const;
202  
203   /**
204     translate in one direction
205     */
206     
207   void translate_axis (Real, Axis);
208
209   /**
210      Find the offset relative to D.  If   D equals THIS, then it is 0.
211      Otherwise, it recursively defd as
212
213      OFFSET_ + PARENT_L_->relative_coordinate (D)
214    */
215   Real relative_coordinate (Score_element const* refp, Axis) const;
216   /**
217     Find the group-element which has both #this# and #s#
218    */
219   Score_element*common_refpoint (Score_element const* s, Axis a) const;
220   Score_element*common_refpoint (SCM elt_list, Axis a) const;
221
222   bool has_offset_callback_b (Offset_callback, Axis)const;
223   void add_offset_callback (Offset_callback, Axis);
224   bool has_extent_callback_b (Extent_callback, Axis)const;  
225   void set_extent_callback (Extent_callback , Axis);
226
227   /**
228     Invoke callbacks to get offset relative to parent.
229    */
230   Real get_offset (Axis a) const;
231   /**
232      Set the  parent refpoint of THIS to E
233    */
234   void set_parent (Score_element* e, Axis);
235   
236   Score_element *parent_l (Axis a) const;
237   void fixup_refpoint ();
238 };
239
240 Score_element * unsmob_element (SCM);
241
242
243
244 #endif // STAFFELEM_HH
245