]> git.donarmstrong.com Git - lilypond.git/blob - lily/default-bar-line-engraver.cc
Web-ja: update introduction
[lilypond.git] / lily / default-bar-line-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21 #include "context.hh"
22 #include "grob.hh"
23 #include "warn.hh"
24
25 class Default_bar_line_engraver : public Engraver
26 {
27 protected:
28   /* Need to know whether we're advancing in grace notes, or not. */
29   Moment last_moment_;
30
31   void start_translation_timestep ();
32   void stop_translation_timestep ();
33
34 public:
35   TRANSLATOR_DECLARATIONS (Default_bar_line_engraver);
36 };
37
38 #include "translator.icc"
39
40 void
41 Default_bar_line_engraver::boot ()
42 {
43
44 }
45
46 ADD_TRANSLATOR (Default_bar_line_engraver,
47                 /* doc */
48                 "This engraver determines what kind of automatic bar lines"
49                 " should be produced, and sets @code{whichBar} accordingly."
50                 "  It should be at the same level as @ref{Timing_translator}.",
51
52                 /* create */
53                 "",
54
55                 /* read */
56                 "automaticBars "
57                 "barAlways "
58                 "defaultBarType "
59                 "measureLength "
60                 "whichBar "
61                 "measurePosition "
62                 "timing ",
63
64                 /* write */
65                 ""
66                );
67
68 Default_bar_line_engraver::Default_bar_line_engraver (Context *c)
69   : Engraver (c)
70 {
71   last_moment_.main_part_ = Rational (-1);
72 }
73
74 void
75 Default_bar_line_engraver::start_translation_timestep ()
76 {
77   SCM automatic_bars = get_property ("automaticBars");
78   Moment now = now_mom ();
79   SCM which = get_property ("whichBar");
80
81   /* Set the first bar of the score? */
82   if (!scm_is_string (which))
83     which = SCM_EOL;
84
85   Moment mp = measure_position (context ());
86   bool start_of_measure = (last_moment_.main_part_ != now.main_part_
87                            && !mp.main_part_
88                            && to_boolean (get_property ("timing")));
89
90   if (!scm_is_string (which) && to_boolean (automatic_bars))
91     {
92       SCM always = get_property ("barAlways");
93
94       if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
95           || to_boolean (always))
96         {
97           /* should this work, or be junked?  See input/bugs/no-bars.ly */
98           which = get_property ("defaultBarType");
99         }
100     }
101
102   context ()->set_property ("whichBar", which);
103 }
104
105 void
106 Default_bar_line_engraver::stop_translation_timestep ()
107 {
108   context ()->set_property ("whichBar", SCM_EOL);
109   last_moment_ = now_mom ();
110 }