Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / lily / chord-tremolo-engraver.cc
blob140ab102373d266347d8775914e0c4382ccdaea4
1 /*
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>
8 */
10 #include "beam.hh"
11 #include "engraver-group.hh"
12 #include "international.hh"
13 #include "item.hh"
14 #include "math.h" // ceil
15 #include "misc.hh"
16 #include "repeated-music.hh"
17 #include "rhythmic-head.hh"
18 #include "spanner.hh"
19 #include "stem-tremolo.hh"
20 #include "stem.hh"
21 #include "stream-event.hh"
22 #include "warn.hh"
24 #include "translator.icc"
26 /**
28 This acknowledges repeated music with "tremolo" style. It typesets
29 a beam.
31 TODO:
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);
43 protected:
44 Stream_event *repeat_;
46 int flags_;
47 // number of beams for short tremolos
48 int expected_beam_count_;
49 // current direction of beam (first RIGHT, then LEFT)
50 Direction beam_dir_;
52 Spanner *beam_;
53 protected:
54 virtual void finalize ();
55 void process_music ();
56 DECLARE_TRANSLATOR_LISTENER (tremolo_span);
57 DECLARE_ACKNOWLEDGER (stem);
60 Chord_tremolo_engraver::Chord_tremolo_engraver ()
62 beam_ = 0;
63 repeat_ = 0;
64 flags_ = 0;
65 expected_beam_count_ = 0;
66 beam_dir_ = CENTER;
69 IMPLEMENT_TRANSLATOR_LISTENER (Chord_tremolo_engraver, tremolo_span);
70 void
71 Chord_tremolo_engraver::listen_tremolo_span (Stream_event *ev)
73 Direction span_dir = to_dir (ev->get_property ("span-direction"));
74 if (span_dir == START)
76 if (ASSIGN_EVENT_ONCE (repeat_, ev))
78 int type = scm_to_int (ev->get_property ("tremolo-type"));
79 /* e.g. 1 for type 8, 2 for type 16 */
80 flags_ = intlog2 (type) - 2;
81 expected_beam_count_ = scm_to_int (ev->get_property ("expected-beam-count"));
82 beam_dir_ = RIGHT;
85 else if (span_dir == STOP)
87 if (!repeat_)
88 ev->origin ()->warning (_ ("No tremolo to end"));
89 repeat_ = 0;
90 beam_ = 0;
91 expected_beam_count_ = 0;
92 beam_dir_ = CENTER;
96 void
97 Chord_tremolo_engraver::process_music ()
99 if (repeat_ && !beam_)
101 beam_ = make_spanner ("Beam", repeat_->self_scm ());
105 void
106 Chord_tremolo_engraver::finalize ()
108 if (beam_)
110 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
111 announce_end_grob (beam_, SCM_EOL);
112 beam_->suicide ();
116 void
117 Chord_tremolo_engraver::acknowledge_stem (Grob_info info)
119 if (beam_)
121 Grob *s = info.grob ();
123 Stem::set_beaming (s, flags_, beam_dir_);
125 if (Stem::duration_log (s) != 1)
126 beam_->set_property ("gap-count", scm_from_int (flags_ - expected_beam_count_));
128 if (beam_dir_ == RIGHT)
130 beam_dir_ = LEFT;
131 announce_end_grob (beam_, s->self_scm ());
134 if (info.ultimate_event_cause ()->in_event_class ("rhythmic-event"))
135 Beam::add_stem (beam_, s);
136 else
138 string s = _ ("stem must have Rhythmic structure");
139 if (info.event_cause ())
140 info.event_cause ()->origin ()->warning (s);
141 else
142 ::warning (s);
147 ADD_ACKNOWLEDGER (Chord_tremolo_engraver, stem);
148 ADD_TRANSLATOR (Chord_tremolo_engraver,
149 /* doc */
150 "Generate beams for tremolo repeats.",
152 /* create */
153 "Beam ",
155 /* read */
158 /* write */