]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
8dfb6a944a7395a79632079bcfdfcec266eab83d
[lilypond.git] / lily / note-head-line-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--2009 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21 #include "pointer-group-interface.hh"
22 #include "stem.hh"
23 #include "rhythmic-head.hh"
24 #include "side-position-interface.hh"
25 #include "staff-symbol-referencer.hh"
26 #include "context.hh"
27 #include "spanner.hh"
28 #include "item.hh"
29
30
31 /**
32    Create line-spanner grobs for lines that connect note heads.
33
34    TODO: have the line commit suicide if the notes are connected with
35    either slur or beam.
36 */
37 class Note_head_line_engraver : public Engraver
38 {
39 public:
40   TRANSLATOR_DECLARATIONS (Note_head_line_engraver);
41
42 protected:
43   DECLARE_ACKNOWLEDGER (rhythmic_head);
44   void process_acknowledged ();
45   void stop_translation_timestep ();
46
47 private:
48   Spanner *line_;
49   Context *last_staff_;
50   bool follow_;
51   Grob *head_;
52   Grob *last_head_;
53 };
54
55 Note_head_line_engraver::Note_head_line_engraver ()
56 {
57   line_ = 0;
58   follow_ = false;
59   head_ = 0;
60   last_head_ = 0;
61   last_staff_ = 0;
62 }
63
64 void
65 Note_head_line_engraver::acknowledge_rhythmic_head (Grob_info info)
66 {
67   head_ = info.grob ();
68   Context *tr = context ();
69
70   while (tr && !tr->is_alias (ly_symbol2scm ("Staff")))
71     tr = tr->get_parent_context ();
72
73   if (tr
74       && tr->is_alias (ly_symbol2scm ("Staff")) && tr != last_staff_
75       && to_boolean (get_property ("followVoice")))
76     {
77       if (last_head_)
78         follow_ = true;
79     }
80   last_staff_ = tr;
81 }
82
83 void
84 Note_head_line_engraver::process_acknowledged ()
85 {
86   if (!line_ && follow_ && last_head_ && head_)
87     {
88       /* TODO: Don't follow if there's a beam.
89
90       We can't do beam-stuff here, since beam doesn't exist yet.
91       Should probably store follow_ in line_, and suicide at some
92       later point */
93       if (follow_)
94         line_ = make_spanner ("VoiceFollower", head_->self_scm ());
95
96       line_->set_bound (LEFT, last_head_);
97       line_->set_bound (RIGHT, head_);
98
99       follow_ = false;
100     }
101 }
102
103 void
104 Note_head_line_engraver::stop_translation_timestep ()
105 {
106   line_ = 0;
107   if (head_)
108     last_head_ = head_;
109   head_ = 0;
110 }
111
112 #include "translator.icc"
113
114 ADD_ACKNOWLEDGER (Note_head_line_engraver, rhythmic_head);
115 ADD_TRANSLATOR (Note_head_line_engraver,
116                 /* doc */
117                 "Engrave a line between two note heads, for example a"
118                 " glissando.  If @code{followVoice} is set, staff switches"
119                 " also generate a line.",
120
121                 /* create */
122                 "Glissando "
123                 "VoiceFollower ",
124
125                 /* read */
126                 "followVoice ",
127
128                 /* write */
129                 ""
130                 );