]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
Merge with git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond.git
[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--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10 #include "pointer-group-interface.hh"
11 #include "stem.hh"
12 #include "rhythmic-head.hh"
13 #include "side-position-interface.hh"
14 #include "staff-symbol-referencer.hh"
15 #include "context.hh"
16
17 /**
18    Create line-spanner grobs for lines that connect note heads.
19
20    TODO: have the line commit suicide if the notes are connected with
21    either slur or beam.
22 */
23 class Note_head_line_engraver : public Engraver
24 {
25 public:
26   TRANSLATOR_DECLARATIONS (Note_head_line_engraver);
27
28 protected:
29   DECLARE_ACKNOWLEDGER (rhythmic_head);
30   void process_acknowledged ();
31   void stop_translation_timestep ();
32
33 private:
34   Spanner *line_;
35   Context *last_staff_;
36   bool follow_;
37   Grob *head_;
38   Grob *last_head_;
39 };
40
41 Note_head_line_engraver::Note_head_line_engraver ()
42 {
43   line_ = 0;
44   follow_ = false;
45   head_ = 0;
46   last_head_ = 0;
47   last_staff_ = 0;
48 }
49
50 void
51 Note_head_line_engraver::acknowledge_rhythmic_head (Grob_info info)
52 {
53   head_ = info.grob ();
54   if (to_boolean (get_property ("followVoice")))
55     {
56       Context *tr = context ();
57       while (tr && !tr->is_alias (ly_symbol2scm ("Staff")))
58         tr = tr->get_parent_context ();
59
60       if (tr
61           && tr->is_alias (ly_symbol2scm ("Staff")) && tr != last_staff_)
62         {
63           if (last_head_)
64             follow_ = true;
65           last_staff_ = tr;
66         }
67     }
68 }
69
70 void
71 Note_head_line_engraver::process_acknowledged ()
72 {
73   if (!line_ && follow_ && last_head_ && head_)
74     {
75       /* TODO: Don't follow if there's a beam.
76
77       We can't do beam-stuff here, since beam doesn't exist yet.
78       Should probably store follow_ in line_, and suicide at some
79       later point */
80       if (follow_)
81         line_ = make_spanner ("VoiceFollower", head_->self_scm ());
82
83       line_->set_bound (LEFT, last_head_);
84       line_->set_bound (RIGHT, head_);
85
86       follow_ = false;
87     }
88 }
89
90 void
91 Note_head_line_engraver::stop_translation_timestep ()
92 {
93   line_ = 0;
94   if (head_)
95     last_head_ = head_;
96   head_ = 0;
97 }
98
99 #include "translator.icc"
100
101 ADD_ACKNOWLEDGER (Note_head_line_engraver, rhythmic_head);
102 ADD_TRANSLATOR (Note_head_line_engraver,
103                 /* doc */ "Engrave a line between two note heads, for example a glissando.  If "
104                 " followVoice is set, staff switches also generate a line.",
105                 /* create */ "Glissando VoiceFollower",
106                 /* read */ "followVoice",
107                 /* write */ "");