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