]> git.donarmstrong.com Git - lilypond.git/blob - lily/grace-spacing-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / grace-spacing-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2015 Han-Wen <hanwen@lilypond.org>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "engraver.hh"
22 #include "moment.hh"
23 #include "pointer-group-interface.hh"
24 #include "spanner.hh"
25
26 #include "translator.icc"
27
28 class Grace_spacing_engraver : public Engraver
29 {
30   TRANSLATOR_DECLARATIONS (Grace_spacing_engraver);
31
32 protected:
33
34   Moment last_moment_;
35   Spanner *grace_spacing_;
36
37   void process_music ();
38   void stop_translation_timestep ();
39 };
40
41 Grace_spacing_engraver::Grace_spacing_engraver (Context *c)
42   : Engraver (c)
43 {
44   grace_spacing_ = 0;
45 }
46
47 void
48 Grace_spacing_engraver::process_music ()
49 {
50   Moment now = now_mom ();
51   if (!last_moment_.grace_part_ and now.grace_part_)
52     {
53       grace_spacing_ = make_spanner ("GraceSpacing", SCM_EOL);
54     }
55
56   if (grace_spacing_ && (now.grace_part_ || last_moment_.grace_part_))
57     {
58       Grob *column = unsmob<Grob> (get_property ("currentMusicalColumn"));
59       Pointer_group_interface::add_grob (grace_spacing_,
60                                          ly_symbol2scm ("columns"),
61                                          column);
62
63       column->set_object ("grace-spacing", grace_spacing_->self_scm ());
64
65       if (!grace_spacing_->get_bound (LEFT))
66         grace_spacing_->set_bound (LEFT, column);
67       else
68         grace_spacing_->set_bound (RIGHT, column);
69     }
70 }
71
72 void
73 Grace_spacing_engraver::stop_translation_timestep ()
74 {
75   last_moment_ = now_mom ();
76
77   if (!last_moment_.grace_part_)
78     grace_spacing_ = 0;
79 }
80
81 void
82 Grace_spacing_engraver::boot ()
83 {
84
85 }
86
87 ADD_TRANSLATOR (Grace_spacing_engraver,
88                 "Bookkeeping of shortest starting and playing notes in grace"
89                 " note runs.",
90
91                 /* create */
92                 "GraceSpacing ",
93
94                 /* read */
95                 "currentMusicalColumn ",
96
97                 /* write */
98                 ""
99                );