]> git.donarmstrong.com Git - lilypond.git/blob - lily/regular-spacing-engraver.cc
c6590c832ef3a9c99f579a06ee46915c2133cf7b
[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   TRANSLATOR_DECLARATIONS(Regular_spacing_engraver);
17   Moment last_moment_;
18   SCM last_col_;
19 protected:
20   virtual void process_music ();
21 };
22
23 Regular_spacing_engraver::Regular_spacing_engraver ()
24 {
25   last_col_ = SCM_EOL;
26 }
27
28 void
29 Regular_spacing_engraver::process_music ()
30 {
31   SCM delta = get_property ("regularSpacingDelta");
32
33   if (unsmob_moment (delta))
34     {
35       SCM mp = get_property ("measurePosition");
36       if (!unsmob_moment (mp))
37         return;
38
39       Rational d = unsmob_moment (delta)->main_part_;
40       Rational p = unsmob_moment (mp)->main_part_;
41
42       if (p.mod_rat (d) != Rational (0))
43         return;
44
45       Moment now = now_mom ();
46       SCM col = get_property ("currentMusicalColumn");
47       if (p
48           && (now -last_moment_ ).main_part_ == d)
49         {
50           unsmob_grob (col)->set_grob_property ("regular-distance-to", last_col_);
51         }
52       last_col_ = col;
53       last_moment_ = now;
54     }
55 }
56
57
58 ENTER_DESCRIPTION(Regular_spacing_engraver,
59 /* descr */       ".",
60 /* creats*/       "",
61 /* acks  */       "",
62 /* reads */       "regularSpacingDelta",
63 /* write */       "");
64