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