]> git.donarmstrong.com Git - lilypond.git/blob - lily/tweak-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / tweak-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "engraver.hh"
22
23 #include "grob.hh"
24 #include "stream-event.hh"
25 #include "translator.icc"
26
27 class Tweak_engraver : public Engraver
28 {
29   TRANSLATOR_DECLARATIONS (Tweak_engraver);
30
31 protected:
32   void acknowledge_grob (Grob_info);
33 };
34
35 Tweak_engraver::Tweak_engraver (Context *c)
36   : Engraver (c)
37 {
38 }
39
40 void
41 Tweak_engraver::acknowledge_grob (Grob_info info)
42 {
43   Stream_event *ev = info.event_cause ();
44   bool direct = ev;
45   SCM grobname = SCM_UNDEFINED;
46   if (!direct)
47     ev = info.ultimate_event_cause ();
48   if (ev)
49     {
50       // Each tweak conses an address and a value.
51       // The address has one of the following forms:
52       // symbol -> direct tweak
53       // (grob . symbol) -> targeted tweak
54       // (#t . symbol-path) -> direct nested tweak
55       // (grob . symbol-path) -> targeted nested tweak
56       for (SCM s = ev->get_property ("tweaks");
57            scm_is_pair (s); s = scm_cdr (s))
58         {
59           if (scm_is_pair (scm_caar (s)))
60             {
61               if (scm_is_symbol (scm_caaar (s)))
62                 {
63                   if (SCM_UNBNDP (grobname))
64                     grobname = scm_from_utf8_symbol
65                       (info.grob ()->name ().c_str ());
66                   if (scm_is_eq (scm_caaar (s), grobname))
67                     {
68                       if (scm_is_symbol (scm_cdaar (s)))
69                         info.grob ()->set_property (scm_cdaar (s), scm_cdar (s));
70                       else
71                         set_nested_property (info.grob (), scm_cdaar (s),
72                                              scm_cdar (s));
73                     }
74                 }
75               else if (direct)
76                 set_nested_property (info.grob (), scm_cdaar (s),
77                                      scm_cdar (s));
78             }
79           else if (direct)
80             info.grob ()->set_property (scm_caar (s), scm_cdar (s));
81         }
82     }
83 }
84
85 void
86 Tweak_engraver::boot ()
87 {
88   ADD_ACKNOWLEDGER (Tweak_engraver, grob);
89 }
90
91 ADD_TRANSLATOR (Tweak_engraver,
92                 /* doc */
93                 "Read the @code{tweaks} property from the originating event,"
94                 " and set properties.",
95
96                 /* create */
97                 "",
98
99                 /* read */
100                 "",
101
102                 /* write */
103                 ""
104                );