]> git.donarmstrong.com Git - lilypond.git/blob - lily/grace-spacing-engraver.cc
* scm/output-lib.scm (grace-spacing::calc-shortest-duration): new function.
[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 Han-Wen <hanwen@lilypond.org>
7
8 */
9
10 #include "engraver.hh"
11 #include "spanner.hh"
12 #include "pointer-group-interface.hh"
13
14 #include "translator.icc"
15
16 class Grace_spacing_engraver : public Engraver
17 {
18   TRANSLATOR_DECLARATIONS (Grace_spacing_engraver);
19
20 protected:
21
22   Moment last_moment_;
23   Spanner *grace_spacing_;
24   
25   void process_music ();
26   void stop_translation_timestep ();
27 };
28
29
30 Grace_spacing_engraver::Grace_spacing_engraver ()
31 {
32   grace_spacing_ = 0;
33 }
34
35 void
36 Grace_spacing_engraver::process_music ()
37 {
38   Moment now = now_mom ();
39   if (!last_moment_.grace_part_ and now.grace_part_)
40     {
41       grace_spacing_ = make_spanner ("GraceSpacing", SCM_EOL);
42     }
43
44
45   if (grace_spacing_ && (now.grace_part_ || last_moment_.grace_part_))
46     {
47       Grob *column = unsmob_grob (get_property ("currentMusicalColumn"));
48       Pointer_group_interface::add_grob (grace_spacing_,
49                                          ly_symbol2scm ("columns"),
50                                          column);
51
52       column->set_object ("grace-spacing", grace_spacing_->self_scm ());
53     }
54 }
55
56 void
57 Grace_spacing_engraver::stop_translation_timestep ()
58 {
59   last_moment_ = now_mom ();
60
61   if (!last_moment_.grace_part_)
62     grace_spacing_ = 0;
63 }
64
65
66 ADD_TRANSLATOR (Grace_spacing_engraver,
67                 "Bookkeeping of shortest starting and playing notes in grace note runs.",
68
69                 /* create */
70                 "GraceSpacing ",
71                 
72                 /* accept */
73                 "",
74
75                 /* read */
76                 "currentMusicalColumn ",
77                 
78                 /* write */ "");