]> git.donarmstrong.com Git - lilypond.git/blob - lily/grace-engraver.cc
new file.
[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
10 #include "engraver.hh"
11 #include "context.hh"
12 #include "warn.hh"
13
14 class Grace_engraver : public Engraver
15 {
16 protected:
17   virtual void start_translation_timestep ();
18   virtual void derived_mark ();
19   
20   TRANSLATOR_DECLARATIONS (Grace_engraver);
21   Moment last_moment_;
22   SCM grace_settings_;
23 public:
24 };
25
26
27 Grace_engraver::Grace_engraver()
28 {
29   grace_settings_ = SCM_EOL;
30 }
31
32 void
33 Grace_engraver::derived_mark ()
34 {
35   scm_gc_mark (grace_settings_);
36 }
37
38 void
39 Grace_engraver::start_translation_timestep ()
40 {
41   Moment now = now_mom ();
42   if (last_moment_.grace_part_ && !now.grace_part_)
43     {
44       for (SCM s = grace_settings_; scm_is_pair (s); s = scm_cdr (s))
45         {
46           SCM context = scm_caar (s);
47           SCM entry = scm_cdar (s);
48           SCM grob = scm_cadr (entry);
49           SCM sym = scm_caddr (entry);
50
51           execute_pushpop_property (unsmob_context (context),
52                                     grob, sym, SCM_UNDEFINED);
53         }
54
55       grace_settings_ = SCM_EOL;
56     }
57   else if (!last_moment_.grace_part_ && now.grace_part_)
58     {
59       SCM settings = get_property ("graceSettings");
60
61       grace_settings_ = SCM_EOL;
62       for (SCM s = settings; scm_is_pair (s); s = scm_cdr (s))
63         {
64           SCM entry = scm_car (s);
65           SCM context_name = scm_car (entry);
66           SCM grob = scm_cadr (entry);
67           SCM sym = scm_caddr (entry);
68           SCM val = scm_cadr (scm_cddr (entry));
69
70           Context *c = context ();
71           while (c  
72                  && c->context_name_symbol () != 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 ("Cannot find context");
87               scm_display (context_name, scm_current_error_port());
88             }
89         }
90     }
91
92   last_moment_ = now;
93 }
94
95
96 ADD_TRANSLATOR (Grace_engraver,
97                    /* descr */       "Set font size and other properties for grace notes.",
98                    /* creats*/       "",
99                    /* accepts */     "",
100                    /* acks  */      "",
101                    /* reads */       "graceSettings",
102                    /* write */       "");