]> git.donarmstrong.com Git - lilypond.git/blob - lily/glissando-engraver.cc
*** empty log message ***
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "warn.hh"
10 #include "spanner.hh"
11 #include "rhythmic-head.hh"
12 #include "engraver.hh"
13
14 /**
15    Create line-spanner grobs for glissandi lines that connect note
16    heads.
17 */
18 class Glissando_engraver : public Engraver
19 {
20 public:
21   TRANSLATOR_DECLARATIONS (Glissando_engraver);
22
23 protected:
24   virtual void acknowledge_grob (Grob_info);
25   virtual void finalize ();
26   virtual void stop_translation_timestep ();
27   virtual bool try_music (Music *);
28   virtual void process_music ();
29 private:
30   Spanner *line_; 
31   Spanner *last_line_; 
32   Music* event_;
33 };
34
35 Glissando_engraver::Glissando_engraver ()
36 {
37   last_line_ = line_ = 0;
38   event_ = 0;
39 }
40
41 bool
42 Glissando_engraver::try_music (Music* m)
43 {
44   if (!event_)
45     {
46       event_ = m;
47       return true;
48     }
49   return false;
50 }
51
52 void
53 Glissando_engraver::process_music ()
54 {
55   if (event_)
56     {
57       line_ = make_spanner ("Glissando", event_->self_scm ());
58     }
59 }
60
61
62 void
63 Glissando_engraver::acknowledge_grob (Grob_info info)
64 {
65   if (Rhythmic_head::has_interface (info.grob_))
66     {
67       Grob * g = info.grob_;
68       if (line_)
69         line_->set_bound (LEFT, g);
70
71       if (last_line_)
72         last_line_->set_bound (RIGHT, g);
73     }    
74 }
75
76
77 void
78 Glissando_engraver::stop_translation_timestep ()
79 {
80   if (last_line_ && last_line_->get_bound (RIGHT))
81     {
82       last_line_ = 0;
83     }
84   if (line_)
85     {
86       if ( last_line_)
87         programming_error ("Overwriting glissando.");
88       last_line_ = line_;
89     }
90   line_ = 0;
91   event_ = 0;
92 }
93
94 void
95 Glissando_engraver::finalize ()
96 {
97   if (line_)
98     {
99       String msg = _("Unterminated glissando.");
100       
101       if (event_)
102         event_->origin ()->warning (msg);
103       else
104         warning (msg);
105       
106       line_->suicide ();
107       line_ = 0;
108     }
109 }
110
111
112
113 ADD_TRANSLATOR (Glissando_engraver,
114 /* descr */       "Engrave a glissandi",
115 /* creats*/       "Glissando",
116 /* accepts */     "glissando-event",
117 /* acks  */       "rhythmic-head-interface",
118 /* reads */       "followVoice",
119 /* write */       "");