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