* lily/ledger-line-engraver.cc: new file.
[lilypond.git] / lily / note-head-line-engraver.cc
blobb489af8b148fa9d18f15495646a96899b2451d1c
1 /*
2 note-head-line-engraver.cc -- implement Note_head_line_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
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 "context.hh"
21 /**
22 Create line-spanner grobs for lines that connect note heads.
24 TODO: have the line commit suicide if the notes are connected with
25 either slur or beam.
28 class Note_head_line_engraver : public Engraver
30 public:
31 TRANSLATOR_DECLARATIONS (Note_head_line_engraver);
33 protected:
34 virtual void acknowledge_grob (Grob_info);
35 virtual void process_acknowledged_grobs ();
36 virtual void stop_translation_timestep ();
38 private:
39 Spanner* line_;
40 Context* last_staff_;
41 bool follow_;
42 Grob* head_;
43 Grob* last_head_;
46 Note_head_line_engraver::Note_head_line_engraver ()
48 line_ = 0;
49 follow_ = false;
50 head_ = 0;
51 last_head_ = 0;
52 last_staff_ = 0;
55 void
56 Note_head_line_engraver::acknowledge_grob (Grob_info info)
58 if (Rhythmic_head::has_interface (info.grob_))
60 head_ = info.grob_;
61 if (to_boolean (get_property ("followVoice")))
63 Context * tr = context ();
64 while (tr && !tr->is_alias (ly_symbol2scm ( "Staff")))
65 tr = tr->get_parent_context () ;
67 if (tr
68 && tr->is_alias (ly_symbol2scm ("Staff")) && tr != last_staff_)
70 if (last_head_)
71 follow_ = true;
72 last_staff_ = tr;
79 void
80 Note_head_line_engraver::process_acknowledged_grobs ()
82 if (!line_ && follow_ && last_head_ && head_)
84 /* TODO: Don't follow if there's a beam.
86 We can't do beam-stuff here, since beam doesn't exist yet.
87 Should probably store follow_ in line_, and suicide at some
88 later point */
89 if (follow_)
90 line_ = make_spanner ("VoiceFollower", head_->self_scm ());
92 line_->set_bound (LEFT, last_head_);
93 line_->set_bound (RIGHT, head_);
96 follow_ = false;
100 void
101 Note_head_line_engraver::stop_translation_timestep ()
103 line_ = 0;
104 if (head_)
105 last_head_ = head_;
106 head_ = 0;
112 ENTER_DESCRIPTION (Note_head_line_engraver,
113 /* descr */ "Engrave a line between two note heads, for example a glissando. If "
114 " followVoice is set, staff switches also generate a line.",
115 /* creats*/ "Glissando VoiceFollower",
116 /* accepts */ "glissando-event",
117 /* acks */ "rhythmic-head-interface",
118 /* reads */ "followVoice",
119 /* write */ "");