]> git.donarmstrong.com Git - lilypond.git/blob - lily/default-bar-line-engraver.cc
e9dd6f8c5fd91591e2cf5d55036b3f2a93b351d8
[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--2007 Han-Wen Nienhuys <hanwen@xs4all.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                 /* doc */
32                 "This engraver determines what kind of automatic bar lines"
33                 " should be produced, and sets @code{whichBar} accordingly."
34                 "  It should be at the same level as @ref{Timing_translator}.",
35                 
36                 /* create */
37                 "",
38
39                 /* read */
40                 "automaticBars "
41                 "barAlways "
42                 "defaultBarType "
43                 "measureLength "
44                 "whichBar "
45                 "measurePosition ",
46                 
47                 /* write */
48                 "automaticBars "
49                 );
50
51 Default_bar_line_engraver::Default_bar_line_engraver ()
52 {
53   last_moment_.main_part_ = Rational (-1);
54 }
55
56 void
57 Default_bar_line_engraver::start_translation_timestep ()
58 {
59   SCM automatic_bars = get_property ("automaticBars");
60   Moment now = now_mom ();
61   SCM which = get_property ("whichBar");
62
63   /* Set the first bar of the score? */
64   if (!scm_is_string (which))
65     which = SCM_EOL;
66
67   Moment mp = measure_position (context ());
68   bool start_of_measure = (last_moment_.main_part_ != now.main_part_
69                            && !mp.main_part_);
70
71   if (!scm_is_string (which) && to_boolean (automatic_bars))
72     {
73       SCM always = get_property ("barAlways");
74
75       if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
76           || to_boolean (always))
77         {
78           /* should this work, or be junked?  See input/bugs/no-bars.ly */
79           which = get_property ("defaultBarType");
80         }
81     }
82
83   context ()->set_property ("whichBar", which);
84 }
85
86 void
87 Default_bar_line_engraver::stop_translation_timestep ()
88 {
89   context ()->set_property ("whichBar", SCM_EOL);
90   last_moment_ = now_mom ();
91 }