]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
8fde243cd851f850d1ac53c79df5f1757325c238
[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-callback.hh"
16
17
18 typedef void (Score_element::*Score_element_method_pointer) (void);
19
20 /**
21    Basic output object.
22
23     Element Properties:
24
25    transparent -- boolean: if true, do not print anything black.
26
27    dependencies -- list of score-element pointers that indicate who to
28    compute first.
29
30    interfaces -- list of symbols indicating the interfaces supported
31    by this object.
32
33    extra-offset -- pair of reals (a cons) forcing an extra offset
34    before outputting
35
36    glyph -- afm character name to output.
37    
38 */
39 class Score_element  {
40   /**
41      The lookup, determined by the font size. Cache this value.
42    */
43   Lookup * lookup_l_;
44 public:
45   /**
46      properties specific for this element. Destructor will not call
47      scm_unprotect, so as to allow more flexible GC arrangements.  The
48      real alist is in (cdr element_property_alist_), to reduce the
49      need for more scm_protect calls.
50
51   */
52   SCM element_property_alist_;
53   
54   Score_element *original_l_;
55
56   /**
57     Administration: Where are we?. This is mainly used by Super_element and
58     Score_element::calcalute_dependencies ()
59
60     0 means ORPHAN,
61     -1 means deleted
62     
63    */
64   int status_i_;
65
66   Paper_score *pscore_l_;
67
68   Score_element ();
69   Score_element (Score_element const&);
70   virtual void print () const;
71
72   /*
73     properties
74    */
75   SCM get_elt_property (String nm) const;
76   void set_elt_property (String, SCM val);
77
78   /**
79      UGH! JUNKME ?
80
81      This gets messy because it changes state
82
83      calling 
84
85      Bar::proc ()
86      {
87        s->remove_elt_property ("foo")
88      } 
89
90      twice may do weird things if Bar::foo has a default set.
91      
92    */
93   SCM remove_elt_property (String nm);
94
95   void Score_element::set_real (String, Real);
96   Real Score_element::get_real (String s) const;
97
98   /*
99     related classes.
100    */
101   Paper_def *paper_l () const;
102   Lookup const *lookup_l () const;
103
104   void add_processing ();
105
106   /**
107     add a dependency. It may be the 0 pointer, in which case, it is ignored.
108     */
109   void add_dependency (Score_element*);    
110   virtual Line_of_score * line_l () const;
111   bool linked_b () const;
112   VIRTUAL_COPY_CONS(Score_element);
113  
114   /**
115      Recursively track all dependencies of this Score_element.  The
116      status_i_ field is used as a mark-field.  It is marked with
117      #busy# during execution of this function, and marked with #final#
118      when finished.
119
120      #funcptr# is the function to call to update this element.
121    */
122   void calculate_dependencies (int final, int busy, Score_element_method_pointer funcptr);
123
124   static SCM handle_broken_smobs (SCM, SCM criterion);
125   void recurse_into_smobs (SCM s, void (Score_element::*meth_ptr)());
126
127   virtual void do_break_processing ();
128   virtual Score_element *find_broken_piece (Line_of_score*) const;
129 protected:
130
131   /**
132     Junk score element. This is protected because this is supposed to
133     be handled by GUILE gc.  */
134   virtual ~Score_element ();
135   
136   virtual void output_processing ();
137   static Interval molecule_extent (Dimension_cache const*);
138
139   /// do printing of derived info.
140   virtual void do_print () const;
141   /// generate the molecule    
142   virtual Molecule do_brew_molecule () const;
143   ///executed directly after the item is added to the Paper_score
144   virtual void do_add_processing ();
145   /// do calculations before determining horizontal spacing
146   virtual void before_line_breaking ();
147
148   /// generate rods & springs
149   virtual void do_space_processing ();
150
151   virtual void do_breakable_col_processing ();
152   /// do calculations after determining horizontal spacing
153   virtual void after_line_breaking ();
154     
155   static Interval dim_cache_callback (Dimension_cache const*);
156 public:
157   static SCM ly_set_elt_property (SCM, SCM,SCM);
158   static SCM ly_get_elt_property (SCM, SCM);  
159   
160   virtual void handle_broken_dependencies ();
161   virtual void handle_prebroken_dependencies ();
162
163
164   DECLARE_SMOBS;
165
166   void init ();
167
168 public:
169   Dimension_cache *dim_cache_[NO_AXES];
170
171   /**
172      Set this if anyone points to me, or if I point to anyone.
173
174      JUNKME.
175    */
176   bool used_b_;
177   
178   char const * name () const;
179   /**
180      Set empty in direction A.
181    */
182   void set_empty (Axis a);
183   bool empty_b (Axis a) const;
184   Interval extent (Axis) const;
185  
186   /**
187     translate in one direction
188     */
189     
190   void translate_axis (Real, Axis);
191
192   Real relative_coordinate (Score_element const* refp, Axis) const;
193   /**
194     Find the group-element which has both #this# and #s#
195    */
196   Score_element*common_refpoint (Score_element const* s, Axis a) const;
197   Score_element*common_refpoint (Link_array<Score_element> elems, Axis a) const;
198
199
200   bool has_offset_callback_b (Offset_cache_callback, Axis)const;
201   void add_offset_callback (Offset_cache_callback, Axis);
202   /**
203      Set the  parent refpoint of THIS to E
204    */
205   void set_parent (Score_element* e, Axis);
206   
207   Score_element *parent_l (Axis a) const;
208   void fixup_refpoint ();
209 };
210
211 Score_element * unsmob_element (SCM);
212
213
214
215 #endif // STAFFELEM_HH
216