2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2011 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"
32 class Glissando_engraver : public Engraver
35 TRANSLATOR_DECLARATIONS (Glissando_engraver);
38 DECLARE_TRANSLATOR_LISTENER (glissando);
39 DECLARE_ACKNOWLEDGER (note_column);
40 virtual void finalize ();
42 void stop_translation_timestep ();
43 void process_music ();
46 vector<Spanner *> lines_;
52 vector<vsize> note_column_1;
53 vector<vsize> note_column_2;
56 Glissando_engraver::Glissando_engraver ()
60 start_glissandi = false;
61 stop_glissandi = false;
64 IMPLEMENT_TRANSLATOR_LISTENER (Glissando_engraver, glissando);
66 Glissando_engraver::listen_glissando (Stream_event *ev)
68 ASSIGN_EVENT_ONCE (event_, ev);
72 Glissando_engraver::process_music ()
75 start_glissandi = true;
79 Glissando_engraver::acknowledge_note_column (Grob_info info)
81 Grob *g = info.grob ();
84 extract_grob_set (g, "note-heads", note_heads);
85 map = get_property ("glissandoMap");
87 for (vsize i = 0; i < note_heads.size (); i++)
89 note_column_1.push_back (i);
90 note_column_2.push_back (i);
93 for (SCM m = map; scm_is_pair (m); m = scm_cdr (m))
95 SCM candidate = scm_car (m);
96 if (!scm_is_pair (candidate))
98 int n1 = robust_scm2int (scm_car (candidate), -1);
99 int n2 = robust_scm2int (scm_cdr (candidate), -1);
100 if (n1 < 0 || n2 < 0 || n1 >= note_heads.size ())
102 note_column_1.push_back (vsize (n1));
103 note_column_2.push_back (vsize (n2));
105 for (vsize i=0; i < note_column_1.size (); i++)
107 lines_.push_back (make_spanner ("Glissando", event_->self_scm ()));
108 lines_.back ()->set_bound (LEFT, note_heads[note_column_1[i]]);
114 extract_grob_set (g, "note-heads", note_heads);
115 int glissando_index = 0;
116 for (vsize i=0; i < note_column_1.size (); i++)
118 if (note_column_2[i] >= note_heads.size ())
119 lines_[i]->suicide ();
122 lines_[i]->set_bound (RIGHT, note_heads[note_column_2[i]]);
123 lines_[i]->set_property ("glissando-index", scm_from_int (glissando_index));
125 announce_end_grob (lines_[i], note_heads[note_column_2[i]]->self_scm ());
129 note_column_1.clear ();
130 note_column_2.clear ();
131 stop_glissandi = false;
136 Glissando_engraver::stop_translation_timestep ()
142 programming_error ("overwriting glissando");
143 stop_glissandi = true;
146 start_glissandi = false;
151 Glissando_engraver::finalize ()
153 if (!lines_.empty ())
155 string msg = _ ("unterminated glissando");
158 event_->origin ()->warning (msg);
162 for (vsize i=0; i < lines_.size (); i++)
163 lines_[i]->suicide ();
167 ADD_ACKNOWLEDGER (Glissando_engraver, note_column);
168 ADD_TRANSLATOR (Glissando_engraver,
170 "Engrave glissandi.",