]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-spacing-engraver.cc
Merge branch 'master-git.sv.gnu.org-lilypond.git' of /home/lilydev/vc/gub/downloads...
[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 "grob-array.hh"
13 #include "context.hh"
14 #include "item.hh"
15 #include "pointer-group-interface.hh"
16
17 #include "translator.icc"
18
19 class Note_spacing_engraver : public Engraver
20 {
21   Grob *last_spacing_;
22   Context *last_spacing_parent_context_;
23   
24   Grob *spacing_;
25
26   void add_spacing_item (Grob *);
27   TRANSLATOR_DECLARATIONS (Note_spacing_engraver);
28 protected:
29
30   DECLARE_ACKNOWLEDGER (rhythmic_grob);
31   DECLARE_ACKNOWLEDGER (note_column);
32   void stop_translation_timestep ();
33   virtual void finalize ();
34   virtual void derived_mark () const;
35 };
36
37 void
38 Note_spacing_engraver::derived_mark () const
39 {
40   if (last_spacing_parent_context_)
41     scm_gc_mark (last_spacing_parent_context_->self_scm ());
42 }
43
44 Note_spacing_engraver::Note_spacing_engraver ()
45 {
46   last_spacing_parent_context_ = 0;
47   last_spacing_ = 0;
48   spacing_ = 0;
49 }
50
51 void
52 Note_spacing_engraver::add_spacing_item (Grob *g)
53 {
54   if (!spacing_)
55     {
56       spacing_ = make_item ("NoteSpacing", g->self_scm ());
57     }
58   
59   if (spacing_)
60     {
61       Pointer_group_interface::add_grob (spacing_,
62                                          ly_symbol2scm ("left-items"),
63                                          g);
64
65       if (last_spacing_)
66         Pointer_group_interface::add_grob (last_spacing_,
67                                            ly_symbol2scm ("right-items"),
68                                            g);
69     }
70 }
71
72
73 void
74 Note_spacing_engraver::acknowledge_note_column (Grob_info gi)
75 {
76   add_spacing_item (gi.grob ());
77 }
78
79 void
80 Note_spacing_engraver::acknowledge_rhythmic_grob (Grob_info gi)
81 {
82   add_spacing_item (gi.grob ());
83 }
84
85 void
86 Note_spacing_engraver::finalize ()
87 {
88   if (last_spacing_
89       && last_spacing_parent_context_
90       && last_spacing_parent_context_ == context ()->get_parent_context ()
91       && !unsmob_grob_array (last_spacing_->get_object ("right-items")))
92     {
93       SCM ccol = get_property ("currentCommandColumn");
94       Grob *column = unsmob_grob (ccol);
95       
96       Pointer_group_interface::add_grob (last_spacing_,
97                                          ly_symbol2scm ("right-items"),
98                                          column);
99     }
100 }
101
102 void
103 Note_spacing_engraver::stop_translation_timestep ()
104 {
105   if (last_spacing_
106       && last_spacing_parent_context_
107       && last_spacing_parent_context_ == context ()->get_parent_context ())
108     {
109       Grob *sep = unsmob_grob (get_property ("breakableSeparationItem"));
110       if (sep)
111         Pointer_group_interface::add_grob (last_spacing_,
112                                            ly_symbol2scm ("right-items"),
113                                            sep);
114     }
115   
116   if (spacing_)
117     {
118       last_spacing_ = spacing_;
119       last_spacing_parent_context_ = context ()->get_parent_context ();
120       spacing_ = 0;
121     }
122
123 }
124
125 ADD_ACKNOWLEDGER (Note_spacing_engraver, note_column);
126 ADD_ACKNOWLEDGER (Note_spacing_engraver, rhythmic_grob);
127
128 ADD_TRANSLATOR (Note_spacing_engraver,
129                 /* doc */ "Generates NoteSpacing, an object linking horizontal lines for use in spacing.",
130                 /* create */ "NoteSpacing",
131                 /* read */ "",
132                 /* write */ "");