lilypond-1.5.9
[lilypond.git] / lily / grace-position-engraver.cc
blob1ea8ce3a4c21d9d4d948f793d255ecf21454c1ee
1 /*
2 grace-position-engraver.cc -- implement Grace_position_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "engraver.hh"
11 #include "grace-align-item.hh"
12 #include "rhythmic-head.hh"
13 #include "local-key-item.hh"
14 #include "paper-column.hh"
15 #include "note-head.hh"
16 #include "side-position-interface.hh"
17 #include "axis-group-interface.hh"
20 class Grace_position_engraver:public Engraver
22 Paper_column *last_musical_col_l_;
23 protected:
24 VIRTUAL_COPY_CONS (Translator);
25 virtual void acknowledge_grob (Grob_info);
26 virtual void create_grobs ();
27 virtual void start_translation_timestep ();
28 virtual void stop_translation_timestep ();
29 Item*align_l_;
30 Link_array<Item> support_;
31 public:
32 Grace_position_engraver ();
36 Grace_position_engraver::Grace_position_engraver ()
38 align_l_ =0;
39 last_musical_col_l_ =0;
42 void
43 Grace_position_engraver::acknowledge_grob (Grob_info i)
45 Item *item = dynamic_cast<Item*> (i.elem_l_);
46 if (item && Grace_align_item::has_interface (i.elem_l_))
48 align_l_ = item;
50 else if (item && Note_head::has_interface (i.elem_l_))
52 if (!to_boolean (item->get_grob_property ("grace")))
53 support_.push (item);
55 else if (item && Local_key_item::has_interface (i.elem_l_))
57 if (!to_boolean (item->get_grob_property ("grace")))
58 support_.push (item);
59 else if (align_l_)
60 item->add_dependency (align_l_);
64 void
65 Grace_position_engraver::create_grobs ()
67 if (align_l_)
69 for (int i=0; i < support_.size (); i++)
70 Side_position_interface::add_support (align_l_,support_[i]);
71 support_.clear ();
75 void
76 Grace_position_engraver::stop_translation_timestep ()
78 if (align_l_ && !Side_position_interface::supported_b (align_l_))
81 We don't have support. Either some moron tried attaching us to a rest,
82 or we're at the end of the piece. In the latter case, we have a
83 problem if there are spanners in the grace section,
84 they will want to be broken into pieces (their line_l () field is nil).
86 Solution: attach ourselves to the last musical column known. A little intricate.
90 Grob * elt = align_l_->parent_l (X_AXIS);
91 if (elt)
92 return;
94 if (last_musical_col_l_)
96 warning (_ ("Unattached grace notes. Attaching to last musical column."));
98 align_l_->set_parent (0, X_AXIS);
99 Axis_group_interface::add_element (last_musical_col_l_, align_l_);
101 else
103 // tja.
106 last_musical_col_l_ = dynamic_cast<Paper_column*> (unsmob_grob (get_property ("currentMusicalColumn")));
109 void
110 Grace_position_engraver::start_translation_timestep ()
112 support_.clear ();
113 align_l_ =0;
116 ADD_THIS_TRANSLATOR (Grace_position_engraver);