]> git.donarmstrong.com Git - lilypond.git/blob - lily/regular-spacing-engraver.cc
release: 1.5.3
[lilypond.git] / lily / regular-spacing-engraver.cc
1 /*   
2   regular-spacing-engraver.cc --  implement Regular_spacing_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "grob.hh"
12
13 class Regular_spacing_engraver : public Engraver
14 {
15 public:
16   Regular_spacing_engraver ();
17   VIRTUAL_COPY_CONS(Translator);
18
19   Moment last_moment_;
20   SCM last_col_;
21 protected:
22   virtual void process_music ();
23 };
24
25 Regular_spacing_engraver::Regular_spacing_engraver ()
26 {
27   last_col_ = SCM_EOL;
28 }
29
30 void
31 Regular_spacing_engraver::process_music ()
32 {
33   SCM delta = get_property ("regularSpacingDelta");
34
35   if (unsmob_moment (delta))
36     {
37       SCM mp = get_property ("measurePosition");
38       if (!unsmob_moment (mp))
39         return;
40
41       Rational d = unsmob_moment (delta)->main_part_;
42       Rational p = unsmob_moment (mp)->main_part_;
43
44       if (p.mod_rat (d) != Rational (0))
45         return;
46
47       Moment now = now_mom ();
48       SCM col = get_property ("currentMusicalColumn");
49       if (p
50           && (now -last_moment_ ).main_part_ == d)
51         {
52           unsmob_grob (col)->set_grob_property ("regular-distance-to", last_col_);
53         }
54       last_col_ = col;
55       last_moment_ = now;
56     }
57 }
58
59
60 ADD_THIS_TRANSLATOR(Regular_spacing_engraver);