]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
(DECLARE_EVENT_SWALLOWER): ENTER_DESCRIPTION -> ADD_TRANSLATOR
[lilypond.git] / lily / rhythmic-column-engraver.cc
1 /*
2   rhythmic-column-grav.cc -- implement Rhythmic_column_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "engraver.hh"
10 #include "rhythmic-head.hh"
11 #include "stem.hh"
12 #include "note-column.hh"
13 #include "dot-column.hh"
14 #include "group-interface.hh"
15
16 /*
17   this engraver  glues together stems, rests and note heads into a NoteColumn
18   grob.
19
20   It also generates spacing objects.  Originally, we have tried to
21   have the spacing functionality at different levels.
22   
23   - by simply using the sequence of Separation-item as
24   spacing-sequences (at staff level). Unfortunately, this fucks up if
25   there are different kinds of tuplets in different voices (8th and
26   8ths triplets combined made the program believe there were 1/12 th
27   notes.).
28
29   Doing it in a separate engraver using timing info is generally
30   complicated (start/end time management), and fucks up if a voice
31   changes staff.
32
33   Now we do it from here again. This has the problem that voices can
34   appear and disappear at will, leaving lots of loose ends (the note
35   spacing engraver don't know where to connect the last note of the
36   voice on the right with), but we don't complain about those, and let
37   the default spacing do its work.
38
39  */
40
41
42 class Rhythmic_column_engraver :public Engraver
43 {
44   Link_array<Grob> rheads_;
45   Grob * stem_;
46   Grob * note_column_;
47   Grob * dotcol_;
48
49   Grob * last_spacing_;
50   Grob * spacing_;
51   
52   TRANSLATOR_DECLARATIONS (Rhythmic_column_engraver);
53 protected:
54
55   virtual void acknowledge_grob (Grob_info);
56   virtual void process_acknowledged_grobs ();
57   virtual void stop_translation_timestep ();
58 };
59
60
61
62 Rhythmic_column_engraver::Rhythmic_column_engraver ()
63 {
64   spacing_ = 0 ;
65   last_spacing_ = 0;
66   
67   stem_ = 0;
68   note_column_ = 0;
69   dotcol_ = 0;
70 }
71
72
73 void
74 Rhythmic_column_engraver::process_acknowledged_grobs ()
75 {
76   if (rheads_.size ())
77     {
78       if (!note_column_)
79         {
80           note_column_ = make_item ("NoteColumn",rheads_[0]->self_scm ());
81
82           spacing_ = make_item ("NoteSpacing", SCM_EOL);
83           spacing_->set_property ("left-items", scm_cons (note_column_->self_scm (), SCM_EOL));
84
85
86           
87
88           if (last_spacing_)
89             {
90               Pointer_group_interface::add_grob (last_spacing_,
91                                                  ly_symbol2scm ("right-items" ),
92                                                  note_column_);
93             }
94
95         }
96
97       for (int i = 0; i < rheads_.size (); i++)
98         {
99           if (!rheads_[i]->get_parent (X_AXIS))
100             Note_column::add_head (note_column_, rheads_[i]);
101         }
102       rheads_.set_size (0);
103     }
104
105   
106   if (note_column_)
107     {
108       if (dotcol_
109           && !dotcol_->get_parent (X_AXIS))
110         {
111           Note_column::set_dotcol (note_column_, dotcol_);
112         }
113
114       if (stem_
115           && !stem_->get_parent (X_AXIS))
116         {
117           Note_column::set_stem (note_column_, stem_);
118           stem_ = 0;
119         }
120
121     }
122 }
123
124 void
125 Rhythmic_column_engraver::acknowledge_grob (Grob_info i)
126 {
127   Item * item =  dynamic_cast <Item *> (i.grob_);
128   if (!item || item->get_parent (X_AXIS))
129     return ; 
130   if (Stem::has_interface (item))
131     {
132       stem_ = item;
133     }
134   else if (Rhythmic_head::has_interface (item))
135     {
136       rheads_.push (item);
137     }
138   else if (Dot_column::has_interface (item))
139     {
140       dotcol_ = item;
141     }
142 }
143
144 void
145 Rhythmic_column_engraver::stop_translation_timestep ()
146 {
147       note_column_ = 0;
148
149   if (spacing_)
150     {
151       last_spacing_ = spacing_;
152       spacing_ = 0;
153     }
154   
155   dotcol_ = 0;
156   stem_ = 0;
157 }
158
159
160
161 ADD_TRANSLATOR (Rhythmic_column_engraver,
162 /* descr */       "Generates NoteColumn, an objects that groups stems, noteheads and rests.",
163 /* creats*/       "NoteColumn NoteSpacing",
164 /* accepts */     "",
165 /* acks  */      "stem-interface rhythmic-head-interface dot-column-interface",
166 /* reads */       "",
167 /* write */       "");