]> git.donarmstrong.com Git - lilypond.git/blob - lily/grace-spacing-engraver.cc
Run `make grand-replace'.
[lilypond.git] / lily / grace-spacing-engraver.cc
1 /*
2   grace-spacing-engraver.cc -- implement Grace_spacing_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2006--2008 Han-Wen <hanwen@lilypond.org>
7
8 */
9
10 #include "engraver.hh"
11 #include "moment.hh"
12 #include "pointer-group-interface.hh"
13 #include "spanner.hh"
14
15 #include "translator.icc"
16
17 class Grace_spacing_engraver : public Engraver
18 {
19   TRANSLATOR_DECLARATIONS (Grace_spacing_engraver);
20
21 protected:
22
23   Moment last_moment_;
24   Spanner *grace_spacing_;
25   
26   void process_music ();
27   void stop_translation_timestep ();
28 };
29
30
31 Grace_spacing_engraver::Grace_spacing_engraver ()
32 {
33   grace_spacing_ = 0;
34 }
35
36 void
37 Grace_spacing_engraver::process_music ()
38 {
39   Moment now = now_mom ();
40   if (!last_moment_.grace_part_ and now.grace_part_)
41     {
42       grace_spacing_ = make_spanner ("GraceSpacing", SCM_EOL);
43     }
44
45
46   if (grace_spacing_ && (now.grace_part_ || last_moment_.grace_part_))
47     {
48       Grob *column = unsmob_grob (get_property ("currentMusicalColumn"));
49       Pointer_group_interface::add_grob (grace_spacing_,
50                                          ly_symbol2scm ("columns"),
51                                          column);
52
53       column->set_object ("grace-spacing", grace_spacing_->self_scm ());
54
55       if (!grace_spacing_->get_bound (LEFT))
56         grace_spacing_->set_bound (LEFT, column);
57       else
58         grace_spacing_->set_bound (RIGHT, column);
59     }
60 }
61
62 void
63 Grace_spacing_engraver::stop_translation_timestep ()
64 {
65   last_moment_ = now_mom ();
66
67   if (!last_moment_.grace_part_)
68     grace_spacing_ = 0;
69 }
70
71
72 ADD_TRANSLATOR (Grace_spacing_engraver,
73                 "Bookkeeping of shortest starting and playing notes in grace"
74                 " note runs.",
75
76                 /* create */
77                 "GraceSpacing ",
78
79                 /* read */
80                 "currentMusicalColumn ",
81                 
82                 /* write */
83                 ""
84                 );