]> git.donarmstrong.com Git - lilypond.git/blob - lily/default-bar-line-engraver.cc
(parse_symbol_list): Bugfix.
[lilypond.git] / lily / default-bar-line-engraver.cc
1 /*
2   timing-engraver.cc -- implement Default_bar_line_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "engraver.hh"
10 #include "context.hh"
11 #include "multi-measure-rest.hh"
12 #include "grob.hh"
13 #include "warn.hh"
14
15 class Default_bar_line_engraver : public Engraver
16 {
17 protected:
18   /* Need to know whether we're advancing in grace notes, or not. */
19   Moment last_moment_;
20
21   void start_translation_timestep ();
22   void stop_translation_timestep ();
23
24 public:
25   TRANSLATOR_DECLARATIONS (Default_bar_line_engraver);
26 };
27
28 #include "translator.icc"
29
30 ADD_TRANSLATOR (Default_bar_line_engraver,
31                 "This engraver determines what kind of automatic bar lines should be produced, "
32                 "and sets @code{whichBar} accordingly. It should be at the same "
33                 "level as @ref{Timing_translator}. ",
34                 /* create */ "",
35                 /* accept */ "",
36                 /* read */
37                 "measurePosition automaticBars whichBar barAlways defaultBarType "
38                 "measureLength",
39                 /* write */ "automaticBars");
40
41 Default_bar_line_engraver::Default_bar_line_engraver ()
42 {
43   last_moment_.main_part_ = Rational (-1);
44 }
45
46 void
47 Default_bar_line_engraver::start_translation_timestep ()
48 {
49   SCM automatic_bars = get_property ("automaticBars");
50   Moment now = now_mom ();
51   SCM which = get_property ("whichBar");
52
53   /* Set the first bar of the score? */
54   if (!scm_is_string (which))
55     which = SCM_EOL;
56
57   Moment mp = measure_position (context ());
58   bool start_of_measure = (last_moment_.main_part_ != now.main_part_
59                            && !mp.main_part_);
60
61   if (!scm_is_string (which) && to_boolean (automatic_bars))
62     {
63       SCM always = get_property ("barAlways");
64
65       if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
66           || to_boolean (always))
67         {
68           /* should this work, or be junked?  See input/bugs/no-bars.ly */
69           which = get_property ("defaultBarType");
70         }
71     }
72
73   context ()->set_property ("whichBar", which);
74 }
75
76 void
77 Default_bar_line_engraver::stop_translation_timestep ()
78 {
79   context ()->set_property ("whichBar", SCM_EOL);
80   last_moment_ = now_mom ();
81 }