]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-spacing-engraver.cc
Merge branch 'master' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / note-spacing-engraver.cc
1 /* 
2   note-spacing-engraver.cc -- implement Note_spacing_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2006 Han-Wen Nienhuys <hanwen@lilypond.org>
7   
8 */
9
10 #include "engraver.hh"
11
12 #include "item.hh"
13 #include "pointer-group-interface.hh"
14
15 #include "translator.icc"
16
17 class Note_spacing_engraver : public Engraver
18 {
19   Grob *last_spacing_;
20   Grob *spacing_;
21
22   void add_spacing_item (Grob *);
23
24   TRANSLATOR_DECLARATIONS (Note_spacing_engraver);
25 protected:
26
27   DECLARE_ACKNOWLEDGER (rhythmic_grob);
28   DECLARE_ACKNOWLEDGER (note_column);
29   void stop_translation_timestep ();
30 };
31
32 Note_spacing_engraver::Note_spacing_engraver ()
33 {
34   last_spacing_ = 0;
35   spacing_ = 0;
36 }
37
38 void
39 Note_spacing_engraver::add_spacing_item (Grob *g)
40 {
41   if (!spacing_)
42     {
43       spacing_ = make_item ("NoteSpacing", g->self_scm ());
44     }
45   
46   
47   if (spacing_)
48     {
49       Pointer_group_interface::add_grob (spacing_,
50                                          ly_symbol2scm ("left-items"),
51                                          g);
52
53       if (last_spacing_)
54         {
55           Pointer_group_interface::add_grob (last_spacing_,
56                                              ly_symbol2scm ("right-items"),
57                                              g);
58         }
59     }
60 }
61
62
63 void
64 Note_spacing_engraver::acknowledge_note_column (Grob_info gi)
65 {
66   add_spacing_item (gi.grob ());
67 }
68
69 void
70 Note_spacing_engraver::acknowledge_rhythmic_grob (Grob_info gi)
71 {
72   add_spacing_item (gi.grob ());
73 }
74
75 void
76 Note_spacing_engraver::stop_translation_timestep ()
77 {
78   if (spacing_)
79     {
80       last_spacing_ = spacing_;
81       spacing_ = 0;
82     }
83 }
84
85 ADD_ACKNOWLEDGER (Note_spacing_engraver, note_column);
86 ADD_ACKNOWLEDGER (Note_spacing_engraver, rhythmic_grob);
87
88 ADD_TRANSLATOR (Note_spacing_engraver,
89                 /* doc */ "Generates NoteSpacing, an object linking horizontal lines for use in spacing.",
90                 /* create */ "NoteSpacing",
91                 /* read */ "",
92                 /* write */ "");