]> git.donarmstrong.com Git - lilypond.git/blob - lily/trill-spanner-engraver.cc
Issue 4938 (3/3) Rename Midi_control_function_performer to Midi_control_change_performer
[lilypond.git] / lily / trill-spanner-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 /*
21   C&P from text-spanner.cc
22
23   - todo: ending should be detected automatically? a new note
24   automatically is the end of the trill?
25 */
26
27 #include "engraver.hh"
28
29 #include "international.hh"
30 #include "note-column.hh"
31 #include "pointer-group-interface.hh"
32 #include "side-position-interface.hh"
33 #include "stream-event.hh"
34 #include "spanner.hh"
35
36 #include "translator.icc"
37
38 class Trill_spanner_engraver : public Engraver
39 {
40 public:
41   TRANSLATOR_DECLARATIONS (Trill_spanner_engraver);
42 protected:
43   virtual void finalize ();
44   void listen_trill_span (Stream_event *);
45   void acknowledge_note_column (Grob_info);
46
47   void stop_translation_timestep ();
48   void process_music ();
49
50 private:
51   Spanner *span_;
52   Spanner *finished_;
53   Stream_event *current_event_;
54   Drul_array<Stream_event *> event_drul_;
55   void typeset_all ();
56 };
57
58 Trill_spanner_engraver::Trill_spanner_engraver ()
59 {
60   finished_ = 0;
61   current_event_ = 0;
62   span_ = 0;
63   event_drul_.set (0, 0);
64 }
65
66 void
67 Trill_spanner_engraver::listen_trill_span (Stream_event *ev)
68 {
69   Direction d = to_dir (ev->get_property ("span-direction"));
70   ASSIGN_EVENT_ONCE (event_drul_[d], ev);
71 }
72
73 void
74 Trill_spanner_engraver::acknowledge_note_column (Grob_info info)
75 {
76   if (span_)
77     {
78       Pointer_group_interface::add_grob (span_,
79                                          ly_symbol2scm ("note-columns"),
80                                          info.grob ());
81       if (!span_->get_bound (LEFT))
82         add_bound_item (span_, info.grob ());
83     }
84   else if (finished_)
85     {
86       Pointer_group_interface::add_grob (finished_, ly_symbol2scm ("note-columns"),
87                                          info.grob ());
88       if (!finished_->get_bound (RIGHT))
89         add_bound_item (finished_, info.grob ());
90     }
91 }
92
93 void
94 Trill_spanner_engraver::process_music ()
95 {
96   if (span_
97       && (event_drul_[STOP] || event_drul_[START]))
98     {
99       Stream_event *ender = event_drul_[STOP];
100       if (!ender)
101         ender = event_drul_[START];
102       finished_ = span_;
103       announce_end_grob (finished_, ender->self_scm ());
104       span_ = 0;
105       current_event_ = 0;
106     }
107
108   if (event_drul_[START])
109     {
110       current_event_ = event_drul_[START];
111       span_ = make_spanner ("TrillSpanner", event_drul_[START]->self_scm ());
112       Side_position_interface::set_axis (span_, Y_AXIS);
113     }
114 }
115
116 void
117 Trill_spanner_engraver::typeset_all ()
118 {
119   if (finished_)
120     {
121       if (!finished_->get_bound (RIGHT))
122         {
123           Grob *e = unsmob<Grob> (get_property ("currentMusicalColumn"));
124           finished_->set_bound (RIGHT, e);
125         }
126       finished_ = 0;
127     }
128 }
129
130 void
131 Trill_spanner_engraver::stop_translation_timestep ()
132 {
133   if (span_ && !span_->get_bound (LEFT))
134     {
135       Grob *e = unsmob<Grob> (get_property ("currentMusicalColumn"));
136       span_->set_bound (LEFT, e);
137     }
138
139   typeset_all ();
140   event_drul_.set (0, 0);
141 }
142
143 void
144 Trill_spanner_engraver::finalize ()
145 {
146   typeset_all ();
147   if (span_)
148     {
149       Grob *e = unsmob<Grob> (get_property ("currentCommandColumn"));
150       span_->set_bound (RIGHT, e);
151     }
152 }
153
154
155 void
156 Trill_spanner_engraver::boot ()
157 {
158   ADD_LISTENER (Trill_spanner_engraver, trill_span);
159   ADD_ACKNOWLEDGER (Trill_spanner_engraver, note_column);
160 }
161
162 ADD_TRANSLATOR (Trill_spanner_engraver,
163                 /* doc */
164                 "Create trill spanner from an event.",
165
166                 /* create */
167                 "TrillSpanner ",
168
169                 /* read */
170                 "currentCommandColumn "
171                 "currentMusicalColumn ",
172
173                 /* write */
174                 ""
175                );