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