]> git.donarmstrong.com Git - lilypond.git/blob - lily/hyphen-engraver.cc
* lily/ : rename Request to Event
[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 "event.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   event, 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_;
26   Grob *current_lyric_;
27   Music* req_;
28   Spanner* hyphen_;
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 process_acknowledged_grobs ();
39 private:
40
41 };
42
43
44
45 Hyphen_engraver::Hyphen_engraver ()
46 {
47   current_lyric_ = 0;
48   last_lyric_ = 0;
49   hyphen_ = 0;
50   req_ = 0;
51 }
52
53 void
54 Hyphen_engraver::acknowledge_grob (Grob_info i)
55 {
56   // -> text-item
57   if (i.grob_->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface")))
58     {
59       current_lyric_ = i.grob_;
60       if (hyphen_
61           && !hyphen_->get_bound (RIGHT)
62             )
63           {
64             Hyphen_spanner (hyphen_).set_textitem (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_spanner (hyphen_).set_textitem (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 }
124
125 void
126 Hyphen_engraver::start_translation_timestep ()
127 {
128   req_ = 0;
129 }
130
131
132 ENTER_DESCRIPTION(Hyphen_engraver,
133 /* descr */       "Create lyric hyphens",
134 /* creats*/       "LyricHyphen",
135 /* accepts */     "hyphen-event",
136 /* acks  */      "lyric-syllable-interface",
137 /* reads */       "",
138 /* write */       "");