]> git.donarmstrong.com Git - lilypond.git/blob - lily/grace-engraver.cc
* lily/include/lily-guile.hh: rename ly_c_X_p -> ly_is_X
[lilypond.git] / lily / grace-engraver.cc
1 /*
2   grace-engraver.cc -- implement Grace_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "engraver.hh"
10 #include "context.hh"
11 #include "warn.hh"
12
13 class Grace_engraver : public Engraver
14 {
15   void consider_change_grace_settings ();
16 protected:
17   virtual void start_translation_timestep ();
18   virtual void derived_mark () const;
19   virtual void initialize (); 
20
21   TRANSLATOR_DECLARATIONS (Grace_engraver);
22   Moment last_moment_;
23   SCM grace_settings_;
24 public:
25 };
26
27 Grace_engraver::Grace_engraver ()
28 {
29   grace_settings_ = SCM_EOL;
30   last_moment_ = Moment (Rational (-1,1));
31 }
32
33 void
34 Grace_engraver::initialize ()
35 {
36   consider_change_grace_settings ();
37 }
38
39 void
40 Grace_engraver::consider_change_grace_settings ()
41 {
42   Moment now = now_mom ();
43   if (last_moment_.grace_part_ && !now.grace_part_)
44     {
45       for (SCM s = grace_settings_; scm_is_pair (s); s = scm_cdr (s))
46         {
47           SCM context = scm_caar (s);
48           SCM entry = scm_cdar (s);
49           SCM grob = scm_cadr (entry);
50           SCM sym = scm_caddr (entry);
51
52           execute_pushpop_property (unsmob_context (context),
53                                     grob, sym, SCM_UNDEFINED);
54         }
55
56       grace_settings_ = SCM_EOL;
57     }
58   else if (!last_moment_.grace_part_ && now.grace_part_)
59     {
60       SCM settings = get_property ("graceSettings");
61
62       grace_settings_ = SCM_EOL;
63       for (SCM s = settings; scm_is_pair (s); s = scm_cdr (s))
64         {
65           SCM entry = scm_car (s);
66           SCM context_name = scm_car (entry);
67           SCM grob = scm_cadr (entry);
68           SCM sym = scm_caddr (entry);
69           SCM val = scm_cadr (scm_cddr (entry));
70
71           Context *c = context ();
72           while (c && !c->is_alias (context_name))
73             {
74               c = c->get_parent_context ();
75             }
76
77           if (c)
78             {
79               execute_pushpop_property (c,
80                                         grob, sym, val);
81               grace_settings_
82                 = scm_cons (scm_cons (c->self_scm (), entry), grace_settings_);
83             }
84           else
85             {
86               programming_error ("can't find context");
87               scm_display (context_name, scm_current_error_port ());
88             }
89         }
90     }
91
92   last_moment_ = now_mom();
93 }
94
95 void
96 Grace_engraver::derived_mark () const
97 {
98   scm_gc_mark (grace_settings_);
99   Engraver::derived_mark ();
100 }
101
102 void
103 Grace_engraver::start_translation_timestep ()
104 {
105   consider_change_grace_settings ();
106 }
107
108 ADD_TRANSLATOR (Grace_engraver,
109                 /* descr */ "Set font size and other properties for grace notes.",
110                 /* creats*/ "",
111                 /* accepts */ "",
112                 /* acks  */ "",
113                 /* reads */ "graceSettings",
114                 /* write */ "");