2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "engraver.hh"
23 #include "grob-properties.hh"
25 class Grace_engraver : public Engraver
27 void consider_change_grace_settings ();
29 void start_translation_timestep ();
30 virtual void derived_mark () const;
31 virtual void initialize ();
33 TRANSLATOR_DECLARATIONS (Grace_engraver);
39 Grace_engraver::Grace_engraver ()
41 grace_settings_ = SCM_EOL;
42 last_moment_ = Moment (Rational (-1, 1));
46 Grace_engraver::initialize ()
48 consider_change_grace_settings ();
52 Grace_engraver::consider_change_grace_settings ()
54 Moment now = now_mom ();
55 if (last_moment_.grace_part_ && !now.grace_part_)
57 for (SCM s = grace_settings_; scm_is_pair (s); s = scm_cdr (s))
59 SCM elt = scm_car (s);
60 SCM context = scm_car (elt);
61 SCM grob = scm_cadr (elt);
62 SCM cell = scm_cddr (elt);
64 Grob_property_info (Context::unsmob (context), grob).matched_pop (cell);
67 grace_settings_ = SCM_EOL;
69 else if (!last_moment_.grace_part_ && now.grace_part_)
71 SCM settings = get_property ("graceSettings");
73 grace_settings_ = SCM_EOL;
74 for (SCM s = settings; scm_is_pair (s); s = scm_cdr (s))
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));
82 if (!scm_is_pair (sym))
83 sym = scm_list_1 (sym);
85 Context *c = context ();
86 while (c && !c->is_alias (context_name))
87 c = c->get_parent_context ();
91 SCM cell = Grob_property_info (c, grob).push (sym, val);
93 = scm_cons (scm_cons2 (c->self_scm (), grob, cell), grace_settings_);
96 programming_error ("cannot find context from graceSettings: "
97 + ly_symbol2string (context_name));
101 last_moment_ = now_mom ();
105 Grace_engraver::derived_mark () const
107 scm_gc_mark (grace_settings_);
108 Engraver::derived_mark ();
112 Grace_engraver::start_translation_timestep ()
114 consider_change_grace_settings ();
117 #include "translator.icc"
119 ADD_TRANSLATOR (Grace_engraver,
121 "Set font size and other properties for grace notes.",