]> git.donarmstrong.com Git - lilypond.git/blob - lily/glissando-engraver.cc
* flower/include/std-string.hh:
[lilypond.git] / lily / glissando-engraver.cc
1 /*
2   note-head-line-engraver.cc -- implement Note_head_line_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10 #include "international.hh"
11 #include "rhythmic-head.hh"
12 #include "spanner.hh"
13 #include "warn.hh"
14
15 /**
16    Create line-spanner grobs for glissandi lines that connect note
17    heads.
18 */
19 class Glissando_engraver : public Engraver
20 {
21 public:
22   TRANSLATOR_DECLARATIONS (Glissando_engraver);
23
24 protected:
25   DECLARE_ACKNOWLEDGER (rhythmic_head);
26   virtual void finalize ();
27   void stop_translation_timestep ();
28   virtual bool try_music (Music *);
29   void process_music ();
30 private:
31   Spanner *line_;
32   Spanner *last_line_;
33   Music *event_;
34 };
35
36 Glissando_engraver::Glissando_engraver ()
37 {
38   last_line_ = line_ = 0;
39   event_ = 0;
40 }
41
42 bool
43 Glissando_engraver::try_music (Music *m)
44 {
45   if (!event_)
46     {
47       event_ = m;
48       return true;
49     }
50   return false;
51 }
52
53 void
54 Glissando_engraver::process_music ()
55 {
56   if (event_)
57     line_ = make_spanner ("Glissando", event_->self_scm ());
58 }
59
60 void
61 Glissando_engraver::acknowledge_rhythmic_head (Grob_info info)
62 {
63   Grob *g = info.grob ();
64   if (line_)
65     line_->set_bound (LEFT, g);
66
67   if (last_line_)
68     last_line_->set_bound (RIGHT, g);
69 }
70
71 void
72 Glissando_engraver::stop_translation_timestep ()
73 {
74   if (last_line_ && last_line_->get_bound (RIGHT))
75     last_line_ = 0;
76   if (line_)
77     {
78       if (last_line_)
79         programming_error ("overwriting glissando");
80       last_line_ = line_;
81     }
82   line_ = 0;
83   event_ = 0;
84 }
85
86 void
87 Glissando_engraver::finalize ()
88 {
89   if (line_)
90     {
91       string msg = _ ("unterminated glissando");
92
93       if (event_)
94         event_->origin ()->warning (msg);
95       else
96         warning (msg);
97
98       line_->suicide ();
99       line_ = 0;
100     }
101 }
102
103 #include "translator.icc"
104
105 ADD_ACKNOWLEDGER (Glissando_engraver, rhythmic_head);
106 ADD_TRANSLATOR (Glissando_engraver,
107                 /* doc */ "Engrave a glissandi",
108                 /* create */ "Glissando",
109                 /* accept */ "glissando-event",
110                 /* read */ "followVoice",
111                 /* write */ "");