]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
release: 1.5.29
[lilypond.git] / lily / note-head-line-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--2002 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "engraver.hh"
10 #include "group-interface.hh"
11 #include "item.hh"
12 #include "musical-request.hh"
13 #include "spanner.hh"
14 #include "stem.hh"
15 #include "rhythmic-head.hh"
16 #include "side-position-interface.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "translator-group.hh"
19
20 /**
21    Create line-spanner grobs for glissandi (and possibly other) lines
22    that connect note heads.
23
24
25    TODO: have the line commit suicide if the notes are connected with
26    either slur or beam.
27
28 */
29 class Note_head_line_engraver : public Engraver
30 {
31 public:
32   TRANSLATOR_DECLARATIONS(Note_head_line_engraver);
33
34 protected:
35   virtual void acknowledge_grob (Grob_info);
36   virtual void create_grobs ();
37   virtual void stop_translation_timestep ();
38   virtual bool try_music (Music *);
39
40 private:
41   Spanner* line_; 
42   Request* req_;
43   Request* last_req_;
44   Translator* last_staff_;
45   bool follow_;
46   Grob* head_;
47   Grob* last_head_;
48 };
49
50 Note_head_line_engraver::Note_head_line_engraver ()
51 {
52   line_ = 0;
53   req_ = 0;
54   last_req_ = 0;
55   follow_ = false;
56   head_ = 0;
57   last_head_ = 0;
58   last_staff_ = 0;
59 }
60
61 bool
62 Note_head_line_engraver::try_music (Music* m)
63 {
64   if (!req_)
65     {
66       if (Glissando_req *r = dynamic_cast<Glissando_req*> (m))
67         {
68           req_ = r;
69           return true;
70         }
71     }
72   return false;
73 }
74
75 void
76 Note_head_line_engraver::acknowledge_grob (Grob_info info)
77 {
78   if (Rhythmic_head::has_interface (info.grob_l_))
79     {
80       head_ = info.grob_l_;
81       if (to_boolean (get_property ("followVoice")))
82         {
83           Translator_group  * tr = daddy_trans_l_;
84           while (tr && tr->type_str_ != "Staff")
85             tr = tr->daddy_trans_l_ ;
86
87           if (tr && tr->type_str_ == "Staff" && tr != last_staff_)
88             {
89               if (last_head_)
90                 follow_ = true;
91               last_staff_ = tr;
92             }
93         }
94     }
95 }
96
97
98 void
99 Note_head_line_engraver::create_grobs ()
100 {
101   if (!line_ && (follow_ || last_req_) && last_head_ && head_
102       && (last_head_ != head_))
103     {
104       /* TODO: Don't follow if there's a beam.
105
106          We can't do beam-stuff here, since beam doesn't exist yet.
107          Should probably store follow_ in line_, and suicide at some
108          later point */
109       if (follow_)
110         line_ = new Spanner (get_property ("VoiceFollower"));
111       else
112         line_ = new Spanner (get_property ("Glissando"));
113           
114       line_->set_bound (LEFT, last_head_);
115       line_->set_bound (RIGHT, head_);
116           
117           /* Note, mustn't set y-parent of breakable symbol to simple item:
118              one of the two broken parts won't have an y-parent! */
119           /* X parent is set by set_bound */
120       line_->set_parent (Staff_symbol_referencer::staff_symbol_l (last_head_),
121                          Y_AXIS);
122           
123       announce_grob (line_, last_req_);
124       last_req_ = 0;    
125
126       follow_ = false;
127     }
128 }
129
130 void
131 Note_head_line_engraver::stop_translation_timestep ()
132 {
133   if (line_)
134     {
135       typeset_grob (line_);
136       line_ = 0;
137     }
138   if (head_)
139     last_head_ = head_;
140   head_ = 0;
141
142   if (req_)
143     {
144       last_req_ = req_;
145       req_ =0;
146     }
147 }
148
149
150
151
152 ENTER_DESCRIPTION(Note_head_line_engraver,
153 /* descr */       "Engrave a line between two note heads, for example a glissando.
154 If followVoice is set, staff switches also generate a line.",
155 /* creats*/       "Glissando VoiceFollower",
156 /* acks  */       "rhythmic-head-interface",
157 /* reads */       "followVoice",
158 /* write */       "");