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