]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/grob.hh
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / lily / include / grob.hh
1 /*
2   grob.hh -- declare Grob
3
4   (c) 1996-1999--2002 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 #include "grob-interface.hh"
17
18 /**
19     for administration of what was done already
20     */
21 enum Grob_status {
22   ORPHAN=0,                     // not yet added to Paper_score
23   VIRGIN,       
24   PRECALCING,
25   PRECALCED,            // calcs before spacing done
26   POSTCALCING,          // busy calculating. This is used to trap cyclic deps.
27   POSTCALCED,           // after spacing calcs done
28 };
29
30 typedef void (Grob::*Grob_method_pointer) (void);
31
32
33 #define get_grob_property(x) internal_get_grob_property(ly_symbol2scm(x))
34 #define set_grob_property(x,y) internal_set_grob_property(ly_symbol2scm(x),y)
35
36 /*
37    Basic output object.
38 */
39 class Grob  {
40 protected:
41   SCM immutable_property_alist_;
42   SCM mutable_property_alist_;
43   friend class Spanner;
44   
45   void substitute_mutable_properties(SCM,SCM);
46 public:
47   Grob *original_;
48
49   /**
50     Administration: Where are we?. This is mainly used by Super_element and
51     Grob::calcalute_dependencies ()
52
53     0 means ORPHAN,
54    */
55   char status_;
56
57
58   /*
59     IDEA: make this a global variable. This is the same for all
60     elements, I think it is safe to assume that we will not have
61     scores being formatted multithreadedly.
62    */
63   Paper_score *pscore_;
64   Dimension_cache dim_cache_[NO_AXES];
65
66   Grob (SCM basic_props);
67   Grob (Grob const&);
68   String name () const;
69   
70   /*
71     properties
72    */
73   SCM internal_get_grob_property (SCM) const;
74   void internal_set_grob_property (SCM, SCM val);
75   void add_to_list_property (SCM, SCM);
76   void warning (String)const;
77   void programming_error (String)const;
78   
79   void set_elt_pointer (const char*, SCM val);
80   friend class Property_engraver; //  UGHUGHUGH.
81   /*
82     related classes.
83    */
84   Paper_def *get_paper () const;
85
86   /**
87     add a dependency. It may be the 0 pointer, in which case, it is ignored.
88     */
89   void add_dependency (Grob*);    
90   virtual System * get_system () const;
91   bool linked_b () const;
92
93
94   VIRTUAL_COPY_CONS (Grob);
95  
96   /**
97      Recursively track all dependencies of this Grob.  The
98      status_ field is used as a mark-field.  It is marked with
99      #busy# during execution of this function, and marked with #final#
100      when finished.
101
102      #funcptr# is the function to call to update this element.
103    */
104   void calculate_dependencies (int final, int busy, SCM funcname);
105
106
107   virtual void do_break_processing ();
108   virtual Grob *find_broken_piece (System*) const;
109   virtual void discretionary_processing ();
110   virtual SCM do_derived_mark () const;
111
112   Molecule * get_molecule () const;
113   SCM get_uncached_molecule () const;
114
115   SCM get_property_alist_chain (SCM) const;
116   void suicide ();
117   bool live () const;
118   
119   DECLARE_SCHEME_CALLBACK (preset_extent, (SCM smob, SCM axis));
120   DECLARE_SCHEME_CALLBACK (point_dimension_callback, (SCM smob, SCM axis));
121   DECLARE_SCHEME_CALLBACK (molecule_extent, (SCM smob, SCM axis));
122
123   static SCM ly_set_grob_property (SCM, SCM,SCM);
124   static SCM ly_get_grob_property (SCM, SCM);  
125
126   bool internal_has_interface (SCM intf);
127   static bool has_interface (Grob*me);  
128
129   virtual void handle_broken_dependencies ();
130   virtual void handle_prebroken_dependencies ();
131
132   DECLARE_SMOBS (Grob,foo);
133
134   void init ();
135 public:
136   bool empty_b (Axis a) const;
137
138   Interval extent (Grob * refpoint, Axis) const;
139  
140   void translate_axis (Real, Axis);
141   Real relative_coordinate (Grob const* refp, Axis) const;
142   Grob*common_refpoint (Grob const* s, Axis a) const;
143
144
145   // duh. slim down interface here. (todo)
146   bool has_offset_callback_b (SCM callback, Axis)const;
147   void add_offset_callback (SCM callback, Axis);
148   bool has_extent_callback_b (SCM, Axis)const;  
149   void set_extent (SCM , Axis);
150   Real get_offset (Axis a) const;
151   
152   void set_parent (Grob* e, Axis);
153   
154   Grob *get_parent (Axis a) const {   return  dim_cache_[a].parent_; }
155   DECLARE_SCHEME_CALLBACK (fixup_refpoint, (SCM));
156 };
157
158 DECLARE_UNSMOB(Grob,grob);
159 Spanner* unsmob_spanner (SCM );
160 Item* unsmob_item (SCM );
161
162 Grob*common_refpoint_of_list (SCM elt_list, Grob * , Axis a);
163 Grob*common_refpoint_of_array (Link_array<Grob> const&, Grob * , Axis a);
164
165 void set_break_subsititution (SCM criterion);
166 SCM substitute_mutable_property_alist (SCM alist);
167
168 Link_array<Grob> ly_scm2grobs (SCM l);
169 SCM ly_grobs2scm (Link_array<Grob> a);
170
171 #endif // STAFFELEM_HH
172