]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
release: 1.3.114
[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 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 class Note_head_line_engraver : public Engraver
26 {
27 public:
28   VIRTUAL_COPY_CONS (Translator);
29   Note_head_line_engraver ();
30
31 protected:
32   virtual void acknowledge_grob (Grob_info);
33   virtual void create_grobs ();
34   virtual void stop_translation_timestep ();
35   virtual bool try_music (Music *);
36
37 private:
38   Spanner* line_; 
39   Request* req_;
40   Request* last_req_;
41   Translator* last_staff_;
42   bool follow_;
43   Grob* head_;
44   Grob* last_head_;
45 };
46
47 Note_head_line_engraver::Note_head_line_engraver ()
48 {
49   line_ = 0;
50   req_ = 0;
51   last_req_ = 0;
52   follow_ = false;
53   head_ = 0;
54   last_head_ = 0;
55   last_staff_ = 0;
56 }
57
58 bool
59 Note_head_line_engraver::try_music (Music* m)
60 {
61   if (!req_)
62     {
63       if (Glissando_req *r = dynamic_cast<Glissando_req*> (m))
64         {
65           req_ = r;
66           return true;
67         }
68     }
69   return false;
70 }
71
72 void
73 Note_head_line_engraver::acknowledge_grob (Grob_info info)
74 {
75   if (Rhythmic_head::has_interface (info.elem_l_))
76     {
77       last_head_ = head_;
78       head_ = info.elem_l_;
79       if (to_boolean (get_property ("followThread")))
80         {
81           Translator* staff = daddy_trans_l_ && daddy_trans_l_->daddy_trans_l_
82             ? daddy_trans_l_->daddy_trans_l_->daddy_trans_l_ : 0;
83           if (staff != last_staff_)
84             {
85               if (last_head_)
86                 follow_ = true;
87               last_staff_ = staff;
88             }
89         }
90     }
91 }
92
93 static Grob*
94 beam_l (Grob *h)
95 {
96   if (Grob *s = Rhythmic_head::stem_l (h))
97     return Stem::beam_l (s);
98   return 0;
99 }
100
101 void
102 Note_head_line_engraver::create_grobs ()
103 {
104   if (!line_ && (follow_ || last_req_) && last_head_ && head_
105       && (last_head_ != head_))
106     {
107       /* Don't follow if there's a beam.
108
109          Hmm, this doesn't work, as head_ does not yet have a beam.
110          Should probably store follow_ in line_, and suicide at some
111          later point */
112       if (!(follow_
113             && beam_l (last_head_) && beam_l (last_head_) == beam_l (head_)))
114         {
115           if (follow_)
116             line_ = new Spanner (get_property ("FollowThread"));
117           else
118             line_ = new Spanner (get_property ("Glissando"));
119           
120           line_->set_bound (LEFT, last_head_);
121           line_->set_bound (RIGHT, head_);
122           
123           /* Note, mustn't set y-parent of breakable symbol to simple item:
124              one of the two broken parts won't have an y-parent! */
125           /* X parent is set by set_bound */
126           line_->set_parent (Staff_symbol_referencer::staff_symbol_l (last_head_),
127                              Y_AXIS);
128           
129           announce_grob (line_, last_req_);
130         }
131       
132       last_req_ = 0;
133       follow_ = false;
134       last_head_ = 0;
135     }
136 }
137
138 void
139 Note_head_line_engraver::stop_translation_timestep ()
140 {
141   if (line_)
142     {
143       typeset_grob (line_);
144       line_ = 0;
145     }
146   last_req_ = req_;
147   req_ = 0;
148 }
149
150
151 ADD_THIS_TRANSLATOR (Note_head_line_engraver);
152