]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
69ac3526fdadf3c19bcd3e76e5fa9b860f689f29
[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   friend class Paper_score;
40   /**
41      properties specific for this element. Destructor will not call
42      scm_unprotect, so as to allow more flexible GC arrangements.  The
43      real alist is in (cdr element_property_alist_), to reduce the
44      need for more scm_protect calls.
45
46   */
47   SCM element_property_alist_;
48   Link_array<Score_element> dependency_arr_;
49   /**
50      The lookup, determined by the font size. Cache this value.
51    */
52   Lookup * lookup_l_;
53 public:
54   Score_element *original_l_;
55
56   /**
57     Administration: Where are we?. This is mainly used by Super_element and
58     Score_element::calcalute_dependencies ()
59
60     0 means ORPHAN,
61     -1 means deleted
62     
63    */
64   int status_i_;
65
66   Paper_score *pscore_l_;
67   Molecule * output_p_;
68   Score_element ();
69   Score_element (Score_element const&);
70   virtual void print () const;
71
72   /*
73     properties
74    */
75   SCM get_elt_property (SCM sym) const;
76   void set_elt_property (SCM sym, SCM val);
77   SCM remove_elt_property (SCM key);
78
79   /*
80     related classes.
81    */
82   Paper_def *paper_l () const;
83   Lookup const *lookup_l () const;
84
85   virtual ~Score_element ();
86   void add_processing ();
87
88   void substitute_dependency (Score_element*,Score_element*);
89   void remove_dependency (Score_element*);
90   /**
91     add a dependency. It may be the 0 pointer, in which case, it is ignored.
92     */
93   void add_dependency (Score_element*);    
94   virtual Line_of_score * line_l () const;
95   bool linked_b () const;
96   VIRTUAL_COPY_CONS(Score_element);
97  
98   /**
99      Recursively track all dependencies of this Score_element.  The
100      status_i_ field is used as a mark-field.  It is marked with
101      #busy# during execution of this function, and marked with #final#
102      when finished.
103
104      #funcptr# is the function to call to update this element.
105    */
106   void calculate_dependencies (int final, int busy, Score_element_method_pointer funcptr);
107
108
109   virtual Score_element *find_broken_piece (Line_of_score*) const;
110 protected:
111   Score_element* dependency (int) const;
112   int dependency_size () const;
113   
114   virtual void output_processing ();
115   virtual Interval do_height () const;
116   virtual Interval do_width () const;
117
118
119   /// do printing of derived info.
120   virtual void do_print () const;
121   /// generate the molecule    
122   virtual Molecule* do_brew_molecule_p () const;
123   ///executed directly after the item is added to the Paper_score
124   virtual void do_add_processing ();
125   /// do calculations before determining horizontal spacing
126   virtual void do_pre_processing ();
127
128   /// generate rods & springs
129   virtual void do_space_processing ();
130
131   /// do postbreak substs on array of pointers.
132   virtual void do_substitute_arrays ();
133
134   virtual void do_breakable_col_processing ();
135   /// do calculations after determining horizontal spacing
136   virtual void do_post_processing ();
137     
138   virtual void do_substitute_element_pointer (Score_element * , Score_element *);
139   virtual void do_break_processing ();
140   virtual void handle_broken_dependencies ();
141   virtual void handle_prebroken_dependencies ();
142   virtual void handle_prebroken_dependents ();
143   virtual void handle_broken_dependents ();
144   virtual Link_array<Score_element> get_extra_dependencies () const;
145
146   static Interval dim_cache_callback (Dimension_cache*);
147 public:
148   SCM smobify_self ();
149   static SCM mark_smob (SCM);
150   static scm_sizet free_smob (SCM s);
151   static int print_smob (SCM s, SCM p, scm_print_state*);
152   static long smob_tag;
153   static void init_smobs();
154   SCM self_scm_;
155 };
156
157
158 template<class T>
159 void
160 substitute_element_array (Link_array<T> &arr, Line_of_score * to)
161 {
162   Link_array<T> newarr;
163   for (int i =0; i < arr.size (); i++)
164     {
165       T * t = arr[i];
166       if (t->line_l () != to)
167         {
168           t = dynamic_cast<T*> (t->find_broken_piece (to));
169         }
170       
171       if (t)
172         newarr.push (t);
173     }
174   arr = newarr;
175 }
176
177
178
179 #endif // STAFFELEM_HH
180