]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-engraver.cc
83ff379f518833f03c0d998cd2b77ab7739b8aca
[lilypond.git] / lily / timing-engraver.cc
1 /*
2   timing-grav.cc -- implement Timing_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "context.hh"
9 #include "grob-info.hh"
10 #include "multi-measure-rest.hh"
11 #include "timing-translator.hh"
12 #include "engraver.hh"
13 #include "grob.hh"
14
15 /**
16   Do time bookkeeping
17  */
18 class Timing_engraver : public Timing_translator, public Engraver
19 {
20 protected:
21   /* Needed to know whether we're advancing in grace notes, or not. */
22   Moment last_moment_;
23   
24   virtual void start_translation_timestep ();
25   virtual void stop_translation_timestep ();
26
27 public:
28   TRANSLATOR_DECLARATIONS (Timing_engraver);
29 };
30
31
32 Timing_engraver::Timing_engraver ()
33 {
34   last_moment_.main_part_ = Rational (-1);
35 }
36
37
38
39 void
40 Timing_engraver::start_translation_timestep ()
41 {
42   Timing_translator::start_translation_timestep ();
43
44   SCM automatic_bars = get_property ("automaticBars");
45   Moment now = now_mom ();
46   SCM which = get_property ("whichBar");
47
48   /* Set the first bar of the score? */
49   if (!gh_string_p (which))
50     which
51       = (now.main_part_ || now.main_part_ == last_moment_.main_part_)
52       ? SCM_EOL : scm_makfrom0str ("|");
53
54   Moment mp = measure_position ();
55   bool start_of_measure = (last_moment_.main_part_ != now.main_part_
56                            && !mp.main_part_);
57
58   if (start_of_measure)
59     {
60       Moment mlen = Moment (measure_length ());
61       unsmob_grob (get_property ("currentCommandColumn"))
62         ->set_grob_property ("measure-length", mlen.smobbed_copy ()); 
63     }
64   
65   if (!gh_string_p (which) && to_boolean (automatic_bars))
66     {
67       SCM always = get_property ("barAlways");
68
69       if ( start_of_measure || (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   daddy_context_->set_property ("whichBar", which);
77 }
78
79 void
80 Timing_engraver::stop_translation_timestep ()
81 {
82   Timing_translator::stop_translation_timestep ();
83   daddy_context_->set_property ("whichBar", SCM_EOL);
84   last_moment_ = now_mom ();
85 }
86
87
88 ENTER_DESCRIPTION (Timing_engraver,
89 /* descr */       " Responsible for synchronizing timing information from staves.  "
90 "Normally in @code{Score}.  In order to create polyrhythmic music, "
91 "this engraver should be removed from @code{Score} and placed in "
92 "@code{Staff}.",
93 /* creats*/       "",
94 /* accepts */     "",
95 /* acks  */      "",
96 /* reads */       "timeSignatureFraction automaticBars whichBar barAlways defaultBarType skipBars timing measureLength measurePosition currentBarNumber",
97 /* write */       "");