]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-engraver.cc
* lily/beam.cc (brew_molecule): rewrite debug output: split up scores.
[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 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             hyphen_->set_bound (RIGHT, i.grob_);
66           }
67     }
68 }
69
70
71 bool
72 Hyphen_engraver::try_music (Music* r)
73 {
74   if (req_)
75         return false;
76
77       req_ = r;
78       return true;
79 }
80
81 void
82 Hyphen_engraver::finalize ()
83 {
84   if (hyphen_)
85     {
86       req_->origin ()->warning (_ ("unterminated hyphen"));
87       hyphen_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn")));
88     }
89 }
90
91 void
92 Hyphen_engraver::process_acknowledged_grobs ()
93 {
94   if (req_ &&! hyphen_)
95     {
96       if (!last_lyric_)
97         {
98           req_->origin ()->warning (_ ("Nothing to connect hyphen to on the left.  Ignoring hyphen event."));
99           return;
100         }
101       
102       hyphen_ = new Spanner (get_property ("LyricHyphen"));
103
104       hyphen_->set_bound (LEFT, last_lyric_);
105       announce_grob(hyphen_, req_->self_scm());
106     }
107 }
108
109
110 void
111 Hyphen_engraver::stop_translation_timestep ()
112 {
113   if (hyphen_)
114     {
115       typeset_grob (hyphen_);
116       hyphen_ = 0;
117     }
118
119   if (current_lyric_)
120     {
121       last_lyric_ = current_lyric_;
122       current_lyric_ =0;
123     }
124 }
125
126 void
127 Hyphen_engraver::start_translation_timestep ()
128 {
129   req_ = 0;
130 }
131
132
133 ENTER_DESCRIPTION(Hyphen_engraver,
134 /* descr */       "Create lyric hyphens",
135 /* creats*/       "LyricHyphen",
136 /* accepts */     "hyphen-event",
137 /* acks  */      "lyric-syllable-interface",
138 /* reads */       "",
139 /* write */       "");