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