]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
25a30532ff396892f3b47f371f064ebf89e9a04b
[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 "graphical-element.hh"
13 #include "lily-guile.hh"
14
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 : public virtual Graphical_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   Link_array<Score_element> dependency_arr_;
47   /**
48      The lookup, determined by the font size. Cache this value.
49    */
50   Lookup * lookup_l_;
51 public:
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   Molecule * output_p_;
66   Score_element ();
67   Score_element (Score_element const&);
68   virtual void print () const;
69
70   /*
71     properties
72    */
73   SCM get_elt_property (SCM sym) const;
74   void set_elt_property (SCM sym, SCM val);
75   SCM remove_elt_property (SCM key);
76
77   /*
78     related classes.
79    */
80   Paper_def *paper_l () const;
81   Lookup const *lookup_l () const;
82
83   void add_processing ();
84
85   void substitute_dependency (Score_element*,Score_element*);
86   void remove_dependency (Score_element*);
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
106   virtual Score_element *find_broken_piece (Line_of_score*) const;
107 protected:
108
109   /**
110     Junk score element. This is protected because this is supposed to
111     be handled by GUILE gc.  */
112   virtual ~Score_element ();
113   
114   Score_element* dependency (int) const;
115   int dependency_size () const;
116   
117   virtual void output_processing ();
118   virtual Interval do_height () const;
119   virtual Interval do_width () const;
120
121
122   /// do printing of derived info.
123   virtual void do_print () const;
124   /// generate the molecule    
125   virtual Molecule* do_brew_molecule_p () const;
126   ///executed directly after the item is added to the Paper_score
127   virtual void do_add_processing ();
128   /// do calculations before determining horizontal spacing
129   virtual void do_pre_processing ();
130
131   /// generate rods & springs
132   virtual void do_space_processing ();
133
134   /// do postbreak substs on array of pointers.
135   virtual void do_substitute_arrays ();
136
137   virtual void do_breakable_col_processing ();
138   /// do calculations after determining horizontal spacing
139   virtual void do_post_processing ();
140     
141   virtual void do_substitute_element_pointer (Score_element * , Score_element *);
142   virtual void do_break_processing ();
143   virtual void handle_broken_dependencies ();
144   virtual void handle_prebroken_dependencies ();
145   virtual void handle_prebroken_dependents ();
146   virtual void handle_broken_dependents ();
147   virtual Link_array<Score_element> get_extra_dependencies () const;
148
149   static Interval dim_cache_callback (Dimension_cache*);
150 public:
151   SCM smobify_self ();
152   static SCM mark_smob (SCM);
153   static scm_sizet free_smob (SCM s);
154   static int print_smob (SCM s, SCM p, scm_print_state*);
155   static long smob_tag;
156   static void init_smobs();
157   SCM self_scm_;
158 };
159
160
161 template<class T>
162 void
163 substitute_element_array (Link_array<T> &arr, Line_of_score * to)
164 {
165   Link_array<T> newarr;
166   for (int i =0; i < arr.size (); i++)
167     {
168       T * t = arr[i];
169       if (t->line_l () != to)
170         {
171           t = dynamic_cast<T*> (t->find_broken_piece (to));
172         }
173       
174       if (t)
175         newarr.push (t);
176     }
177   arr = newarr;
178 }
179
180
181
182 #endif // STAFFELEM_HH
183