LSR: Update.
[lilypond/mpolesky.git] / lily / chord-tremolo-engraver.cc
blob141f7313e45d266c8489137d16c97cff1a411d98
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2000--2010 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/>.
21 #include "beam.hh"
22 #include "engraver-group.hh"
23 #include "international.hh"
24 #include "item.hh"
25 #include "math.h" // ceil
26 #include "misc.hh"
27 #include "repeated-music.hh"
28 #include "rhythmic-head.hh"
29 #include "spanner.hh"
30 #include "stem-tremolo.hh"
31 #include "stem.hh"
32 #include "stream-event.hh"
33 #include "warn.hh"
35 #include "translator.icc"
37 /**
39 This acknowledges repeated music with "tremolo" style. It typesets
40 a beam.
42 TODO:
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);
54 protected:
55 Stream_event *repeat_;
57 // current direction of beam (first RIGHT, then LEFT)
58 Direction beam_dir_;
60 Spanner *beam_;
62 protected:
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 ()
71 beam_ = 0;
72 repeat_ = 0;
73 beam_dir_ = CENTER;
76 IMPLEMENT_TRANSLATOR_LISTENER (Chord_tremolo_engraver, tremolo_span);
77 void
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 if (ASSIGN_EVENT_ONCE (repeat_, ev))
85 beam_dir_ = RIGHT;
88 else if (span_dir == STOP)
90 if (!repeat_)
91 ev->origin ()->warning (_ ("No tremolo to end"));
92 repeat_ = 0;
93 beam_ = 0;
94 beam_dir_ = CENTER;
98 void
99 Chord_tremolo_engraver::process_music ()
101 if (repeat_ && !beam_)
103 beam_ = make_spanner ("Beam", repeat_->self_scm ());
107 void
108 Chord_tremolo_engraver::finalize ()
110 if (beam_)
112 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
113 announce_end_grob (beam_, SCM_EOL);
114 beam_->suicide ();
118 void
119 Chord_tremolo_engraver::acknowledge_stem (Grob_info info)
121 if (beam_)
123 int tremolo_type = robust_scm2int (repeat_->get_property ("tremolo-type"), 1);
124 int flags = max (0, intlog2 (tremolo_type) - 2);
125 int repeat_count = robust_scm2int (repeat_->get_property ("repeat-count"), 1);
126 int gap_count = min (flags, intlog2 (repeat_count) + 1);
128 Grob *s = info.grob ();
129 Stem::set_beaming (s, flags, beam_dir_);
131 if (Stem::duration_log (s) != 1)
132 beam_->set_property ("gap-count", scm_from_int (gap_count));
134 if (beam_dir_ == RIGHT)
136 beam_dir_ = LEFT;
137 announce_end_grob (beam_, s->self_scm ());
140 if (info.ultimate_event_cause ()->in_event_class ("rhythmic-event"))
141 Beam::add_stem (beam_, s);
142 else
144 string s = _ ("stem must have Rhythmic structure");
145 if (info.event_cause ())
146 info.event_cause ()->origin ()->warning (s);
147 else
148 ::warning (s);
153 ADD_ACKNOWLEDGER (Chord_tremolo_engraver, stem);
154 ADD_TRANSLATOR (Chord_tremolo_engraver,
155 /* doc */
156 "Generate beams for tremolo repeats.",
158 /* create */
159 "Beam ",
161 /* read */
164 /* write */