]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-engraver.cc
compile fixes while han-wen's so long away
[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-2002 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 start_translation_timestep ();
40   virtual void process_acknowledged_grobs ();
41 private:
42
43 };
44
45
46
47 Hyphen_engraver::Hyphen_engraver ()
48 {
49   current_lyric_ = 0;
50   last_lyric_ = 0;
51   hyphen_ = 0;
52   req_ = 0;
53 }
54
55 void
56 Hyphen_engraver::acknowledge_grob (Grob_info i)
57 {
58   // -> text-item
59   if (i.grob_->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
60     {
61       current_lyric_ = i.grob_;
62       if (hyphen_
63           && !hyphen_->get_bound (RIGHT)
64             )
65           {
66             Hyphen_spanner (hyphen_).set_textitem (RIGHT, i.grob_);
67           }
68     }
69 }
70
71
72 bool
73 Hyphen_engraver::try_music (Music* r)
74 {
75   if (req_)
76         return false;
77
78       req_ = r;
79       return true;
80 }
81
82 void
83 Hyphen_engraver::finalize ()
84 {
85   if (hyphen_)
86     {
87       req_->origin ()->warning (_ ("unterminated hyphen"));
88       hyphen_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
89     }
90 }
91
92 void
93 Hyphen_engraver::process_acknowledged_grobs ()
94 {
95   if (req_ &&! hyphen_)
96     {
97       if (!last_lyric_)
98         {
99           req_->origin ()->warning (_ ("Nothing to connect hyphen to on the left.  Ignoring hyphen event."));
100           return;
101         }
102       
103       hyphen_ = new Spanner (get_property ("LyricHyphen"));
104
105       Hyphen_spanner (hyphen_).set_textitem (LEFT, last_lyric_);
106       announce_grob(hyphen_, req_->self_scm());
107     }
108 }
109
110
111 void
112 Hyphen_engraver::stop_translation_timestep ()
113 {
114   if (hyphen_)
115     {
116       typeset_grob (hyphen_);
117       hyphen_ = 0;
118     }
119
120   if (current_lyric_)
121     {
122       last_lyric_ = current_lyric_;
123       current_lyric_ =0;
124     }
125 }
126
127 void
128 Hyphen_engraver::start_translation_timestep ()
129 {
130   req_ = 0;
131 }
132
133
134 ENTER_DESCRIPTION(Hyphen_engraver,
135 /* descr */       "Create lyric hyphens",
136 /* creats*/       "LyricHyphen",
137 /* accepts */     "hyphen-event",
138 /* acks  */      "lyric-syllable-interface",
139 /* reads */       "",
140 /* write */       "");