]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-engraver.cc
* lily/break-substitution.cc (fast_substitute_grob_array): do
[lilypond.git] / lily / timing-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
16 class Default_bar_line_engraver : public Engraver
17 {
18 protected:
19   /* Need to know whether we're advancing in grace notes, or not. */
20   Moment last_moment_;
21
22   PRECOMPUTED_VIRTUAL void start_translation_timestep ();
23   PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
24
25 public:
26   TRANSLATOR_DECLARATIONS (Default_bar_line_engraver);
27 };
28
29 #include "translator.icc"
30
31 ADD_TRANSLATOR (Default_bar_line_engraver,
32                 "This engraver determines what kind of automatic bar lines should be produced, "
33                 "and sets @code{whichBar} accordingly. It should be at the same "
34                 "level as @ref{Timing_translator}. ",  
35                 /* creats*/ "",
36                 /* accepts */ "",
37                 /* acks  */ "",
38                 /* reads */
39                 "measurePosition automaticBars whichBar barAlways defaultBarType "
40                 "measureLength",
41                 /* write */ "automaticBars");
42
43
44 Default_bar_line_engraver::Default_bar_line_engraver ()
45 {
46   last_moment_.main_part_ = Rational (-1);
47 }
48
49 void
50 Default_bar_line_engraver::start_translation_timestep ()
51 {
52   SCM automatic_bars = get_property ("automaticBars");
53   Moment now = now_mom ();
54   SCM which = get_property ("whichBar");
55
56   /* Set the first bar of the score? */
57   if (!scm_is_string (which))
58     which = SCM_EOL;
59
60   Moment mp = measure_position (context ());
61   bool start_of_measure = (last_moment_.main_part_ != now.main_part_
62                            && !mp.main_part_);
63
64   if (!scm_is_string (which) && to_boolean (automatic_bars))
65     {
66       SCM always = get_property ("barAlways");
67
68       if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
69           || to_boolean (always))
70         {
71           /* should this work, or be junked?  See input/bugs/no-bars.ly */
72           which = get_property ("defaultBarType");
73         }
74     }
75
76   context ()->set_property ("whichBar", which);
77 }
78
79 void
80 Default_bar_line_engraver::stop_translation_timestep ()
81 {
82   context ()->set_property ("whichBar", SCM_EOL);
83   last_moment_ = now_mom ();
84 }