]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/engraver.hh
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[lilypond.git] / lily / include / engraver.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef ENGRAVER_HH
21 #define ENGRAVER_HH
22
23 #include "callback.hh"
24 #include "grob.hh"
25 #include "grob-info.hh"
26 #include "translator.hh"
27
28 /**
29    a struct which processes events, and creates the #Grob#s.
30    It may use derived classes.
31 */
32 class Engraver : public Translator
33 {
34   Grob *internal_make_grob (SCM sym, SCM cause, char const *name,
35                             char const *f, int l, char const *fun);
36   friend SCM ly_engraver_make_grob (SCM, SCM, SCM);
37   friend class Engraver_group;
38 protected:
39   /*
40     take note of item/spanner
41     put item in spanner. Adjust local key; etc.
42
43     Default: ignore the info
44   */
45   virtual void acknowledge_grob (Grob_info) {}
46   virtual void announce_grob (Grob_info, Context *reroute_context = 0);
47   virtual void announce_end_grob (Grob_info, Context *reroute_context = 0);
48   Engraver_group *get_daddy_engraver () const;
49
50 public:
51   template <class T, void (T::*callback)(Grob_info)>
52   static SCM ack_trampoline (SCM target, SCM grob, SCM source_engraver)
53   {
54     T *t = LY_ASSERT_SMOB (T, target, 1);
55     Grob *g = LY_ASSERT_SMOB (Grob, grob, 2);
56     Engraver *e = LY_ASSERT_SMOB (Engraver, source_engraver, 3);
57
58     (t->*callback) (Grob_info (e, g));
59     return SCM_UNSPECIFIED;
60   }
61
62   /**
63      Announce element. Default: pass on to daddy. Utility
64   */
65   void announce_grob (Grob *, SCM cause);
66   void announce_end_grob (Grob *, SCM cause);
67
68   Grob_info make_grob_info (Grob *, SCM cause);
69
70   Item *internal_make_item (SCM sym, SCM cause, char const *name,
71                             char const *f, int l, char const *fun);
72   Spanner *internal_make_spanner (SCM sym, SCM cause, char const *name,
73                                   char const *f, int l, char const *fun);
74   Paper_column *internal_make_column (SCM sym, char const *name,
75                                       char const *f, int l, char const *fun);
76
77   /**
78      override other ctor
79   */
80   DECLARE_CLASSNAME (Engraver);
81   DECLARE_TRANSLATOR_CALLBACKS (Engraver);
82   Engraver ();
83 };
84
85 #define make_item(x, cause) internal_make_item (ly_symbol2scm (x), cause, x, __FILE__, __LINE__, __FUNCTION__)
86 #define make_spanner(x, cause) internal_make_spanner (ly_symbol2scm (x), cause, x, __FILE__, __LINE__, __FUNCTION__)
87 #define make_paper_column(x) internal_make_column (ly_symbol2scm (x), x, __FILE__, __LINE__, __FUNCTION__)
88
89 bool ly_is_grob_cause (SCM obj);
90
91 #endif // ENGRAVER_HH