2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>
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 "international.hh"
23 #include "pointer-group-interface.hh"
24 #include "rhythmic-head.hh"
26 #include "stream-event.hh"
30 #include "translator.icc"
35 class Glissando_engraver : public Engraver
38 TRANSLATOR_DECLARATIONS (Glissando_engraver);
41 DECLARE_TRANSLATOR_LISTENER (glissando);
42 DECLARE_ACKNOWLEDGER (note_column);
43 virtual void finalize ();
45 void stop_translation_timestep ();
46 void process_music ();
49 vector<Spanner *> lines_;
50 vector<Spanner *> kill_me_;
51 bool start_glissandi_;
55 vector<vsize> note_column_1;
56 vector<vsize> note_column_2;
59 Glissando_engraver::Glissando_engraver ()
62 start_glissandi_ = false;
63 stop_glissandi_ = false;
66 IMPLEMENT_TRANSLATOR_LISTENER (Glissando_engraver, glissando);
68 Glissando_engraver::listen_glissando (Stream_event *ev)
70 ASSIGN_EVENT_ONCE (event_, ev);
74 Glissando_engraver::process_music ()
77 start_glissandi_ = true;
81 Glissando_engraver::acknowledge_note_column (Grob_info info)
83 Grob *g = info.grob ();
84 if (to_boolean (g->get_property ("glissando-skip")))
89 extract_grob_set (g, "note-heads", note_heads);
90 int glissando_index = 0;
91 for (vsize i = 0; i < note_column_1.size (); i++)
93 if (note_column_2[i] >= note_heads.size ())
95 kill_me_.push_back (lines_[i]);
96 announce_end_grob (lines_[i], SCM_EOL);
100 lines_[i]->set_bound (RIGHT, note_heads[note_column_2[i]]);
101 lines_[i]->set_property ("glissando-index", scm_from_int (glissando_index));
103 announce_end_grob (lines_[i], note_heads[note_column_2[i]]->self_scm ());
107 note_column_1.clear ();
108 note_column_2.clear ();
109 stop_glissandi_ = false;
112 if (start_glissandi_)
114 extract_grob_set (g, "note-heads", note_heads);
115 SCM map = get_property ("glissandoMap");
116 if (scm_is_null (map))
117 for (vsize i = 0; i < note_heads.size (); i++)
119 note_column_1.push_back (i);
120 note_column_2.push_back (i);
123 for (SCM m = map; scm_is_pair (m); m = scm_cdr (m))
125 SCM candidate = scm_car (m);
126 if (!scm_is_pair (candidate))
128 int n1 = robust_scm2int (scm_car (candidate), -1);
129 int n2 = robust_scm2int (scm_cdr (candidate), -1);
130 if ((n1 < 0) || (n2 < 0) || (size_t (n1) >= note_heads.size ()))
132 note_column_1.push_back (vsize (n1));
133 note_column_2.push_back (vsize (n2));
135 for (vsize i = 0; i < note_column_1.size (); i++)
137 lines_.push_back (make_spanner ("Glissando", event_->self_scm ()));
138 lines_.back ()->set_bound (LEFT, note_heads[note_column_1[i]]);
144 Glissando_engraver::stop_translation_timestep ()
146 if (start_glissandi_)
149 programming_error ("overwriting glissando");
150 stop_glissandi_ = true;
151 start_glissandi_ = false;
157 Glissando_engraver::finalize ()
159 if (!lines_.empty ())
161 string msg = _ ("unterminated glissando");
164 event_->origin ()->warning (msg);
168 for (vsize i = 0; i < lines_.size (); i++)
169 lines_[i]->suicide ();
172 for (vsize i = 0; i < kill_me_.size (); i++)
173 kill_me_[i]->suicide ();
176 ADD_ACKNOWLEDGER (Glissando_engraver, note_column);
177 ADD_TRANSLATOR (Glissando_engraver,
179 "Engrave glissandi.",