]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
release: 1.3.11
[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      properties specific for this element. Destructor will not call
40      scm_unprotect, so as to allow more flexible GC arrangements.  The
41      real alist is in (cdr element_property_alist_), to reduce the
42      need for more scm_protect calls.
43
44   */
45   SCM element_property_alist_;
46   /**
47      The lookup, determined by the font size. Cache this value.
48    */
49   Lookup * lookup_l_;
50 public:
51   Score_element *original_l_;
52
53   /**
54     Administration: Where are we?. This is mainly used by Super_element and
55     Score_element::calcalute_dependencies ()
56
57     0 means ORPHAN,
58     -1 means deleted
59     
60    */
61   int status_i_;
62
63   Paper_score *pscore_l_;
64   Molecule * output_p_;
65   Score_element ();
66   Score_element (Score_element const&);
67   virtual void print () const;
68
69   /*
70     properties
71    */
72   SCM get_elt_property (String nm) const;
73   void set_elt_property (String, SCM val);
74   SCM remove_elt_property (String nm);
75
76   void Score_element::set_real (String, Real);
77   Real Score_element::get_real (String s) const;
78
79   /*
80     related classes.
81    */
82   Paper_def *paper_l () const;
83   Lookup const *lookup_l () const;
84
85   void add_processing ();
86
87   /**
88     add a dependency. It may be the 0 pointer, in which case, it is ignored.
89     */
90   void add_dependency (Score_element*);    
91   virtual Line_of_score * line_l () const;
92   bool linked_b () const;
93   VIRTUAL_COPY_CONS(Score_element);
94  
95   /**
96      Recursively track all dependencies of this Score_element.  The
97      status_i_ field is used as a mark-field.  It is marked with
98      #busy# during execution of this function, and marked with #final#
99      when finished.
100
101      #funcptr# is the function to call to update this element.
102    */
103   void calculate_dependencies (int final, int busy, Score_element_method_pointer funcptr);
104
105   static SCM handle_broken_smobs (SCM, SCM criterion);
106   void recurse_into_smobs (SCM s, void (Score_element::*meth_ptr)());
107
108   virtual void do_break_processing ();
109   virtual Score_element *find_broken_piece (Line_of_score*) const;
110 protected:
111
112   /**
113     Junk score element. This is protected because this is supposed to
114     be handled by GUILE gc.  */
115   virtual ~Score_element ();
116   
117   virtual void output_processing ();
118   static Interval molecule_extent (Dimension_cache const*);
119
120   /// do printing of derived info.
121   virtual void do_print () const;
122   /// generate the molecule    
123   virtual Molecule* do_brew_molecule_p () const;
124   ///executed directly after the item is added to the Paper_score
125   virtual void do_add_processing ();
126   /// do calculations before determining horizontal spacing
127   virtual void do_pre_processing ();
128
129   /// generate rods & springs
130   virtual void do_space_processing ();
131
132   virtual void do_breakable_col_processing ();
133   /// do calculations after determining horizontal spacing
134   virtual void do_post_processing ();
135     
136   virtual Link_array<Score_element> get_extra_dependencies () const;
137
138   static Interval dim_cache_callback (Dimension_cache const*);
139 public:
140   virtual void handle_broken_dependencies ();
141   virtual void handle_prebroken_dependencies ();
142
143
144   DECLARE_SMOBS;
145
146   void init ();
147
148 public:
149   Dimension_cache *dim_cache_[NO_AXES];
150
151   /**
152      Set this if anyone points to me, or if I point to anyone.
153    */
154   bool used_b_;
155   
156   char const * name () const;
157   /**
158      Set empty in direction A.
159    */
160   void set_empty (Axis a);
161   bool empty_b (Axis a) const;
162   void invalidate_cache (Axis);
163   Interval extent (Axis) const;
164  
165   /**
166     translate in one direction
167     */
168     
169   void translate_axis (Real, Axis);
170
171   Real relative_coordinate (Score_element const* refp, Axis) const;
172   /**
173     Find the group-element which has both #this# and #s#
174    */
175   Score_element*common_refpoint (Score_element const* s, Axis a) const;
176   Score_element*common_refpoint (Link_array<Score_element> elems, Axis a) const;
177
178   /**
179      Set the  parent refpoint of THIS to E
180    */
181   void set_parent (Score_element* e, Axis);
182   
183   Score_element *parent_l (Axis a) const;
184   void fixup_refpoint ();
185 };
186
187 Score_element * unsmob_element (SCM);
188
189
190
191 #endif // STAFFELEM_HH
192