]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
release: 1.3.69
[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   /**
64      properties specific for this element. Destructor will not call
65      scm_unprotect, so as to allow more flexible GC arrangements.  The
66      real alist is in (cdr element_property_alist_), to reduce the
67      need for more scm_protect calls.
68
69   */
70 public:                         // ugh.
71   SCM immutable_property_alist_;
72   SCM mutable_property_alist_;
73
74 public:
75   Score_element *original_l_;
76
77   /**
78     Administration: Where are we?. This is mainly used by Super_element and
79     Score_element::calcalute_dependencies ()
80
81     0 means ORPHAN,
82    */
83   char status_i_;
84   char const * name () const;
85
86   /*
87     IDEA: make this a global variable. This is the same for all
88     elements, I think it is safe to assume that we will not have
89     scores being formatted multithreadedly.
90    */
91   Paper_score *pscore_l_;
92
93   Score_element (SCM basic_props);
94   Score_element (Score_element const&);
95
96   /*
97     properties
98    */
99   SCM get_elt_property (const char*) const;
100   SCM get_elt_property (SCM) const;
101   void set_elt_property (const char * , SCM val);
102   void set_immutable_elt_property (const char * , SCM val);
103   void set_immutable_elt_property (SCM key, SCM val);  
104   void set_elt_property (SCM , SCM val);  
105   void set_elt_pointer (const char*, SCM val);
106   friend class Property_engraver; //  UGHUGHUGH.
107   SCM remove_elt_property (const char* nm);
108
109   /*
110     related classes.
111    */
112   Paper_def *paper_l () const;
113   Lookup const *lookup_l () const;
114
115   void add_processing ();
116
117   /**
118     add a dependency. It may be the 0 pointer, in which case, it is ignored.
119     */
120   void add_dependency (Score_element*);    
121   virtual Line_of_score * line_l () const;
122   bool linked_b () const;
123
124
125   VIRTUAL_COPY_CONS(Score_element);
126  
127   /**
128      Recursively track all dependencies of this Score_element.  The
129      status_i_ field is used as a mark-field.  It is marked with
130      #busy# during execution of this function, and marked with #final#
131      when finished.
132
133      #funcptr# is the function to call to update this element.
134    */
135   void calculate_dependencies (int final, int busy, SCM funcname);
136
137
138   static SCM handle_broken_smobs (SCM, SCM criterion);
139
140   virtual void do_break_processing ();
141   virtual Score_element *find_broken_piece (Line_of_score*) const;
142   /// generate rods & springs
143   virtual void do_space_processing ();
144   virtual void discretionary_processing ();
145   virtual void do_derived_mark ();
146
147   Molecule get_molecule () const;
148   void suicide ();
149   
150   static Interval preset_extent (Score_element *,Axis);
151   static Interval point_dimension_callback (Score_element *,Axis );
152   static Interval molecule_extent (Score_element *,Axis);
153
154 protected:
155   /**
156     Junk score element. This is protected because this is supposed to
157     be handled by GUILE gc.  */
158   virtual ~Score_element ();
159   
160   ///executed directly after the item is added to the Paper_score
161   virtual void do_add_processing ();
162   static Interval dim_cache_callback (Dimension_cache const*);
163   
164 public:
165   static SCM ly_set_elt_property (SCM, SCM,SCM);
166   static SCM ly_get_elt_property (SCM, SCM);  
167
168   bool has_interface (SCM intf);
169   void set_interface (SCM intf);
170
171
172   static SCM brew_molecule (SCM);
173   virtual void handle_broken_dependencies ();
174   virtual void handle_prebroken_dependencies ();
175
176
177   DECLARE_SMOBS;
178
179   void init ();
180
181   Dimension_cache dim_cache_[NO_AXES];
182
183 public:
184   bool empty_b (Axis a) const;
185   Interval extent (Axis) const;
186  
187   /**
188     translate in one direction
189     */
190     
191   void translate_axis (Real, Axis);
192
193   /**
194      Find the offset relative to D.  If   D equals THIS, then it is 0.
195      Otherwise, it recursively defd as
196
197      OFFSET_ + PARENT_L_->relative_coordinate (D)
198    */
199   Real relative_coordinate (Score_element const* refp, Axis) const;
200   /**
201     Find the group-element which has both #this# and #s#
202    */
203   Score_element*common_refpoint (Score_element const* s, Axis a) const;
204   Score_element*common_refpoint (SCM elt_list, Axis a) const;
205
206   bool has_offset_callback_b (Offset_callback, Axis)const;
207   void add_offset_callback (Offset_callback, Axis);
208   bool has_extent_callback_b (Extent_callback, Axis)const;  
209   void set_extent_callback (Extent_callback , Axis);
210
211   /**
212     Invoke callbacks to get offset relative to parent.
213    */
214   Real get_offset (Axis a) const;
215   /**
216      Set the  parent refpoint of THIS to E
217    */
218   void set_parent (Score_element* e, Axis);
219   
220   Score_element *parent_l (Axis a) const;
221   static SCM fixup_refpoint (SCM);
222 };
223
224 Score_element * unsmob_element (SCM);
225
226 #endif // STAFFELEM_HH
227