]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
* flower
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10 #include "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   virtual void acknowledge_grob (Grob_info);
30   virtual void process_acknowledged_grobs ();
31   virtual 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_grob (Grob_info info)
52 {
53   if (Rhythmic_head::has_interface (info.grob_))
54     {
55       head_ = info.grob_;
56       if (to_boolean (get_property ("followVoice")))
57         {
58           Context *tr = context ();
59           while (tr && !tr->is_alias (ly_symbol2scm ("Staff")))
60             tr = tr->get_parent_context ();
61
62           if (tr
63               && tr->is_alias (ly_symbol2scm ("Staff")) && tr != last_staff_)
64             {
65               if (last_head_)
66                 follow_ = true;
67               last_staff_ = tr;
68             }
69         }
70     }
71 }
72
73 void
74 Note_head_line_engraver::process_acknowledged_grobs ()
75 {
76   if (!line_ && follow_ && last_head_ && head_)
77     {
78       /* TODO: Don't follow if there's a beam.
79
80       We can't do beam-stuff here, since beam doesn't exist yet.
81       Should probably store follow_ in line_, and suicide at some
82       later point */
83       if (follow_)
84         line_ = make_spanner ("VoiceFollower", head_->self_scm ());
85
86       line_->set_bound (LEFT, last_head_);
87       line_->set_bound (RIGHT, head_);
88
89       follow_ = false;
90     }
91 }
92
93 void
94 Note_head_line_engraver::stop_translation_timestep ()
95 {
96   line_ = 0;
97   if (head_)
98     last_head_ = head_;
99   head_ = 0;
100 }
101
102
103 ADD_TRANSLATOR (Note_head_line_engraver,
104                 /* descr */ "Engrave a line between two note heads, for example a glissando.  If "
105                 " followVoice is set, staff switches also generate a line.",
106                 /* creats*/ "Glissando VoiceFollower",
107                 /* accepts */ "glissando-event",
108                 /* acks  */ "rhythmic-head-interface",
109                 /* reads */ "followVoice",
110                 /* write */ "");