]> git.donarmstrong.com Git - lilypond.git/blob - lily/grace-position-engraver.cc
release: 1.3.19
[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 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
17 class Grace_position_engraver:public Engraver
18 {
19   Paper_column *last_musical_col_l_;
20 protected:
21   VIRTUAL_COPY_CONS(Translator);
22   virtual void acknowledge_element (Score_element_info);
23   virtual void process_acknowledged ();
24   virtual void do_post_move_processing ();
25   virtual void do_pre_move_processing ();
26   Grace_align_item*align_l_;
27   Link_array<Item> support_;
28 public:
29   Grace_position_engraver();
30 };
31
32
33 Grace_position_engraver::Grace_position_engraver ()
34 {
35   align_l_ =0;
36   last_musical_col_l_ =0;
37 }
38
39 void
40 Grace_position_engraver::acknowledge_element (Score_element_info i)
41 {
42   if (Grace_align_item*g  =dynamic_cast<Grace_align_item*>(i.elem_l_))
43     {
44       align_l_ = g;
45     }
46   else if (Note_head * n = dynamic_cast <Note_head*> (i.elem_l_))
47     {
48       if (!to_boolean (n->get_elt_property ("grace")))
49         support_.push (n);
50     }
51   else if (Local_key_item*it = dynamic_cast<Local_key_item*>(i.elem_l_))
52     {
53       if (!to_boolean (it->get_elt_property ("grace")))
54         support_.push (it);
55       else if (align_l_) 
56         it->add_dependency (align_l_);
57     }
58 }
59
60 void
61 Grace_position_engraver::process_acknowledged ()
62 {
63   if (align_l_)
64     {
65       for (int i=0; i < support_.size (); i++)
66         align_l_->add_support (support_[i]);
67       support_.clear ();
68     }
69 }
70
71 void
72 Grace_position_engraver::do_pre_move_processing ()
73 {
74   /*
75      We don't have support. Either some moron tried attaching us to a rest,
76      or we're at the end of the piece.  In the latter case, we have a
77      problem if there are spanners in the grace section,
78      they will want to  be broken into pieces (their line_l () field  is nil).
79
80      Solution: attach ourselves to  the last musical column known.  A little intricate.
81      
82   */
83   if (align_l_ && !align_l_->supported_b ())
84     {
85       Score_element * elt = align_l_->parent_l (X_AXIS);
86       if (elt)
87         return;
88
89       warning (_("Unattached grace notes.  Attaching to last musical column."));
90       /*      if (ae)
91         ae->remove_element (align_l_);
92         else if (elt)*/
93
94       
95       align_l_->set_parent (0, X_AXIS);
96       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