]> git.donarmstrong.com Git - lilypond.git/blob - lily/grace-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / grace-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2014 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 #include "engraver.hh"
21 #include "context.hh"
22 #include "warn.hh"
23
24 class Grace_engraver : public Engraver
25 {
26   void consider_change_grace_settings ();
27 protected:
28   void start_translation_timestep ();
29   virtual void derived_mark () const;
30   virtual void initialize ();
31
32   TRANSLATOR_DECLARATIONS (Grace_engraver);
33   Moment last_moment_;
34   SCM grace_settings_;
35 public:
36 };
37
38 Grace_engraver::Grace_engraver ()
39 {
40   grace_settings_ = SCM_EOL;
41   last_moment_ = Moment (Rational (-1, 1));
42 }
43
44 void
45 Grace_engraver::initialize ()
46 {
47   consider_change_grace_settings ();
48 }
49
50 void
51 Grace_engraver::consider_change_grace_settings ()
52 {
53   Moment now = now_mom ();
54   if (last_moment_.grace_part_ && !now.grace_part_)
55     {
56       for (SCM s = grace_settings_; scm_is_pair (s); s = scm_cdr (s))
57         {
58           SCM context = scm_caar (s);
59           SCM entry = scm_cdar (s);
60           SCM grob = scm_cadr (entry);
61           SCM sym = scm_caddr (entry);
62
63           execute_pushpop_property (unsmob_context (context),
64                                     grob, sym, SCM_UNDEFINED);
65         }
66
67       grace_settings_ = SCM_EOL;
68     }
69   else if (!last_moment_.grace_part_ && now.grace_part_)
70     {
71       SCM settings = get_property ("graceSettings");
72
73       grace_settings_ = SCM_EOL;
74       for (SCM s = settings; scm_is_pair (s); s = scm_cdr (s))
75         {
76           SCM entry = scm_car (s);
77           SCM context_name = scm_car (entry);
78           SCM grob = scm_cadr (entry);
79           SCM sym = scm_caddr (entry);
80           SCM val = scm_cadr (scm_cddr (entry));
81
82           Context *c = context ();
83           while (c && !c->is_alias (context_name))
84             c = c->get_parent_context ();
85
86           if (c)
87             {
88               execute_pushpop_property (c,
89                                         grob, sym, val);
90               grace_settings_
91                 = scm_cons (scm_cons (c->self_scm (), entry), grace_settings_);
92             }
93           else
94             programming_error ("cannot find context from graceSettings: "
95                                + ly_symbol2string (context_name));
96         }
97     }
98
99   last_moment_ = now_mom ();
100 }
101
102 void
103 Grace_engraver::derived_mark () const
104 {
105   scm_gc_mark (grace_settings_);
106   Engraver::derived_mark ();
107 }
108
109 void
110 Grace_engraver::start_translation_timestep ()
111 {
112   consider_change_grace_settings ();
113 }
114
115 #include "translator.icc"
116
117 ADD_TRANSLATOR (Grace_engraver,
118                 /* doc */
119                 "Set font size and other properties for grace notes.",
120
121                 /* create */
122                 "",
123
124                 /* read */
125                 "graceSettings ",
126
127                 /* write */
128                 ""
129                );