property-init.ly: Organize, cleanup.
[lilypond/mpolesky.git] / lily / chord-tremolo-engraver.cc
blob28790b5a868019d928deada7a9d305f50d5d55eb
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 // current direction of beam (first RIGHT, then LEFT)
47 Direction beam_dir_;
49 Spanner *beam_;
51 protected:
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 ()
60 beam_ = 0;
61 repeat_ = 0;
62 beam_dir_ = CENTER;
65 IMPLEMENT_TRANSLATOR_LISTENER (Chord_tremolo_engraver, tremolo_span);
66 void
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))
74 beam_dir_ = RIGHT;
77 else if (span_dir == STOP)
79 if (!repeat_)
80 ev->origin ()->warning (_ ("No tremolo to end"));
81 repeat_ = 0;
82 beam_ = 0;
83 beam_dir_ = CENTER;
87 void
88 Chord_tremolo_engraver::process_music ()
90 if (repeat_ && !beam_)
92 beam_ = make_spanner ("Beam", repeat_->self_scm ());
96 void
97 Chord_tremolo_engraver::finalize ()
99 if (beam_)
101 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
102 announce_end_grob (beam_, SCM_EOL);
103 beam_->suicide ();
107 void
108 Chord_tremolo_engraver::acknowledge_stem (Grob_info info)
110 if (beam_)
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)
125 beam_dir_ = LEFT;
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);
131 else
133 string s = _ ("stem must have Rhythmic structure");
134 if (info.event_cause ())
135 info.event_cause ()->origin ()->warning (s);
136 else
137 ::warning (s);
142 ADD_ACKNOWLEDGER (Chord_tremolo_engraver, stem);
143 ADD_TRANSLATOR (Chord_tremolo_engraver,
144 /* doc */
145 "Generate beams for tremolo repeats.",
147 /* create */
148 "Beam ",
150 /* read */
153 /* write */