]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
7ce14c8cc1aef7a8e6d650fd2fc918db2e23a87f
[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   /**
145     Junk score element. This is protected because this is supposed to
146     be handled by GUILE gc.  */
147   virtual ~Score_element ();
148   
149   ///executed directly after the item is added to the Paper_score
150   virtual void do_add_processing ();
151   static Interval dim_cache_callback (Dimension_cache const*);
152   
153 public:
154   static SCM ly_set_elt_property (SCM, SCM,SCM);
155   static SCM ly_get_elt_property (SCM, SCM);  
156
157   bool has_interface (SCM intf);
158   void set_interface (SCM intf);
159
160
161   static SCM brew_molecule (SCM);
162   virtual void handle_broken_dependencies ();
163   virtual void handle_prebroken_dependencies ();
164
165
166   DECLARE_SMOBS;
167
168   void init ();
169
170   Dimension_cache dim_cache_[NO_AXES];
171
172 public:
173   bool empty_b (Axis a) const;
174   Interval extent (Axis) const;
175  
176   /**
177     translate in one direction
178     */
179     
180   void translate_axis (Real, Axis);
181
182   /**
183      Find the offset relative to D.  If   D equals THIS, then it is 0.
184      Otherwise, it recursively defd as
185
186      OFFSET_ + PARENT_L_->relative_coordinate (D)
187    */
188   Real relative_coordinate (Score_element const* refp, Axis) const;
189   /**
190     Find the group-element which has both #this# and #s#
191    */
192   Score_element*common_refpoint (Score_element const* s, Axis a) const;
193   Score_element*common_refpoint (SCM elt_list, Axis a) const;
194
195   bool has_offset_callback_b (Offset_callback, Axis)const;
196   void add_offset_callback (Offset_callback, Axis);
197   bool has_extent_callback_b (Extent_callback, Axis)const;  
198   void set_extent_callback (Extent_callback , Axis);
199
200   /**
201     Invoke callbacks to get offset relative to parent.
202    */
203   Real get_offset (Axis a) const;
204   /**
205      Set the  parent refpoint of THIS to E
206    */
207   void set_parent (Score_element* e, Axis);
208   
209   Score_element *parent_l (Axis a) const;
210   static SCM fixup_refpoint (SCM);
211 };
212
213 Score_element * unsmob_element (SCM);
214
215 #endif // STAFFELEM_HH
216