]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
1c0d7e4ef3e5e4216cb26bb5d37dc5905978c9e9
[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
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 public:                         // ugh.
70   SCM property_alist_;
71   SCM pointer_alist_;
72 public:
73   Score_element *original_l_;
74
75   /**
76     Administration: Where are we?. This is mainly used by Super_element and
77     Score_element::calcalute_dependencies ()
78
79     0 means ORPHAN,
80    */
81   char status_i_;
82   /**
83      Set this if anyone points to me, or if I point to anyone.
84
85      JUNKME.
86    */
87   bool used_b_;
88   
89   char const * name () const;
90
91   /*
92     IDEA: make this a global variable. This is the same for all
93     elements, I think it is safe to assume that we will not have
94     scores being formatted multithreadedly.
95    */
96   Paper_score *pscore_l_;
97
98   Score_element ();
99   Score_element (Score_element const&);
100
101   /*
102     properties
103    */
104   SCM get_elt_property (String nm) const;
105   void set_elt_property (String, SCM val);
106
107   /**
108      Pointers are like properties, but they are subject to    a substitution
109      after line breaking.
110    */
111   SCM get_elt_pointer (const char*) const;
112   void set_elt_pointer (const char*, SCM val);
113   friend class Property_engraver; //  UGHUGHUGH.
114   /**
115      UGH! JUNKME ?
116
117      This gets messy because it changes state
118
119      calling 
120
121      Bar::proc ()
122      {
123        s->remove_elt_property ("foo")
124      } 
125
126      twice may do weird things if Bar::foo has a default set.
127      
128    */
129   SCM remove_elt_property (const char* nm);
130
131   /*
132     related classes.
133    */
134   Paper_def *paper_l () const;
135   Lookup const *lookup_l () const;
136
137   void add_processing ();
138
139   /**
140     add a dependency. It may be the 0 pointer, in which case, it is ignored.
141     */
142   void add_dependency (Score_element*);    
143   virtual Line_of_score * line_l () const;
144   bool linked_b () const;
145
146
147   VIRTUAL_COPY_CONS(Score_element);
148  
149   /**
150      Recursively track all dependencies of this Score_element.  The
151      status_i_ field is used as a mark-field.  It is marked with
152      #busy# during execution of this function, and marked with #final#
153      when finished.
154
155      #funcptr# is the function to call to update this element.
156    */
157   void calculate_dependencies (int final, int busy, Score_element_method_pointer funcptr);
158
159
160   static SCM handle_broken_smobs (SCM, SCM criterion);
161
162   virtual void do_break_processing ();
163   virtual Score_element *find_broken_piece (Line_of_score*) const;
164   /// generate rods & springs
165   virtual void do_space_processing ();
166   virtual void discretionary_processing ();
167
168   /// do calculations before determining horizontal spacing
169   virtual void before_line_breaking ();
170   /// do calculations after determining horizontal spacing
171   virtual void after_line_breaking ();
172
173   Molecule get_molecule () const;
174   void suicide ();
175   
176   static Interval preset_extent (Score_element const*,Axis);
177   static Interval point_dimension_callback (Score_element const*,Axis );
178   static Interval molecule_extent (Score_element const*,Axis);
179
180 protected:
181
182   /**
183     Junk score element. This is protected because this is supposed to
184     be handled by GUILE gc.  */
185   virtual ~Score_element ();
186   
187   /// generate the molecule    
188   virtual Molecule do_brew_molecule () const;
189   ///executed directly after the item is added to the Paper_score
190   virtual void do_add_processing ();
191     
192   static Interval dim_cache_callback (Dimension_cache const*);
193   
194 public:
195   static SCM ly_set_elt_property (SCM, SCM,SCM);
196   static SCM ly_get_elt_property (SCM, SCM);  
197
198   virtual void handle_broken_dependencies ();
199   virtual void handle_prebroken_dependencies ();
200
201
202   DECLARE_SMOBS;
203
204   void init ();
205
206   Dimension_cache dim_cache_[NO_AXES];
207
208 public:
209   bool empty_b (Axis a) const;
210   Interval extent (Axis) const;
211  
212   /**
213     translate in one direction
214     */
215     
216   void translate_axis (Real, Axis);
217
218   /**
219      Find the offset relative to D.  If   D equals THIS, then it is 0.
220      Otherwise, it recursively defd as
221
222      OFFSET_ + PARENT_L_->relative_coordinate (D)
223    */
224   Real relative_coordinate (Score_element const* refp, Axis) const;
225   /**
226     Find the group-element which has both #this# and #s#
227    */
228   Score_element*common_refpoint (Score_element const* s, Axis a) const;
229   Score_element*common_refpoint (SCM elt_list, Axis a) const;
230
231   bool has_offset_callback_b (Offset_callback, Axis)const;
232   void add_offset_callback (Offset_callback, Axis);
233   bool has_extent_callback_b (Extent_callback, Axis)const;  
234   void set_extent_callback (Extent_callback , Axis);
235
236   /**
237     Invoke callbacks to get offset relative to parent.
238    */
239   Real get_offset (Axis a) const;
240   /**
241      Set the  parent refpoint of THIS to E
242    */
243   void set_parent (Score_element* e, Axis);
244   
245   Score_element *parent_l (Axis a) const;
246   void fixup_refpoint ();
247 };
248
249 Score_element * unsmob_element (SCM);
250
251
252
253 #endif // STAFFELEM_HH
254