]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
81fa3115fce0ad28a88e22ae4dfcb56ea4611f10
[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 /**
18     for administration of what was done already
19     */
20 enum Score_element_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   BREWING,
28   BREWED,
29 };
30
31 typedef void (Score_element::*Score_element_method_pointer) (void);
32
33 /**
34    Basic output object.
35
36     Element Properties:
37
38    transparent -- boolean: if true, do not print anything black.
39
40    dependencies -- list of score-element pointers that indicate who to
41    compute first.
42
43    interfaces -- list of symbols indicating the interfaces supported
44    by this object.
45
46    extra-offset -- pair of reals (a cons) forcing an extra offset
47    before outputting
48
49    glyph -- afm character name to output.
50    
51 */
52 class Score_element  {
53   /**
54      The lookup, determined by the font size. Cache this value.
55    */
56   Lookup * lookup_l_;
57
58 public:
59   SCM immutable_property_alist_;
60   SCM mutable_property_alist_;
61   Score_element *original_l_;
62
63   /**
64     Administration: Where are we?. This is mainly used by Super_element and
65     Score_element::calcalute_dependencies ()
66
67     0 means ORPHAN,
68    */
69   char status_i_;
70   String name () const;
71
72   /*
73     IDEA: make this a global variable. This is the same for all
74     elements, I think it is safe to assume that we will not have
75     scores being formatted multithreadedly.
76    */
77   Paper_score *pscore_l_;
78
79   Score_element (SCM basic_props);
80   Score_element (Score_element const&);
81
82   /*
83     properties
84    */
85   SCM get_elt_property (const char*) const;
86   SCM get_elt_property (SCM) const;
87   void set_elt_property (const char * , SCM val);
88   void set_immutable_elt_property (const char * , SCM val);
89   void set_immutable_elt_property (SCM key, SCM val);  
90   void set_elt_property (SCM , SCM val);  
91   void set_elt_pointer (const char*, SCM val);
92   friend class Property_engraver; //  UGHUGHUGH.
93   SCM remove_elt_property (const char* nm);
94
95   /*
96     related classes.
97    */
98   Paper_def *paper_l () const;
99   Lookup const *lookup_l () const;
100
101   /**
102     add a dependency. It may be the 0 pointer, in which case, it is ignored.
103     */
104   void add_dependency (Score_element*);    
105   virtual Line_of_score * line_l () const;
106   bool linked_b () const;
107
108
109   VIRTUAL_COPY_CONS(Score_element);
110  
111   /**
112      Recursively track all dependencies of this Score_element.  The
113      status_i_ field is used as a mark-field.  It is marked with
114      #busy# during execution of this function, and marked with #final#
115      when finished.
116
117      #funcptr# is the function to call to update this element.
118    */
119   void calculate_dependencies (int final, int busy, SCM funcname);
120   static SCM handle_broken_smobs (SCM, SCM criterion);
121
122   virtual void do_break_processing ();
123   virtual Score_element *find_broken_piece (Line_of_score*) const;
124   virtual void discretionary_processing ();
125   virtual SCM do_derived_mark ();
126
127   Molecule get_molecule () const;
128   void suicide ();
129   
130   DECLARE_SCHEME_CALLBACK(preset_extent, (SCM smob, SCM axis));
131   DECLARE_SCHEME_CALLBACK(point_dimension_callback, (SCM smob, SCM axis));
132   DECLARE_SCHEME_CALLBACK(molecule_extent, (SCM smob, SCM axis));
133
134
135   static SCM ly_set_elt_property (SCM, SCM,SCM);
136   static SCM ly_get_elt_property (SCM, SCM);  
137
138   bool has_interface (SCM intf);
139   void set_interface (SCM intf);
140
141
142   DECLARE_SCHEME_CALLBACK(brew_molecule, (SCM ));
143   virtual void handle_broken_dependencies ();
144   virtual void handle_prebroken_dependencies ();
145
146
147   DECLARE_SMOBS(Score_element,foo);
148
149   void init ();
150
151   Dimension_cache dim_cache_[NO_AXES];
152
153 public:
154   bool empty_b (Axis a) const;
155
156   Interval extent (Score_element * refpoint, Axis) const;
157  
158   /**
159     translate in one direction
160     */
161     
162   void translate_axis (Real, Axis);
163
164   /**
165      Find the offset relative to D.  If   D equals THIS, then it is 0.
166      Otherwise, it recursively defd as
167
168      OFFSET_ + PARENT_L_->relative_coordinate (D)
169    */
170   Real relative_coordinate (Score_element const* refp, Axis) const;
171   /**
172     Find the group-element which has both #this# and #s#
173    */
174   Score_element*common_refpoint (Score_element const* s, Axis a) const;
175   Score_element*common_refpoint (SCM elt_list, Axis a) const;
176
177   // duh. slim down interface here. (todo)
178   bool has_offset_callback_b (SCM callback, Axis)const;
179   void add_offset_callback (SCM callback, Axis);
180   bool has_extent_callback_b (SCM, Axis)const;  
181   void set_extent_callback (SCM , Axis);
182   bool has_extent_callback_b (Axis) const;
183
184   
185   /**
186     Invoke callbacks to get offset relative to parent.
187    */
188   Real get_offset (Axis a) const;
189   /**
190      Set the  parent refpoint of THIS to E
191    */
192   void set_parent (Score_element* e, Axis);
193   
194   Score_element *parent_l (Axis a) const;
195   DECLARE_SCHEME_CALLBACK(fixup_refpoint, (SCM));
196 };
197
198 Score_element * unsmob_element (SCM);
199
200 #endif // STAFFELEM_HH
201