Merge remote branch 'origin' into release/unstable
[lilypond/patrick.git] / lily / phrasing-slur-engraver.cc
blob8ace05fe10d8bad48f7017fa989ccb65a0cf236b
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "engraver.hh"
22 #include "context.hh"
23 #include "directional-element-interface.hh"
24 #include "international.hh"
25 #include "note-column.hh"
26 #include "slur.hh"
27 #include "spanner.hh"
28 #include "stream-event.hh"
29 #include "warn.hh"
31 #include "translator.icc"
34 It is possible that a slur starts and ends on the same note. At
35 least, it is for phrasing slurs: a note can be both beginning and
36 ending of a phrase.
41 NOTE NOTE NOTE
43 This is largely similar to Slur_engraver. Check if fixes apply there too.
45 (on principle, engravers don't use inheritance for code sharing)
48 class Phrasing_slur_engraver : public Engraver
50 Drul_array<Stream_event *> events_;
51 Stream_event *running_slur_start_;
52 vector<Grob*> slurs_;
53 vector<Grob*> end_slurs_;
55 protected:
56 void acknowledge_extra_object (Grob_info);
57 DECLARE_ACKNOWLEDGER (accidental);
58 DECLARE_ACKNOWLEDGER (fingering);
59 DECLARE_ACKNOWLEDGER (note_column);
60 DECLARE_ACKNOWLEDGER (slur);
61 DECLARE_ACKNOWLEDGER (script);
62 DECLARE_ACKNOWLEDGER (text_script);
63 DECLARE_ACKNOWLEDGER (tie);
64 DECLARE_ACKNOWLEDGER (tuplet_number);
65 DECLARE_TRANSLATOR_LISTENER (phrasing_slur);
67 void stop_translation_timestep ();
68 virtual void finalize ();
69 void process_music ();
71 public:
72 TRANSLATOR_DECLARATIONS (Phrasing_slur_engraver);
75 Phrasing_slur_engraver::Phrasing_slur_engraver ()
77 events_[START] = events_[STOP] = 0;
80 IMPLEMENT_TRANSLATOR_LISTENER (Phrasing_slur_engraver, phrasing_slur);
81 void
82 Phrasing_slur_engraver::listen_phrasing_slur (Stream_event *ev)
85 Let's not start more than one slur per moment.
87 Direction d = to_dir (ev->get_property ("span-direction"));
88 if (d == START)
89 ASSIGN_EVENT_ONCE (events_[START], ev);
90 else if (d == STOP && !slurs_.empty ())
91 ASSIGN_EVENT_ONCE (events_[STOP], ev);
94 void
95 Phrasing_slur_engraver::acknowledge_note_column (Grob_info info)
97 Grob *e = info.grob ();
98 for (vsize i = slurs_.size (); i--;)
99 Slur::add_column (slurs_[i], e);
100 for (vsize i = end_slurs_.size (); i--;)
101 Slur::add_column (end_slurs_[i], e);
104 void
105 Phrasing_slur_engraver::acknowledge_extra_object (Grob_info info)
107 Slur::auxiliary_acknowledge_extra_object (info, slurs_, end_slurs_);
110 void
111 Phrasing_slur_engraver::acknowledge_accidental (Grob_info info)
113 acknowledge_extra_object (info);
116 void
117 Phrasing_slur_engraver::acknowledge_fingering (Grob_info info)
119 acknowledge_extra_object (info);
122 void
123 Phrasing_slur_engraver::acknowledge_text_script (Grob_info info)
125 acknowledge_extra_object (info);
128 void
129 Phrasing_slur_engraver::acknowledge_script (Grob_info info)
131 if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
132 acknowledge_extra_object (info);
135 void
136 Phrasing_slur_engraver::acknowledge_tie (Grob_info info)
138 acknowledge_extra_object (info);
141 void
142 Phrasing_slur_engraver::acknowledge_tuplet_number (Grob_info info)
144 acknowledge_extra_object (info);
147 void
148 Phrasing_slur_engraver::acknowledge_slur (Grob_info info)
150 acknowledge_extra_object (info);
153 void
154 Phrasing_slur_engraver::finalize ()
156 if (slurs_.size ())
157 slurs_[0]->warning (_ ("unterminated phrasing slur"));
160 void
161 Phrasing_slur_engraver::process_music ()
163 if (events_[STOP])
165 end_slurs_ = slurs_;
166 slurs_.clear ();
169 if (events_[START] && slurs_.empty ())
171 Stream_event *ev = events_[START];
173 Grob *slur = make_spanner ("PhrasingSlur", events_[START]->self_scm ());
174 Direction updown = to_dir (ev->get_property ("direction"));
175 if (updown)
176 set_grob_direction (slur, updown);
178 slurs_.push_back (slur);
182 void
183 Phrasing_slur_engraver::stop_translation_timestep ()
185 end_slurs_.clear ();
186 events_[START] = events_[STOP] = 0;
189 ADD_ACKNOWLEDGER (Phrasing_slur_engraver, accidental);
190 ADD_ACKNOWLEDGER (Phrasing_slur_engraver, fingering)
191 ADD_ACKNOWLEDGER (Phrasing_slur_engraver, note_column);
192 ADD_ACKNOWLEDGER (Phrasing_slur_engraver, slur);
193 ADD_ACKNOWLEDGER (Phrasing_slur_engraver, script);
194 ADD_ACKNOWLEDGER (Phrasing_slur_engraver, text_script);
195 ADD_ACKNOWLEDGER (Phrasing_slur_engraver, tie);
196 ADD_ACKNOWLEDGER (Phrasing_slur_engraver, tuplet_number);
198 ADD_TRANSLATOR (Phrasing_slur_engraver,
199 /* doc */
200 "Print phrasing slurs. Similar to @ref{Slur_engraver}.",
202 /* create */
203 "PhrasingSlur ",
205 /* read */
208 /* write */