2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Erik Sandberg <mandolaerik@gmail.com>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 #include "engraver-group.hh"
23 #include "international.hh"
25 #include "math.h" // ceil
27 #include "repeated-music.hh"
28 #include "rhythmic-head.hh"
30 #include "stem-tremolo.hh"
32 #include "stream-event.hh"
35 #include "translator.icc"
39 This acknowledges repeated music with "tremolo" style. It typesets
44 - perhaps use engraver this to steer other engravers? That would
45 create dependencies between engravers, which is bad.
47 - create dots if appropriate.
49 - create TremoloBeam iso Beam?
51 class Chord_tremolo_engraver : public Engraver
53 TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver);
55 Stream_event *repeat_;
58 // Store the pointer to the previous stem, so we can create a beam if
59 // necessary and end the spanner
63 virtual void finalize ();
64 void process_music ();
65 DECLARE_TRANSLATOR_LISTENER (tremolo_span);
66 DECLARE_ACKNOWLEDGER (stem);
69 Chord_tremolo_engraver::Chord_tremolo_engraver ()
76 IMPLEMENT_TRANSLATOR_LISTENER (Chord_tremolo_engraver, tremolo_span);
78 Chord_tremolo_engraver::listen_tremolo_span (Stream_event *ev)
80 Direction span_dir = to_dir (ev->get_property ("span-direction"));
81 if (span_dir == START)
83 ASSIGN_EVENT_ONCE (repeat_, ev);
85 else if (span_dir == STOP)
88 ev->origin ()->warning (_ ("No tremolo to end"));
96 Chord_tremolo_engraver::process_music ()
98 if (repeat_ && !beam_)
100 beam_ = make_spanner ("Beam", repeat_->self_scm ());
105 Chord_tremolo_engraver::finalize ()
109 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
110 announce_end_grob (beam_, SCM_EOL);
116 Chord_tremolo_engraver::acknowledge_stem (Grob_info info)
120 int tremolo_type = robust_scm2int (repeat_->get_property ("tremolo-type"), 1);
121 int flags = max (0, intlog2 (tremolo_type) - 2);
122 int repeat_count = robust_scm2int (repeat_->get_property ("repeat-count"), 1);
123 int gap_count = min (flags, intlog2 (repeat_count) + 1);
125 Grob *s = info.grob ();
128 // FIXME: We know that the beam has ended only in listen_tremolo_span
129 // but then it is too late for Spanner_break_forbid_engraver
130 // to allow a line break... So, as a nasty hack, announce the
131 // spanner's end after each note except the first. The only
132 // "drawback" is that for multi-note tremolos a break would
133 // theoretically be allowed after the second note (but since
134 // that note is typically not at a barline, I don't think
135 // anyone will ever notice!)
136 announce_end_grob (beam_, previous_stem_->self_scm ());
137 // Create the whole beam between previous and current note
138 Stem::set_beaming (previous_stem_, flags, RIGHT);
139 Stem::set_beaming (s, flags, LEFT);
142 if (Stem::duration_log (s) != 1)
143 beam_->set_property ("gap-count", scm_from_int (gap_count));
145 if (info.ultimate_event_cause ()->in_event_class ("rhythmic-event"))
146 Beam::add_stem (beam_, s);
149 string s = _ ("stem must have Rhythmic structure");
150 if (info.event_cause ())
151 info.event_cause ()->origin ()->warning (s);
155 // Store current grob, so we can possibly end the spanner here (and
156 // reset the beam direction to RIGHT)
161 ADD_ACKNOWLEDGER (Chord_tremolo_engraver, stem);
162 ADD_TRANSLATOR (Chord_tremolo_engraver,
164 "Generate beams for tremolo repeats.",