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