2 chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Erik Sandberg <mandolaerik@gmail.com>
11 #include "engraver-group.hh"
12 #include "international.hh"
14 #include "math.h" // ceil
16 #include "repeated-music.hh"
17 #include "rhythmic-head.hh"
19 #include "stem-tremolo.hh"
21 #include "stream-event.hh"
24 #include "translator.icc"
28 This acknowledges repeated music with "tremolo" style. It typesets
33 - perhaps use engraver this to steer other engravers? That would
34 create dependencies between engravers, which is bad.
36 - create dots if appropriate.
38 - create TremoloBeam iso Beam?
40 class Chord_tremolo_engraver
: public Engraver
42 TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver
);
44 Stream_event
*repeat_
;
46 // current direction of beam (first RIGHT, then LEFT)
52 virtual void finalize ();
53 void process_music ();
54 DECLARE_TRANSLATOR_LISTENER (tremolo_span
);
55 DECLARE_ACKNOWLEDGER (stem
);
58 Chord_tremolo_engraver::Chord_tremolo_engraver ()
65 IMPLEMENT_TRANSLATOR_LISTENER (Chord_tremolo_engraver
, tremolo_span
);
67 Chord_tremolo_engraver::listen_tremolo_span (Stream_event
*ev
)
69 Direction span_dir
= to_dir (ev
->get_property ("span-direction"));
70 if (span_dir
== START
)
72 if (ASSIGN_EVENT_ONCE (repeat_
, ev
))
77 else if (span_dir
== STOP
)
80 ev
->origin ()->warning (_ ("No tremolo to end"));
88 Chord_tremolo_engraver::process_music ()
90 if (repeat_
&& !beam_
)
92 beam_
= make_spanner ("Beam", repeat_
->self_scm ());
97 Chord_tremolo_engraver::finalize ()
101 repeat_
->origin ()->warning (_ ("unterminated chord tremolo"));
102 announce_end_grob (beam_
, SCM_EOL
);
108 Chord_tremolo_engraver::acknowledge_stem (Grob_info info
)
112 int tremolo_type
= robust_scm2int (repeat_
->get_property ("tremolo-type"), 1);
113 int flags
= max (0, intlog2 (tremolo_type
) - 2);
114 int repeat_count
= robust_scm2int (repeat_
->get_property ("repeat-count"), 1);
115 int gap_count
= min (flags
, intlog2 (repeat_count
) + 1);
117 Grob
*s
= info
.grob ();
118 Stem::set_beaming (s
, flags
, beam_dir_
);
120 if (Stem::duration_log (s
) != 1)
121 beam_
->set_property ("gap-count", scm_from_int (gap_count
));
123 if (beam_dir_
== RIGHT
)
126 announce_end_grob (beam_
, s
->self_scm ());
129 if (info
.ultimate_event_cause ()->in_event_class ("rhythmic-event"))
130 Beam::add_stem (beam_
, s
);
133 string s
= _ ("stem must have Rhythmic structure");
134 if (info
.event_cause ())
135 info
.event_cause ()->origin ()->warning (s
);
142 ADD_ACKNOWLEDGER (Chord_tremolo_engraver
, stem
);
143 ADD_TRANSLATOR (Chord_tremolo_engraver
,
145 "Generate beams for tremolo repeats.",