]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-engraver.cc
patch::: 1.1.52.gp2
[lilypond.git] / lily / hyphen-engraver.cc
1 /*
2   hyphen-engraver.cc -- implement Hyphen_engraver
3
4   (c) 1999 Glen Prideaux <glenprideaux@iname.com>
5 */
6
7 #include "proto.hh"
8 #include "musical-request.hh"
9 #include "hyphen-engraver.hh"
10 #include "hyphen-spanner.hh"
11 #include "score-column.hh"
12 #include "text-item.hh"
13 #include "extender-engraver.hh"
14
15 ADD_THIS_TRANSLATOR (Hyphen_engraver);
16
17 Hyphen_engraver::Hyphen_engraver ()
18 {
19   hyphen_spanner_p_ = 0;
20   req_l_ = 0;
21 }
22
23 void
24 Hyphen_engraver::acknowledge_element (Score_element_info i)
25 {
26   if (Text_item* t = dynamic_cast<Text_item*> (i.elem_l_))
27     {
28       Rhythmic_req * rh = dynamic_cast<Rhythmic_req*>  (i.req_l_);
29       if (!rh)
30         return;
31
32       now_lyrics_.push (Text_lyric_tuple (t, rh, now_mom () + rh->length_mom ()));
33       /*
34         UGH.  What do we do in case of multiple alternatives? 
35        */
36       if (hyphen_spanner_p_
37           && !hyphen_spanner_p_->spanned_drul_[RIGHT]
38             )
39           {
40             hyphen_spanner_p_->set_textitem (RIGHT, t);
41           }
42     }
43 }
44
45
46 bool
47 Hyphen_engraver::do_try_music (Music* r)
48 {
49   if (Hyphen_req* p = dynamic_cast <Hyphen_req *> (r))
50     {
51       if (req_l_)
52         return false;
53
54       req_l_ = p;
55       return true;
56     }
57   return false;
58 }
59
60 void
61 Hyphen_engraver::do_removal_processing ()
62 {
63   if (hyphen_spanner_p_)
64     {
65       req_l_->warning (_ ("unterminated hyphen"));
66       hyphen_spanner_p_->set_bounds(RIGHT, get_staff_info ().command_pcol_l ());
67     }
68 }
69
70 void
71 Hyphen_engraver::do_process_requests ()
72 {
73   Array<Text_lyric_tuple> stopped_texts;
74   Moment now = now_mom ();
75
76   stopped_texts.clear ();
77   while (past_lyrics_pq_.size ()
78          && past_lyrics_pq_.front ().end_ == now)
79     stopped_texts.push (past_lyrics_pq_.get ());
80
81   if (req_l_)
82     {
83       if (!stopped_texts.size ())
84         {
85           req_l_->warning ("Nothing to connect hyphen to on the left. Ignoring hyphen request");
86           return;
87         }
88       
89       hyphen_spanner_p_ = new Hyphen_spanner;
90       hyphen_spanner_p_->set_textitem  (LEFT, stopped_texts[0].text_l_);
91       announce_element (Score_element_info (hyphen_spanner_p_, req_l_));
92     }
93 }
94
95
96 void
97 Hyphen_engraver::do_pre_move_processing ()
98 {
99   for (int i=0; i < now_lyrics_.size (); i++)
100     {
101       past_lyrics_pq_.insert (now_lyrics_[i]);
102     }
103   now_lyrics_.clear ();
104
105   if (hyphen_spanner_p_)
106     {
107       typeset_element (hyphen_spanner_p_);
108       hyphen_spanner_p_ = 0;
109     }
110 }
111 void
112 Hyphen_engraver::do_post_move_processing ()
113 {
114   Moment now = now_mom ();
115   while (past_lyrics_pq_.size () && past_lyrics_pq_.front ().end_ < now)
116     past_lyrics_pq_.delmin ();
117
118   req_l_ =0;
119 }
120
121