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/>.
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_
;
57 // current direction of beam (first RIGHT, then LEFT)
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 if (ASSIGN_EVENT_ONCE (repeat_
, ev
))
88 else if (span_dir
== STOP
)
91 ev
->origin ()->warning (_ ("No tremolo to end"));
99 Chord_tremolo_engraver::process_music ()
101 if (repeat_
&& !beam_
)
103 beam_
= make_spanner ("Beam", repeat_
->self_scm ());
108 Chord_tremolo_engraver::finalize ()
112 repeat_
->origin ()->warning (_ ("unterminated chord tremolo"));
113 announce_end_grob (beam_
, SCM_EOL
);
119 Chord_tremolo_engraver::acknowledge_stem (Grob_info info
)
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
)
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
);
144 string s
= _ ("stem must have Rhythmic structure");
145 if (info
.event_cause ())
146 info
.event_cause ()->origin ()->warning (s
);
153 ADD_ACKNOWLEDGER (Chord_tremolo_engraver
, stem
);
154 ADD_TRANSLATOR (Chord_tremolo_engraver
,
156 "Generate beams for tremolo repeats.",