]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
Docs: Fix fixed IR compilation (copy @q and @qq from macros.itely)
[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--2007 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 #include "spanner.hh"
17 #include "item.hh"
18
19
20 /**
21    Create line-spanner grobs for lines that connect note heads.
22
23    TODO: have the line commit suicide if the notes are connected with
24    either slur or beam.
25 */
26 class Note_head_line_engraver : public Engraver
27 {
28 public:
29   TRANSLATOR_DECLARATIONS (Note_head_line_engraver);
30
31 protected:
32   DECLARE_ACKNOWLEDGER (rhythmic_head);
33   void process_acknowledged ();
34   void stop_translation_timestep ();
35
36 private:
37   Spanner *line_;
38   Context *last_staff_;
39   bool follow_;
40   Grob *head_;
41   Grob *last_head_;
42 };
43
44 Note_head_line_engraver::Note_head_line_engraver ()
45 {
46   line_ = 0;
47   follow_ = false;
48   head_ = 0;
49   last_head_ = 0;
50   last_staff_ = 0;
51 }
52
53 void
54 Note_head_line_engraver::acknowledge_rhythmic_head (Grob_info info)
55 {
56   head_ = info.grob ();
57   Context *tr = context ();
58
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       && to_boolean (get_property ("followVoice")))
65     {
66       if (last_head_)
67         follow_ = true;
68     }
69   last_staff_ = tr;
70 }
71
72 void
73 Note_head_line_engraver::process_acknowledged ()
74 {
75   if (!line_ && follow_ && last_head_ && head_)
76     {
77       /* TODO: Don't follow if there's a beam.
78
79       We can't do beam-stuff here, since beam doesn't exist yet.
80       Should probably store follow_ in line_, and suicide at some
81       later point */
82       if (follow_)
83         line_ = make_spanner ("VoiceFollower", head_->self_scm ());
84
85       line_->set_bound (LEFT, last_head_);
86       line_->set_bound (RIGHT, head_);
87
88       follow_ = false;
89     }
90 }
91
92 void
93 Note_head_line_engraver::stop_translation_timestep ()
94 {
95   line_ = 0;
96   if (head_)
97     last_head_ = head_;
98   head_ = 0;
99 }
100
101 #include "translator.icc"
102
103 ADD_ACKNOWLEDGER (Note_head_line_engraver, rhythmic_head);
104 ADD_TRANSLATOR (Note_head_line_engraver,
105                 /* doc */
106                 "Engrave a line between two note heads, for example a"
107                 " glissando.  If @code{followVoice} is set, staff switches"
108                 " also generate a line.",
109
110                 /* create */
111                 "Glissando "
112                 "VoiceFollower ",
113
114                 /* read */
115                 "followVoice ",
116
117                 /* write */
118                 ""
119                 );