]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
*** empty log message ***
[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--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "engraver.hh"
10 #include "group-interface.hh"
11 #include "item.hh"
12 #include "event.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 process_acknowledged_grobs ();
37   virtual void stop_translation_timestep ();
38   virtual bool try_music (Music *);
39
40 private:
41   Spanner* line_; 
42   Music* req_;
43   Music* 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       req_ = m;
67       return true;
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.grob_))
76     {
77       head_ = info.grob_;
78       if (to_boolean (get_property ("followVoice")))
79         {
80           Translator_group  * tr = daddy_trans_;
81           while (tr && tr->type_string_ != "Staff")
82             tr = tr->daddy_trans_ ;
83
84           if (tr && tr->type_string_ == "Staff" && tr != last_staff_)
85             {
86               if (last_head_)
87                 follow_ = true;
88               last_staff_ = tr;
89             }
90         }
91     }
92 }
93
94
95 void
96 Note_head_line_engraver::process_acknowledged_grobs ()
97 {
98   if (!line_ && (follow_ || last_req_) && last_head_ && head_
99       && (last_head_ != head_))
100     {
101       /* TODO: Don't follow if there's a beam.
102
103          We can't do beam-stuff here, since beam doesn't exist yet.
104          Should probably store follow_ in line_, and suicide at some
105          later point */
106       if (follow_)
107         line_ = new Spanner (get_property ("VoiceFollower"));
108       else
109         line_ = new Spanner (get_property ("Glissando"));
110           
111       line_->set_bound (LEFT, last_head_);
112       line_->set_bound (RIGHT, head_);
113           
114           /* Note, mustn't set y-parent of breakable symbol to simple item:
115              one of the two broken parts won't have an y-parent! */
116           /* X parent is set by set_bound */
117       line_->set_parent (Staff_symbol_referencer::get_staff_symbol (last_head_),
118                          Y_AXIS);
119           
120       SCM c = last_req_? last_req_->self_scm () : SCM_EOL;
121       announce_grob(line_, c);
122       last_req_ = 0;    
123
124       follow_ = false;
125     }
126 }
127
128 void
129 Note_head_line_engraver::stop_translation_timestep ()
130 {
131   if (line_)
132     {
133       typeset_grob (line_);
134       line_ = 0;
135     }
136   if (head_)
137     last_head_ = head_;
138   head_ = 0;
139
140   if (req_)
141     {
142       last_req_ = req_;
143       req_ =0;
144     }
145 }
146
147
148
149
150 ENTER_DESCRIPTION(Note_head_line_engraver,
151 /* descr */       "Engrave a line between two note heads, for example a glissando.  If "
152 " followVoice is set, staff switches also generate a line.",
153 /* creats*/       "Glissando VoiceFollower",
154 /* accepts */     "glissando-event",
155 /* acks  */       "rhythmic-head-interface",
156 /* reads */       "followVoice",
157 /* write */       "");