]> git.donarmstrong.com Git - lilypond.git/blob - lily/timing-engraver.cc
* lily/dynamic-engraver.cc (stop_translation_timestep): first set
[lilypond.git] / lily / timing-engraver.cc
1 /*
2   timing-engraver.cc -- implement Timing_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 "context.hh"
10 #include "multi-measure-rest.hh"
11 #include "timing-translator.hh"
12 #include "engraver.hh"
13 #include "grob.hh"
14
15
16
17 class Timing_engraver : public Timing_translator, public Engraver
18 {
19 protected:
20   /* Need to know whether we're advancing in grace notes, or not. */
21   Moment last_moment_;
22
23   virtual void start_translation_timestep ();
24   virtual void process_music ();
25   virtual void stop_translation_timestep ();
26
27 public:
28   TRANSLATOR_DECLARATIONS (Timing_engraver);
29 };
30
31 ADD_TRANSLATOR (Timing_engraver,
32                 /* descr */ " Responsible for synchronizing timing information from staves.  "
33                 "Normally in @code{Score}.  In order to create polyrhythmic music, "
34                 "this engraver should be removed from @code{Score} and placed in "
35                 "@code{Staff}. "
36                 "\n\nThis engraver adds the alias @code{Timing} to its containing context.",
37                 /* creats*/ "",
38                 /* accepts */ "",
39                 /* acks  */ "",
40                 /* reads */ "automaticBars whichBar barAlways defaultBarType "
41                 "skipBars timing measureLength measurePosition currentBarNumber",
42                 /* write */ "");
43
44
45 Timing_engraver::Timing_engraver ()
46 {
47   last_moment_.main_part_ = Rational (-1);
48 }
49
50 void
51 Timing_engraver::process_music ()
52 {
53   Timing_translator::process_music ();
54
55   bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
56                            && !measure_position ().main_part_);
57
58   /*
59     We can't do this in start_translation_timestep(), since time sig
60     changes won't have happened by then.
61   */
62   if (start_of_measure)
63     {
64       Moment mlen = Moment (measure_length ());
65       unsmob_grob (get_property ("currentCommandColumn"))
66         ->set_property ("measure-length", mlen.smobbed_copy ());
67     }
68 }
69
70 void
71 Timing_engraver::start_translation_timestep ()
72 {
73   Timing_translator::start_translation_timestep ();
74
75   SCM automatic_bars = get_property ("automaticBars");
76   Moment now = now_mom ();
77   SCM which = get_property ("whichBar");
78
79   /* Set the first bar of the score? */
80   if (!scm_is_string (which))
81     which = SCM_EOL;
82
83   Moment mp = measure_position ();
84   bool start_of_measure = (last_moment_.main_part_ != now.main_part_
85                            && !mp.main_part_);
86
87   if (!scm_is_string (which) && to_boolean (automatic_bars))
88     {
89       SCM always = get_property ("barAlways");
90
91       if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
92           || to_boolean (always))
93         {
94           /* should this work, or be junked?  See input/bugs/no-bars.ly */
95           which = get_property ("defaultBarType");
96         }
97     }
98
99   context ()->set_property ("whichBar", which);
100 }
101
102 void
103 Timing_engraver::stop_translation_timestep ()
104 {
105   Timing_translator::stop_translation_timestep ();
106   context ()->set_property ("whichBar", SCM_EOL);
107   last_moment_ = now_mom ();
108 }