]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/score-element.hh
release: 1.3.106
[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 /**
18     for administration of what was done already
19     */
20 enum Score_element_status {
21   ORPHAN=0,                     // not yet added to Paper_score
22   VIRGIN,       
23   PRECALCING,
24   PRECALCED,            // calcs before spacing done
25   POSTCALCING,          // busy calculating. This is used to trap cyclic deps.
26   POSTCALCED,           // after spacing calcs done
27 };
28
29 typedef void (Score_element::*Score_element_method_pointer) (void);
30
31 /*
32    Basic output object.
33 */
34 class Score_element  {
35 public:
36   SCM immutable_property_alist_;
37   SCM mutable_property_alist_;
38   Score_element *original_l_;
39
40   /**
41     Administration: Where are we?. This is mainly used by Super_element and
42     Score_element::calcalute_dependencies ()
43
44     0 means ORPHAN,
45    */
46   char status_i_;
47   String name () const;
48
49   /*
50     IDEA: make this a global variable. This is the same for all
51     elements, I think it is safe to assume that we will not have
52     scores being formatted multithreadedly.
53    */
54   Paper_score *pscore_l_;
55
56   Score_element (SCM basic_props);
57   Score_element (Score_element const&);
58
59   /*
60     properties
61    */
62   SCM get_elt_property (const char*) const;
63   SCM get_elt_property (SCM) const;
64   void set_elt_property (const char * , SCM val);
65   void set_immutable_elt_property (const char * , SCM val);
66   void set_immutable_elt_property (SCM key, SCM val);  
67   void set_elt_property (SCM , SCM val);  
68   void set_elt_pointer (const char*, SCM val);
69   friend class Property_engraver; //  UGHUGHUGH.
70   SCM remove_elt_property (const char* nm);
71
72   /*
73     related classes.
74    */
75   Paper_def *paper_l () const;
76
77   /**
78     add a dependency. It may be the 0 pointer, in which case, it is ignored.
79     */
80   void add_dependency (Score_element*);    
81   virtual Line_of_score * line_l () const;
82   bool linked_b () const;
83
84
85   VIRTUAL_COPY_CONS(Score_element);
86  
87   /**
88      Recursively track all dependencies of this Score_element.  The
89      status_i_ field is used as a mark-field.  It is marked with
90      #busy# during execution of this function, and marked with #final#
91      when finished.
92
93      #funcptr# is the function to call to update this element.
94    */
95   void calculate_dependencies (int final, int busy, SCM funcname);
96   static SCM handle_broken_smobs (SCM, SCM criterion);
97
98   virtual void do_break_processing ();
99   virtual Score_element *find_broken_piece (Line_of_score*) const;
100   virtual void discretionary_processing ();
101   virtual SCM do_derived_mark ();
102
103   Molecule * get_molecule () const;
104   void suicide ();
105   
106   DECLARE_SCHEME_CALLBACK(preset_extent, (SCM smob, SCM axis));
107   DECLARE_SCHEME_CALLBACK(point_dimension_callback, (SCM smob, SCM axis));
108   DECLARE_SCHEME_CALLBACK(molecule_extent, (SCM smob, SCM axis));
109
110
111   static SCM ly_set_elt_property (SCM, SCM,SCM);
112   static SCM ly_get_elt_property (SCM, SCM);  
113
114   bool has_interface (SCM intf);
115   void set_interface (SCM intf);
116
117   virtual void handle_broken_dependencies ();
118   virtual void handle_prebroken_dependencies ();
119
120
121   DECLARE_SMOBS(Score_element,foo);
122
123   void init ();
124
125   Dimension_cache dim_cache_[NO_AXES];
126
127 public:
128   bool empty_b (Axis a) const;
129
130   Interval extent (Score_element * refpoint, Axis) const;
131  
132   /**
133     translate in one direction
134     */
135     
136   void translate_axis (Real, Axis);
137
138   /**
139      Find the offset relative to D.  If   D equals THIS, then it is 0.
140      Otherwise, it recursively defd as
141
142      OFFSET_ + PARENT_L_->relative_coordinate (D)
143    */
144   Real relative_coordinate (Score_element const* refp, Axis) const;
145   /**
146     Find the group-element which has both #this# and #s#
147    */
148   Score_element*common_refpoint (Score_element const* s, Axis a) const;
149   Score_element*common_refpoint (SCM elt_list, Axis a) const;
150
151   // duh. slim down interface here. (todo)
152   bool has_offset_callback_b (SCM callback, Axis)const;
153   void add_offset_callback (SCM callback, Axis);
154   bool has_extent_callback_b (SCM, Axis)const;  
155   void set_extent_callback (SCM , Axis);
156   bool has_extent_callback_b (Axis) const;
157
158   
159   /**
160     Invoke callbacks to get offset relative to parent.
161    */
162   Real get_offset (Axis a) const;
163   /**
164      Set the  parent refpoint of THIS to E
165    */
166   void set_parent (Score_element* e, Axis);
167   
168   Score_element *parent_l (Axis a) const;
169   DECLARE_SCHEME_CALLBACK(fixup_refpoint, (SCM));
170 };
171
172 Score_element * unsmob_element (SCM);
173
174 #endif // STAFFELEM_HH
175