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