]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/engraver.hh
release: 0.1.8
[lilypond.git] / lily / include / engraver.hh
1 /*
2   engraver.hh -- declare Engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #ifndef ENGRAVER_HH
11 #define ENGRAVER_HH
12
13 #include "lily-proto.hh"
14 #include "varray.hh"
15 #include "request.hh"
16 #include "score-elem-info.hh"
17 #include "staff-info.hh"
18
19
20
21
22 /**
23   a struct which processes requests, and creates the #Score_elem#s.
24   It may use derived classes. Hungarian postfix: grav
25   
26   */
27
28 class Engraver {
29     
30     friend class Engraver_group_engraver;
31     /**
32       You cannot copy a Engraver
33      */
34     Engraver (const Engraver&){}
35
36     enum { 
37         VIRGIN,
38         CREATION_INITED,
39         MOVE_INITED,
40         ACCEPTED_REQS,
41         PROCESSED_REQS,
42         ACKED_REQS,
43         MOVE_DONE
44     } status;
45
46 protected:
47     
48
49     /// utility
50     virtual Paper_def * paper() const;
51
52     
53     /// make items/spanners with the requests you got
54     virtual void do_process_requests(){}
55
56     /** typeset any items/spanners. Default: do nothing
57      */
58     virtual void do_pre_move_processing(){}
59     /** reset any appropriate data. Default: do nothing
60      */
61     virtual void do_post_move_processing(){}
62    
63
64     virtual void do_creation_processing() {}
65     virtual void do_removal_processing() {}
66
67     /**
68       Invoke walker method to typeset element. Default: pass on to daddy.
69       */
70     virtual void typeset_element (Score_elem*elem_p);
71     
72      /**
73       take note of item/spanner
74       put item in spanner. Adjust local key; etc.
75
76       Default: ignore the info
77       */
78     virtual void acknowledge_element (Score_elem_info) {}
79     /**
80       Announce element. Default: pass on to daddy. Utility
81       */
82     virtual void announce_element (Score_elem_info);
83     /**
84       Set Feature of the engraver (s). Default: ignore Feature.
85      */
86     virtual void set_feature (Feature){}
87     /**
88       ask daddy for a feature
89      */
90     virtual Scalar get_feature (String type_str);
91     /**
92       Does this equal or contain a certain engraver?
93      */
94
95     virtual void sync_features() {}
96    
97     virtual bool contains_b (Engraver*grav_l)const;
98     /**
99       Get information on the staff. Default: ask daddy.
100       */
101     virtual Staff_info get_staff_info()const;
102     virtual void fill_staff_info (Staff_info&);
103
104
105     virtual void do_print()const;  
106     /*    
107           @see{try_request}
108           Default: always return false
109       */
110     virtual bool do_try_request (Request *req_l);
111 public:
112     void pre_move_processing();
113     void process_requests();
114     /**
115       try to fit the request in this engraver
116
117       @return
118       false: not noted,  not taken.
119
120       true: request swallowed. Don't try to put the request elsewhere.
121
122       */
123     bool try_request (Request*);
124     bool is_bottom_engraver() const;
125
126     void post_move_processing();
127     void removal_processing();
128     
129     Engraver_group_engraver * daddy_grav_l_;
130
131     Engraver();
132     virtual ~Engraver(){}
133     DECLARE_MY_RUNTIME_TYPEINFO;
134     void print() const;
135 };
136
137 /**
138   A macro to automate administration of engravers.
139  */
140 #define ADD_THIS_ENGRAVER(c)                            \
141 struct c ## init {                                      \
142     static Engraver * globalctor(){             \
143         return new c;                                   \
144     }                                                   \
145     c ## init() {                                       \
146         add_engraver (c::static_name(), globalctor);    \
147                                                         \
148     }                                                   \
149 } _ ## c ## init;
150
151 typedef Engraver*(*Grav_ctor)(void);
152 void add_engraver (String s, Grav_ctor f);
153
154 #endif // ENGRAVER_HH
155