]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-engraver.cc
release: 1.5.13
[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 "flower-proto.hh"
8 #include "musical-request.hh"
9 #include "hyphen-spanner.hh"
10 #include "paper-column.hh"
11 #include "item.hh"
12 #include "engraver.hh"
13
14 /**
15   Generate an centred hyphen.  Should make a Hyphen_spanner that
16   typesets a nice centred hyphen of varying length depending on the
17   gap between syllables.
18
19   We remember the last Item that come across. When we get a
20   request, we create the spanner, and attach the left point to the
21   last lyrics, and the right point to any lyrics we receive by
22   then.  */
23 class Hyphen_engraver : public Engraver
24 {
25   Grob *last_lyric_l_;
26   Grob *current_lyric_l_;
27   Hyphen_req* req_l_;
28   Spanner* hyphen_p_;
29 public:
30   TRANSLATOR_DECLARATIONS(Hyphen_engraver);
31
32 protected:
33   virtual void acknowledge_grob (Grob_info);
34   virtual void finalize ();
35   virtual bool try_music (Music*);
36   virtual void stop_translation_timestep ();
37   virtual void start_translation_timestep ();
38   virtual void create_grobs ();
39 private:
40
41 };
42
43
44
45 Hyphen_engraver::Hyphen_engraver ()
46 {
47   current_lyric_l_ = 0;
48   last_lyric_l_ = 0;
49   hyphen_p_ = 0;
50   req_l_ = 0;
51 }
52
53 void
54 Hyphen_engraver::acknowledge_grob (Grob_info i)
55 {
56   // -> text-item
57   if (i.grob_l_->has_interface (ly_symbol2scm ("lyric-syllable-interface")))
58     {
59       current_lyric_l_ = i.grob_l_;
60       if (hyphen_p_
61           && !hyphen_p_->get_bound (RIGHT)
62             )
63           {
64             Hyphen_spanner (hyphen_p_).set_textitem (RIGHT, i.grob_l_);
65           }
66     }
67 }
68
69
70 bool
71 Hyphen_engraver::try_music (Music* r)
72 {
73   if (Hyphen_req* p = dynamic_cast <Hyphen_req *> (r))
74     {
75       if (req_l_)
76         return false;
77
78       req_l_ = p;
79       return true;
80     }
81   return false;
82 }
83
84 void
85 Hyphen_engraver::finalize ()
86 {
87   if (hyphen_p_)
88     {
89       req_l_->origin ()->warning (_ ("unterminated hyphen"));
90       hyphen_p_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
91     }
92 }
93
94 void
95 Hyphen_engraver::create_grobs ()
96 {
97   if (req_l_ &&! hyphen_p_)
98     {
99       if (!last_lyric_l_)
100         {
101           req_l_->origin ()->warning (_ ("Nothing to connect hyphen to on the left.  Ignoring hyphen request."));
102           return;
103         }
104       
105       hyphen_p_ = new Spanner (get_property ("LyricHyphen"));
106
107       Hyphen_spanner (hyphen_p_).set_textitem (LEFT, last_lyric_l_);
108       announce_grob (hyphen_p_, req_l_);
109     }
110 }
111
112
113 void
114 Hyphen_engraver::stop_translation_timestep ()
115 {
116   if (hyphen_p_)
117     {
118       typeset_grob (hyphen_p_);
119       hyphen_p_ = 0;
120     }
121
122   if (current_lyric_l_)
123     {
124       last_lyric_l_ = current_lyric_l_;
125       current_lyric_l_ =0;
126     }
127 }
128
129 void
130 Hyphen_engraver::start_translation_timestep ()
131 {
132   req_l_ = 0;
133 }
134
135
136 ENTER_DESCRIPTION(Hyphen_engraver,
137 /* descr */       "Create lyric hyphens",
138 /* creats*/       "LyricHyphen",
139 /* acks  */       "lyric-syllable-interface",
140 /* reads */       "",
141 /* write */       "");