]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-head-line-engraver.cc
Issue 4938 (1/3) Add Audio_item and Midi_item subclasses for control changes
[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--2015 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    Create line-spanner grobs for lines that connect note heads.
32
33    TODO: have the line commit suicide if the notes are connected with
34    either slur or beam.
35 */
36 class Note_head_line_engraver : public Engraver
37 {
38 public:
39   TRANSLATOR_DECLARATIONS (Note_head_line_engraver);
40
41 protected:
42   void acknowledge_rhythmic_head (Grob_info);
43   void process_acknowledged ();
44   void stop_translation_timestep ();
45
46 private:
47   Spanner *line_;
48   Context *last_staff_;
49   bool follow_;
50   Grob *head_;
51   Grob *last_head_;
52 };
53
54 Note_head_line_engraver::Note_head_line_engraver ()
55 {
56   line_ = 0;
57   follow_ = false;
58   head_ = 0;
59   last_head_ = 0;
60   last_staff_ = 0;
61 }
62
63 void
64 Note_head_line_engraver::acknowledge_rhythmic_head (Grob_info info)
65 {
66   head_ = info.grob ();
67   Context *tr = find_context_above (context (), ly_symbol2scm ("Staff"));
68   if (tr
69       && tr != last_staff_
70       && to_boolean (get_property ("followVoice")))
71     {
72       if (last_head_)
73         follow_ = true;
74     }
75   last_staff_ = tr;
76 }
77
78 void
79 Note_head_line_engraver::process_acknowledged ()
80 {
81   if (!line_ && follow_ && last_head_ && head_)
82     {
83       /* TODO: Don't follow if there's a beam.
84
85       We can't do beam-stuff here, since beam doesn't exist yet.
86       Should probably store follow_ in line_, and suicide at some
87       later point */
88       if (follow_)
89         line_ = make_spanner ("VoiceFollower", head_->self_scm ());
90
91       line_->set_bound (LEFT, last_head_);
92       line_->set_bound (RIGHT, head_);
93
94       follow_ = false;
95     }
96 }
97
98 void
99 Note_head_line_engraver::stop_translation_timestep ()
100 {
101   line_ = 0;
102   if (head_)
103     last_head_ = head_;
104   head_ = 0;
105 }
106
107 #include "translator.icc"
108
109 void
110 Note_head_line_engraver::boot ()
111 {
112   ADD_ACKNOWLEDGER (Note_head_line_engraver, rhythmic_head);
113 }
114
115 ADD_TRANSLATOR (Note_head_line_engraver,
116                 /* doc */
117                 "Engrave a line between two note heads in a staff"
118                 " switch if @code{followVoice} is set.",
119
120                 /* create */
121                 "VoiceFollower ",
122
123                 /* read */
124                 "followVoice ",
125
126                 /* write */
127                 ""
128                );