]> git.donarmstrong.com Git - lilypond.git/blob - lily/grace-position-engraver.cc
3805612e1cb42f23b438e7e536d88516ee604bcf
[lilypond.git] / lily / grace-position-engraver.cc
1 /*   
2   grace-position-engraver.cc --  implement Grace_position_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "grace-align-item.hh"
12 #include "note-head.hh"
13 #include "local-key-item.hh"
14 #include "paper-column.hh"
15 #include "dimension-cache.hh"
16 #include "side-position-interface.hh"
17 #include "axis-group-interface.hh"
18
19
20 class Grace_position_engraver:public Engraver
21 {
22   Paper_column *last_musical_col_l_;
23 protected:
24   VIRTUAL_COPY_CONS(Translator);
25   virtual void acknowledge_element (Score_element_info);
26   virtual void process_acknowledged ();
27   virtual void do_post_move_processing ();
28   virtual void do_pre_move_processing ();
29   Grace_align_item*align_l_;
30   Link_array<Item> support_;
31 public:
32   Grace_position_engraver();
33 };
34
35
36 Grace_position_engraver::Grace_position_engraver ()
37 {
38   align_l_ =0;
39   last_musical_col_l_ =0;
40 }
41
42 void
43 Grace_position_engraver::acknowledge_element (Score_element_info i)
44 {
45   if (Grace_align_item*g  =dynamic_cast<Grace_align_item*>(i.elem_l_))
46     {
47       align_l_ = g;
48     }
49   else if (Note_head * n = dynamic_cast <Note_head*> (i.elem_l_))
50     {
51       if (!to_boolean (n->get_elt_property ("grace")))
52         support_.push (n);
53     }
54   else if (Local_key_item*it = dynamic_cast<Local_key_item*>(i.elem_l_))
55     {
56       if (!to_boolean (it->get_elt_property ("grace")))
57         support_.push (it);
58       else if (align_l_) 
59         it->add_dependency (align_l_);
60     }
61 }
62
63 void
64 Grace_position_engraver::process_acknowledged ()
65 {
66   if (align_l_)
67     {
68       for (int i=0; i < support_.size (); i++)
69         side_position  (align_l_).add_support (support_[i]);
70       support_.clear ();
71     }
72 }
73
74 void
75 Grace_position_engraver::do_pre_move_processing ()
76 {
77   if (align_l_ && !side_position (align_l_).supported_b ())
78     {
79   /*
80      We don't have support. Either some moron tried attaching us to a rest,
81      or we're at the end of the piece.  In the latter case, we have a
82      problem if there are spanners in the grace section,
83      they will want to  be broken into pieces (their line_l () field  is nil).
84
85      Solution: attach ourselves to  the last musical column known.  A little intricate.
86      
87   */
88
89       Score_element * elt = align_l_->parent_l (X_AXIS);
90       if (elt)
91         return;
92
93       warning (_("Unattached grace notes.  Attaching to last musical column."));
94       
95       align_l_->set_parent (0, X_AXIS);
96       Axis_group_interface (last_musical_col_l_).add_element (align_l_);
97     }
98
99   last_musical_col_l_ = get_staff_info ().musical_pcol_l ();
100 }
101
102 void
103 Grace_position_engraver::do_post_move_processing ()
104 {
105   support_.clear ();
106   align_l_ =0;
107 }
108
109 ADD_THIS_TRANSLATOR(Grace_position_engraver);
110