]> git.donarmstrong.com Git - lilypond.git/blob - lily/default-bar-line-engraver.cc
* The grand 2005-2006 replace.
[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                 /* accept */ "",
39
40                 /* read */
41                 "automaticBars "
42                 "barAlways "
43                 "defaultBarType "
44                 "measureLength "
45                 "whichBar "
46                 "measurePosition ",
47                 
48                 /* write */ "automaticBars");
49
50 Default_bar_line_engraver::Default_bar_line_engraver ()
51 {
52   last_moment_.main_part_ = Rational (-1);
53 }
54
55 void
56 Default_bar_line_engraver::start_translation_timestep ()
57 {
58   SCM automatic_bars = get_property ("automaticBars");
59   Moment now = now_mom ();
60   SCM which = get_property ("whichBar");
61
62   /* Set the first bar of the score? */
63   if (!scm_is_string (which))
64     which = SCM_EOL;
65
66   Moment mp = measure_position (context ());
67   bool start_of_measure = (last_moment_.main_part_ != now.main_part_
68                            && !mp.main_part_);
69
70   if (!scm_is_string (which) && to_boolean (automatic_bars))
71     {
72       SCM always = get_property ("barAlways");
73
74       if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
75           || to_boolean (always))
76         {
77           /* should this work, or be junked?  See input/bugs/no-bars.ly */
78           which = get_property ("defaultBarType");
79         }
80     }
81
82   context ()->set_property ("whichBar", which);
83 }
84
85 void
86 Default_bar_line_engraver::stop_translation_timestep ()
87 {
88   context ()->set_property ("whichBar", SCM_EOL);
89   last_moment_ = now_mom ();
90 }