]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
release: 1.3.33
[lilypond.git] / lily / include / score-element.hh
1 /*
2   score-element.hh -- declare Score_element
3
4   (c) 1996-1999 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
16 typedef void (Score_element::*Score_element_method_pointer) (void);
17
18 /** Both Spanner and Item are Score_element's. Most Score_element's depend
19   on other Score_element's, eg, Beam needs to know and set direction of
20   Stem. So the Beam has to be calculated *before* Stem. This is
21   accomplished with the dependencies fields of struct Score_element,
22   which are implemented in the Directed_graph_node class: all elements
23   form an acyclic graph.
24
25   (elem)
26
27
28 Element Properties:
29
30 Boolean (true iff defined)
31
32  break_helper_only -- if defined try to junk this after calcing breakpoints.
33
34  transparent -- do not calc. output
35
36 */
37 class Score_element  {
38   /**
39      The lookup, determined by the font size. Cache this value.
40    */
41   Lookup * lookup_l_;
42 public:
43   /**
44      properties specific for this element. Destructor will not call
45      scm_unprotect, so as to allow more flexible GC arrangements.  The
46      real alist is in (cdr element_property_alist_), to reduce the
47      need for more scm_protect calls.
48
49   */
50   SCM element_property_alist_;
51   
52   Score_element *original_l_;
53
54   /**
55     Administration: Where are we?. This is mainly used by Super_element and
56     Score_element::calcalute_dependencies ()
57
58     0 means ORPHAN,
59     -1 means deleted
60     
61    */
62   int status_i_;
63
64   Paper_score *pscore_l_;
65
66   Score_element ();
67   Score_element (Score_element const&);
68   virtual void print () const;
69
70   /*
71     properties
72    */
73   SCM get_elt_property (String nm) const;
74   void set_elt_property (String, SCM val);
75
76   /**
77      UGH! JUNKME ?
78
79      This gets messy because it changes state
80
81      calling 
82
83      Bar::proc ()
84      {
85        s->remove_elt_property ("foo")
86      } 
87
88      twice may do weird things if Bar::foo has a default set.
89      
90    */
91   SCM remove_elt_property (String nm);
92
93   void Score_element::set_real (String, Real);
94   Real Score_element::get_real (String s) const;
95
96   /*
97     related classes.
98    */
99   Paper_def *paper_l () const;
100   Lookup const *lookup_l () const;
101
102   void add_processing ();
103
104   /**
105     add a dependency. It may be the 0 pointer, in which case, it is ignored.
106     */
107   void add_dependency (Score_element*);    
108   virtual Line_of_score * line_l () const;
109   bool linked_b () const;
110   VIRTUAL_COPY_CONS(Score_element);
111  
112   /**
113      Recursively track all dependencies of this Score_element.  The
114      status_i_ field is used as a mark-field.  It is marked with
115      #busy# during execution of this function, and marked with #final#
116      when finished.
117
118      #funcptr# is the function to call to update this element.
119    */
120   void calculate_dependencies (int final, int busy, Score_element_method_pointer funcptr);
121
122   static SCM handle_broken_smobs (SCM, SCM criterion);
123   void recurse_into_smobs (SCM s, void (Score_element::*meth_ptr)());
124
125   virtual void do_break_processing ();
126   virtual Score_element *find_broken_piece (Line_of_score*) const;
127 protected:
128
129   /**
130     Junk score element. This is protected because this is supposed to
131     be handled by GUILE gc.  */
132   virtual ~Score_element ();
133   
134   virtual void output_processing ();
135   static Interval molecule_extent (Dimension_cache const*);
136
137   /// do printing of derived info.
138   virtual void do_print () const;
139   /// generate the molecule    
140   virtual Molecule do_brew_molecule () const;
141   ///executed directly after the item is added to the Paper_score
142   virtual void do_add_processing ();
143   /// do calculations before determining horizontal spacing
144   virtual void before_line_breaking ();
145
146   /// generate rods & springs
147   virtual void do_space_processing ();
148
149   virtual void do_breakable_col_processing ();
150   /// do calculations after determining horizontal spacing
151   virtual void after_line_breaking ();
152     
153   virtual Link_array<Score_element> get_extra_dependencies () const;
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   bool used_b_;
175   
176   char const * name () const;
177   /**
178      Set empty in direction A.
179    */
180   void set_empty (Axis a);
181   bool empty_b (Axis a) const;
182   Interval extent (Axis) const;
183  
184   /**
185     translate in one direction
186     */
187     
188   void translate_axis (Real, Axis);
189
190   Real relative_coordinate (Score_element const* refp, Axis) const;
191   /**
192     Find the group-element which has both #this# and #s#
193    */
194   Score_element*common_refpoint (Score_element const* s, Axis a) const;
195   Score_element*common_refpoint (Link_array<Score_element> elems, Axis a) const;
196
197   /**
198      Set the  parent refpoint of THIS to E
199    */
200   void set_parent (Score_element* e, Axis);
201   
202   Score_element *parent_l (Axis a) const;
203   void fixup_refpoint ();
204 };
205
206 Score_element * unsmob_element (SCM);
207
208
209
210 #endif // STAFFELEM_HH
211